@depup/nestjs__cli 11.0.24-depup.7 → 12.0.0-depup.0
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/README.md +7 -15
- package/actions/abstract.action.d.ts +1 -2
- package/actions/abstract.action.js +1 -5
- package/actions/add.action.d.ts +3 -4
- package/actions/add.action.js +44 -53
- package/actions/build.action.d.ts +18 -11
- package/actions/build.action.js +172 -79
- package/actions/deploy.action.d.ts +6 -0
- package/actions/deploy.action.js +51 -0
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +61 -59
- package/actions/index.d.ts +9 -7
- package/actions/index.js +9 -23
- package/actions/info.action.d.ts +18 -28
- package/actions/info.action.js +80 -60
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +108 -104
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +40 -47
- package/actions/upgrade.action.d.ts +6 -0
- package/actions/upgrade.action.js +53 -0
- package/bin/nest.js +11 -10
- package/changes.json +9 -41
- package/commands/abstract.command.d.ts +3 -3
- package/commands/abstract.command.js +2 -5
- package/commands/add.command.d.ts +3 -3
- package/commands/add.command.js +17 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +52 -56
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +29 -22
- package/commands/context/add.context.d.ts +7 -0
- package/commands/context/add.context.js +1 -0
- package/commands/context/build.context.d.ts +17 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/deploy.context.d.ts +7 -0
- package/commands/context/deploy.context.js +1 -0
- package/commands/context/generate.context.d.ts +18 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +7 -0
- package/commands/context/index.js +7 -0
- package/commands/context/new.context.d.ts +19 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +22 -0
- package/commands/context/start.context.js +1 -0
- package/commands/context/upgrade.context.d.ts +11 -0
- package/commands/context/upgrade.context.js +1 -0
- package/commands/deploy.command.d.ts +5 -0
- package/commands/deploy.command.js +22 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +35 -66
- package/commands/index.d.ts +3 -2
- package/commands/index.js +3 -18
- package/commands/info.command.d.ts +3 -3
- package/commands/info.command.js +4 -8
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +34 -36
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +48 -73
- package/commands/upgrade.command.d.ts +5 -0
- package/commands/upgrade.command.js +32 -0
- package/lib/compiler/assets-manager.d.ts +20 -8
- package/lib/compiler/assets-manager.js +199 -63
- package/lib/compiler/base-compiler.d.ts +5 -5
- package/lib/compiler/base-compiler.js +10 -13
- package/lib/compiler/compiler.d.ts +6 -6
- package/lib/compiler/compiler.js +7 -9
- package/lib/compiler/defaults/rspack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/rspack-defaults.js +179 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +5 -2
- package/lib/compiler/defaults/swc-defaults.js +22 -6
- package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
- package/lib/compiler/defaults/webpack-defaults.js +59 -19
- package/lib/compiler/helpers/append-extension.js +3 -6
- package/lib/compiler/helpers/copy-path-resolve.js +2 -5
- package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
- package/lib/compiler/helpers/delete-out-dir.js +45 -10
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-effective-root-dir.d.ts +16 -0
- package/lib/compiler/helpers/get-effective-root-dir.js +56 -0
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +10 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +19 -0
- package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
- package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
- package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
- package/lib/compiler/helpers/get-value-or-default.js +3 -8
- package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
- package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
- package/lib/compiler/helpers/glob.d.ts +19 -0
- package/lib/compiler/helpers/glob.js +185 -0
- package/lib/compiler/helpers/manual-restart.js +4 -8
- package/lib/compiler/helpers/path-confinement.d.ts +33 -0
- package/lib/compiler/helpers/path-confinement.js +63 -0
- package/lib/compiler/helpers/tsconfig-provider.d.ts +7 -6
- package/lib/compiler/helpers/tsconfig-provider.js +32 -13
- package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
- package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +37 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +113 -13
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
- package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
- package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
- package/lib/compiler/plugins/plugins-loader.js +12 -12
- package/lib/compiler/rspack-compiler.d.ts +21 -0
- package/lib/compiler/rspack-compiler.js +111 -0
- package/lib/compiler/swc/constants.d.ts +0 -1
- package/lib/compiler/swc/constants.js +9 -13
- package/lib/compiler/swc/forked-type-checker.js +13 -18
- package/lib/compiler/swc/swc-compiler.d.ts +13 -6
- package/lib/compiler/swc/swc-compiler.js +116 -70
- package/lib/compiler/swc/type-checker-host.js +31 -24
- package/lib/compiler/typescript-loader.js +7 -9
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +13 -15
- package/lib/compiler/watchers/recursive-directory-watcher.d.ts +37 -0
- package/lib/compiler/watchers/recursive-directory-watcher.js +334 -0
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +46 -23
- package/lib/configuration/configuration.d.ts +16 -3
- package/lib/configuration/configuration.js +1 -2
- package/lib/configuration/configuration.loader.d.ts +1 -1
- package/lib/configuration/configuration.loader.js +1 -2
- package/lib/configuration/defaults.d.ts +2 -1
- package/lib/configuration/defaults.js +8 -10
- package/lib/configuration/index.d.ts +3 -3
- package/lib/configuration/index.js +3 -19
- package/lib/configuration/nest-configuration.loader.d.ts +3 -3
- package/lib/configuration/nest-configuration.loader.js +28 -29
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +21 -32
- package/lib/package-managers/bun.package-manager.d.ts +7 -0
- package/lib/package-managers/bun.package-manager.js +22 -0
- package/lib/package-managers/index.d.ts +9 -8
- package/lib/package-managers/index.js +9 -24
- package/lib/package-managers/npm.package-manager.d.ts +2 -2
- package/lib/package-managers/npm.package-manager.js +6 -10
- package/lib/package-managers/package-manager-commands.js +1 -2
- package/lib/package-managers/package-manager.d.ts +2 -1
- package/lib/package-managers/package-manager.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +23 -20
- package/lib/package-managers/package-manager.js +3 -5
- package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
- package/lib/package-managers/pnpm.package-manager.js +6 -10
- package/lib/package-managers/project.dependency.js +1 -2
- package/lib/package-managers/yarn.package-manager.d.ts +2 -2
- package/lib/package-managers/yarn.package-manager.js +6 -10
- package/lib/questions/questions.d.ts +5 -1
- package/lib/questions/questions.js +2 -7
- package/lib/readers/file-system.reader.d.ts +1 -1
- package/lib/readers/file-system.reader.js +6 -9
- package/lib/readers/index.d.ts +2 -2
- package/lib/readers/index.js +2 -18
- package/lib/readers/reader.js +3 -5
- package/lib/runners/abstract.runner.js +40 -21
- package/lib/runners/bun.runner.d.ts +4 -0
- package/lib/runners/bun.runner.js +6 -0
- package/lib/runners/git.runner.d.ts +1 -1
- package/lib/runners/git.runner.js +2 -6
- package/lib/runners/index.d.ts +3 -3
- package/lib/runners/index.js +3 -19
- package/lib/runners/mau.runner.d.ts +8 -0
- package/lib/runners/mau.runner.js +10 -0
- package/lib/runners/npm.runner.d.ts +1 -1
- package/lib/runners/npm.runner.js +2 -6
- package/lib/runners/pnpm.runner.d.ts +1 -1
- package/lib/runners/pnpm.runner.js +2 -6
- package/lib/runners/runner.d.ts +2 -1
- package/lib/runners/runner.factory.d.ts +7 -6
- package/lib/runners/runner.factory.js +18 -20
- package/lib/runners/runner.js +3 -5
- package/lib/runners/schematic.runner.d.ts +1 -1
- package/lib/runners/schematic.runner.js +5 -7
- package/lib/runners/yarn.runner.d.ts +1 -1
- package/lib/runners/yarn.runner.js +2 -6
- package/lib/schematics/abstract.collection.d.ts +3 -3
- package/lib/schematics/abstract.collection.js +3 -5
- package/lib/schematics/collection.factory.d.ts +2 -2
- package/lib/schematics/collection.factory.js +9 -13
- package/lib/schematics/collection.js +2 -5
- package/lib/schematics/custom.collection.d.ts +2 -2
- package/lib/schematics/custom.collection.js +4 -8
- package/lib/schematics/index.d.ts +4 -4
- package/lib/schematics/index.js +4 -20
- package/lib/schematics/nest.collection.d.ts +3 -3
- package/lib/schematics/nest.collection.js +113 -109
- package/lib/schematics/schematic.option.js +10 -9
- package/lib/ui/banner.js +1 -4
- package/lib/ui/emojis.d.ts +17 -17
- package/lib/ui/emojis.js +19 -22
- package/lib/ui/errors.js +1 -4
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.d.ts +8 -0
- package/lib/ui/messages.js +23 -18
- package/lib/ui/prefixes.js +3 -6
- package/lib/utils/extra-args-warning.js +3 -6
- package/lib/utils/formatting.js +1 -4
- package/lib/utils/get-default-tsconfig-path.js +4 -7
- package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
- package/lib/utils/is-esm-project.d.ts +5 -0
- package/lib/utils/is-esm-project.js +16 -0
- package/lib/utils/is-interactive.d.ts +8 -0
- package/lib/utils/is-interactive.js +10 -0
- package/lib/utils/is-module-available.js +3 -4
- package/lib/utils/load-configuration.d.ts +1 -1
- package/lib/utils/load-configuration.js +4 -7
- package/lib/utils/local-binaries.d.ts +2 -2
- package/lib/utils/local-binaries.js +8 -11
- package/lib/utils/mau.d.ts +14 -0
- package/lib/utils/mau.js +46 -0
- package/lib/utils/os-info.utils.js +1 -4
- package/lib/utils/project-utils.d.ts +1 -3
- package/lib/utils/project-utils.js +16 -28
- package/lib/utils/remaining-flags.d.ts +2 -2
- package/lib/utils/remaining-flags.js +13 -8
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +70 -83
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { red } from 'ansis';
|
|
3
|
+
import { PackageManagerFactory } from '../lib/package-managers/index.js';
|
|
4
|
+
import { MauRunner } from '../lib/runners/mau.runner.js';
|
|
5
|
+
import { ERROR_PREFIX, INFO_PREFIX, MESSAGES } from '../lib/ui/index.js';
|
|
6
|
+
import { gracefullyExitOnPromptError } from '../lib/utils/gracefully-exit-on-prompt-error.js';
|
|
7
|
+
import { isInteractive } from '../lib/utils/is-interactive.js';
|
|
8
|
+
import { MAU_PACKAGE_NAME, findMauBinary } from '../lib/utils/mau.js';
|
|
9
|
+
import { AbstractAction } from './abstract.action.js';
|
|
10
|
+
const INSTALL_COMMAND = `npm install --save-dev ${MAU_PACKAGE_NAME}`;
|
|
11
|
+
export class DeployAction extends AbstractAction {
|
|
12
|
+
async handle(context) {
|
|
13
|
+
const binaryPath = findMauBinary() ?? (await this.installMau());
|
|
14
|
+
const runner = new MauRunner(binaryPath);
|
|
15
|
+
// Not collected: mau owns the terminal from here on, so its output and
|
|
16
|
+
// any prompts it shows must reach the user directly.
|
|
17
|
+
await runner.run(['deploy', ...context.args].join(' '));
|
|
18
|
+
}
|
|
19
|
+
async installMau() {
|
|
20
|
+
if (!isInteractive()) {
|
|
21
|
+
console.error(`\n${ERROR_PREFIX} ${MESSAGES.MAU_NOT_INSTALLED_NON_INTERACTIVE(MAU_PACKAGE_NAME, INSTALL_COMMAND)}`);
|
|
22
|
+
throw new Error(MESSAGES.MAU_INSTALLATION_FAILED(MAU_PACKAGE_NAME));
|
|
23
|
+
}
|
|
24
|
+
const shouldInstall = await confirm({
|
|
25
|
+
message: MESSAGES.MAU_INSTALLATION_QUESTION(MAU_PACKAGE_NAME),
|
|
26
|
+
default: true,
|
|
27
|
+
}).catch(gracefullyExitOnPromptError);
|
|
28
|
+
if (!shouldInstall) {
|
|
29
|
+
console.error(`\n${ERROR_PREFIX} ${MESSAGES.MAU_INSTALLATION_DECLINED(MAU_PACKAGE_NAME, INSTALL_COMMAND)}`);
|
|
30
|
+
throw new Error(MESSAGES.MAU_INSTALLATION_FAILED(MAU_PACKAGE_NAME));
|
|
31
|
+
}
|
|
32
|
+
console.info(`${INFO_PREFIX} ${MESSAGES.MAU_INSTALLATION_IN_PROGRESS(MAU_PACKAGE_NAME)}`);
|
|
33
|
+
try {
|
|
34
|
+
const manager = await PackageManagerFactory.find();
|
|
35
|
+
await manager.addDevelopment([MAU_PACKAGE_NAME], 'latest');
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof Error && error.message) {
|
|
39
|
+
console.error(red(error.message));
|
|
40
|
+
}
|
|
41
|
+
throw new Error(MESSAGES.MAU_INSTALLATION_FAILED(MAU_PACKAGE_NAME));
|
|
42
|
+
}
|
|
43
|
+
// Resolve again rather than assuming a path: the package manager decides
|
|
44
|
+
// where the package physically lands.
|
|
45
|
+
const binaryPath = findMauBinary();
|
|
46
|
+
if (!binaryPath) {
|
|
47
|
+
throw new Error(MESSAGES.MAU_INSTALLATION_FAILED(MAU_PACKAGE_NAME));
|
|
48
|
+
}
|
|
49
|
+
return binaryPath;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { GenerateCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
3
|
export declare class GenerateAction extends AbstractAction {
|
|
4
|
-
handle(
|
|
4
|
+
handle(context: GenerateCommandContext): Promise<void>;
|
|
5
5
|
}
|
|
@@ -1,48 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const type_assertions_1 = require("../lib/utils/type-assertions");
|
|
13
|
-
class GenerateAction extends abstract_action_1.AbstractAction {
|
|
14
|
-
async handle(inputs, options) {
|
|
15
|
-
await generateFiles(inputs.concat(options));
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
4
|
+
import { Collection, CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
5
|
+
import { MESSAGES } from '../lib/ui/index.js';
|
|
6
|
+
import { loadConfiguration } from '../lib/utils/load-configuration.js';
|
|
7
|
+
import { askForProjectName, getSpecFileSuffix, moveDefaultProjectToStart, shouldAskForProject, shouldGenerateFlat, shouldGenerateSpec, } from '../lib/utils/project-utils.js';
|
|
8
|
+
import { AbstractAction } from './abstract.action.js';
|
|
9
|
+
export class GenerateAction extends AbstractAction {
|
|
10
|
+
async handle(context) {
|
|
11
|
+
await generateFiles(context);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const flat = inputs.find((option) => option.name === 'flat');
|
|
28
|
-
const specFileSuffix = inputs.find((option) => option.name === 'specFileSuffix');
|
|
29
|
-
const collection = schematics_1.CollectionFactory.create(collectionOption || configuration.collection || schematics_1.Collection.NESTJS);
|
|
30
|
-
const schematicOptions = mapSchematicOptions(inputs);
|
|
31
|
-
schematicOptions.push(new schematics_1.SchematicOption('language', configuration.language));
|
|
14
|
+
const generateFiles = async (context) => {
|
|
15
|
+
const configuration = await loadConfiguration();
|
|
16
|
+
const collectionOption = context.collection;
|
|
17
|
+
const schematic = context.schematic;
|
|
18
|
+
const appName = context.project ?? '';
|
|
19
|
+
const specFileSuffix = context.specFileSuffix;
|
|
20
|
+
const collection = CollectionFactory.create(collectionOption || configuration.collection || Collection.NESTJS);
|
|
21
|
+
const schematicOptions = mapContextToSchematicOptions(context);
|
|
22
|
+
schematicOptions.push(new SchematicOption('language', configuration.language));
|
|
32
23
|
const configurationProjects = configuration.projects;
|
|
33
24
|
let sourceRoot = appName
|
|
34
|
-
?
|
|
25
|
+
? getValueOrDefault(configuration, 'sourceRoot', appName)
|
|
35
26
|
: configuration.sourceRoot;
|
|
36
|
-
const specValue = spec.value;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
let generateSpec =
|
|
41
|
-
let generateFlat =
|
|
42
|
-
let generateSpecFileSuffix =
|
|
27
|
+
const specValue = typeof context.spec === 'boolean' ? context.spec : context.spec.value;
|
|
28
|
+
const specPassedAsInput = typeof context.spec === 'boolean' ? false : context.spec.passedAsInput;
|
|
29
|
+
const flatValue = context.flat !== undefined ? !!context.flat : false;
|
|
30
|
+
const specFileSuffixValue = specFileSuffix;
|
|
31
|
+
let generateSpec = shouldGenerateSpec(configuration, schematic, appName, specValue, specPassedAsInput);
|
|
32
|
+
let generateFlat = shouldGenerateFlat(configuration, appName, flatValue);
|
|
33
|
+
let generateSpecFileSuffix = getSpecFileSuffix(configuration, appName, specFileSuffixValue);
|
|
43
34
|
// If you only add a `lib` we actually don't have monorepo: true BUT we do have "projects"
|
|
44
35
|
// Ensure we don't run for new app/libs schematics
|
|
45
|
-
if (
|
|
36
|
+
if (shouldAskForProject(schematic, configurationProjects, appName)) {
|
|
46
37
|
const defaultLabel = ' [ Default ]';
|
|
47
38
|
let defaultProjectName = configuration.sourceRoot + defaultLabel;
|
|
48
39
|
for (const property in configurationProjects) {
|
|
@@ -51,47 +42,58 @@ const generateFiles = async (inputs) => {
|
|
|
51
42
|
break;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
|
-
const projects =
|
|
55
|
-
const selectedProjectName = (await
|
|
45
|
+
const projects = moveDefaultProjectToStart(configuration, defaultProjectName, defaultLabel);
|
|
46
|
+
const selectedProjectName = (await askForProjectName(MESSAGES.PROJECT_SELECTION_QUESTION, projects));
|
|
56
47
|
const project = selectedProjectName.replace(defaultLabel, '');
|
|
57
48
|
if (project !== configuration.sourceRoot) {
|
|
58
49
|
sourceRoot = configurationProjects[project].sourceRoot;
|
|
59
50
|
}
|
|
60
51
|
if (selectedProjectName !== defaultProjectName) {
|
|
61
52
|
// Only overwrite if the appName is not the default- as it has already been loaded above
|
|
62
|
-
generateSpec =
|
|
63
|
-
generateFlat =
|
|
64
|
-
generateSpecFileSuffix =
|
|
53
|
+
generateSpec = shouldGenerateSpec(configuration, schematic, selectedProjectName, specValue, specPassedAsInput);
|
|
54
|
+
generateFlat = shouldGenerateFlat(configuration, selectedProjectName, flatValue);
|
|
55
|
+
generateSpecFileSuffix = getSpecFileSuffix(configuration, selectedProjectName, specFileSuffixValue);
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
58
|
if (configuration.generateOptions?.baseDir) {
|
|
68
59
|
sourceRoot = path.join(sourceRoot, configuration.generateOptions.baseDir);
|
|
69
60
|
}
|
|
70
|
-
schematicOptions.push(new
|
|
71
|
-
schematicOptions.push(new
|
|
72
|
-
schematicOptions.push(new
|
|
73
|
-
schematicOptions.push(new
|
|
61
|
+
schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
|
|
62
|
+
schematicOptions.push(new SchematicOption('spec', generateSpec));
|
|
63
|
+
schematicOptions.push(new SchematicOption('flat', generateFlat));
|
|
64
|
+
schematicOptions.push(new SchematicOption('specFileSuffix', generateSpecFileSuffix));
|
|
65
|
+
schematicOptions.push(new SchematicOption('format', context.format));
|
|
74
66
|
try {
|
|
75
|
-
|
|
76
|
-
if (!schematicInput) {
|
|
67
|
+
if (!schematic) {
|
|
77
68
|
throw new Error('Unable to find a schematic for this configuration');
|
|
78
69
|
}
|
|
79
|
-
await collection.execute(
|
|
70
|
+
await collection.execute(schematic, schematicOptions);
|
|
80
71
|
}
|
|
81
72
|
catch (error) {
|
|
82
73
|
if (error && error.message) {
|
|
83
|
-
console.error(
|
|
74
|
+
console.error(red(error.message));
|
|
84
75
|
}
|
|
85
76
|
}
|
|
86
77
|
};
|
|
87
|
-
const
|
|
88
|
-
const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix'];
|
|
78
|
+
const mapContextToSchematicOptions = (context) => {
|
|
89
79
|
const options = [];
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
// Only include fields that schematics expect; exclude those handled separately
|
|
81
|
+
if (context.name !== undefined)
|
|
82
|
+
options.push(new SchematicOption('name', context.name));
|
|
83
|
+
if (context.path !== undefined)
|
|
84
|
+
options.push(new SchematicOption('path', context.path));
|
|
85
|
+
if (context.dryRun)
|
|
86
|
+
options.push(new SchematicOption('dry-run', true));
|
|
87
|
+
if (context.collection !== undefined)
|
|
88
|
+
options.push(new SchematicOption('collection', context.collection));
|
|
89
|
+
if (context.project !== undefined)
|
|
90
|
+
options.push(new SchematicOption('project', context.project));
|
|
91
|
+
if (context.skipImport !== undefined)
|
|
92
|
+
options.push(new SchematicOption('skipImport', context.skipImport));
|
|
93
|
+
if (context.type !== undefined)
|
|
94
|
+
options.push(new SchematicOption('type', context.type));
|
|
95
|
+
if (context.crud !== undefined)
|
|
96
|
+
options.push(new SchematicOption('crud', context.crud));
|
|
97
|
+
// 'schematic', 'spec', 'flat', 'specFileSuffix' are handled separately
|
|
96
98
|
return options;
|
|
97
99
|
};
|
package/actions/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from './abstract.action';
|
|
2
|
-
export * from './build.action';
|
|
3
|
-
export * from './generate.action';
|
|
4
|
-
export * from './info.action';
|
|
5
|
-
export * from './new.action';
|
|
6
|
-
export * from './start.action';
|
|
7
|
-
export * from './add.action';
|
|
1
|
+
export * from './abstract.action.js';
|
|
2
|
+
export * from './build.action.js';
|
|
3
|
+
export * from './generate.action.js';
|
|
4
|
+
export * from './info.action.js';
|
|
5
|
+
export * from './new.action.js';
|
|
6
|
+
export * from './start.action.js';
|
|
7
|
+
export * from './add.action.js';
|
|
8
|
+
export * from './deploy.action.js';
|
|
9
|
+
export * from './upgrade.action.js';
|
package/actions/index.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./abstract.action"), exports);
|
|
18
|
-
__exportStar(require("./build.action"), exports);
|
|
19
|
-
__exportStar(require("./generate.action"), exports);
|
|
20
|
-
__exportStar(require("./info.action"), exports);
|
|
21
|
-
__exportStar(require("./new.action"), exports);
|
|
22
|
-
__exportStar(require("./start.action"), exports);
|
|
23
|
-
__exportStar(require("./add.action"), exports);
|
|
1
|
+
export * from './abstract.action.js';
|
|
2
|
+
export * from './build.action.js';
|
|
3
|
+
export * from './generate.action.js';
|
|
4
|
+
export * from './info.action.js';
|
|
5
|
+
export * from './new.action.js';
|
|
6
|
+
export * from './start.action.js';
|
|
7
|
+
export * from './add.action.js';
|
|
8
|
+
export * from './deploy.action.js';
|
|
9
|
+
export * from './upgrade.action.js';
|
package/actions/info.action.d.ts
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
import { AbstractAction } from './abstract.action';
|
|
2
|
-
interface LockfileDependency {
|
|
3
|
-
version: string;
|
|
4
|
-
}
|
|
5
|
-
interface PackageJsonDependencies {
|
|
6
|
-
[key: string]: LockfileDependency;
|
|
7
|
-
}
|
|
8
|
-
interface NestDependency {
|
|
9
|
-
name: string;
|
|
10
|
-
value: string;
|
|
11
|
-
packageName: string;
|
|
12
|
-
}
|
|
13
|
-
interface NestDependencyWarnings {
|
|
14
|
-
[key: string]: Array<NestDependency>;
|
|
15
|
-
}
|
|
1
|
+
import { AbstractAction } from './abstract.action.js';
|
|
16
2
|
export declare class InfoAction extends AbstractAction {
|
|
17
3
|
private manager;
|
|
18
4
|
private warningMessageDependenciesWhiteList;
|
|
19
5
|
handle(): Promise<void>;
|
|
20
6
|
private displayBanner;
|
|
21
7
|
private displaySystemInformation;
|
|
22
|
-
displayPackageManagerVersion
|
|
23
|
-
displayNestInformation
|
|
24
|
-
displayNestInformationFromPackage
|
|
25
|
-
displayCliVersion
|
|
26
|
-
readProjectPackageDependencies
|
|
27
|
-
displayNestVersions
|
|
28
|
-
displayWarningMessage
|
|
29
|
-
buildNestVersionsWarningMessage
|
|
30
|
-
buildNestVersionsMessage
|
|
31
|
-
collectNestDependencies
|
|
32
|
-
|
|
33
|
-
|
|
8
|
+
private displayPackageManagerVersion;
|
|
9
|
+
private displayNestInformation;
|
|
10
|
+
private displayNestInformationFromPackage;
|
|
11
|
+
private displayCliVersion;
|
|
12
|
+
private readProjectPackageDependencies;
|
|
13
|
+
private displayNestVersions;
|
|
14
|
+
private displayWarningMessage;
|
|
15
|
+
private buildNestVersionsWarningMessage;
|
|
16
|
+
private buildNestVersionsMessage;
|
|
17
|
+
private collectNestDependencies;
|
|
18
|
+
/**
|
|
19
|
+
* Reads the installed version of a package, or returns undefined when it
|
|
20
|
+
* cannot be determined (package not installed, or its "exports" map does
|
|
21
|
+
* not expose "./package.json" — as with @nestjs/* v12+).
|
|
22
|
+
*/
|
|
23
|
+
private readInstalledVersion;
|
|
24
|
+
private format;
|
|
34
25
|
}
|
|
35
|
-
export {};
|
package/actions/info.action.js
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { blue, bold, green, red, yellow } from 'ansis';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { platform, release } from 'os';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { dirname } from 'path';
|
|
8
|
+
import { PackageManagerFactory, } from '../lib/package-managers/index.js';
|
|
9
|
+
import { BANNER, MESSAGES } from '../lib/ui/index.js';
|
|
10
|
+
import osName from '../lib/utils/os-info.utils.js';
|
|
11
|
+
import { AbstractAction } from './abstract.action.js';
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
export class InfoAction extends AbstractAction {
|
|
16
|
+
manager;
|
|
17
|
+
// Nest dependencies whitelist used to compare the major version
|
|
18
|
+
warningMessageDependenciesWhiteList = [
|
|
19
|
+
'@nestjs/core',
|
|
20
|
+
'@nestjs/common',
|
|
21
|
+
'@nestjs/schematics',
|
|
22
|
+
'@nestjs/platform-express',
|
|
23
|
+
'@nestjs/platform-fastify',
|
|
24
|
+
'@nestjs/platform-socket.io',
|
|
25
|
+
'@nestjs/platform-ws',
|
|
26
|
+
'@nestjs/websockets',
|
|
27
|
+
];
|
|
27
28
|
async handle() {
|
|
28
|
-
this.manager = await
|
|
29
|
+
this.manager = await PackageManagerFactory.find();
|
|
29
30
|
this.displayBanner();
|
|
30
31
|
await this.displaySystemInformation();
|
|
31
32
|
await this.displayNestInformation();
|
|
32
33
|
}
|
|
33
34
|
displayBanner() {
|
|
34
|
-
console.info(
|
|
35
|
+
console.info(red(BANNER));
|
|
35
36
|
}
|
|
36
37
|
async displaySystemInformation() {
|
|
37
|
-
console.info(
|
|
38
|
-
console.info('OS Version :',
|
|
39
|
-
console.info('NodeJS Version :',
|
|
38
|
+
console.info(green `[System Information]`);
|
|
39
|
+
console.info('OS Version :', blue(osName(platform(), release()) + ' ' + release()));
|
|
40
|
+
console.info('NodeJS Version :', blue(process.version));
|
|
40
41
|
await this.displayPackageManagerVersion();
|
|
41
42
|
}
|
|
42
43
|
async displayPackageManagerVersion() {
|
|
43
44
|
try {
|
|
44
45
|
const version = await this.manager.version();
|
|
45
|
-
console.info(`${this.manager.name} Version :`,
|
|
46
|
+
console.info(`${this.manager.name} Version :`, blue(version), '\n');
|
|
46
47
|
}
|
|
47
48
|
catch {
|
|
48
|
-
console.error(`${this.manager.name} Version :`,
|
|
49
|
+
console.error(`${this.manager.name} Version :`, red `Unknown`, '\n');
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
async displayNestInformation() {
|
|
52
53
|
this.displayCliVersion();
|
|
53
|
-
console.info(
|
|
54
|
+
console.info(green `[Nest Platform Information]`);
|
|
54
55
|
await this.displayNestInformationFromPackage();
|
|
55
56
|
}
|
|
56
57
|
async displayNestInformationFromPackage() {
|
|
@@ -58,17 +59,17 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
58
59
|
const dependencies = this.readProjectPackageDependencies();
|
|
59
60
|
this.displayNestVersions(dependencies);
|
|
60
61
|
}
|
|
61
|
-
catch
|
|
62
|
-
console.error(
|
|
62
|
+
catch {
|
|
63
|
+
console.error(red(MESSAGES.NEST_INFORMATION_PACKAGE_MANAGER_FAILED));
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
displayCliVersion() {
|
|
66
|
-
console.info(
|
|
67
|
-
console.info('Nest CLI Version :',
|
|
67
|
+
console.info(green `[Nest CLI]`);
|
|
68
|
+
console.info('Nest CLI Version :', blue(JSON.parse(readFileSync(join(__dirname, '../package.json')).toString())
|
|
68
69
|
.version), '\n');
|
|
69
70
|
}
|
|
70
71
|
readProjectPackageDependencies() {
|
|
71
|
-
const buffer =
|
|
72
|
+
const buffer = readFileSync(join(process.cwd(), 'package.json'));
|
|
72
73
|
const pack = JSON.parse(buffer.toString());
|
|
73
74
|
const dependencies = { ...pack.dependencies, ...pack.devDependencies };
|
|
74
75
|
Object.keys(dependencies).forEach((key) => {
|
|
@@ -80,7 +81,15 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
80
81
|
}
|
|
81
82
|
displayNestVersions(dependencies) {
|
|
82
83
|
const nestDependencies = this.buildNestVersionsMessage(dependencies);
|
|
83
|
-
nestDependencies.
|
|
84
|
+
if (nestDependencies.length === 0) {
|
|
85
|
+
// No @nestjs/* packages declared in this package.json. Surfacing this
|
|
86
|
+
// explicitly is much more useful than letting `format([])` throw and
|
|
87
|
+
// showing the generic "cannot read your project package.json" error,
|
|
88
|
+
// which is misleading when the file was actually read successfully.
|
|
89
|
+
console.info('No @nestjs/* dependencies were found in package.json.');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
nestDependencies.forEach((dependency) => console.info(dependency.name, blue(dependency.value)));
|
|
84
93
|
this.displayWarningMessage(nestDependencies);
|
|
85
94
|
}
|
|
86
95
|
displayWarningMessage(nestDependencies) {
|
|
@@ -89,11 +98,11 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
89
98
|
const majorVersions = Object.keys(warnings);
|
|
90
99
|
if (majorVersions.length > 0) {
|
|
91
100
|
console.info('\r');
|
|
92
|
-
console.info(
|
|
101
|
+
console.info(yellow `[Warnings]`);
|
|
93
102
|
console.info('The following packages are not in the same major version');
|
|
94
103
|
console.info('This could lead to runtime errors');
|
|
95
104
|
majorVersions.forEach((version) => {
|
|
96
|
-
console.info(
|
|
105
|
+
console.info(bold `* Under version ${version}`);
|
|
97
106
|
warnings[version].forEach(({ packageName, value }) => {
|
|
98
107
|
console.info(`- ${packageName} ${value}`);
|
|
99
108
|
});
|
|
@@ -102,7 +111,7 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
102
111
|
}
|
|
103
112
|
catch {
|
|
104
113
|
console.info('\t');
|
|
105
|
-
console.error(
|
|
114
|
+
console.error(red(MESSAGES.NEST_INFORMATION_PACKAGE_WARNING_FAILED(this.warningMessageDependenciesWhiteList)));
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
117
|
buildNestVersionsWarningMessage(nestDependencies) {
|
|
@@ -145,37 +154,48 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
145
154
|
const nestDependencies = [];
|
|
146
155
|
Object.keys(dependencies).forEach((key) => {
|
|
147
156
|
if (key.indexOf('@nestjs') > -1) {
|
|
148
|
-
const depPackagePath = require.resolve(key + '/package.json', {
|
|
149
|
-
paths: [process.cwd()],
|
|
150
|
-
});
|
|
151
|
-
const depPackage = (0, fs_1.readFileSync)(depPackagePath).toString();
|
|
152
|
-
const value = JSON.parse(depPackage).version;
|
|
153
157
|
nestDependencies.push({
|
|
154
158
|
name: `${key.replace(/@nestjs\//, '').replace(/@.*/, '')} version`,
|
|
155
|
-
value:
|
|
159
|
+
value: this.readInstalledVersion(key) ?? dependencies[key].version,
|
|
156
160
|
packageName: key,
|
|
157
161
|
});
|
|
158
162
|
}
|
|
159
163
|
});
|
|
160
164
|
return nestDependencies;
|
|
161
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Reads the installed version of a package, or returns undefined when it
|
|
168
|
+
* cannot be determined (package not installed, or its "exports" map does
|
|
169
|
+
* not expose "./package.json" — as with @nestjs/* v12+).
|
|
170
|
+
*/
|
|
171
|
+
readInstalledVersion(packageName) {
|
|
172
|
+
let depPackagePath;
|
|
173
|
+
try {
|
|
174
|
+
depPackagePath = require.resolve(packageName + '/package.json', {
|
|
175
|
+
paths: [process.cwd()],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
depPackagePath = join(process.cwd(), 'node_modules', packageName, 'package.json');
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
return JSON.parse(readFileSync(depPackagePath).toString()).version;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
162
188
|
format(dependencies) {
|
|
189
|
+
if (dependencies.length === 0) {
|
|
190
|
+
return dependencies;
|
|
191
|
+
}
|
|
163
192
|
const sorted = dependencies.sort((dependencyA, dependencyB) => dependencyB.name.length - dependencyA.name.length);
|
|
164
193
|
const length = sorted[0].name.length;
|
|
165
194
|
sorted.forEach((dependency) => {
|
|
166
|
-
|
|
167
|
-
dependency.name = this.rightPad(dependency.name, length);
|
|
168
|
-
}
|
|
195
|
+
dependency.name = dependency.name.padEnd(length);
|
|
169
196
|
dependency.name = dependency.name.concat(' :');
|
|
170
|
-
dependency.value = dependency.value.replace(/(
|
|
197
|
+
dependency.value = dependency.value.replace(/([\^~])/, '');
|
|
171
198
|
});
|
|
172
199
|
return sorted;
|
|
173
200
|
}
|
|
174
|
-
rightPad(name, length) {
|
|
175
|
-
while (name.length < length) {
|
|
176
|
-
name = name.concat(' ');
|
|
177
|
-
}
|
|
178
|
-
return name;
|
|
179
|
-
}
|
|
180
201
|
}
|
|
181
|
-
exports.InfoAction = InfoAction;
|
package/actions/new.action.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { NewCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
3
|
export declare class NewAction extends AbstractAction {
|
|
4
|
-
handle(
|
|
4
|
+
handle(context: NewCommandContext): Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
export declare const retrieveCols: () => number;
|
|
7
7
|
export declare const exit: () => never;
|