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 +66 -28
- package/lib/util/prompt-suggestion.js +2 -2
- package/package.json +14 -14
package/lib/index.js
CHANGED
|
@@ -486,29 +486,42 @@ class Generator extends EventEmitter {
|
|
|
486
486
|
_.invokeMap(this._composedWith, 'run');
|
|
487
487
|
});
|
|
488
488
|
|
|
489
|
-
|
|
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}
|
|
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
|
-
* @
|
|
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(
|
|
511
|
-
let
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
585
|
+
instantiatedGenerator.run();
|
|
548
586
|
} else {
|
|
549
|
-
this._composedWith.push(
|
|
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
|
-
|
|
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.
|
|
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
|
|
27
|
-
"eslint-config-prettier": "^
|
|
28
|
-
"eslint-config-xo": "^0.
|
|
29
|
-
"eslint-plugin-prettier": "^
|
|
30
|
-
"husky": "^
|
|
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": "^
|
|
33
|
+
"lint-staged": "^8.1.0",
|
|
34
34
|
"mocha": "^5.1.1",
|
|
35
35
|
"mockery": "^2.1.0",
|
|
36
|
-
"nock": "^
|
|
37
|
-
"nyc": "^
|
|
38
|
-
"prettier": "^1.
|
|
36
|
+
"nock": "^10.0.4",
|
|
37
|
+
"nyc": "^13.1.0",
|
|
38
|
+
"prettier": "^1.15.3",
|
|
39
39
|
"proxyquire": "^2.0.1",
|
|
40
|
-
"sinon": "^
|
|
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": "^
|
|
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": "^
|
|
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": "^
|
|
81
|
+
"through2": "^3.0.0",
|
|
82
82
|
"yeoman-environment": "^2.0.5"
|
|
83
83
|
},
|
|
84
84
|
"lint-staged": {
|