【问题标题】:Downloading zip with yeoman generator使用 yeoman 生成器下载 zip
【发布时间】:2013-10-22 14:21:42
【问题描述】:

我正在创建我的第一个 Yeoman 生成器。我想下载一个包含 CMS 的外部 zip 并将其解压缩到根目录中。根据this thread,这应该是可能的。这还没有实施吗?如果没有,我需要将什么复制到我的生成器?

我已经运行了 generator generator 并启动了我的基本生成器。这是我目前的代码。

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', '.');
}

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

【问题讨论】:

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

标签: node.js yeoman yeoman-generator


【解决方案1】:

我为你做了一点调查。

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
 */

【讨论】:

  • 需要帮助!! repovendors/user-repo 是什么意思? repo 是实际 repository 的整个 URL 路径吗?
  • @Daggerhunt:remote.copy 的参数是“源”和“目标”路径(本地),因此您只需将目标更改为您希望文件结束的位置。 'repo' 应该只是存储库名称,用于构造 url: url = 'github.com' + [username, repo, 'archive', branch].join('/') + '.tar.gz ';'
猜你喜欢
  • 1970-01-01
  • 2015-08-05
  • 2018-07-18
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-13
  • 1970-01-01
相关资源
最近更新 更多