Skip to content

Commit 9729a58

Browse files
committed
Add features argument to constructor.
1 parent 9b9a9cb commit 9729a58

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

lib/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ class Generator extends Base {
111111
* @param {string[]} args - Provide arguments at initialization
112112
* @param {Object} options - Provide options at initialization
113113
* @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-
*
118114
* @property {Object} env - the current Environment being run
119115
* @property {String} resolved - the path to the current generator
120116
* @property {String} description - Used in `--help` output
@@ -131,10 +127,11 @@ class Generator extends Base {
131127
* }
132128
* };
133129
*/
134-
constructor(args, options) {
130+
constructor(args, options, features) {
135131
super();
136132

137133
if (!Array.isArray(args)) {
134+
features = options;
138135
options = args;
139136
args = [];
140137
}
@@ -150,6 +147,7 @@ class Generator extends Base {
150147
this._namespace = this.options.namespace;
151148
this._namespaceId = this.options.namespaceId;
152149
this.yoGeneratorVersion = packageJson.version;
150+
this.features = features || {unique: this.options.unique};
153151

154152
this.option('help', {
155153
type: Boolean,
@@ -269,19 +267,35 @@ class Generator extends Base {
269267
}
270268
}
271269

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+
272283
/**
273284
* Specifications for Environment features.
274285
*
275286
* @return {Object}
276287
*/
277288
getFeatures() {
278-
if (this.options.unique) {
289+
if (this.features.unique) {
279290
const {namespace} = this.options;
280291
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+
) {
282296
uniqueBy = namespace;
283297
} else if (
284-
this.options.unique === 'argument' &&
298+
this.features.unique === 'argument' &&
285299
this._args.length === 1
286300
) {
287301
const namespaceId = this.env
@@ -290,7 +304,7 @@ class Generator extends Base {
290304
uniqueBy = namespaceId.id;
291305
} else {
292306
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}'`
294308
);
295309
}
296310

0 commit comments

Comments
 (0)