node.js - 使用 yeoman 生成器下载 zip

标签 node.js yeoman yeoman-generator

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

我已经运行了生成器 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', '.');
}

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

最佳答案

我为你做了一点调查。

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

关于node.js - 使用 yeoman 生成器下载 zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19520511/

相关文章:

javascript - 创建 yeoman 生成器时无法要求/导入

ubuntu - dotnet restore 使用新的 csproj 文件出错,没有 project.json 文件

node.js - SQLite3 - 在一条语句中创建多个表

node.js - 连接池和 lambda 终止

node.js - 如何在Next Js中以表单数据发送文件?

javascript - 使用 RequireJS 时,我应该将脚本放在 Yeoman 项目的什么位置?

javascript - AngularJS http post 不适用于 Node 服务器

backbone.js - 人们如何使用 Yeoman?

intellij-idea - 无法使用yeoman生成器Gradle + Kotlin生成新项目

node.js - 安装生成器平均种子时出错