@nestjs/cli
Version:
The Nest CLI: create NestJS applications, generate modules, controllers and CRUD resources, and build, run and watch projects and monorepos.
34 lines (33 loc) • 1.48 kB
JavaScript
import { NodeWorkflow } from '@angular-devkit/schematics/tools/index.js';
import { AbstractCollection } from './abstract.collection.js';
export class CustomCollection extends AbstractCollection {
getSchematics() {
// Without `resolvePaths`, the workflow resolves collections relative to the
// CLI's own install rather than the project.
const workflow = new NodeWorkflow(process.cwd(), {
resolvePaths: [process.cwd()],
});
const collection = workflow.engine.createCollection(this.collection);
const collectionDescriptions = [
collection.description,
...(collection.baseDescriptions ?? []),
];
const usedNames = new Set();
const schematics = [];
for (const collectionDesc of collectionDescriptions) {
const schematicsDescs = Object.entries(collectionDesc.schematics);
for (const [name, { description, aliases = [] }] of schematicsDescs) {
if (usedNames.has(name)) {
continue;
}
usedNames.add(name);
const alias = aliases.find((a) => !usedNames.has(a)) ?? name;
for (const alias of aliases) {
usedNames.add(alias);
}
schematics.push({ name, alias, description });
}
}
return schematics.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
}
}