2013-10-22 34 views
5

我正在创建我的第一个Yeoman发电机。我想下载一个包含CMS的外部zip文件,并将其解压缩到根目录中。根据this thread这应该是可能的。这尚未实施吗?如果不是我需要复制到我的发电机,我需要什么?与yeoman发电机下载zip

我运行了发电机发电机,并获得了我的基本发电机。这是我的代码到目前为止。

Generator.prototype.getVersion = function getVersion() { 
    var cb = this.async() 
    , self = this 

    this.log.writeln('Downloading Umbraco version 6.1.6') 
    this.download('http://our.umbraco.org/ReleaseDownload?id=92348', '.'); 
} 

这会产生一个错误,告诉我它“无法找到模块'下载'”。什么是正确的语法?

+0

嗨。你介意接受我的回答吗?谢谢。 –

回答

6

我为你做了一些调查。

There are two methods to download something with yeoman...

/** 
* Download a string or an array of files to a given destination. 
* 
* @param {String|Array} url 
* @param {String} destination 
* @param {Function} cb 
*/ 

this.fetch(url, destination, cb) 

/** 
* Fetch a string or an array of archives and extract it/them to a given 
* destination. 
* 
* @param {String|Array} archive 
* @param {String} destination 
* @param {Function} cb 
*/ 

this.extract(archive, destination, cb) 

回调,如果出了问题会传递一个错误。

There's also a method to download packages from Github.

/** 
* Remotely fetch a package from github (or an archive), store this into a _cache 
* folder, and provide a "remote" object as a facade API to ourself (part of 
* generator API, copy, template, directory). It's possible to remove local cache, 
* and force a new remote fetch of the package. 
* 
* ### Examples: 
* 
*  this.remote('user', 'repo', function(err, remote) { 
*  remote.copy('.', 'vendors/user-repo'); 
*  }); 
* 
*  this.remote('user', 'repo', 'branch', function(err, remote) { 
*  remote.copy('.', 'vendors/user-repo'); 
*  }); 
* 
*  this.remote('http://foo.com/bar.zip', function(err, remote) { 
*  remote.copy('.', 'vendors/user-repo'); 
*  }); 
* 
* When fetching from Github 
* @param {String} username 
* @param {String} repo 
* @param {String} branch 
* @param {Function} cb 
* @param {Boolean} refresh 
* 
* @also 
* When fetching an archive 
* @param {String} url 
* @param {Function} cb 
* @param {Boolean} refresh 
*/ 
+0

需要帮助! 'repo'和'vendors/user-repo'是什么意思? 'repo'是实际'repository'的整个'URL'路径吗? – Daggerhunt

+0

@Daggerhunt:remote.copy的参数是'源'和'目标'路径(本地),所以应该只是将目标更改为您希望文件最终到达的位置。 'repo'应该只是存储库名称,用于构建url:url ='https://github.com/'+ [username,repo,'archive',branch] .join('/')+ ”名为.tar.gz ';' –