yeoman-generator 3.1.1 → 3.2.0

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.
package/lib/index.js CHANGED
@@ -486,29 +486,42 @@ class Generator extends EventEmitter {
486
486
  _.invokeMap(this._composedWith, 'run');
487
487
  });
488
488
 
489
- promise.then(cb, cb);
489
+ // Maintain backward compatibility with the callback function
490
+ if (_.isFunction(cb)) {
491
+ promise.then(cb, cb);
492
+ }
493
+
490
494
  return promise;
491
495
  }
492
496
 
493
497
  /**
494
498
  * Compose this generator with another one.
495
- * @param {String} namespace The generator namespace to compose with
499
+ * @param {String|Object} generator The path to the generator module or an object (see examples)
496
500
  * @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}
501
+ * @return {this} This generator
503
502
  *
504
503
  * @example <caption>Using a peerDependency generator</caption>
505
504
  * this.composeWith('bootstrap', { sass: true });
506
505
  *
507
506
  * @example <caption>Using a direct dependency generator</caption>
508
507
  * this.composeWith(require.resolve('generator-bootstrap/app/main.js'), { sass: true });
508
+ *
509
+ * @example <caption>Passing a Generator class</caption>
510
+ * this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });
509
511
  */
510
- composeWith(modulePath, options) {
511
- let generator;
512
+ composeWith(generator, options) {
513
+ let instantiatedGenerator;
514
+
515
+ const instantiate = (Generator, path) => {
516
+ Generator.resolved = require.resolve(path);
517
+ Generator.namespace = this.env.namespace(path);
518
+
519
+ return this.env.instantiate(Generator, {
520
+ options,
521
+ arguments: options.arguments
522
+ });
523
+ };
524
+
512
525
  options = options || {};
513
526
 
514
527
  // Pass down the default options so they're correctly mirrored down the chain.
@@ -524,29 +537,54 @@ class Generator extends EventEmitter {
524
537
  options
525
538
  );
526
539
 
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;
540
+ if (typeof generator === 'string') {
541
+ try {
542
+ const Generator = require(generator); // eslint-disable-line import/no-dynamic-require
543
+ instantiatedGenerator = instantiate(Generator, generator);
544
+ } catch (err) {
545
+ if (err.code === 'MODULE_NOT_FOUND') {
546
+ instantiatedGenerator = this.env.create(generator, {
547
+ options,
548
+ arguments: options.arguments
549
+ });
550
+ } else {
551
+ throw err;
552
+ }
543
553
  }
554
+ } else {
555
+ assert(
556
+ generator.Generator,
557
+ `${chalk.red('Missing Generator property')}\n` +
558
+ `When passing an object to Generator${chalk.cyan(
559
+ '#composeWith'
560
+ )} include the generator class to run in the ${chalk.cyan(
561
+ 'Generator'
562
+ )} property\n\n` +
563
+ `this.composeWith({\n` +
564
+ ` ${chalk.yellow('Generator')}: MyGenerator,\n` +
565
+ ` ...\n` +
566
+ `});`
567
+ );
568
+ assert(
569
+ typeof generator.path === 'string',
570
+ `${chalk.red('path property is not a string')}\n` +
571
+ `When passing an object to Generator${chalk.cyan(
572
+ '#composeWith'
573
+ )} include the path to the generators files in the ${chalk.cyan(
574
+ 'path'
575
+ )} property\n\n` +
576
+ `this.composeWith({\n` +
577
+ ` ${chalk.yellow('path')}: '../my-generator',\n` +
578
+ ` ...\n` +
579
+ `});`
580
+ );
581
+ instantiatedGenerator = instantiate(generator.Generator, generator.path);
544
582
  }
545
583
 
546
584
  if (this._running) {
547
- generator.run();
585
+ instantiatedGenerator.run();
548
586
  } else {
549
- this._composedWith.push(generator);
587
+ this._composedWith.push(instantiatedGenerator);
550
588
  }
551
589
 
552
590
  return this;
@@ -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.1",
3
+ "version": "3.2.0",
4
4
  "description": "Rails-inspired generator system that provides scaffolding for your apps",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -23,21 +23,21 @@
23
23
  ],
24
24
  "devDependencies": {
25
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",
26
+ "eslint": "^5.10.0",
27
+ "eslint-config-prettier": "^3.3.0",
28
+ "eslint-config-xo": "^0.25.1",
29
+ "eslint-plugin-prettier": "^3.0.0",
30
+ "husky": "^1.2.1",
31
31
  "inquirer": "^6.0.0",
32
32
  "jsdoc": "^3.5.5",
33
- "lint-staged": "^7.2.0",
33
+ "lint-staged": "^8.1.0",
34
34
  "mocha": "^5.1.1",
35
35
  "mockery": "^2.1.0",
36
- "nock": "^9.1.6",
37
- "nyc": "^12.0.2",
38
- "prettier": "^1.7.0",
36
+ "nock": "^10.0.4",
37
+ "nyc": "^13.1.0",
38
+ "prettier": "^1.15.3",
39
39
  "proxyquire": "^2.0.1",
40
- "sinon": "^6.0.1",
40
+ "sinon": "^7.2.2",
41
41
  "tui-jsdoc-template": "^1.2.2",
42
42
  "yeoman-assert": "^3.1.1",
43
43
  "yeoman-test": "^1.8.0"
@@ -61,7 +61,7 @@
61
61
  "cross-spawn": "^6.0.5",
62
62
  "dargs": "^6.0.0",
63
63
  "dateformat": "^3.0.3",
64
- "debug": "^3.1.0",
64
+ "debug": "^4.1.0",
65
65
  "detect-conflict": "^1.0.0",
66
66
  "error": "^7.0.2",
67
67
  "find-up": "^3.0.0",
@@ -72,13 +72,13 @@
72
72
  "mem-fs-editor": "^5.0.0",
73
73
  "minimist": "^1.2.0",
74
74
  "pretty-bytes": "^5.1.0",
75
- "read-chunk": "^2.1.0",
75
+ "read-chunk": "^3.0.0",
76
76
  "read-pkg-up": "^4.0.0",
77
77
  "rimraf": "^2.6.2",
78
78
  "run-async": "^2.0.0",
79
79
  "shelljs": "^0.8.0",
80
80
  "text-table": "^0.2.0",
81
- "through2": "^2.0.0",
81
+ "through2": "^3.0.0",
82
82
  "yeoman-environment": "^2.0.5"
83
83
  },
84
84
  "lint-staged": {