@nestjs/cli 11.0.16 → 12.0.0-alpha.1
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/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 +38 -52
- package/actions/build.action.d.ts +11 -10
- package/actions/build.action.js +85 -72
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +56 -59
- package/actions/index.d.ts +7 -7
- package/actions/index.js +7 -23
- package/actions/info.action.d.ts +12 -28
- package/actions/info.action.js +47 -55
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +75 -105
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +36 -46
- package/bin/nest.js +14 -10
- 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 +13 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +25 -54
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +18 -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 +13 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/generate.context.d.ts +15 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +5 -0
- package/commands/context/index.js +5 -0
- package/commands/context/new.context.d.ts +11 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +19 -0
- package/commands/context/start.context.js +1 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +26 -54
- 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 +2 -6
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +24 -33
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +34 -71
- package/lib/compiler/assets-manager.d.ts +1 -1
- package/lib/compiler/assets-manager.js +27 -33
- 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 +2 -0
- package/lib/compiler/defaults/rspack-defaults.js +138 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +1 -1
- package/lib/compiler/defaults/swc-defaults.js +1 -5
- package/lib/compiler/defaults/webpack-defaults.d.ts +3 -3
- package/lib/compiler/defaults/webpack-defaults.js +36 -18
- 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 +5 -8
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +9 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +15 -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/manual-restart.js +4 -8
- package/lib/compiler/helpers/tsconfig-provider.d.ts +1 -1
- package/lib/compiler/helpers/tsconfig-provider.js +8 -11
- 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 +1 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +10 -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 +13 -13
- package/lib/compiler/rspack-compiler.d.ts +19 -0
- package/lib/compiler/rspack-compiler.js +105 -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 +4 -4
- package/lib/compiler/swc/swc-compiler.js +41 -39
- package/lib/compiler/swc/type-checker-host.js +12 -18
- package/lib/compiler/typescript-loader.js +5 -7
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +14 -18
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +30 -22
- package/lib/configuration/configuration.d.ts +9 -4
- 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 +11 -20
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +19 -30
- package/lib/package-managers/index.d.ts +8 -8
- package/lib/package-managers/index.js +8 -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.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +16 -20
- package/lib/package-managers/package-manager.js +2 -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 +10 -12
- 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/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.factory.d.ts +6 -6
- package/lib/runners/runner.factory.js +15 -20
- package/lib/runners/runner.js +2 -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 +104 -108
- package/lib/schematics/schematic.option.js +7 -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 -5
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.js +15 -19
- package/lib/ui/prefixes.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-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 +1 -1
- package/lib/utils/local-binaries.js +8 -11
- 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 +2 -5
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +59 -38
package/actions/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
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';
|
package/actions/info.action.d.ts
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
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
|
-
format
|
|
33
|
-
rightPad(name: string, length: number): string;
|
|
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
|
+
private format;
|
|
34
19
|
}
|
|
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,7 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
80
81
|
}
|
|
81
82
|
displayNestVersions(dependencies) {
|
|
82
83
|
const nestDependencies = this.buildNestVersionsMessage(dependencies);
|
|
83
|
-
nestDependencies.forEach((dependency) => console.info(dependency.name,
|
|
84
|
+
nestDependencies.forEach((dependency) => console.info(dependency.name, blue(dependency.value)));
|
|
84
85
|
this.displayWarningMessage(nestDependencies);
|
|
85
86
|
}
|
|
86
87
|
displayWarningMessage(nestDependencies) {
|
|
@@ -89,11 +90,11 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
89
90
|
const majorVersions = Object.keys(warnings);
|
|
90
91
|
if (majorVersions.length > 0) {
|
|
91
92
|
console.info('\r');
|
|
92
|
-
console.info(
|
|
93
|
+
console.info(yellow `[Warnings]`);
|
|
93
94
|
console.info('The following packages are not in the same major version');
|
|
94
95
|
console.info('This could lead to runtime errors');
|
|
95
96
|
majorVersions.forEach((version) => {
|
|
96
|
-
console.info(
|
|
97
|
+
console.info(bold `* Under version ${version}`);
|
|
97
98
|
warnings[version].forEach(({ packageName, value }) => {
|
|
98
99
|
console.info(`- ${packageName} ${value}`);
|
|
99
100
|
});
|
|
@@ -102,7 +103,7 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
102
103
|
}
|
|
103
104
|
catch {
|
|
104
105
|
console.info('\t');
|
|
105
|
-
console.error(
|
|
106
|
+
console.error(red(MESSAGES.NEST_INFORMATION_PACKAGE_WARNING_FAILED(this.warningMessageDependenciesWhiteList)));
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
buildNestVersionsWarningMessage(nestDependencies) {
|
|
@@ -148,7 +149,7 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
148
149
|
const depPackagePath = require.resolve(key + '/package.json', {
|
|
149
150
|
paths: [process.cwd()],
|
|
150
151
|
});
|
|
151
|
-
const depPackage =
|
|
152
|
+
const depPackage = readFileSync(depPackagePath).toString();
|
|
152
153
|
const value = JSON.parse(depPackage).version;
|
|
153
154
|
nestDependencies.push({
|
|
154
155
|
name: `${key.replace(/@nestjs\//, '').replace(/@.*/, '')} version`,
|
|
@@ -163,19 +164,10 @@ class InfoAction extends abstract_action_1.AbstractAction {
|
|
|
163
164
|
const sorted = dependencies.sort((dependencyA, dependencyB) => dependencyB.name.length - dependencyA.name.length);
|
|
164
165
|
const length = sorted[0].name.length;
|
|
165
166
|
sorted.forEach((dependency) => {
|
|
166
|
-
|
|
167
|
-
dependency.name = this.rightPad(dependency.name, length);
|
|
168
|
-
}
|
|
167
|
+
dependency.name = dependency.name.padEnd(length);
|
|
169
168
|
dependency.name = dependency.name.concat(' :');
|
|
170
|
-
dependency.value = dependency.value.replace(/(
|
|
169
|
+
dependency.value = dependency.value.replace(/([\^~])/, '');
|
|
171
170
|
});
|
|
172
171
|
return sorted;
|
|
173
172
|
}
|
|
174
|
-
rightPad(name, length) {
|
|
175
|
-
while (name.length < length) {
|
|
176
|
-
name = name.concat(' ');
|
|
177
|
-
}
|
|
178
|
-
return name;
|
|
179
|
-
}
|
|
180
173
|
}
|
|
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;
|
package/actions/new.action.js
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const dryRunOption = options.find((option) => option.name === 'dry-run');
|
|
23
|
-
const isDryRunEnabled = dryRunOption && dryRunOption.value;
|
|
24
|
-
await askForMissingInformation(inputs, options);
|
|
25
|
-
await generateApplicationFiles(inputs, options).catch(exports.exit);
|
|
26
|
-
const shouldSkipInstall = options.some((option) => option.name === 'skip-install' && option.value === true);
|
|
27
|
-
const shouldSkipGit = options.some((option) => option.name === 'skip-git' && option.value === true);
|
|
28
|
-
const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
|
|
29
|
-
if (!shouldSkipInstall) {
|
|
30
|
-
await installPackages(options, isDryRunEnabled, projectDirectory);
|
|
1
|
+
import { input, select } from '@inquirer/prompts';
|
|
2
|
+
import ansis from 'ansis';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { defaultGitIgnore } from '../lib/configuration/defaults.js';
|
|
7
|
+
import { PackageManager, PackageManagerFactory, } from '../lib/package-managers/index.js';
|
|
8
|
+
import { generateInput, generateSelect } from '../lib/questions/questions.js';
|
|
9
|
+
import { GitRunner } from '../lib/runners/git.runner.js';
|
|
10
|
+
import { Collection, CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
11
|
+
import { EMOJIS, MESSAGES } from '../lib/ui/index.js';
|
|
12
|
+
import { normalizeToKebabOrSnakeCase } from '../lib/utils/formatting.js';
|
|
13
|
+
import { gracefullyExitOnPromptError } from '../lib/utils/gracefully-exit-on-prompt-error.js';
|
|
14
|
+
import { AbstractAction } from './abstract.action.js';
|
|
15
|
+
export class NewAction extends AbstractAction {
|
|
16
|
+
async handle(context) {
|
|
17
|
+
await askForMissingInformation(context);
|
|
18
|
+
await generateApplicationFiles(context).catch(exit);
|
|
19
|
+
const projectDirectory = getProjectDirectory(context);
|
|
20
|
+
if (!context.skipInstall) {
|
|
21
|
+
await installPackages(context, projectDirectory);
|
|
31
22
|
}
|
|
32
|
-
if (!
|
|
33
|
-
if (!
|
|
23
|
+
if (!context.dryRun) {
|
|
24
|
+
if (!context.skipGit) {
|
|
34
25
|
await initializeGitRepository(projectDirectory);
|
|
35
26
|
await createGitIgnoreFile(projectDirectory);
|
|
36
27
|
}
|
|
@@ -39,81 +30,72 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
39
30
|
process.exit(0);
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const getPackageManagerInput = (inputs) => inputs.find((options) => options.name === 'packageManager');
|
|
45
|
-
const getProjectDirectory = (applicationName, directoryOption) => {
|
|
46
|
-
return ((directoryOption && directoryOption.value) ||
|
|
47
|
-
(0, formatting_1.normalizeToKebabOrSnakeCase)(applicationName.value));
|
|
33
|
+
const getProjectDirectory = (context) => {
|
|
34
|
+
return (context.directory || normalizeToKebabOrSnakeCase(context.name));
|
|
48
35
|
};
|
|
49
|
-
const askForMissingInformation = async (
|
|
50
|
-
console.info(
|
|
36
|
+
const askForMissingInformation = async (context) => {
|
|
37
|
+
console.info(MESSAGES.PROJECT_INFORMATION_START);
|
|
51
38
|
console.info();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const answer = await (0, prompts_1.input)(question).catch(gracefully_exit_on_prompt_error_1.gracefullyExitOnPromptError);
|
|
57
|
-
replaceInputMissingInformation(inputs, { name: 'name', value: answer });
|
|
39
|
+
if (!context.name) {
|
|
40
|
+
const message = MESSAGES.PROJECT_NAME_QUESTION;
|
|
41
|
+
const question = generateInput('name', message)('nest-app');
|
|
42
|
+
context.name = (await input(question).catch(gracefullyExitOnPromptError));
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const answer = await askForPackageManager();
|
|
62
|
-
replaceInputMissingInformation(options, {
|
|
63
|
-
name: 'packageManager',
|
|
64
|
-
value: answer,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const replaceInputMissingInformation = (inputs, answer) => {
|
|
69
|
-
const input = inputs.find((input) => input.name === answer.name);
|
|
70
|
-
if (input) {
|
|
71
|
-
input.value = input.value !== undefined ? input.value : answer.value;
|
|
44
|
+
if (!context.packageManager) {
|
|
45
|
+
context.packageManager = (await askForPackageManager());
|
|
72
46
|
}
|
|
73
47
|
};
|
|
74
|
-
const generateApplicationFiles = async (
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const schematicOptions = mapSchematicOptions(args.concat(options));
|
|
48
|
+
const generateApplicationFiles = async (context) => {
|
|
49
|
+
const collection = CollectionFactory.create(context.collection || Collection.NESTJS);
|
|
50
|
+
const schematicOptions = mapContextToSchematicOptions(context);
|
|
78
51
|
await collection.execute('application', schematicOptions);
|
|
79
52
|
console.info();
|
|
80
53
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
const mapContextToSchematicOptions = (context) => {
|
|
55
|
+
const options = [];
|
|
56
|
+
if (context.name !== undefined)
|
|
57
|
+
options.push(new SchematicOption('name', context.name));
|
|
58
|
+
if (context.directory !== undefined)
|
|
59
|
+
options.push(new SchematicOption('directory', context.directory));
|
|
60
|
+
if (context.dryRun)
|
|
61
|
+
options.push(new SchematicOption('dry-run', true));
|
|
62
|
+
options.push(new SchematicOption('skip-git', context.skipGit));
|
|
63
|
+
options.push(new SchematicOption('strict', context.strict));
|
|
64
|
+
if (context.packageManager !== undefined)
|
|
65
|
+
options.push(new SchematicOption('packageManager', context.packageManager));
|
|
66
|
+
if (context.collection !== undefined)
|
|
67
|
+
options.push(new SchematicOption('collection', context.collection));
|
|
68
|
+
options.push(new SchematicOption('language', context.language));
|
|
69
|
+
// note: skip-install is intentionally excluded — not sent to schematics
|
|
70
|
+
return options;
|
|
89
71
|
};
|
|
90
|
-
const installPackages = async (
|
|
91
|
-
const inputPackageManager =
|
|
72
|
+
const installPackages = async (context, installDirectory) => {
|
|
73
|
+
const inputPackageManager = context.packageManager;
|
|
92
74
|
let packageManager;
|
|
93
|
-
if (
|
|
75
|
+
if (context.dryRun) {
|
|
94
76
|
console.info();
|
|
95
|
-
console.info(ansis.green(
|
|
77
|
+
console.info(ansis.green(MESSAGES.DRY_RUN_MODE));
|
|
96
78
|
console.info();
|
|
97
79
|
return;
|
|
98
80
|
}
|
|
99
81
|
try {
|
|
100
|
-
packageManager =
|
|
82
|
+
packageManager = PackageManagerFactory.create(inputPackageManager);
|
|
101
83
|
await packageManager.install(installDirectory, inputPackageManager);
|
|
102
84
|
}
|
|
103
85
|
catch (error) {
|
|
104
|
-
if (error
|
|
86
|
+
if (error instanceof Error) {
|
|
105
87
|
console.error(ansis.red(error.message));
|
|
106
88
|
}
|
|
107
89
|
}
|
|
108
90
|
};
|
|
109
91
|
const askForPackageManager = async () => {
|
|
110
|
-
const question =
|
|
111
|
-
return
|
|
92
|
+
const question = generateSelect('packageManager')(MESSAGES.PACKAGE_MANAGER_QUESTION)([PackageManager.NPM, PackageManager.YARN, PackageManager.PNPM]);
|
|
93
|
+
return select(question).catch(gracefullyExitOnPromptError);
|
|
112
94
|
};
|
|
113
95
|
const initializeGitRepository = async (dir) => {
|
|
114
|
-
const runner = new
|
|
115
|
-
await runner.run('init', true,
|
|
116
|
-
console.error(ansis.red(
|
|
96
|
+
const runner = new GitRunner();
|
|
97
|
+
await runner.run('init', true, join(process.cwd(), dir)).catch(() => {
|
|
98
|
+
console.error(ansis.red(MESSAGES.GIT_INITIALIZATION_ERROR));
|
|
117
99
|
});
|
|
118
100
|
};
|
|
119
101
|
/**
|
|
@@ -127,8 +109,8 @@ const initializeGitRepository = async (dir) => {
|
|
|
127
109
|
* @return Resolves when succeeds, or rejects with any error from `fn.writeFile`.
|
|
128
110
|
*/
|
|
129
111
|
const createGitIgnoreFile = (dir, content) => {
|
|
130
|
-
const fileContent = content ||
|
|
131
|
-
const filePath =
|
|
112
|
+
const fileContent = content || defaultGitIgnore;
|
|
113
|
+
const filePath = join(process.cwd(), dir, '.gitignore');
|
|
132
114
|
if (fileExists(filePath)) {
|
|
133
115
|
return;
|
|
134
116
|
}
|
|
@@ -139,17 +121,18 @@ const printCollective = () => {
|
|
|
139
121
|
const yellow = print('yellow');
|
|
140
122
|
const emptyLine = print();
|
|
141
123
|
emptyLine();
|
|
142
|
-
yellow(`Thanks for installing Nest ${
|
|
124
|
+
yellow(`Thanks for installing Nest ${EMOJIS.PRAY}`);
|
|
143
125
|
dim('Please consider donating to our open collective');
|
|
144
126
|
dim('to help us maintain this package.');
|
|
145
127
|
emptyLine();
|
|
146
128
|
emptyLine();
|
|
147
|
-
print()(`${ansis.bold `${
|
|
129
|
+
print()(`${ansis.bold `${EMOJIS.WINE} Donate:`} ${ansis.underline('https://opencollective.com/nest')}`);
|
|
148
130
|
emptyLine();
|
|
149
131
|
};
|
|
150
132
|
const print = (color = null) => (str = '') => {
|
|
151
|
-
const terminalCols =
|
|
152
|
-
|
|
133
|
+
const terminalCols = retrieveCols();
|
|
134
|
+
// eslint-disable-next-line no-control-regex
|
|
135
|
+
const strLength = str.replace(/\x1b\[[0-9]+m/g, '').length;
|
|
153
136
|
const leftPaddingLength = Math.floor((terminalCols - strLength) / 2);
|
|
154
137
|
const leftPadding = ' '.repeat(Math.max(leftPaddingLength, 0));
|
|
155
138
|
if (color) {
|
|
@@ -157,10 +140,10 @@ const print = (color = null) => (str = '') => {
|
|
|
157
140
|
}
|
|
158
141
|
console.log(leftPadding, str);
|
|
159
142
|
};
|
|
160
|
-
const retrieveCols = () => {
|
|
143
|
+
export const retrieveCols = () => {
|
|
161
144
|
const defaultCols = 80;
|
|
162
145
|
try {
|
|
163
|
-
const terminalCols =
|
|
146
|
+
const terminalCols = execSync('tput cols', {
|
|
164
147
|
stdio: ['pipe', 'pipe', 'ignore'],
|
|
165
148
|
});
|
|
166
149
|
return parseInt(terminalCols.toString(), 10) || defaultCols;
|
|
@@ -169,18 +152,5 @@ const retrieveCols = () => {
|
|
|
169
152
|
return defaultCols;
|
|
170
153
|
}
|
|
171
154
|
};
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
try {
|
|
175
|
-
fs.accessSync(path);
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
if (err.code === 'ENOENT') {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
throw err;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const exit = () => process.exit(1);
|
|
186
|
-
exports.exit = exit;
|
|
155
|
+
const fileExists = (path) => fs.existsSync(path);
|
|
156
|
+
export const exit = () => process.exit(1);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BuildAction } from './build.action';
|
|
1
|
+
import { StartCommandContext } from '../commands/index.js';
|
|
2
|
+
import { BuildAction } from './build.action.js';
|
|
3
3
|
export declare class StartAction extends BuildAction {
|
|
4
|
-
handle(
|
|
5
|
-
createOnSuccessHook
|
|
6
|
-
shell: boolean;
|
|
7
|
-
envFile?: string[];
|
|
8
|
-
}): () => void;
|
|
4
|
+
handle(context: StartCommandContext): Promise<void>;
|
|
5
|
+
private createOnSuccessHook;
|
|
9
6
|
private spawnChildProcess;
|
|
10
7
|
}
|