yeoman-generator 5.5.0 → 5.6.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.
package/lib/index.js CHANGED
@@ -191,13 +191,15 @@ class Generator extends Base {
191
191
 
192
192
  this.env = this.options.env;
193
193
 
194
- this.resolved = this.options.resolved || __dirname;
194
+ this.resolved = this.options.resolved || __filename;
195
195
  this.description = this.description || '';
196
196
 
197
197
  if (this.env) {
198
198
  // Determine the app root
199
199
  this.contextRoot = this.env.cwd;
200
200
  this.destinationRoot(this.options.destinationRoot || this.env.cwd);
201
+ // Clear destionationRoot, _destinationRoot will take priority when composing, but not override passed options.
202
+ delete this.options.destinationRoot;
201
203
 
202
204
  // Ensure source/destination path, can be configured from subclasses
203
205
  this.sourceRoot(path.join(path.dirname(this.resolved), 'templates'));
@@ -335,10 +337,27 @@ class Generator extends Base {
335
337
  *
336
338
  * @param {Object[]} priorities - Priorities
337
339
  * @param {String} priorities.priorityName - Priority name
338
- * @param {String} priorities.before - The new priority will be queued before the `before` priority.
340
+ * @param {String} [priorities.before] - The new priority will be queued before the `before` priority. Required for new priorities.
339
341
  * @param {String} [priorities.queueName] - Name to be used at grouped-queue
342
+ * @param {boolean} [priorities.edit] - Edit a priority
343
+ * @param {boolean} [priorities.skip] - Queued manually only
344
+ * @param {Object[]|function} [priorities.args] - Arguments to pass to tasks
340
345
  */
341
346
  registerPriorities(priorities) {
347
+ priorities = priorities.filter((priority) => {
348
+ if (priority.edit) {
349
+ const queue = this._queues[priority.priorityName];
350
+ if (!queue) {
351
+ throw new Error(
352
+ `Error editing priority ${priority.priorityName}, not found`
353
+ );
354
+ }
355
+
356
+ Object.assign(queue, {...priority, edit: undefined});
357
+ }
358
+
359
+ return !priority.edit;
360
+ });
342
361
  const customPriorities = priorities.map((customPriority) => {
343
362
  // Keep backward compatibility with name
344
363
  const newPriority = {
@@ -868,16 +887,6 @@ class Generator extends Base {
868
887
  * @param {TaskOptions} [taskOptions]: options.
869
888
  */
870
889
  extractTasksFromPriority(name, taskOptions = {}) {
871
- const {taskPrefix} = this.features;
872
- const propertyName = taskPrefix ? `${taskPrefix}${name}` : name;
873
- const property = Object.getOwnPropertyDescriptor(
874
- Object.getPrototypeOf(this),
875
- propertyName
876
- );
877
- if (!property) return [];
878
-
879
- const item = property.value ? property.value : property.get.call(this);
880
-
881
890
  const priority = this._queues[name];
882
891
  taskOptions = {
883
892
  ...priority,
@@ -886,19 +895,26 @@ class Generator extends Base {
886
895
  ...taskOptions
887
896
  };
888
897
 
889
- if (!item || (taskOptions.auto && priority && priority.skip)) {
898
+ if (taskOptions.auto && priority && priority.skip) {
890
899
  return [];
891
900
  }
892
901
 
902
+ const {taskPrefix = this.features.taskPrefix || ''} = taskOptions;
903
+ const propertyName = taskPrefix ? `${taskPrefix}${name}` : name;
904
+ const property = Object.getOwnPropertyDescriptor(
905
+ taskOptions.taskOrigin || Object.getPrototypeOf(this),
906
+ propertyName
907
+ );
908
+ if (!property) return [];
909
+
910
+ const item = property.value ? property.value : property.get.call(this);
911
+
893
912
  // Name points to a function; single task
894
913
  if (typeof item === 'function') {
895
- taskOptions.taskName = name;
896
- taskOptions.method = item;
897
- return [taskOptions];
914
+ return [{...taskOptions, taskName: name, method: item}];
898
915
  }
899
916
 
900
- // Not a queue hash; stop
901
- if (!priority) {
917
+ if (!item || !priority) {
902
918
  return [];
903
919
  }
904
920
 
@@ -1058,7 +1074,6 @@ class Generator extends Base {
1058
1074
  method
1059
1075
  } = task;
1060
1076
  const {namespace = ''} = this.options || {};
1061
- args = typeof args === 'function' ? args(this) : args;
1062
1077
 
1063
1078
  const priority = Object.entries(this._queues).find(
1064
1079
  ([_, options]) => options.queueName === queueName
@@ -1076,6 +1091,7 @@ class Generator extends Base {
1076
1091
  const generator = this;
1077
1092
 
1078
1093
  runAsync(function () {
1094
+ args = typeof args === 'function' ? args(generator) : args;
1079
1095
  generator.async = () => this.async();
1080
1096
  generator.runningState = {namespace, queueName, methodName};
1081
1097
  return method.apply(generator, args);
@@ -1276,12 +1292,12 @@ class Generator extends Base {
1276
1292
 
1277
1293
  // Pass down the default options so they're correctly mirrored down the chain.
1278
1294
  options = {
1295
+ destinationRoot: this._destinationRoot,
1279
1296
  ...options,
1280
1297
  skipInstall: this.options.skipInstall,
1281
1298
  skipCache: this.options.skipCache,
1282
1299
  forceInstall: this.options.forceInstall,
1283
- skipLocalCache: this.options.skipLocalCache,
1284
- destinationRoot: this._destinationRoot
1300
+ skipLocalCache: this.options.skipLocalCache
1285
1301
  };
1286
1302
 
1287
1303
  const instantiate = (Generator, path) => {
@@ -1386,12 +1402,19 @@ this.composeWith({
1386
1402
  * Return a storage instance.
1387
1403
  * @param {String} storePath The path of the json file
1388
1404
  * @param {String} [path] The name in which is stored inside the json
1389
- * @param {String} [lodashPath] Treat path as an lodash path
1405
+ * @param {boolean|Object} [options] Treat path as an lodash path
1390
1406
  * @return {Storage} json storage
1391
1407
  */
1392
- createStorage(storePath, path, lodashPath = false) {
1408
+ createStorage(storePath, path, options) {
1409
+ if (typeof path === 'object') {
1410
+ options = path;
1411
+ path = undefined;
1412
+ } else if (typeof options === 'boolean') {
1413
+ options = {lodashPath: options};
1414
+ }
1415
+
1393
1416
  storePath = this.destinationPath(storePath);
1394
- return new Storage(path, this.fs, storePath, lodashPath);
1417
+ return new Storage(path, this.fs, storePath, options);
1395
1418
  }
1396
1419
 
1397
1420
  /**
@@ -64,7 +64,7 @@ class Storage {
64
64
  }
65
65
 
66
66
  _.defaults(options, {
67
- lodash: false,
67
+ lodashPath: false,
68
68
  disableCache: false,
69
69
  disableCacheByFile: false,
70
70
  sorted: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-generator",
3
- "version": "5.5.0",
3
+ "version": "5.6.1",
4
4
  "description": "Rails-inspired generator system that provides scaffolding for your apps",
5
5
  "homepage": "http://yeoman.io",
6
6
  "author": "Yeoman",
@@ -71,7 +71,7 @@
71
71
  "read-pkg-up": "^7.0.1",
72
72
  "run-async": "^2.0.0",
73
73
  "semver": "^7.2.1",
74
- "shelljs": "^0.8.4",
74
+ "shelljs": "^0.8.5",
75
75
  "sort-keys": "^4.2.0",
76
76
  "text-table": "^0.2.0"
77
77
  },