我尝试了两种不同的方法来创建Yeoman生成器,两者都失败了。这是我目前所处的位置,但首先是几个笔记:
yo doctor
通过了所有测试尝试1:我安装了发电机 - 发电机模块没有错误,但执行yo generator
会导致以下错误:
module.js:328
throw err;
^
Error: Cannot find module 'download'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/generator-generator/node_modules/yeoman-generator/lib/actions/fetch.js:3:16)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
我猜了一下并跑了npm install -g download
,但这并没有解决任何问题。
尝试2我按照Yeoman's Authoring page上列出的步骤,但即使在npm link
导致我的新生成器的有效路径后,yo boilerplate
只是导致生成器未安装错误。生成器文件结构如下:
generator-boilerplate
app
index.js
.yo-rc.json
package.json
package.json的内容是:
{
"name": "generator-boilerplate",
"version": "0.1.0",
"description": "A Yeoman generator for a standard front-end project",
"files": [
"app"
],
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"yeoman-generator",
"boilerplate"
],
"author": "<my name>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"yeoman-generator": "^0.22.3"
}
}
app / index.js的内容是(只是为了让某些东西起作用):
'use strict';
var util = require('util');
var path = require('path');
var generators = require('yeoman-generator');
var chalk = require('chalk');
var Boilerplate = generators.Base.extend({
// The name `constructor` is important here
constructor: function () {
// Calling the super constructor is important so our generator is correctly set up
generators.Base.apply(this, arguments);
// Next, add your custom code
this.option('coffee'); // This method adds support for a `--coffee` flag
},
promptUser: function() {
var done = this.async();
// have Yeoman greet the user
console.log(this.yeoman);
var prompts = [{
name: 'appName',
message: 'What is your app\'s name ?'
},{
type: 'confirm',
name: 'addDemoSection',
message: 'Would you like to generate a demo section ?',
default: true
}];
this.prompt(prompts, function (props) {
this.appName = props.appName;
this.addDemoSection = props.addDemoSection;
done();
}.bind(this));
}
});
module.exports = Boilerplate;
任何帮助将不胜感激。谢谢!
错误1:不幸的是,这是一个npm错误。您应该将npm更新到最新版本,卸载并重新安装。这些错误发生在npm 2和3之间。
错误2:确保你在最新的哟。然后你可以运行DEBUG=* yo boilerplate
,这将让你更深入地了解Yeoman搜索寄存器的位置以及为什么它没有找到你的链接本地生成器。