@@ -111,10 +111,6 @@ class Generator extends Base {
111
111
* @param {string[] } args - Provide arguments at initialization
112
112
* @param {Object } options - Provide options at initialization
113
113
* @param {Priority[] } [options.customPriorities] - Custom priorities
114
- * @param {boolean|string } [options.unique] - Generates a uniqueBy id for the environment
115
- * Accepts 'namespace' or 'true' for one instance by namespace
116
- Accepts 'argument' for one instance by namespace and 1 argument
117
- *
118
114
* @property {Object } env - the current Environment being run
119
115
* @property {String } resolved - the path to the current generator
120
116
* @property {String } description - Used in `--help` output
@@ -131,10 +127,11 @@ class Generator extends Base {
131
127
* }
132
128
* };
133
129
*/
134
- constructor ( args , options ) {
130
+ constructor ( args , options , features ) {
135
131
super ( ) ;
136
132
137
133
if ( ! Array . isArray ( args ) ) {
134
+ features = options ;
138
135
options = args ;
139
136
args = [ ] ;
140
137
}
@@ -150,6 +147,7 @@ class Generator extends Base {
150
147
this . _namespace = this . options . namespace ;
151
148
this . _namespaceId = this . options . namespaceId ;
152
149
this . yoGeneratorVersion = packageJson . version ;
150
+ this . features = features || { unique : this . options . unique } ;
153
151
154
152
this . option ( 'help' , {
155
153
type : Boolean ,
@@ -269,19 +267,35 @@ class Generator extends Base {
269
267
}
270
268
}
271
269
270
+ /**
271
+ * Configure Generator behaviours.
272
+ *
273
+ * @param {Object } features
274
+ * @param {boolean|string } [features.unique] - Generates a uniqueBy id for the environment
275
+ * Accepts 'namespace' or 'true' for one instance by namespace
276
+ * Accepts 'argument' for one instance by namespace and 1 argument
277
+ *
278
+ */
279
+ setFeatures ( features ) {
280
+ Object . assign ( this . features , features ) ;
281
+ }
282
+
272
283
/**
273
284
* Specifications for Environment features.
274
285
*
275
286
* @return {Object }
276
287
*/
277
288
getFeatures ( ) {
278
- if ( this . options . unique ) {
289
+ if ( this . features . unique ) {
279
290
const { namespace} = this . options ;
280
291
let uniqueBy ;
281
- if ( this . options . unique === true || this . options . unique === 'namespace' ) {
292
+ if (
293
+ this . features . unique === true ||
294
+ this . features . unique === 'namespace'
295
+ ) {
282
296
uniqueBy = namespace ;
283
297
} else if (
284
- this . options . unique === 'argument' &&
298
+ this . features . unique === 'argument' &&
285
299
this . _args . length === 1
286
300
) {
287
301
const namespaceId = this . env
@@ -290,7 +304,7 @@ class Generator extends Base {
290
304
uniqueBy = namespaceId . id ;
291
305
} else {
292
306
throw new Error (
293
- `Error generating a uniqueBy value. Uniqueness ${ this . options . unique } is not supported`
307
+ `Error generating a uniqueBy value. Uniqueness ' ${ this . features . unique } ' not supported by ' ${ this . options . namespace } ' `
294
308
) ;
295
309
}
296
310
0 commit comments