2013-10-22 36 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 ';' –