@tsed/cli-core 7.0.0-alpha.8 → 7.0.0-beta.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/lib/esm/CliCore.js +21 -3
- package/lib/esm/services/index.js +0 -1
- package/lib/esm/utils/createInjector.js +9 -8
- package/lib/types/CliCore.d.ts +2 -0
- package/lib/types/interfaces/index.d.ts +9 -1
- package/lib/types/services/index.d.ts +0 -1
- package/lib/types/utils/createInjector.d.ts +1 -2
- package/package.json +3 -3
- package/lib/esm/services/CliConfiguration.js +0 -12
- package/lib/types/services/CliConfiguration.d.ts +0 -4
package/lib/esm/CliCore.js
CHANGED
|
@@ -8,7 +8,6 @@ import { Command } from "commander";
|
|
|
8
8
|
import semver from "semver";
|
|
9
9
|
import updateNotifier from "update-notifier";
|
|
10
10
|
import { CliError } from "./domains/CliError.js";
|
|
11
|
-
import { CliConfiguration } from "./services/CliConfiguration.js";
|
|
12
11
|
import { CliPackageJson } from "./services/CliPackageJson.js";
|
|
13
12
|
import { CliService } from "./services/CliService.js";
|
|
14
13
|
import { ProjectPackageJson } from "./services/ProjectPackageJson.js";
|
|
@@ -23,6 +22,19 @@ export class CliCore {
|
|
|
23
22
|
this.injector = inject(InjectorService);
|
|
24
23
|
this.cliService = inject(CliService);
|
|
25
24
|
}
|
|
25
|
+
static checkPrecondition(settings) {
|
|
26
|
+
const { pkg } = settings;
|
|
27
|
+
this.checkPackage(pkg);
|
|
28
|
+
if (pkg?.engines?.node) {
|
|
29
|
+
this.checkNodeVersion(pkg.engines.node, pkg.name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static checkPackage(pkg) {
|
|
33
|
+
if (!pkg) {
|
|
34
|
+
console.log(chalk.red(`settings.pkg is required. Require the package.json of your CLI when you bootstrap the CLI.`));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
static checkNodeVersion(wanted, id) {
|
|
27
39
|
if (!semver.satisfies(process.version, wanted)) {
|
|
28
40
|
console.log(chalk.red("You are using Node " +
|
|
@@ -45,11 +57,17 @@ export class CliCore {
|
|
|
45
57
|
return inject(CliCore);
|
|
46
58
|
}
|
|
47
59
|
static async bootstrap(settings, module = CliCore) {
|
|
60
|
+
if (settings.checkPrecondition) {
|
|
61
|
+
this.checkPrecondition(settings);
|
|
62
|
+
}
|
|
63
|
+
if (settings.updateNotifier) {
|
|
64
|
+
await this.updateNotifier(settings.pkg);
|
|
65
|
+
}
|
|
48
66
|
const cli = await this.create(settings, module);
|
|
49
67
|
return cli.bootstrap();
|
|
50
68
|
}
|
|
51
69
|
static async loadInjector(injector, module = CliCore) {
|
|
52
|
-
await
|
|
70
|
+
await $asyncEmit("$beforeInit");
|
|
53
71
|
injector.addProvider(CliCore, {
|
|
54
72
|
useClass: module
|
|
55
73
|
});
|
|
@@ -93,4 +111,4 @@ export class CliCore {
|
|
|
93
111
|
return this;
|
|
94
112
|
}
|
|
95
113
|
}
|
|
96
|
-
injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService
|
|
114
|
+
injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService]);
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import "@tsed/logger-std";
|
|
2
2
|
import "@tsed/logger-pattern-layout";
|
|
3
|
-
import {
|
|
3
|
+
import { injector } from "@tsed/di";
|
|
4
4
|
import { Logger } from "@tsed/logger";
|
|
5
|
-
import { CliConfiguration } from "../services/CliConfiguration.js";
|
|
6
5
|
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
7
6
|
let logger;
|
|
8
7
|
export function getLogger() {
|
|
9
8
|
return logger;
|
|
10
9
|
}
|
|
11
|
-
function createConfiguration(injector) {
|
|
12
|
-
injector.addProvider(CliConfiguration);
|
|
13
|
-
return inject(CliConfiguration);
|
|
14
|
-
}
|
|
15
10
|
export function createInjector(settings = {}) {
|
|
16
11
|
const inj = injector();
|
|
17
|
-
inj.settings = createConfiguration(inj);
|
|
18
12
|
logger = inj.logger = new Logger(settings.name || "CLI");
|
|
19
13
|
inj.addProvider(ProjectPackageJson);
|
|
20
|
-
inj.settings.set(
|
|
14
|
+
inj.settings.set({
|
|
15
|
+
...settings,
|
|
16
|
+
project: {
|
|
17
|
+
root: process.cwd(),
|
|
18
|
+
srcDir: "src",
|
|
19
|
+
...(settings.project || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
21
22
|
/* istanbul ignore next */
|
|
22
23
|
if (inj.settings.env === "test") {
|
|
23
24
|
inj.logger.stop();
|
package/lib/types/CliCore.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { CliService } from "./services/CliService.js";
|
|
|
5
5
|
export declare class CliCore {
|
|
6
6
|
readonly injector: InjectorService;
|
|
7
7
|
readonly cliService: CliService;
|
|
8
|
+
static checkPrecondition(settings: any): void;
|
|
9
|
+
static checkPackage(pkg: any): void;
|
|
8
10
|
static checkNodeVersion(wanted: string, id: string): typeof CliCore;
|
|
9
11
|
static create<Cli extends CliCore = CliCore>(settings: Partial<TsED.Configuration>, module?: Type): Promise<Cli>;
|
|
10
12
|
static bootstrap(settings: Partial<TsED.Configuration>, module?: Type): Promise<CliCore>;
|
|
@@ -33,7 +33,7 @@ declare global {
|
|
|
33
33
|
*/
|
|
34
34
|
templateDir?: string;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* A function that return default projet settings set in fresh project.
|
|
37
37
|
* @param pkg
|
|
38
38
|
*/
|
|
39
39
|
defaultProjectPreferences?: (pkg?: any) => Record<string, any>;
|
|
@@ -50,6 +50,14 @@ declare global {
|
|
|
50
50
|
* Enable plugins loading
|
|
51
51
|
*/
|
|
52
52
|
plugins: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check version and node version before running a command
|
|
55
|
+
*/
|
|
56
|
+
checkPrecondition?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Display available update on terminal before running a command
|
|
59
|
+
*/
|
|
60
|
+
updateNotifier?: boolean;
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "@tsed/logger-std";
|
|
2
2
|
import "@tsed/logger-pattern-layout";
|
|
3
|
-
import { InjectorService } from "@tsed/di";
|
|
4
3
|
import { Logger } from "@tsed/logger";
|
|
5
4
|
declare global {
|
|
6
5
|
namespace TsED {
|
|
@@ -13,4 +12,4 @@ declare global {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
export declare function getLogger(): Logger;
|
|
16
|
-
export declare function createInjector(settings?: Partial<TsED.Configuration>): InjectorService;
|
|
15
|
+
export declare function createInjector(settings?: Partial<TsED.Configuration>): import("@tsed/di").InjectorService;
|
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-
|
|
4
|
+
"version": "7.0.0-beta.1",
|
|
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-
|
|
68
|
+
"@tsed/typescript": "7.0.0-beta.1",
|
|
69
69
|
"@types/commander": "2.12.2",
|
|
70
70
|
"@types/figures": "3.0.1",
|
|
71
71
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -105,6 +105,6 @@
|
|
|
105
105
|
"author": "Romain Lenzotti",
|
|
106
106
|
"license": "MIT",
|
|
107
107
|
"publishConfig": {
|
|
108
|
-
"tag": "
|
|
108
|
+
"tag": "beta"
|
|
109
109
|
}
|
|
110
110
|
}
|