yeoman-generator 3.1.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ install.scheduleInstallTask = function(installer, paths, options, spawnOptions)
41
41
  }
42
42
 
43
43
  // Return early if we're skipping installation
44
- if (this.options.skipInstall) {
44
+ if (this.options.skipInstall || this.options['skip-install']) {
45
45
  this.log(
46
46
  'Skipping install command: ' + chalk.yellow(installer + ' ' + args.join(' '))
47
47
  );
@@ -66,24 +66,29 @@ install.scheduleInstallTask = function(installer, paths, options, spawnOptions)
66
66
  ' is already installed, try running the following command manually: ' +
67
67
  chalk.yellow(installer + ' ' + args.join(' '))
68
68
  );
69
- if (this.options.forceInstall) {
69
+ if (this.options.forceInstall || this.options['force-install']) {
70
70
  this.emit('error', error);
71
71
  }
72
+
72
73
  done();
73
74
  })
74
75
  .on('exit', (code, signal) => {
75
76
  this.emit(`${installer}Install:end`, paths);
76
- if ((code || signal) && this.options.forceInstall) {
77
+ if (
78
+ (code || signal) &&
79
+ (this.options.forceInstall || this.options['force-install'])
80
+ ) {
77
81
  this.emit(
78
82
  'error',
79
83
  new Error(`Installation of ${installer} failed with code ${code || signal}`)
80
84
  );
81
85
  }
86
+
82
87
  done();
83
88
  });
84
89
  },
85
90
  {
86
- once: installer + ' ' + args.join(' '),
91
+ once: installer + ' ' + args.join(' ') + ' ' + JSON.stringify(spawnOptions),
87
92
  run: false
88
93
  }
89
94
  );
