@tsed/cli-core 6.6.2 → 7.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/lib/esm/CliCore.js +12 -19
- package/lib/esm/decorators/command.js +4 -4
- package/lib/esm/fn/command.js +5 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/interfaces/CommandData.js +1 -0
- package/lib/esm/interfaces/CommandProvider.js +2 -1
- package/lib/esm/interfaces/index.js +1 -0
- package/lib/esm/packageManagers/PackageManagersModule.js +2 -4
- package/lib/esm/services/CliConfiguration.js +4 -9
- package/lib/esm/services/CliDockerComposeYaml.js +4 -8
- package/lib/esm/services/CliExeca.js +4 -8
- package/lib/esm/services/CliFs.js +16 -11
- package/lib/esm/services/CliHooks.js +4 -8
- package/lib/esm/services/CliHttpClient.js +5 -10
- package/lib/esm/services/CliLoadFile.js +4 -9
- package/lib/esm/services/CliPackageJson.js +3 -7
- package/lib/esm/services/CliPlugins.js +4 -8
- package/lib/esm/services/CliProxyAgent.js +10 -15
- package/lib/esm/services/CliService.js +20 -18
- package/lib/esm/services/CliYaml.js +4 -8
- package/lib/esm/services/NpmRegistryClient.js +5 -10
- package/lib/esm/services/ProjectPackageJson.js +15 -11
- package/lib/esm/utils/createInjector.js +2 -2
- package/lib/types/fn/command.d.ts +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/interfaces/CommandData.d.ts +12 -0
- package/lib/types/interfaces/CommandMetadata.d.ts +1 -1
- package/lib/types/interfaces/CommandProvider.d.ts +7 -0
- package/lib/types/interfaces/index.d.ts +1 -0
- package/lib/types/services/CliDockerComposeYaml.d.ts +2 -1
- package/lib/types/services/CliFs.d.ts +7 -1
- package/lib/types/services/CliProxyAgent.d.ts +2 -1
- package/lib/types/services/CliService.d.ts +8 -6
- package/lib/types/services/ProjectPackageJson.d.ts +6 -0
- package/package.json +9 -6
- package/readme.md +5 -104
package/lib/esm/CliCore.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
var CliCore_1;
|
|
2
|
-
import { __decorate } from "tslib";
|
|
3
1
|
import "@tsed/logger-std";
|
|
4
|
-
// import "@tsed/logger/layouts/ColoredLayout";
|
|
5
2
|
import { join, resolve } from "node:path";
|
|
6
3
|
import { Type } from "@tsed/core";
|
|
7
|
-
import { inject,
|
|
4
|
+
import { inject, injectable, InjectorService } from "@tsed/di";
|
|
5
|
+
import { $asyncEmit } from "@tsed/hooks";
|
|
8
6
|
import chalk from "chalk";
|
|
9
7
|
import { Command } from "commander";
|
|
10
8
|
import semver from "semver";
|
|
@@ -20,7 +18,7 @@ import { resolveConfiguration } from "./utils/resolveConfiguration.js";
|
|
|
20
18
|
function isHelpManual(argv) {
|
|
21
19
|
return argv.includes("-h") || argv.includes("--help");
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
export class CliCore {
|
|
24
22
|
constructor() {
|
|
25
23
|
this.injector = inject(InjectorService);
|
|
26
24
|
this.cliService = inject(CliService);
|
|
@@ -38,26 +36,26 @@ let CliCore = CliCore_1 = class CliCore {
|
|
|
38
36
|
}
|
|
39
37
|
return this;
|
|
40
38
|
}
|
|
41
|
-
static async create(settings, module =
|
|
39
|
+
static async create(settings, module = CliCore) {
|
|
42
40
|
settings = resolveConfiguration(settings);
|
|
43
41
|
const injector = this.createInjector(settings);
|
|
44
42
|
settings.plugins && (await loadPlugins());
|
|
45
43
|
await this.loadInjector(injector, module);
|
|
46
|
-
await
|
|
47
|
-
return
|
|
44
|
+
await $asyncEmit("$onReady");
|
|
45
|
+
return inject(CliCore);
|
|
48
46
|
}
|
|
49
|
-
static async bootstrap(settings, module =
|
|
47
|
+
static async bootstrap(settings, module = CliCore) {
|
|
50
48
|
const cli = await this.create(settings, module);
|
|
51
49
|
return cli.bootstrap();
|
|
52
50
|
}
|
|
53
|
-
static async loadInjector(injector, module =
|
|
51
|
+
static async loadInjector(injector, module = CliCore) {
|
|
54
52
|
await injector.emit("$beforeInit");
|
|
55
|
-
injector.addProvider(
|
|
53
|
+
injector.addProvider(CliCore, {
|
|
56
54
|
useClass: module
|
|
57
55
|
});
|
|
58
56
|
await injector.load();
|
|
59
57
|
await injector.invoke(module);
|
|
60
|
-
await
|
|
58
|
+
await $asyncEmit("$afterInit");
|
|
61
59
|
injector.settings.set("loaded", true);
|
|
62
60
|
}
|
|
63
61
|
static async updateNotifier(pkg) {
|
|
@@ -94,10 +92,5 @@ let CliCore = CliCore_1 = class CliCore {
|
|
|
94
92
|
}
|
|
95
93
|
return this;
|
|
96
94
|
}
|
|
97
|
-
}
|
|
98
|
-
CliCore
|
|
99
|
-
Module({
|
|
100
|
-
imports: [CliPackageJson, ProjectPackageJson, CliService, CliConfiguration]
|
|
101
|
-
})
|
|
102
|
-
], CliCore);
|
|
103
|
-
export { CliCore };
|
|
95
|
+
}
|
|
96
|
+
injectable(CliCore).imports([CliPackageJson, ProjectPackageJson, CliService, CliConfiguration]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Injectable } from "@tsed/di";
|
|
3
|
-
import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
1
|
+
import { command } from "../fn/command.js";
|
|
4
2
|
export function Command(options) {
|
|
5
|
-
return
|
|
3
|
+
return (token) => {
|
|
4
|
+
command(token, options);
|
|
5
|
+
};
|
|
6
6
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import "./utils/patchCommander.js";
|
|
|
2
2
|
import Inquirer from "inquirer";
|
|
3
3
|
export * from "./CliCore.js";
|
|
4
4
|
export * from "./decorators/index.js";
|
|
5
|
+
export * from "./fn/command.js";
|
|
5
6
|
export * from "./interfaces/index.js";
|
|
6
7
|
export * from "./packageManagers/index.js";
|
|
7
8
|
export * from "./services/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import "inquirer-autocomplete-prompt";
|
|
2
|
+
import AutocompletePrompt from "inquirer-autocomplete-prompt";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Inject,
|
|
2
|
+
import { Inject, injectable } from "@tsed/di";
|
|
3
3
|
import { EMPTY, throwError } from "rxjs";
|
|
4
4
|
import { catchError } from "rxjs/operators";
|
|
5
5
|
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
@@ -122,10 +122,8 @@ __decorate([
|
|
|
122
122
|
__metadata("design:type", ProjectPackageJson)
|
|
123
123
|
], PackageManagersModule.prototype, "projectPackageJson", void 0);
|
|
124
124
|
PackageManagersModule = __decorate([
|
|
125
|
-
Injectable({
|
|
126
|
-
imports: [YarnManager, YarnBerryManager, NpmManager, PNpmManager, BunManager]
|
|
127
|
-
}),
|
|
128
125
|
__param(0, Inject("package:manager")),
|
|
129
126
|
__metadata("design:paramtypes", [Array])
|
|
130
127
|
], PackageManagersModule);
|
|
131
128
|
export { PackageManagersModule };
|
|
129
|
+
injectable(PackageManagersModule).imports([YarnManager, YarnBerryManager, NpmManager, PNpmManager, BunManager]);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
let CliConfiguration = class CliConfiguration extends DIConfiguration {
|
|
1
|
+
import { DIConfiguration, injectable } from "@tsed/di";
|
|
2
|
+
export class CliConfiguration extends DIConfiguration {
|
|
4
3
|
constructor() {
|
|
5
4
|
super({
|
|
6
5
|
project: {
|
|
@@ -9,9 +8,5 @@ let CliConfiguration = class CliConfiguration extends DIConfiguration {
|
|
|
9
8
|
}
|
|
10
9
|
});
|
|
11
10
|
}
|
|
12
|
-
}
|
|
13
|
-
CliConfiguration
|
|
14
|
-
Injectable(),
|
|
15
|
-
__metadata("design:paramtypes", [])
|
|
16
|
-
], CliConfiguration);
|
|
17
|
-
export { CliConfiguration };
|
|
11
|
+
}
|
|
12
|
+
injectable(CliConfiguration);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { setValue } from "@tsed/core";
|
|
4
|
-
import { inject,
|
|
3
|
+
import { inject, injectable } from "@tsed/di";
|
|
5
4
|
import { snakeCase } from "change-case";
|
|
6
5
|
import { CliFs } from "./CliFs.js";
|
|
7
6
|
import { CliYaml } from "./CliYaml.js";
|
|
8
7
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
9
|
-
|
|
8
|
+
export class CliDockerComposeYaml {
|
|
10
9
|
constructor() {
|
|
11
10
|
this.cliYaml = inject(CliYaml);
|
|
12
11
|
this.fs = inject(CliFs);
|
|
@@ -84,8 +83,5 @@ let CliDockerComposeYaml = class CliDockerComposeYaml {
|
|
|
84
83
|
await this.write(dockerCompose);
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
|
-
}
|
|
88
|
-
CliDockerComposeYaml
|
|
89
|
-
Injectable()
|
|
90
|
-
], CliDockerComposeYaml);
|
|
91
|
-
export { CliDockerComposeYaml };
|
|
86
|
+
}
|
|
87
|
+
injectable(CliDockerComposeYaml);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Injectable } from "@tsed/di";
|
|
1
|
+
import { injectable } from "@tsed/di";
|
|
3
2
|
import { execa, execaSync } from "execa";
|
|
4
3
|
import { filter, mergeWith } from "rxjs/operators";
|
|
5
4
|
// @ts-ignore
|
|
6
5
|
import split from "split";
|
|
7
6
|
import { streamToObservable } from "../utils/streamToObservable.js";
|
|
8
|
-
|
|
7
|
+
export class CliExeca {
|
|
9
8
|
constructor() {
|
|
10
9
|
this.raw = execa;
|
|
11
10
|
this.rawSync = execaSync;
|
|
@@ -31,8 +30,5 @@ let CliExeca = class CliExeca {
|
|
|
31
30
|
get(cmd, args, opts) {
|
|
32
31
|
return this.rawSync(cmd, args, opts).stdout;
|
|
33
32
|
}
|
|
34
|
-
}
|
|
35
|
-
CliExeca
|
|
36
|
-
Injectable()
|
|
37
|
-
], CliExeca);
|
|
38
|
-
export { CliExeca };
|
|
33
|
+
}
|
|
34
|
+
injectable(CliExeca);
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
1
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
2
|
+
import { RealFileSystemHost } from "@ts-morph/common";
|
|
3
|
+
import { injectable } from "@tsed/di";
|
|
4
4
|
import { normalizePath } from "@tsed/normalize-path";
|
|
5
5
|
import Fs, {} from "fs-extra";
|
|
6
|
-
|
|
6
|
+
export class CliFs extends RealFileSystemHost {
|
|
7
7
|
constructor() {
|
|
8
|
+
super(...arguments);
|
|
8
9
|
this.raw = Fs;
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
* @param path
|
|
14
|
+
*/
|
|
10
15
|
exists(path) {
|
|
11
16
|
return this.raw.existsSync(path);
|
|
12
17
|
}
|
|
@@ -14,10 +19,10 @@ let CliFs = class CliFs {
|
|
|
14
19
|
return normalizePath(join(...args));
|
|
15
20
|
}
|
|
16
21
|
readFile(file, encoding) {
|
|
17
|
-
return
|
|
22
|
+
return super.readFile(file, encoding);
|
|
18
23
|
}
|
|
19
24
|
readFileSync(file, encoding) {
|
|
20
|
-
return
|
|
25
|
+
return super.readFileSync(file, encoding);
|
|
21
26
|
}
|
|
22
27
|
async readJson(file, encoding) {
|
|
23
28
|
const content = await this.readFile(file, encoding);
|
|
@@ -30,6 +35,9 @@ let CliFs = class CliFs {
|
|
|
30
35
|
async writeJson(file, data, options) {
|
|
31
36
|
await this.raw.writeFile(file, JSON.stringify(data, null, 2), options || { encoding: "utf8" });
|
|
32
37
|
}
|
|
38
|
+
writeJsonSync(file, data, options) {
|
|
39
|
+
this.raw.writeFileSync(file, JSON.stringify(data, null, 2), options || { encoding: "utf8" });
|
|
40
|
+
}
|
|
33
41
|
writeFileSync(path, data, options) {
|
|
34
42
|
return this.raw.writeFileSync(path, data, options);
|
|
35
43
|
}
|
|
@@ -43,7 +51,7 @@ let CliFs = class CliFs {
|
|
|
43
51
|
return this.raw.ensureDirSync(path, options);
|
|
44
52
|
}
|
|
45
53
|
findUpFile(root, file) {
|
|
46
|
-
return [join(root, file), join(root, "..", file), join(root, "..", "..", file), join(root, "..", "..", "..", file)].find((path) => this.
|
|
54
|
+
return [join(root, file), join(root, "..", file), join(root, "..", "..", file), join(root, "..", "..", "..", file)].find((path) => this.fileExistsSync(path));
|
|
47
55
|
}
|
|
48
56
|
async importModule(mod, root = process.cwd()) {
|
|
49
57
|
try {
|
|
@@ -60,8 +68,5 @@ let CliFs = class CliFs {
|
|
|
60
68
|
}
|
|
61
69
|
return import(mod);
|
|
62
70
|
}
|
|
63
|
-
}
|
|
64
|
-
CliFs
|
|
65
|
-
Injectable()
|
|
66
|
-
], CliFs);
|
|
67
|
-
export { CliFs };
|
|
71
|
+
}
|
|
72
|
+
injectable(CliFs);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
let CliHooks = class CliHooks {
|
|
1
|
+
import { injectable, injector } from "@tsed/di";
|
|
2
|
+
export class CliHooks {
|
|
4
3
|
async emit(hookName, cmd, ...args) {
|
|
5
4
|
const inj = injector();
|
|
6
5
|
const providers = inj.getProviders();
|
|
@@ -20,8 +19,5 @@ let CliHooks = class CliHooks {
|
|
|
20
19
|
}
|
|
21
20
|
return results.filter((o) => o !== undefined);
|
|
22
21
|
}
|
|
23
|
-
}
|
|
24
|
-
CliHooks
|
|
25
|
-
Injectable()
|
|
26
|
-
], CliHooks);
|
|
27
|
-
export { CliHooks };
|
|
22
|
+
}
|
|
23
|
+
injectable(CliHooks);
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
var CliHttpClient_1;
|
|
2
|
-
import { __decorate } from "tslib";
|
|
3
1
|
import { stringify } from "node:querystring";
|
|
4
2
|
import { URL } from "node:url";
|
|
5
3
|
import { cleanObject } from "@tsed/core";
|
|
6
|
-
import { inject,
|
|
4
|
+
import { inject, injectable } from "@tsed/di";
|
|
7
5
|
import axios, {} from "axios";
|
|
8
6
|
import { CliHttpLogClient } from "./CliHttpLogClient.js";
|
|
9
7
|
import { CliProxyAgent } from "./CliProxyAgent.js";
|
|
10
|
-
|
|
8
|
+
export class CliHttpClient extends CliHttpLogClient {
|
|
11
9
|
constructor() {
|
|
12
10
|
super(...arguments);
|
|
13
11
|
this.cliProxyAgent = inject(CliProxyAgent);
|
|
@@ -80,7 +78,7 @@ let CliHttpClient = CliHttpClient_1 = class CliHttpClient extends CliHttpLogClie
|
|
|
80
78
|
const startTime = new Date().getTime();
|
|
81
79
|
try {
|
|
82
80
|
const response = await axios({
|
|
83
|
-
paramsSerializer:
|
|
81
|
+
paramsSerializer: CliHttpClient.getParamsSerializer,
|
|
84
82
|
...options
|
|
85
83
|
});
|
|
86
84
|
this.onSuccess({ startTime, ...options });
|
|
@@ -96,8 +94,5 @@ let CliHttpClient = CliHttpClient_1 = class CliHttpClient extends CliHttpLogClie
|
|
|
96
94
|
const data = !withHeaders ? result?.data : result;
|
|
97
95
|
return withHeaders ? { data, headers: result?.headers } : data;
|
|
98
96
|
}
|
|
99
|
-
}
|
|
100
|
-
CliHttpClient
|
|
101
|
-
Injectable()
|
|
102
|
-
], CliHttpClient);
|
|
103
|
-
export { CliHttpClient };
|
|
97
|
+
}
|
|
98
|
+
injectable(CliHttpClient);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import { extname } from "node:path";
|
|
3
|
-
import { inject,
|
|
2
|
+
import { inject, injectable } from "@tsed/di";
|
|
4
3
|
import { default as Ajv } from "ajv";
|
|
5
4
|
import { CliFs } from "./CliFs.js";
|
|
6
5
|
import { CliYaml } from "./CliYaml.js";
|
|
7
|
-
|
|
6
|
+
export class CliLoadFile {
|
|
8
7
|
// @ts-ignore
|
|
9
8
|
#ajv;
|
|
10
9
|
constructor() {
|
|
@@ -49,9 +48,5 @@ let CliLoadFile = class CliLoadFile {
|
|
|
49
48
|
}
|
|
50
49
|
return config;
|
|
51
50
|
}
|
|
52
|
-
}
|
|
53
|
-
CliLoadFile
|
|
54
|
-
Injectable(),
|
|
55
|
-
__metadata("design:paramtypes", [])
|
|
56
|
-
], CliLoadFile);
|
|
57
|
-
export { CliLoadFile };
|
|
51
|
+
}
|
|
52
|
+
injectable(CliLoadFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constant, Inject, inject, injectable } from "@tsed/di";
|
|
2
2
|
import {} from "../interfaces/PackageJson.js";
|
|
3
3
|
export function CliPackageJson() {
|
|
4
4
|
return Inject(CliPackageJson);
|
|
@@ -6,10 +6,6 @@ export function CliPackageJson() {
|
|
|
6
6
|
export function cliPackageJson() {
|
|
7
7
|
return inject(CliPackageJson);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
deps: [Configuration],
|
|
12
|
-
useFactory(configuration) {
|
|
13
|
-
return configuration.get("pkg", {});
|
|
14
|
-
}
|
|
9
|
+
injectable(CliPackageJson).factory(() => {
|
|
10
|
+
return constant("pkg", {});
|
|
15
11
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { constant, inject, Injectable } from "@tsed/di";
|
|
1
|
+
import { constant, inject, injectable } from "@tsed/di";
|
|
3
2
|
import chalk from "chalk";
|
|
4
3
|
import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
5
4
|
import { PackageManagersModule } from "../packageManagers/PackageManagersModule.js";
|
|
@@ -15,7 +14,7 @@ function mapPlugins({ package: { name, description = "", ...otherProps } }) {
|
|
|
15
14
|
...otherProps
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
export class CliPlugins {
|
|
19
18
|
constructor() {
|
|
20
19
|
this.name = constant("name", "");
|
|
21
20
|
this.loadPlugins = loadPlugins;
|
|
@@ -57,8 +56,5 @@ let CliPlugins = class CliPlugins {
|
|
|
57
56
|
isPlugin(name) {
|
|
58
57
|
return name.startsWith(`@${this.name}/cli-plugin`) || name.includes(`${this.name}-cli-plugin`);
|
|
59
58
|
}
|
|
60
|
-
}
|
|
61
|
-
CliPlugins
|
|
62
|
-
Injectable()
|
|
63
|
-
], CliPlugins);
|
|
64
|
-
export { CliPlugins };
|
|
59
|
+
}
|
|
60
|
+
injectable(CliPlugins);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
1
|
import { URL } from "node:url";
|
|
3
|
-
import {
|
|
2
|
+
import { inject, injectable, refValue } from "@tsed/di";
|
|
4
3
|
import { camelCase } from "change-case";
|
|
5
4
|
import { coerce } from "../utils/coerce.js";
|
|
6
5
|
import { CliExeca } from "./CliExeca.js";
|
|
7
6
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
8
|
-
|
|
7
|
+
export class CliProxyAgent {
|
|
9
8
|
constructor() {
|
|
10
9
|
this.proxySettings = refValue("proxy", {});
|
|
11
|
-
this.projectPackageJson =
|
|
10
|
+
this.projectPackageJson = inject(ProjectPackageJson);
|
|
12
11
|
this.cliExeca = inject(CliExeca);
|
|
13
12
|
}
|
|
14
13
|
async $onInit() {
|
|
@@ -73,14 +72,10 @@ let CliProxyAgent = class CliProxyAgent {
|
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
}
|
|
77
|
-
CliProxyAgent
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
], CliProxyAgent);
|
|
86
|
-
export { CliProxyAgent };
|
|
75
|
+
}
|
|
76
|
+
injectable(CliProxyAgent).configuration({
|
|
77
|
+
proxy: {
|
|
78
|
+
url: process.env.HTTPS_PROXY || process.env.HTTP_PROXY,
|
|
79
|
+
strictSsl: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== undefined ? process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0" : true
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
1
|
import { classOf } from "@tsed/core";
|
|
3
|
-
import { configuration, constant, destroyInjector, DIContext, getContext, inject,
|
|
4
|
-
import { $asyncEmit } from "@tsed/hooks";
|
|
2
|
+
import { configuration, constant, destroyInjector, DIContext, getContext, inject, injectable, injector, logger, Provider, runInContext } from "@tsed/di";
|
|
3
|
+
import { $asyncAlter, $asyncEmit } from "@tsed/hooks";
|
|
4
|
+
import { pascalCase } from "change-case";
|
|
5
5
|
import { Argument, Command } from "commander";
|
|
6
6
|
import Inquirer from "inquirer";
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
import inquirer_autocomplete_prompt from "inquirer-autocomplete-prompt";
|
|
9
8
|
import { v4 } from "uuid";
|
|
10
9
|
import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
@@ -17,7 +16,7 @@ import { parseOption } from "../utils/parseOption.js";
|
|
|
17
16
|
import { CliHooks } from "./CliHooks.js";
|
|
18
17
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
19
18
|
Inquirer.registerPrompt("autocomplete", inquirer_autocomplete_prompt);
|
|
20
|
-
|
|
19
|
+
export class CliService {
|
|
21
20
|
constructor() {
|
|
22
21
|
this.reinstallAfterRun = constant("project.reinstallAfterRun", false);
|
|
23
22
|
this.program = new Command();
|
|
@@ -84,17 +83,17 @@ let CliService = class CliService {
|
|
|
84
83
|
/**
|
|
85
84
|
* Run prompt for a given command
|
|
86
85
|
* @param cmdName
|
|
87
|
-
* @param
|
|
86
|
+
* @param data Initial data
|
|
88
87
|
*/
|
|
89
|
-
async beforePrompt(cmdName,
|
|
88
|
+
async beforePrompt(cmdName, data = {}) {
|
|
90
89
|
const provider = this.commands.get(cmdName);
|
|
91
90
|
const instance = inject(provider.useClass);
|
|
92
|
-
const verbose =
|
|
91
|
+
const verbose = data.verbose;
|
|
93
92
|
if (instance.$beforePrompt) {
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
data = await instance.$beforePrompt(JSON.parse(JSON.stringify(data)));
|
|
94
|
+
data.verbose = verbose;
|
|
96
95
|
}
|
|
97
|
-
return
|
|
96
|
+
return data;
|
|
98
97
|
}
|
|
99
98
|
/**
|
|
100
99
|
* Run prompt for a given command
|
|
@@ -131,7 +130,11 @@ let CliService = class CliService {
|
|
|
131
130
|
if (instance.$beforeExec) {
|
|
132
131
|
await instance.$beforeExec(data);
|
|
133
132
|
}
|
|
134
|
-
return [
|
|
133
|
+
return [
|
|
134
|
+
...(await instance.$exec(data)),
|
|
135
|
+
...(await this.hooks.emit(CommandStoreKeys.EXEC_HOOKS, cmdName, data)),
|
|
136
|
+
...(await $asyncAlter(`$alter${pascalCase(cmdName)}Tasks`, [], [data]))
|
|
137
|
+
];
|
|
135
138
|
}
|
|
136
139
|
async getPostInstallTasks(cmdName, data) {
|
|
137
140
|
const provider = this.commands.get(cmdName);
|
|
@@ -140,6 +143,7 @@ let CliService = class CliService {
|
|
|
140
143
|
return [
|
|
141
144
|
...(instance.$postInstall ? await instance.$postInstall(data) : []),
|
|
142
145
|
...(await this.hooks.emit(CommandStoreKeys.POST_INSTALL_HOOKS, cmdName, data)),
|
|
146
|
+
...(await $asyncAlter(`$alter${pascalCase(cmdName)}PostInstallTasks`, [], [data])),
|
|
143
147
|
...(instance.$afterPostInstall ? await instance.$afterPostInstall(data) : [])
|
|
144
148
|
];
|
|
145
149
|
}
|
|
@@ -193,6 +197,7 @@ let CliService = class CliService {
|
|
|
193
197
|
const provider = this.commands.get(cmdName);
|
|
194
198
|
const instance = inject(provider.useClass);
|
|
195
199
|
const verbose = data.verbose;
|
|
200
|
+
data.commandName ||= cmdName;
|
|
196
201
|
if (instance.$mapContext) {
|
|
197
202
|
data = instance.$mapContext(JSON.parse(JSON.stringify(data)));
|
|
198
203
|
data.verbose = verbose;
|
|
@@ -203,7 +208,7 @@ let CliService = class CliService {
|
|
|
203
208
|
else {
|
|
204
209
|
logger().level = "info";
|
|
205
210
|
}
|
|
206
|
-
data.bindLogger = $ctx.get("command")
|
|
211
|
+
data.bindLogger = $ctx.get("command")?.bindLogger;
|
|
207
212
|
$ctx.set("data", data);
|
|
208
213
|
return data;
|
|
209
214
|
}
|
|
@@ -255,8 +260,5 @@ let CliService = class CliService {
|
|
|
255
260
|
return cmd.addArgument(argument);
|
|
256
261
|
}, cmd);
|
|
257
262
|
}
|
|
258
|
-
}
|
|
259
|
-
CliService
|
|
260
|
-
Injectable()
|
|
261
|
-
], CliService);
|
|
262
|
-
export { CliService };
|
|
263
|
+
}
|
|
264
|
+
injectable(CliService);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { inject, Injectable } from "@tsed/di";
|
|
1
|
+
import { inject, injectable } from "@tsed/di";
|
|
3
2
|
import JsYaml from "js-yaml";
|
|
4
3
|
import { CliFs } from "./CliFs.js";
|
|
5
|
-
|
|
4
|
+
export class CliYaml {
|
|
6
5
|
constructor() {
|
|
7
6
|
this.fs = inject(CliFs);
|
|
8
7
|
}
|
|
@@ -14,8 +13,5 @@ let CliYaml = class CliYaml {
|
|
|
14
13
|
const content = JsYaml.dump(obj);
|
|
15
14
|
return this.fs.writeFile(path, content, { encoding: "utf8" });
|
|
16
15
|
}
|
|
17
|
-
}
|
|
18
|
-
CliYaml
|
|
19
|
-
Injectable()
|
|
20
|
-
], CliYaml);
|
|
21
|
-
export { CliYaml };
|
|
16
|
+
}
|
|
17
|
+
injectable(CliYaml);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
var NpmRegistryClient_1;
|
|
2
|
-
import { __decorate } from "tslib";
|
|
3
1
|
import url from "node:url";
|
|
4
|
-
import { inject,
|
|
2
|
+
import { inject, injectable } from "@tsed/di";
|
|
5
3
|
import registry_auth_token from "registry-auth-token";
|
|
6
4
|
import registry_url from "registry-url";
|
|
7
5
|
import { CliHttpClient } from "./CliHttpClient.js";
|
|
@@ -14,7 +12,7 @@ export function addSuffix(pattern, suffix) {
|
|
|
14
12
|
return pattern;
|
|
15
13
|
}
|
|
16
14
|
export const SCOPE_SEPARATOR = "%2f";
|
|
17
|
-
|
|
15
|
+
export class NpmRegistryClient {
|
|
18
16
|
constructor() {
|
|
19
17
|
this.httpClient = inject(CliHttpClient);
|
|
20
18
|
this.host = registry_url();
|
|
@@ -44,7 +42,7 @@ let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
|
|
|
44
42
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
45
43
|
opts.retry -= 1;
|
|
46
44
|
opts.unfiltered = true;
|
|
47
|
-
return this.request(
|
|
45
|
+
return this.request(NpmRegistryClient.escapeName(pathname), opts);
|
|
48
46
|
}
|
|
49
47
|
throw error;
|
|
50
48
|
}
|
|
@@ -118,8 +116,5 @@ let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
|
|
|
118
116
|
headers.Authorization = `${authInfo.type} ${authInfo.token}`;
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
}
|
|
122
|
-
NpmRegistryClient
|
|
123
|
-
Injectable()
|
|
124
|
-
], NpmRegistryClient);
|
|
125
|
-
export { NpmRegistryClient };
|
|
119
|
+
}
|
|
120
|
+
injectable(NpmRegistryClient);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import { dirname, join } from "node:path";
|
|
3
2
|
import { getValue, setValue } from "@tsed/core";
|
|
4
|
-
import { configuration, constant, inject,
|
|
3
|
+
import { configuration, constant, inject, injectable } from "@tsed/di";
|
|
5
4
|
import { readPackageUpSync } from "read-pkg-up";
|
|
6
5
|
import { isValidVersion } from "../utils/isValidVersion.js";
|
|
7
6
|
import { CliFs } from "./CliFs.js";
|
|
@@ -28,7 +27,7 @@ function mapPackages(deps) {
|
|
|
28
27
|
return deps;
|
|
29
28
|
}, { valid: {}, invalid: {} });
|
|
30
29
|
}
|
|
31
|
-
|
|
30
|
+
export class ProjectPackageJson {
|
|
32
31
|
constructor() {
|
|
33
32
|
this.rewrite = false;
|
|
34
33
|
this.reinstall = false;
|
|
@@ -84,6 +83,15 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
84
83
|
get preferences() {
|
|
85
84
|
return this.raw[constant("name")];
|
|
86
85
|
}
|
|
86
|
+
fillWithPreferences(ctx) {
|
|
87
|
+
return {
|
|
88
|
+
...ctx,
|
|
89
|
+
packageManager: this.preferences.packageManager,
|
|
90
|
+
runtime: this.preferences.runtime,
|
|
91
|
+
architecture: this.preferences.architecture,
|
|
92
|
+
convention: this.preferences.convention
|
|
93
|
+
};
|
|
94
|
+
}
|
|
87
95
|
$loadPackageJson() {
|
|
88
96
|
return this.read();
|
|
89
97
|
}
|
|
@@ -239,10 +247,10 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
239
247
|
}
|
|
240
248
|
getPackageJson() {
|
|
241
249
|
const cwd = constant("project.rootDir");
|
|
242
|
-
const disableReadUpPkg = constant("command.metadata.disableReadUpPkg");
|
|
250
|
+
const disableReadUpPkg = constant("command.metadata.disableReadUpPkg", constant("disableReadUpPkg"));
|
|
243
251
|
const name = constant("name");
|
|
244
252
|
const pkgPath = join(String(cwd), "package.json");
|
|
245
|
-
const fileExists = this.fs.
|
|
253
|
+
const fileExists = this.fs.fileExistsSync(pkgPath);
|
|
246
254
|
if (fileExists) {
|
|
247
255
|
const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
|
|
248
256
|
configuration().set("project.root", pkgPath);
|
|
@@ -271,9 +279,5 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
271
279
|
devDependencies: {}
|
|
272
280
|
};
|
|
273
281
|
}
|
|
274
|
-
}
|
|
275
|
-
ProjectPackageJson
|
|
276
|
-
Injectable({}),
|
|
277
|
-
__metadata("design:paramtypes", [])
|
|
278
|
-
], ProjectPackageJson);
|
|
279
|
-
export { ProjectPackageJson };
|
|
282
|
+
}
|
|
283
|
+
injectable(ProjectPackageJson);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "@tsed/logger-std";
|
|
2
2
|
import "@tsed/logger-pattern-layout";
|
|
3
|
-
import { injector, InjectorService } from "@tsed/di";
|
|
3
|
+
import { inject, injector, InjectorService } from "@tsed/di";
|
|
4
4
|
import { Logger } from "@tsed/logger";
|
|
5
5
|
import { CliConfiguration } from "../services/CliConfiguration.js";
|
|
6
6
|
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
@@ -10,7 +10,7 @@ export function getLogger() {
|
|
|
10
10
|
}
|
|
11
11
|
function createConfiguration(injector) {
|
|
12
12
|
injector.addProvider(CliConfiguration);
|
|
13
|
-
return
|
|
13
|
+
return inject(CliConfiguration);
|
|
14
14
|
}
|
|
15
15
|
export function createInjector(settings = {}) {
|
|
16
16
|
const inj = injector();
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import "./utils/patchCommander.js";
|
|
|
2
2
|
import Inquirer from "inquirer";
|
|
3
3
|
export * from "./CliCore.js";
|
|
4
4
|
export * from "./decorators/index.js";
|
|
5
|
+
export * from "./fn/command.js";
|
|
5
6
|
export * from "./interfaces/index.js";
|
|
6
7
|
export * from "./packageManagers/index.js";
|
|
7
8
|
export * from "./services/index.js";
|
|
@@ -12,7 +12,7 @@ export interface CommandMetadata extends CommandParameters {
|
|
|
12
12
|
options: {
|
|
13
13
|
[key: string]: CommandOptions;
|
|
14
14
|
};
|
|
15
|
-
allowUnknownOption
|
|
15
|
+
allowUnknownOption?: boolean;
|
|
16
16
|
enableFeatures: string[];
|
|
17
17
|
disableReadUpPkg: boolean;
|
|
18
18
|
bindLogger: boolean;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import "inquirer-autocomplete-prompt";
|
|
1
2
|
import type { Answers, QuestionCollection } from "inquirer";
|
|
3
|
+
import AutocompletePrompt from "inquirer-autocomplete-prompt";
|
|
2
4
|
import type { Tasks } from "./Tasks.js";
|
|
5
|
+
declare module "inquirer" {
|
|
6
|
+
interface QuestionMap<T extends Answers = Answers> {
|
|
7
|
+
autocomplete: AutocompletePrompt.AutocompleteQuestionOptions<T>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
export type QuestionOptions<T extends Answers = Answers> = QuestionCollection<T>;
|
|
4
11
|
export interface CommandProvider<Ctx = any> {
|
|
5
12
|
/**
|
|
@@ -2,6 +2,7 @@ import { Type } from "@tsed/core";
|
|
|
2
2
|
import type { CommandProvider } from "./CommandProvider.js";
|
|
3
3
|
import type { PackageJson } from "./PackageJson.js";
|
|
4
4
|
export * from "./CliDefaultOptions.js";
|
|
5
|
+
export * from "./CommandData.js";
|
|
5
6
|
export * from "./CommandMetadata.js";
|
|
6
7
|
export * from "./CommandParameters.js";
|
|
7
8
|
export * from "./CommandProvider.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CliFs } from "./CliFs.js";
|
|
2
2
|
import { CliYaml } from "./CliYaml.js";
|
|
3
3
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
4
|
+
export type CliDatabases = "mysql" | "mariadb" | "sqlite" | "better-sqlite3" | "postgres" | "cockroachdb" | "mssql" | "oracle" | "mongodb";
|
|
4
5
|
export declare class CliDockerComposeYaml {
|
|
5
6
|
protected cliYaml: CliYaml;
|
|
6
7
|
protected fs: CliFs;
|
|
7
8
|
protected projectPackageJson: ProjectPackageJson;
|
|
8
9
|
read(): Promise<unknown>;
|
|
9
10
|
write(obj: any): Promise<void>;
|
|
10
|
-
addDatabaseService(name: string, database:
|
|
11
|
+
addDatabaseService(name: string, database: CliDatabases | undefined): Promise<void>;
|
|
11
12
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { PathLike, WriteFileOptions } from "node:fs";
|
|
2
|
+
import { RealFileSystemHost } from "@ts-morph/common";
|
|
2
3
|
import Fs, { type EnsureDirOptions } from "fs-extra";
|
|
3
|
-
export declare class CliFs {
|
|
4
|
+
export declare class CliFs extends RealFileSystemHost {
|
|
4
5
|
raw: typeof Fs;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
* @param path
|
|
9
|
+
*/
|
|
5
10
|
exists(path: string): boolean;
|
|
6
11
|
join(...args: string[]): string;
|
|
7
12
|
readFile(file: string | Buffer | number, encoding?: any): Promise<string>;
|
|
@@ -9,6 +14,7 @@ export declare class CliFs {
|
|
|
9
14
|
readJson(file: string, encoding?: any): Promise<any>;
|
|
10
15
|
readJsonSync(file: string, encoding?: any): any;
|
|
11
16
|
writeJson(file: string | Buffer | number, data: any, options?: WriteFileOptions | string): Promise<any>;
|
|
17
|
+
writeJsonSync(file: string | Buffer | number, data: any, options?: WriteFileOptions | string): void;
|
|
12
18
|
writeFileSync(path: PathLike | number, data: any, options?: WriteFileOptions): void;
|
|
13
19
|
writeFile(file: string | Buffer | number, data: any, options?: WriteFileOptions | string): Promise<void>;
|
|
14
20
|
ensureDir(path: string, options?: EnsureDirOptions | number): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliExeca } from "./CliExeca.js";
|
|
2
|
+
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
2
3
|
export interface CliProxySettings {
|
|
3
4
|
url: string;
|
|
4
5
|
strictSsl: boolean;
|
|
@@ -7,7 +8,7 @@ export declare class CliProxyAgent {
|
|
|
7
8
|
readonly proxySettings: {
|
|
8
9
|
value: CliProxySettings;
|
|
9
10
|
};
|
|
10
|
-
protected projectPackageJson:
|
|
11
|
+
protected projectPackageJson: ProjectPackageJson;
|
|
11
12
|
protected cliExeca: CliExeca;
|
|
12
13
|
protected tunnel: typeof import("tunnel");
|
|
13
14
|
$onInit(): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DIContext } from "@tsed/di";
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
+
import type { CommandData } from "../interfaces/CommandData.js";
|
|
3
4
|
import type { CommandMetadata } from "../interfaces/CommandMetadata.js";
|
|
5
|
+
import type { Task } from "../interfaces/index.js";
|
|
4
6
|
import { PackageManagersModule } from "../packageManagers/index.js";
|
|
5
7
|
import { CliHooks } from "./CliHooks.js";
|
|
6
8
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
@@ -23,27 +25,27 @@ export declare class CliService {
|
|
|
23
25
|
* @param data
|
|
24
26
|
* @param $ctx
|
|
25
27
|
*/
|
|
26
|
-
runLifecycle(cmdName: string, data:
|
|
27
|
-
dispatch(cmdName: string, data:
|
|
28
|
+
runLifecycle(cmdName: string, data: CommandData | undefined, $ctx: DIContext): Promise<Promise<void>>;
|
|
29
|
+
dispatch(cmdName: string, data: CommandData, $ctx: DIContext): Promise<void>;
|
|
28
30
|
exec(cmdName: string, data: any, $ctx: DIContext): Promise<any>;
|
|
29
31
|
/**
|
|
30
32
|
* Run prompt for a given command
|
|
31
33
|
* @param cmdName
|
|
32
|
-
* @param
|
|
34
|
+
* @param data Initial data
|
|
33
35
|
*/
|
|
34
|
-
beforePrompt(cmdName: string,
|
|
36
|
+
beforePrompt(cmdName: string, data?: CommandData): Promise<CommandData>;
|
|
35
37
|
/**
|
|
36
38
|
* Run prompt for a given command
|
|
37
39
|
* @param cmdName
|
|
38
40
|
* @param ctx Initial data
|
|
39
41
|
*/
|
|
40
|
-
prompt(cmdName: string, ctx?:
|
|
42
|
+
prompt(cmdName: string, ctx?: CommandData): Promise<CommandData>;
|
|
41
43
|
/**
|
|
42
44
|
* Run lifecycle
|
|
43
45
|
* @param cmdName
|
|
44
46
|
* @param data
|
|
45
47
|
*/
|
|
46
|
-
getTasks(cmdName: string, data: any): Promise<
|
|
48
|
+
getTasks(cmdName: string, data: any): Promise<Task[]>;
|
|
47
49
|
getPostInstallTasks(cmdName: string, data: any): Promise<any[]>;
|
|
48
50
|
createCommand(metadata: CommandMetadata): any;
|
|
49
51
|
private load;
|
|
@@ -28,6 +28,12 @@ export declare class ProjectPackageJson {
|
|
|
28
28
|
[key: string]: string;
|
|
29
29
|
};
|
|
30
30
|
get preferences(): ProjectPreferences;
|
|
31
|
+
fillWithPreferences<T extends {}>(ctx: T): T & {
|
|
32
|
+
packageManager: import("../interfaces/ProjectPreferences.js").PackageManager;
|
|
33
|
+
runtime: any;
|
|
34
|
+
architecture: any;
|
|
35
|
+
convention: any;
|
|
36
|
+
};
|
|
31
37
|
$loadPackageJson(): this;
|
|
32
38
|
toJSON(): PackageJson;
|
|
33
39
|
read(): this;
|
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": "
|
|
4
|
+
"version": "7.0.0-alpha.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"listr"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tsed/logger": ">=8.0.
|
|
36
|
-
"@tsed/logger-pattern-layout": ">=8.0.
|
|
37
|
-
"@tsed/logger-std": ">=8.0.
|
|
35
|
+
"@tsed/logger": ">=8.0.3",
|
|
36
|
+
"@tsed/logger-pattern-layout": ">=8.0.3",
|
|
37
|
+
"@tsed/logger-std": ">=8.0.3",
|
|
38
38
|
"@tsed/normalize-path": ">=8.0.0",
|
|
39
39
|
"@types/inquirer": "^9.0.7",
|
|
40
40
|
"ajv": "^8.17.1",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"uuid": "^10.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@tsed/typescript": "
|
|
67
|
+
"@tsed/typescript": "7.0.0-alpha.1",
|
|
68
68
|
"@types/commander": "2.12.2",
|
|
69
69
|
"@types/figures": "3.0.1",
|
|
70
70
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -102,5 +102,8 @@
|
|
|
102
102
|
},
|
|
103
103
|
"homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/cli-core",
|
|
104
104
|
"author": "Romain Lenzotti",
|
|
105
|
-
"license": "MIT"
|
|
105
|
+
"license": "MIT",
|
|
106
|
+
"publishConfig": {
|
|
107
|
+
"tag": "alpha"
|
|
108
|
+
}
|
|
106
109
|
}
|
package/readme.md
CHANGED
|
@@ -39,10 +39,10 @@ npm install @tsed/core @tsed/di @tsed/cli-core
|
|
|
39
39
|
|
|
40
40
|
## Getting started
|
|
41
41
|
|
|
42
|
-
Create CLI
|
|
42
|
+
Create CLI requires some steps like create a package.json with the right information and create a structure directory
|
|
43
43
|
aligned with TypeScript to be compiled correctly for a npm deployment.
|
|
44
44
|
|
|
45
|
-
Here a structure directory example:
|
|
45
|
+
Here is a structure directory example:
|
|
46
46
|
|
|
47
47
|
```
|
|
48
48
|
.
|
|
@@ -57,93 +57,6 @@ Here a structure directory example:
|
|
|
57
57
|
└── tsconfig.compile.json
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
## Create package.json and tsconfig
|
|
61
|
-
|
|
62
|
-
The first step is to create the package.json with the following lines:
|
|
63
|
-
|
|
64
|
-
```jsonc
|
|
65
|
-
{
|
|
66
|
-
"name": "{{name}}",
|
|
67
|
-
"version": "1.0.0",
|
|
68
|
-
"main": "./lib/index.js",
|
|
69
|
-
"typings": "./lib/index.d.ts",
|
|
70
|
-
"bin": {
|
|
71
|
-
"tsed": "lib/bin/{{name}}.js"
|
|
72
|
-
},
|
|
73
|
-
"files": ["lib/bin/{{name}}.js", "lib/bin", "lib", "templates"],
|
|
74
|
-
"description": "An awesome CLI build on top of @tsed/cli-core",
|
|
75
|
-
"dependencies": {
|
|
76
|
-
"@tsed/cli-core": "1.3.1",
|
|
77
|
-
"tslib": "1.11.1"
|
|
78
|
-
},
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@tsed/cli-testing": "1.3.1",
|
|
81
|
-
"ts-node": "latest",
|
|
82
|
-
"typescript": "latest"
|
|
83
|
-
},
|
|
84
|
-
"scripts": {
|
|
85
|
-
"build": "tsc --build tsconfig.compile.json",
|
|
86
|
-
"start:cmd:add": "cross-env NODE_ENV=development ts-node -r src/bin/{{name}}.ts add -r ./.tmp"
|
|
87
|
-
},
|
|
88
|
-
"engines": {
|
|
89
|
-
"node": ">=8.9"
|
|
90
|
-
},
|
|
91
|
-
"peerDependencies": {}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Then create tsconfig files one for the IDE (`tsconfig.json`):
|
|
96
|
-
|
|
97
|
-
```json
|
|
98
|
-
{
|
|
99
|
-
"compilerOptions": {
|
|
100
|
-
"module": "commonjs",
|
|
101
|
-
"target": "es2016",
|
|
102
|
-
"sourceMap": true,
|
|
103
|
-
"declaration": false,
|
|
104
|
-
"experimentalDecorators": true,
|
|
105
|
-
"emitDecoratorMetadata": true,
|
|
106
|
-
"moduleResolution": "node",
|
|
107
|
-
"isolatedModules": false,
|
|
108
|
-
"suppressImplicitAnyIndexErrors": false,
|
|
109
|
-
"noImplicitAny": true,
|
|
110
|
-
"strictNullChecks": true,
|
|
111
|
-
"noUnusedLocals": false,
|
|
112
|
-
"noUnusedParameters": false,
|
|
113
|
-
"allowSyntheticDefaultImports": true,
|
|
114
|
-
"importHelpers": true,
|
|
115
|
-
"newLine": "LF",
|
|
116
|
-
"noEmit": true,
|
|
117
|
-
"lib": ["es7", "dom", "esnext.asynciterable"],
|
|
118
|
-
"typeRoots": ["./node_modules/@types"]
|
|
119
|
-
},
|
|
120
|
-
"linterOptions": {
|
|
121
|
-
"exclude": []
|
|
122
|
-
},
|
|
123
|
-
"exclude": []
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
And another one to compile source (`tsconfig.compile.json`):
|
|
128
|
-
|
|
129
|
-
```json
|
|
130
|
-
{
|
|
131
|
-
"extends": "./tsconfig.compile.json",
|
|
132
|
-
"compilerOptions": {
|
|
133
|
-
"rootDir": "src",
|
|
134
|
-
"outDir": "lib",
|
|
135
|
-
"moduleResolution": "node",
|
|
136
|
-
"declaration": true,
|
|
137
|
-
"noResolve": false,
|
|
138
|
-
"preserveConstEnums": true,
|
|
139
|
-
"sourceMap": true,
|
|
140
|
-
"noEmit": false,
|
|
141
|
-
"inlineSources": true
|
|
142
|
-
},
|
|
143
|
-
"exclude": ["node_modules", "test", "lib", "**/*.spec.ts"]
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
|
|
147
60
|
## Create the bin file
|
|
148
61
|
|
|
149
62
|
The bin file is used by npm to create your node.js executable program when you install the node_module globally.
|
|
@@ -155,19 +68,13 @@ Create a new file according to your project name (example: `name.ts`) and add th
|
|
|
155
68
|
import {AddCmd, CliCore} from "@tsed/cli-core";
|
|
156
69
|
import {resolve} from "node:path";
|
|
157
70
|
|
|
158
|
-
const pkg = require("../../package.json");
|
|
159
|
-
const TEMPLATE_DIR = resolve(__dirname, "..", "..", "templates");
|
|
160
|
-
|
|
161
71
|
CliCore.bootstrap({
|
|
162
72
|
commands: [
|
|
163
73
|
AddCmd // CommandProvider to install a plugin
|
|
164
74
|
// then add you commands
|
|
165
75
|
],
|
|
166
|
-
|
|
167
76
|
// optionals
|
|
168
|
-
name: "name"
|
|
169
|
-
pkg,
|
|
170
|
-
templateDir: TEMPLATE_DIR
|
|
77
|
+
name: "name" // replace by the cli name. This property will be used by Plugins command
|
|
171
78
|
}).catch(console.error);
|
|
172
79
|
```
|
|
173
80
|
|
|
@@ -265,12 +172,6 @@ export class GenerateCmd implements CommandProvider {
|
|
|
265
172
|
}
|
|
266
173
|
```
|
|
267
174
|
|
|
268
|
-
Finally, create a handlebars template in templates directory:
|
|
269
|
-
|
|
270
|
-
```hbs
|
|
271
|
-
import {Injectable} from "@tsed/di"; @Injectable() export class {{symbolName}} { }
|
|
272
|
-
```
|
|
273
|
-
|
|
274
175
|
## Run command in dev mode
|
|
275
176
|
|
|
276
177
|
In your package.json add the following line in scripts property:
|
|
@@ -281,13 +182,13 @@ In your package.json add the following line in scripts property:
|
|
|
281
182
|
}
|
|
282
183
|
```
|
|
283
184
|
|
|
284
|
-
> Note: replace {{name}} by the name of
|
|
185
|
+
> Note: replace {{name}} by the name of your bin file located in src/bin.
|
|
285
186
|
|
|
286
187
|
> Note 2: The option `-r ./.tmp` create a temporary directory to generate files with your command.
|
|
287
188
|
|
|
288
189
|
## More examples
|
|
289
190
|
|
|
290
|
-
Here other
|
|
191
|
+
Here are other command examples:
|
|
291
192
|
|
|
292
193
|
- Init a project command: https://github.com/tsedio/tsed-cli/tree/master/packages/cli/src/commands/init/InitCmd
|
|
293
194
|
- Generate command: https://github.com/tsedio/tsed-cli/tree/master/packages/cli/src/commands/generate/GenerateCmd
|