Skip to content

Commit

Permalink
Move uniqueBy calculation to the constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Mar 13, 2021
1 parent 26797e6 commit 4dcda8a
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ class Generator extends Base {
return;
}

if (this.features.unique && !this.features.uniqueBy) {
const {namespace} = this.options;
let uniqueBy;
if (
this.features.unique === true ||
this.features.unique === 'namespace'
) {
uniqueBy = namespace;
} else if (
this.features.unique === 'argument' &&
this._args.length === 1
) {
const namespaceId = this.env
.requireNamespace(namespace)
.with({instanceId: this._args[0]});
uniqueBy = namespaceId.id;
} else {
throw new Error(
`Error generating a uniqueBy value. Uniqueness '${this.features.unique}' not supported by '${this.options.namespace}'`
);
}

this.features.uniqueBy = uniqueBy;
}

// Ensure the environment support features this yeoman-generator version require.
if (
!this.env.adapter ||
Expand Down Expand Up @@ -286,32 +311,7 @@ class Generator extends Base {
* @return {Object}
*/
getFeatures() {
if (this.features.unique) {
const {namespace} = this.options;
let uniqueBy;
if (
this.features.unique === true ||
this.features.unique === 'namespace'
) {
uniqueBy = namespace;
} else if (
this.features.unique === 'argument' &&
this._args.length === 1
) {
const namespaceId = this.env
.requireNamespace(namespace)
.with({instanceId: this._args[0]});
uniqueBy = namespaceId.id;
} else {
throw new Error(
`Error generating a uniqueBy value. Uniqueness '${this.features.unique}' not supported by '${this.options.namespace}'`
);
}

return {uniqueBy};
}

return {};
return this.features;
}

/**
Expand Down

0 comments on commit 4dcda8a

Please sign in to comment.