yeoman-environment 3.4.0 → 3.6.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/environment.js +36 -17
- package/lib/spawn-command.js +2 -2
- package/package.json +1 -1
package/lib/environment.js
CHANGED
|
@@ -164,7 +164,7 @@ class Environment extends Base {
|
|
|
164
164
|
rootCommand.emit('yeoman:environment', command.env);
|
|
165
165
|
|
|
166
166
|
const generator = command.env.instantiate(GeneratorClass, this.args, this.opts());
|
|
167
|
-
command.env.queueGenerator(generator);
|
|
167
|
+
await command.env.queueGenerator(generator);
|
|
168
168
|
return command.env.start().then(() => command.env);
|
|
169
169
|
});
|
|
170
170
|
return command;
|
|
@@ -759,8 +759,16 @@ class Environment extends Base {
|
|
|
759
759
|
};
|
|
760
760
|
|
|
761
761
|
maybeGenerator = maybeGenerator || this.get(namespaceOrPath);
|
|
762
|
-
if (maybeGenerator && maybeGenerator.then) {
|
|
763
|
-
return
|
|
762
|
+
if (maybeGenerator && (maybeGenerator.then || maybeGenerator.prototype._postConstruct)) {
|
|
763
|
+
return Promise.resolve(maybeGenerator)
|
|
764
|
+
.then(Generator => checkGenerator(Generator))
|
|
765
|
+
.then(Generator => this.instantiate(Generator, args, options))
|
|
766
|
+
.then(async generator => {
|
|
767
|
+
if (!options.help && generator._postConstruct) {
|
|
768
|
+
await generator._postConstruct();
|
|
769
|
+
}
|
|
770
|
+
return generator;
|
|
771
|
+
});
|
|
764
772
|
}
|
|
765
773
|
|
|
766
774
|
return this.instantiate(checkGenerator(maybeGenerator), args, options);
|
|
@@ -812,14 +820,23 @@ class Environment extends Base {
|
|
|
812
820
|
* @param {String} namespaceOrPath
|
|
813
821
|
* @param {Array} [args]
|
|
814
822
|
* @param {Object} [options]
|
|
823
|
+
* @param {Boolean} [schedule]
|
|
815
824
|
* @return {Generator} The instantiated generator or the singleton instance.
|
|
816
825
|
*/
|
|
817
|
-
composeWith(generator, args, options) {
|
|
826
|
+
composeWith(generator, args, options, schedule = true) {
|
|
827
|
+
if (typeof args === 'boolean') {
|
|
828
|
+
schedule = args;
|
|
829
|
+
args = undefined;
|
|
830
|
+
options = undefined;
|
|
831
|
+
} else if (typeof options === 'boolean') {
|
|
832
|
+
schedule = options;
|
|
833
|
+
options = undefined;
|
|
834
|
+
}
|
|
818
835
|
const generatorInstance = this.create(generator, args, options);
|
|
819
836
|
if (generatorInstance.then) {
|
|
820
|
-
return generatorInstance.then(generatorInstance => this.queueGenerator(generatorInstance,
|
|
837
|
+
return generatorInstance.then(generatorInstance => this.queueGenerator(generatorInstance, schedule));
|
|
821
838
|
}
|
|
822
|
-
return this.queueGenerator(generatorInstance,
|
|
839
|
+
return this.queueGenerator(generatorInstance, schedule);
|
|
823
840
|
}
|
|
824
841
|
|
|
825
842
|
/**
|
|
@@ -913,21 +930,20 @@ class Environment extends Base {
|
|
|
913
930
|
// Generator > 5
|
|
914
931
|
this.once('run', () => generator.emit('run'));
|
|
915
932
|
this.once('end', () => generator.emit('end'));
|
|
916
|
-
generator.queueTasks();
|
|
917
|
-
} else {
|
|
918
|
-
if (!generator.options.forwardErrorToEnvironment) {
|
|
919
|
-
generator.on('error', error => this.emit('error', error));
|
|
920
|
-
}
|
|
921
|
-
generator.promise = generator.run();
|
|
933
|
+
return generator.queueTasks();
|
|
922
934
|
}
|
|
935
|
+
if (!generator.options.forwardErrorToEnvironment) {
|
|
936
|
+
generator.on('error', error => this.emit('error', error));
|
|
937
|
+
}
|
|
938
|
+
generator.promise = generator.run();
|
|
923
939
|
};
|
|
924
940
|
|
|
925
941
|
if (schedule) {
|
|
926
942
|
this.runLoop.add(
|
|
927
943
|
'environment:run',
|
|
928
|
-
(done, stop) => {
|
|
944
|
+
async (done, stop) => {
|
|
929
945
|
try {
|
|
930
|
-
runGenerator();
|
|
946
|
+
await runGenerator();
|
|
931
947
|
done();
|
|
932
948
|
} catch (error) {
|
|
933
949
|
stop(error);
|
|
@@ -935,7 +951,10 @@ class Environment extends Base {
|
|
|
935
951
|
}
|
|
936
952
|
);
|
|
937
953
|
} else {
|
|
938
|
-
runGenerator();
|
|
954
|
+
const maybePromise = runGenerator();
|
|
955
|
+
if (maybePromise && maybePromise.then) {
|
|
956
|
+
return maybePromise.then(() => generator);
|
|
957
|
+
}
|
|
939
958
|
}
|
|
940
959
|
return generator;
|
|
941
960
|
}
|
|
@@ -950,7 +969,7 @@ class Environment extends Base {
|
|
|
950
969
|
* @param {Object} [options]
|
|
951
970
|
*/
|
|
952
971
|
async run(args, options, done) {
|
|
953
|
-
if (done
|
|
972
|
+
if (done || typeof options === 'function' || typeof args === 'function') {
|
|
954
973
|
throw new Error('Callback support have been removed.');
|
|
955
974
|
}
|
|
956
975
|
|
|
@@ -1056,7 +1075,7 @@ class Environment extends Base {
|
|
|
1056
1075
|
async runGenerator(generator) {
|
|
1057
1076
|
try {
|
|
1058
1077
|
generator = await generator;
|
|
1059
|
-
generator = this.queueGenerator(generator);
|
|
1078
|
+
generator = await this.queueGenerator(generator);
|
|
1060
1079
|
} catch (error) {
|
|
1061
1080
|
return Promise.reject(error);
|
|
1062
1081
|
}
|
package/lib/spawn-command.js
CHANGED
|
@@ -15,7 +15,7 @@ const spawnCommand = module.exports;
|
|
|
15
15
|
* @param {object} [opt] any execa options
|
|
16
16
|
* @return {String} spawned process reference
|
|
17
17
|
*/
|
|
18
|
-
spawnCommand.spawnCommand = (command, args, opt)
|
|
18
|
+
spawnCommand.spawnCommand = function (command, args, opt) {
|
|
19
19
|
return spawn(command, args, {stdio: 'inherit', cwd: this.cwd, ...opt});
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -27,6 +27,6 @@ spawnCommand.spawnCommand = (command, args, opt) => {
|
|
|
27
27
|
* @param {object} [opt] any execa options
|
|
28
28
|
* @return {String} spawn.sync result
|
|
29
29
|
*/
|
|
30
|
-
spawnCommand.spawnCommandSync = (command, args, opt)
|
|
30
|
+
spawnCommand.spawnCommandSync = function (command, args, opt) {
|
|
31
31
|
return spawn.sync(command, args, {stdio: 'inherit', cwd: this.cwd, ...opt});
|
|
32
32
|
};
|