@tsed/cli-core 7.0.0-beta.1 → 7.0.0-beta.2
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/lib/esm/CliCore.js +20 -39
- package/lib/esm/services/ProjectPackageJson.js +17 -4
- package/lib/esm/utils/createInjector.js +1 -1
- package/lib/types/CliCore.d.ts +2 -9
- package/lib/types/services/ProjectPackageJson.d.ts +9 -0
- package/lib/types/utils/resolveConfiguration.d.ts +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
package/lib/esm/CliCore.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import "@tsed/logger-std";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { inject, injectable, InjectorService } from "@tsed/di";
|
|
3
|
+
import { constant, inject, injector } from "@tsed/di";
|
|
5
4
|
import { $asyncEmit } from "@tsed/hooks";
|
|
6
5
|
import chalk from "chalk";
|
|
7
6
|
import { Command } from "commander";
|
|
8
7
|
import semver from "semver";
|
|
9
8
|
import updateNotifier from "update-notifier";
|
|
10
9
|
import { CliError } from "./domains/CliError.js";
|
|
11
|
-
import { CliPackageJson } from "./services/CliPackageJson.js";
|
|
12
10
|
import { CliService } from "./services/CliService.js";
|
|
13
|
-
import { ProjectPackageJson } from "./services/ProjectPackageJson.js";
|
|
14
11
|
import { createInjector } from "./utils/createInjector.js";
|
|
15
12
|
import { loadPlugins } from "./utils/loadPlugins.js";
|
|
16
13
|
import { resolveConfiguration } from "./utils/resolveConfiguration.js";
|
|
@@ -18,9 +15,8 @@ function isHelpManual(argv) {
|
|
|
18
15
|
return argv.includes("-h") || argv.includes("--help");
|
|
19
16
|
}
|
|
20
17
|
export class CliCore {
|
|
21
|
-
constructor() {
|
|
22
|
-
|
|
23
|
-
this.cliService = inject(CliService);
|
|
18
|
+
constructor(settings) {
|
|
19
|
+
createInjector(settings);
|
|
24
20
|
}
|
|
25
21
|
static checkPrecondition(settings) {
|
|
26
22
|
const { pkg } = settings;
|
|
@@ -48,51 +44,30 @@ export class CliCore {
|
|
|
48
44
|
}
|
|
49
45
|
return this;
|
|
50
46
|
}
|
|
51
|
-
static async
|
|
52
|
-
settings = resolveConfiguration(settings);
|
|
53
|
-
const injector = this.createInjector(settings);
|
|
54
|
-
settings.plugins && (await loadPlugins());
|
|
55
|
-
await this.loadInjector(injector, module);
|
|
56
|
-
await $asyncEmit("$onReady");
|
|
57
|
-
return inject(CliCore);
|
|
58
|
-
}
|
|
59
|
-
static async bootstrap(settings, module = CliCore) {
|
|
47
|
+
static async bootstrap(settings) {
|
|
60
48
|
if (settings.checkPrecondition) {
|
|
61
49
|
this.checkPrecondition(settings);
|
|
62
50
|
}
|
|
63
51
|
if (settings.updateNotifier) {
|
|
64
52
|
await this.updateNotifier(settings.pkg);
|
|
65
53
|
}
|
|
66
|
-
|
|
67
|
-
return cli.bootstrap();
|
|
68
|
-
}
|
|
69
|
-
static async loadInjector(injector, module = CliCore) {
|
|
70
|
-
await $asyncEmit("$beforeInit");
|
|
71
|
-
injector.addProvider(CliCore, {
|
|
72
|
-
useClass: module
|
|
73
|
-
});
|
|
74
|
-
await injector.load();
|
|
75
|
-
await injector.invoke(module);
|
|
76
|
-
await $asyncEmit("$afterInit");
|
|
77
|
-
injector.settings.set("loaded", true);
|
|
78
|
-
}
|
|
79
|
-
static async updateNotifier(pkg) {
|
|
80
|
-
updateNotifier({ pkg, updateCheckInterval: 0 }).notify();
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
static createInjector(settings) {
|
|
54
|
+
settings = resolveConfiguration(settings);
|
|
84
55
|
const argv = settings.argv || process.argv;
|
|
85
|
-
return
|
|
56
|
+
return new CliCore({
|
|
86
57
|
...settings,
|
|
87
58
|
name: settings.name || "tsed",
|
|
88
59
|
argv,
|
|
89
60
|
project: {
|
|
90
|
-
rootDir: this.getProjectRoot(argv),
|
|
61
|
+
// rootDir: this.getProjectRoot(argv),
|
|
91
62
|
srcDir: "src",
|
|
92
63
|
scriptsDir: "scripts",
|
|
93
64
|
...(settings.project || {})
|
|
94
65
|
}
|
|
95
|
-
});
|
|
66
|
+
}).bootstrap();
|
|
67
|
+
}
|
|
68
|
+
static async updateNotifier(pkg) {
|
|
69
|
+
updateNotifier({ pkg, updateCheckInterval: 0 }).notify();
|
|
70
|
+
return this;
|
|
96
71
|
}
|
|
97
72
|
static getProjectRoot(argv) {
|
|
98
73
|
if (!isHelpManual(argv)) {
|
|
@@ -103,7 +78,14 @@ export class CliCore {
|
|
|
103
78
|
}
|
|
104
79
|
async bootstrap() {
|
|
105
80
|
try {
|
|
106
|
-
|
|
81
|
+
const cliService = inject(CliService);
|
|
82
|
+
constant("plugins") && (await loadPlugins());
|
|
83
|
+
await $asyncEmit("$beforeInit");
|
|
84
|
+
await injector().load();
|
|
85
|
+
await $asyncEmit("$afterInit");
|
|
86
|
+
injector().settings.set("loaded", true);
|
|
87
|
+
await $asyncEmit("$onReady");
|
|
88
|
+
await cliService.parseArgs(constant("argv"));
|
|
107
89
|
}
|
|
108
90
|
catch (er) {
|
|
109
91
|
throw new CliError({ origin: er, cli: this });
|
|
@@ -111,4 +93,3 @@ export class CliCore {
|
|
|
111
93
|
return this;
|
|
112
94
|
}
|
|
113
95
|
}
|
|
114
|
-
injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService]);
|
|
@@ -45,12 +45,21 @@ export class ProjectPackageJson {
|
|
|
45
45
|
get path() {
|
|
46
46
|
return join(this.dir, "package.json");
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated
|
|
50
|
+
*/
|
|
48
51
|
get dir() {
|
|
49
|
-
return
|
|
52
|
+
return this.cwd;
|
|
50
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated
|
|
56
|
+
* @param dir
|
|
57
|
+
*/
|
|
51
58
|
set dir(dir) {
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
this.setCWD(dir);
|
|
60
|
+
}
|
|
61
|
+
get cwd() {
|
|
62
|
+
return String(constant("project.rootDir"));
|
|
54
63
|
}
|
|
55
64
|
get name() {
|
|
56
65
|
return this.raw.name;
|
|
@@ -83,6 +92,10 @@ export class ProjectPackageJson {
|
|
|
83
92
|
get preferences() {
|
|
84
93
|
return this.raw[constant("name")];
|
|
85
94
|
}
|
|
95
|
+
setCWD(dir) {
|
|
96
|
+
configuration().set("project.rootDir", dir);
|
|
97
|
+
this.read();
|
|
98
|
+
}
|
|
86
99
|
fillWithPreferences(ctx) {
|
|
87
100
|
return {
|
|
88
101
|
...ctx,
|
|
@@ -222,7 +235,7 @@ export class ProjectPackageJson {
|
|
|
222
235
|
refresh() {
|
|
223
236
|
this.reinstall = false;
|
|
224
237
|
this.rewrite = false;
|
|
225
|
-
const cwd =
|
|
238
|
+
const cwd = this.cwd;
|
|
226
239
|
const pkgPath = join(String(cwd), "package.json");
|
|
227
240
|
const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
|
|
228
241
|
pkg.scripts = {
|
package/lib/types/CliCore.d.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import "@tsed/logger-std";
|
|
2
|
-
import { Type } from "@tsed/core";
|
|
3
|
-
import { InjectorService } from "@tsed/di";
|
|
4
|
-
import { CliService } from "./services/CliService.js";
|
|
5
2
|
export declare class CliCore {
|
|
6
|
-
|
|
7
|
-
readonly cliService: CliService;
|
|
3
|
+
protected constructor(settings: Partial<TsED.Configuration>);
|
|
8
4
|
static checkPrecondition(settings: any): void;
|
|
9
5
|
static checkPackage(pkg: any): void;
|
|
10
6
|
static checkNodeVersion(wanted: string, id: string): typeof CliCore;
|
|
11
|
-
static
|
|
12
|
-
static bootstrap(settings: Partial<TsED.Configuration>, module?: Type): Promise<CliCore>;
|
|
13
|
-
static loadInjector(injector: InjectorService, module?: Type): Promise<void>;
|
|
7
|
+
static bootstrap(settings: Partial<TsED.Configuration>): Promise<CliCore>;
|
|
14
8
|
static updateNotifier(pkg: any): Promise<typeof CliCore>;
|
|
15
|
-
protected static createInjector(settings: Partial<TsED.Configuration>): InjectorService;
|
|
16
9
|
protected static getProjectRoot(argv: string[]): string;
|
|
17
10
|
bootstrap(): Promise<this>;
|
|
18
11
|
}
|
|
@@ -9,8 +9,16 @@ export declare class ProjectPackageJson {
|
|
|
9
9
|
private raw;
|
|
10
10
|
constructor();
|
|
11
11
|
get path(): string;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
12
15
|
get dir(): string;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
* @param dir
|
|
19
|
+
*/
|
|
13
20
|
set dir(dir: string);
|
|
21
|
+
get cwd(): string;
|
|
14
22
|
get name(): string;
|
|
15
23
|
set name(name: string);
|
|
16
24
|
get version(): string;
|
|
@@ -28,6 +36,7 @@ export declare class ProjectPackageJson {
|
|
|
28
36
|
[key: string]: string;
|
|
29
37
|
};
|
|
30
38
|
get preferences(): ProjectPreferences;
|
|
39
|
+
setCWD(dir: string): void;
|
|
31
40
|
fillWithPreferences<T extends {}>(ctx: T): T & {
|
|
32
41
|
packageManager: import("../interfaces/ProjectPreferences.js").PackageManager;
|
|
33
42
|
runtime: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function resolveConfiguration(settings:
|
|
1
|
+
export declare function resolveConfiguration(settings: Partial<TsED.Configuration>): Partial<TsED.Configuration>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-core",
|
|
3
3
|
"description": "Build your CLI with TypeScript and Decorators",
|
|
4
|
-
"version": "7.0.0-beta.
|
|
4
|
+
"version": "7.0.0-beta.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"uuid": "^10.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@tsed/typescript": "7.0.0-beta.
|
|
68
|
+
"@tsed/typescript": "7.0.0-beta.2",
|
|
69
69
|
"@types/commander": "2.12.2",
|
|
70
70
|
"@types/figures": "3.0.1",
|
|
71
71
|
"@types/fs-extra": "^11.0.4",
|
package/readme.md
CHANGED
|
@@ -216,7 +216,7 @@ website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
|
216
216
|
|
|
217
217
|
The MIT License (MIT)
|
|
218
218
|
|
|
219
|
-
Copyright (c) 2016 -
|
|
219
|
+
Copyright (c) 2016 - Today Romain Lenzotti
|
|
220
220
|
|
|
221
221
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
222
222
|
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|