package/lib/index.js CHANGED
@@ -167,7 +167,7 @@ class Generator extends EventEmitter {
167
167
  questions = promptSuggestion.prefillQuestions(this.config, questions);
168
168
 
169
169
  return this.env.adapter.prompt(questions).then(answers => {
170
- if (!this.options['skip-cache']) {
170
+ if (!this.options['skip-cache'] && !this.options.skipCache) {
171
171
  promptSuggestion.storeAnswers(this._globalConfig, questions, answers, false);
172
172
  promptSuggestion.storeAnswers(this.config, questions, answers, true);
173
173
  }
@@ -199,6 +199,7 @@ class Generator extends EventEmitter {
199
199
  if ('defaults' in config) {
200
200
  config.default = config.defaults;
201
201
  }
202
+
202
203
  config.description = config.description || config.desc;
203
204
 
204
205
  _.defaults(config, {
@@ -261,6 +262,7 @@ class Generator extends EventEmitter {
261
262
  if ('defaults' in config) {
262
263
  config.default = config.defaults;
263
264
  }
265
+
264
266
  config.description = config.description || config.desc;
265
267
 
266
268
  _.defaults(config, {
@@ -317,6 +319,7 @@ class Generator extends EventEmitter {
317
319
  parsedOpts[name] = undefined;
318
320
  return;
319
321
  }
322
+
320
323
  if (this._options[name] && option !== undefined) {
321
324
  parsedOpts[name] = this._options[name].type(option);
322
325
  }
@@ -486,67 +489,105 @@ class Generator extends EventEmitter {
486
489
  _.invokeMap(this._composedWith, 'run');
487
490
  });
488
491
 
489
- promise.then(cb, cb);
492
+ // Maintain backward compatibility with the callback function
493
+ if (_.isFunction(cb)) {
494
+ promise.then(cb, cb);
495
+ }
496
+
490
497
  return promise;
491
498
  }
492
499
 
493
500
  /**
494
501
  * Compose this generator with another one.
495
- * @param {String} namespace The generator namespace to compose with
502
+ * @param {String|Object} generator The path to the generator module or an object (see examples)
496
503
  * @param {Object} options The options passed to the Generator
497
- * @param {Object} [settings] Settings hash on the composition relation
498
- * @param {string} [settings.local] Path to a locally stored generator
499
- * @param {String} [settings.link="weak"] If "strong", the composition will occured
500
- * even when the composition is initialized by
501
- * the end user
502
- * @return {this}
504
+ * @return {this} This generator
503
505
  *
504
506
  * @example <caption>Using a peerDependency generator</caption>
505
507
  * this.composeWith('bootstrap', { sass: true });
506
508
  *
507
509
  * @example <caption>Using a direct dependency generator</caption>
508
510
  * this.composeWith(require.resolve('generator-bootstrap/app/main.js'), { sass: true });
511
+ *
512
+ * @example <caption>Passing a Generator class</caption>
513
+ * this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });
509
514
  */
510
- composeWith(modulePath, options) {
511
- let generator;
515
+ composeWith(generator, options) {
516
+ let instantiatedGenerator;
517
+
518
+ const instantiate = (Generator, path) => {
519
+ Generator.resolved = require.resolve(path);
520
+ Generator.namespace = this.env.namespace(path);
521
+
522
+ return this.env.instantiate(Generator, {
523
+ options,
524
+ arguments: options.arguments
525
+ });
526
+ };
527
+
512
528
  options = options || {};
513
529
 
514
530
  // Pass down the default options so they're correctly mirrored down the chain.
515
531
  options = _.extend(
516
532
  {
517
- skipInstall: this.options.skipInstall,
518
- 'skip-install': this.options.skipInstall,
519
- skipCache: this.options.skipCache,
520
- 'skip-cache': this.options.skipCache,
521
- forceInstall: this.options.forceInstall,
522
- 'force-install': this.options.forceInstall
533
+ skipInstall: this.options.skipInstall || this.options['skip-install'],
534
+ 'skip-install': this.options.skipInstall || this.options['skip-install'],
535
+ skipCache: this.options.skipCache || this.options['skip-cache'],
536
+ 'skip-cache': this.options.skipCache || this.options['skip-cache'],
537
+ forceInstall: this.options.forceInstall || this.options['force-install'],
538
+ 'force-install': this.options.forceInstall || this.options['force-install']
523
539
  },
524
540
  options
525
541
  );
526
542
 
527
- try {
528
- const Generator = require(modulePath); // eslint-disable-line import/no-dynamic-require
529
- Generator.resolved = require.resolve(modulePath);
530
- Generator.namespace = this.env.namespace(modulePath);
531
- generator = this.env.instantiate(Generator, {
532
- options,
533
- arguments: options.arguments
534
- });
535
- } catch (err) {
536
- if (err.code === 'MODULE_NOT_FOUND') {
537
- generator = this.env.create(modulePath, {
538
- options,
539
- arguments: options.arguments
540
- });
541
- } else {
542
- throw err;
543
+ if (typeof generator === 'string') {
544
+ try {
545
+ const Generator = require(generator); // eslint-disable-line import/no-dynamic-require
546
+ instantiatedGenerator = instantiate(Generator, generator);
547
+ } catch (err) {
548
+ if (err.code === 'MODULE_NOT_FOUND') {
549
+ instantiatedGenerator = this.env.create(generator, {
550
+ options,
551
+ arguments: options.arguments
552
+ });
553
+ } else {
554
+ throw err;
555
+ }
543
556
  }
557
+ } else {
558
+ assert(
559
+ generator.Generator,
560
+ `${chalk.red('Missing Generator property')}\n` +
561
+ `When passing an object to Generator${chalk.cyan(
562
+ '#composeWith'
563
+ )} include the generator class to run in the ${chalk.cyan(
564
+ 'Generator'
565
+ )} property\n\n` +
566
+ `this.composeWith({\n` +
567
+ ` ${chalk.yellow('Generator')}: MyGenerator,\n` +
568
+ ` ...\n` +
569
+ `});`
570
+ );
571
+ assert(
572
+ typeof generator.path === 'string',
573
+ `${chalk.red('path property is not a string')}\n` +
574
+ `When passing an object to Generator${chalk.cyan(
575
+ '#composeWith'
576
+ )} include the path to the generators files in the ${chalk.cyan(
577
+ 'path'
578
+ )} property\n\n` +
579
+ `this.composeWith({\n` +
580
+ ` ${chalk.yellow('path')}: '../my-generator',\n` +
581
+ ` ...\n` +
582
+ `});`
583
+ );
584
+ instantiatedGenerator = instantiate(generator.Generator, generator.path);
544
585
  }
545
586
 
546
587
  if (this._running) {
547
- generator.run();
588
+ instantiatedGenerator.run();
548
589
  } else {
549
- this._composedWith.push(generator);
590
+ this._composedWith.push(instantiatedGenerator);
550
591
  }
551
592
 
552
593
  return this;
@@ -696,6 +737,7 @@ class Generator extends EventEmitter {
696
737
  if (!Array.isArray(streams)) {
697
738
  streams = [streams];
698
739
  }
740
+
699
741
  this._transformStreams = this._transformStreams.concat(streams);
700
742
  return this;
701
743
  }
@@ -36,8 +36,8 @@ const getCheckboxDefault = (question, defaultValue) => {
36
36
  * @private
37
37
  */
38
38
  const getListDefault = (question, defaultValue) => {
39
- const choiceValues = question.choices.map(
40
- choice => (typeof choice === 'object' ? choice.value : choice)
39
+ const choiceValues = question.choices.map(choice =>
40
+ typeof choice === 'object' ? choice.value : choice
41
41
  );
42
42
  return choiceValues.indexOf(defaultValue);
43
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-generator",
3
- "version": "3.1.0",
3
+ "version": "4.0.1",
4
4
  "description": "Rails-inspired generator system that provides scaffolding for your apps",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -22,25 +22,25 @@
22
22
  "app"
23
23
  ],
24
24
  "devDependencies": {
25
- "coveralls": "^3.0.2",
26
- "eslint": "^5.0.1",
27
- "eslint-config-prettier": "^2.4.0",
28
- "eslint-config-xo": "^0.23.0",
29
- "eslint-plugin-prettier": "^2.2.0",
30
- "husky": "^0.14.3",
31
- "inquirer": "^6.0.0",
32
- "jsdoc": "^3.5.5",
33
- "lint-staged": "^7.2.0",
34
- "mocha": "^5.1.1",
25
+ "coveralls": "^3.0.3",
26
+ "eslint": "^5.16.0",
27
+ "eslint-config-prettier": "^4.3.0",
28
+ "eslint-config-xo": "^0.26.0",
29
+ "eslint-plugin-prettier": "^3.1.0",
30
+ "husky": "^2.3.0",
31
+ "inquirer": "^6.3.1",
32
+ "jsdoc": "^3.6.2",
33
+ "lint-staged": "^8.1.7",
34
+ "mocha": "^6.1.4",
35
35
  "mockery": "^2.1.0",
36
- "nock": "^9.1.6",
37
- "nyc": "^12.0.2",
38
- "prettier": "^1.7.0",
39
- "proxyquire": "^2.0.1",
40
- "sinon": "^6.0.1",
36
+ "nock": "^10.0.6",
37
+ "nyc": "^14.1.1",
38
+ "prettier": "^1.17.1",
39
+ "proxyquire": "^2.1.0",
40
+ "sinon": "^7.3.2",
41
41
  "tui-jsdoc-template": "^1.2.2",
42
42
  "yeoman-assert": "^3.1.1",
43
- "yeoman-test": "^1.8.0"
43
+ "yeoman-test": "^1.9.1"
44
44
  },
45
45
  "license": "BSD-2-Clause",
46
46
  "repository": "yeoman/generator",
@@ -51,35 +51,34 @@
51
51
  "pretest": "eslint .",
52
52
  "test": "nyc mocha",
53
53
  "doc": "jsdoc -c jsdoc.json",
54
- "coverage": "nyc report --reporter=text-lcov | coveralls",
55
- "precommit": "lint-staged"
54
+ "coverage": "nyc report --reporter=text-lcov | coveralls"
56
55
  },
57
56
  "dependencies": {
58
- "async": "^2.6.0",
59
- "chalk": "^2.3.0",
57
+ "async": "^2.6.2",
58
+ "chalk": "^2.4.2",
60
59
  "cli-table": "^0.3.1",
61
60
  "cross-spawn": "^6.0.5",
62
- "dargs": "^6.0.0",
61
+ "dargs": "^6.1.0",
63
62
  "dateformat": "^3.0.3",
64
- "debug": "^3.1.0",
63
+ "debug": "^4.1.1",
65
64
  "detect-conflict": "^1.0.0",
66
65
  "error": "^7.0.2",
67
66
  "find-up": "^3.0.0",
68
- "github-username": "^4.0.0",
69
- "istextorbinary": "^2.2.1",
70
- "lodash": "^4.17.10",
71
- "make-dir": "^1.1.0",
72
- "mem-fs-editor": "^5.0.0",
67
+ "github-username": "^3.0.0",
68
+ "istextorbinary": "^2.5.1",
69
+ "lodash": "^4.17.11",
70
+ "make-dir": "^3.0.0",
71
+ "mem-fs-editor": "^6.0.0",
73
72
  "minimist": "^1.2.0",
74
- "pretty-bytes": "^5.1.0",
75
- "read-chunk": "^2.1.0",
76
- "read-pkg-up": "^4.0.0",
77
- "rimraf": "^2.6.2",
73
+ "pretty-bytes": "^5.2.0",
74
+ "read-chunk": "^3.2.0",
75
+ "read-pkg-up": "^5.0.0",
76
+ "rimraf": "^2.6.3",
78
77
  "run-async": "^2.0.0",
79
- "shelljs": "^0.8.0",
78
+ "shelljs": "^0.8.3",
80
79
  "text-table": "^0.2.0",
81
- "through2": "^2.0.0",
82
- "yeoman-environment": "^2.0.5"
80
+ "through2": "^3.0.1",
81
+ "yeoman-environment": "^2.3.4"
83
82
  },
84
83
  "lint-staged": {
85
84
  "*.js": [
@@ -112,5 +111,10 @@
112
111
  "plugins": [
113
112
  "prettier"
114
113
  ]
114
+ },
115
+ "husky": {
116
+ "hooks": {
117
+ "pre-commit": "lint-staged"
118
+ }
115
119
  }
116
120
  }