I tried two different approaches to creating a Yeoman generator, and both of them fail. Here, where I am now, but first with a few notes:
yo doctor passes all tests- I have fixed npm permissions by changing the default installation path as described here .
Attempt 1:
I installed the generator-generator module without errors, but execution yo generatorleads to the following error:
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)
I made an assumption and ran npm install -g download, but nothing can be fixed.
2
, Yeoman Authoring, , 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({
constructor: function () {
generators.Base.apply(this, arguments);
this.option('coffee');
},
promptUser: function() {
var done = this.async();
console.log(this.yeoman);
var prompts = [{
name: 'appName',
message: 'What is your app\ 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;
. !