@tsed/cli-core 6.0.0-alpha.9 → 6.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 +7 -12
- package/lib/esm/decorators/command.js +0 -1
- package/lib/esm/decorators/index.js +0 -1
- package/lib/esm/decorators/on.js +0 -1
- package/lib/esm/decorators/onAdd.js +0 -1
- package/lib/esm/decorators/onExec.js +0 -1
- package/lib/esm/decorators/onPostInstall.js +0 -1
- package/lib/esm/decorators/onPrompt.js +0 -1
- package/lib/esm/domains/CliError.js +0 -1
- package/lib/esm/domains/CommandStoreKeys.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/interfaces/CliDefaultOptions.js +0 -1
- package/lib/esm/interfaces/CommandMetadata.js +0 -1
- package/lib/esm/interfaces/CommandParameters.js +0 -1
- package/lib/esm/interfaces/CommandProvider.js +0 -1
- package/lib/esm/interfaces/PackageJson.js +0 -1
- package/lib/esm/interfaces/ProjectPreferences.js +0 -1
- package/lib/esm/interfaces/Tasks.js +0 -1
- package/lib/esm/interfaces/index.js +0 -1
- package/lib/esm/packageManagers/PackageManagersModule.js +3 -4
- package/lib/esm/packageManagers/index.js +0 -1
- package/lib/esm/packageManagers/supports/BaseManager.js +1 -5
- package/lib/esm/packageManagers/supports/BunManager.js +0 -1
- package/lib/esm/packageManagers/supports/NpmManager.js +0 -1
- package/lib/esm/packageManagers/supports/PNpmManager.js +0 -1
- package/lib/esm/packageManagers/supports/YarnBerryManager.js +0 -1
- package/lib/esm/packageManagers/supports/YarnManager.js +0 -1
- package/lib/esm/services/CliConfiguration.js +0 -1
- package/lib/esm/services/CliDockerComposeYaml.js +7 -15
- package/lib/esm/services/CliExeca.js +0 -1
- package/lib/esm/services/CliFs.js +0 -1
- package/lib/esm/services/CliHooks.js +5 -9
- package/lib/esm/services/CliHttpClient.js +6 -7
- package/lib/esm/services/CliHttpLogClient.js +2 -6
- package/lib/esm/services/CliLoadFile.js +3 -10
- package/lib/esm/services/CliPackageJson.js +4 -2
- package/lib/esm/services/CliPlugins.js +10 -30
- package/lib/esm/services/CliProxyAgent.js +11 -19
- package/lib/esm/services/CliRunScript.js +3 -8
- package/lib/esm/services/CliService.js +30 -49
- package/lib/esm/services/CliYaml.js +5 -7
- package/lib/esm/services/NpmRegistryClient.js +5 -7
- package/lib/esm/services/ProjectPackageJson.js +23 -24
- package/lib/esm/services/Renderer.js +5 -15
- package/lib/esm/services/index.js +0 -1
- package/lib/esm/utils/coerce.js +0 -1
- package/lib/esm/utils/createInjector.js +11 -12
- package/lib/esm/utils/createTasksRunner.js +1 -2
- package/lib/esm/utils/getCommandMetadata.js +1 -2
- package/lib/esm/utils/getTemplateDirectory.js +0 -1
- package/lib/esm/utils/hbs/array.js +0 -1
- package/lib/esm/utils/hbs/collection.js +0 -1
- package/lib/esm/utils/hbs/comparison.js +0 -1
- package/lib/esm/utils/hbs/index.js +0 -1
- package/lib/esm/utils/hbs/object.js +0 -1
- package/lib/esm/utils/hbs/switch.js +0 -1
- package/lib/esm/utils/index.js +0 -1
- package/lib/esm/utils/isValidVersion.js +0 -1
- package/lib/esm/utils/loadPlugins.js +16 -16
- package/lib/esm/utils/logToCurl.js +0 -1
- package/lib/esm/utils/mapCommanderArgs.js +0 -1
- package/lib/esm/utils/mapCommanderOptions.js +4 -2
- package/lib/esm/utils/parseOption.js +0 -1
- package/lib/esm/utils/patchCommander.js +0 -1
- package/lib/esm/utils/renderer/insertAfter.js +0 -1
- package/lib/esm/utils/renderer/insertImport.js +0 -1
- package/lib/esm/utils/resolveConfiguration.js +0 -1
- package/lib/esm/utils/streamToObservable.js +0 -1
- package/lib/types/packageManagers/PackageManagersModule.d.ts +1 -1
- package/lib/types/services/CliExeca.d.ts +6 -5
- package/lib/types/services/CliHooks.d.ts +0 -2
- package/lib/types/services/CliPackageJson.d.ts +2 -1
- package/lib/types/services/CliPlugins.d.ts +2 -2
- package/lib/types/services/CliProxyAgent.d.ts +4 -3
- package/lib/types/services/CliRunScript.d.ts +0 -2
- package/lib/types/services/CliService.d.ts +4 -5
- package/lib/types/services/ProjectPackageJson.d.ts +2 -4
- package/lib/types/services/Renderer.d.ts +3 -4
- package/lib/types/utils/getCommandMetadata.d.ts +2 -2
- package/lib/types/utils/loadPlugins.d.ts +1 -2
- package/lib/types/utils/mapCommanderOptions.d.ts +1 -1
- package/package.json +10 -11
- package/lib/esm/CliCore.js.map +0 -1
- package/lib/esm/decorators/command.js.map +0 -1
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/decorators/on.js.map +0 -1
- package/lib/esm/decorators/onAdd.js.map +0 -1
- package/lib/esm/decorators/onExec.js.map +0 -1
- package/lib/esm/decorators/onPostInstall.js.map +0 -1
- package/lib/esm/decorators/onPrompt.js.map +0 -1
- package/lib/esm/domains/CliError.js.map +0 -1
- package/lib/esm/domains/CommandStoreKeys.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/CliDefaultOptions.js.map +0 -1
- package/lib/esm/interfaces/CommandMetadata.js.map +0 -1
- package/lib/esm/interfaces/CommandParameters.js.map +0 -1
- package/lib/esm/interfaces/CommandProvider.js.map +0 -1
- package/lib/esm/interfaces/PackageJson.js.map +0 -1
- package/lib/esm/interfaces/ProjectPreferences.js.map +0 -1
- package/lib/esm/interfaces/Tasks.js.map +0 -1
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/packageManagers/PackageManagersModule.js.map +0 -1
- package/lib/esm/packageManagers/index.js.map +0 -1
- package/lib/esm/packageManagers/supports/BaseManager.js.map +0 -1
- package/lib/esm/packageManagers/supports/BunManager.js.map +0 -1
- package/lib/esm/packageManagers/supports/NpmManager.js.map +0 -1
- package/lib/esm/packageManagers/supports/PNpmManager.js.map +0 -1
- package/lib/esm/packageManagers/supports/YarnBerryManager.js.map +0 -1
- package/lib/esm/packageManagers/supports/YarnManager.js.map +0 -1
- package/lib/esm/services/CliConfiguration.js.map +0 -1
- package/lib/esm/services/CliDockerComposeYaml.js.map +0 -1
- package/lib/esm/services/CliExeca.js.map +0 -1
- package/lib/esm/services/CliFs.js.map +0 -1
- package/lib/esm/services/CliHooks.js.map +0 -1
- package/lib/esm/services/CliHttpClient.js.map +0 -1
- package/lib/esm/services/CliHttpLogClient.js.map +0 -1
- package/lib/esm/services/CliLoadFile.js.map +0 -1
- package/lib/esm/services/CliPackageJson.js.map +0 -1
- package/lib/esm/services/CliPlugins.js.map +0 -1
- package/lib/esm/services/CliProxyAgent.js.map +0 -1
- package/lib/esm/services/CliRunScript.js.map +0 -1
- package/lib/esm/services/CliService.js.map +0 -1
- package/lib/esm/services/CliYaml.js.map +0 -1
- package/lib/esm/services/NpmRegistryClient.js.map +0 -1
- package/lib/esm/services/ProjectPackageJson.js.map +0 -1
- package/lib/esm/services/Renderer.js.map +0 -1
- package/lib/esm/services/index.js.map +0 -1
- package/lib/esm/utils/coerce.js.map +0 -1
- package/lib/esm/utils/createInjector.js.map +0 -1
- package/lib/esm/utils/createTasksRunner.js.map +0 -1
- package/lib/esm/utils/getCommandMetadata.js.map +0 -1
- package/lib/esm/utils/getTemplateDirectory.js.map +0 -1
- package/lib/esm/utils/hbs/array.js.map +0 -1
- package/lib/esm/utils/hbs/collection.js.map +0 -1
- package/lib/esm/utils/hbs/comparison.js.map +0 -1
- package/lib/esm/utils/hbs/index.js.map +0 -1
- package/lib/esm/utils/hbs/object.js.map +0 -1
- package/lib/esm/utils/hbs/switch.js.map +0 -1
- package/lib/esm/utils/index.js.map +0 -1
- package/lib/esm/utils/isValidVersion.js.map +0 -1
- package/lib/esm/utils/loadPlugins.js.map +0 -1
- package/lib/esm/utils/logToCurl.js.map +0 -1
- package/lib/esm/utils/mapCommanderArgs.js.map +0 -1
- package/lib/esm/utils/mapCommanderOptions.js.map +0 -1
- package/lib/esm/utils/parseOption.js.map +0 -1
- package/lib/esm/utils/patchCommander.js.map +0 -1
- package/lib/esm/utils/renderer/insertAfter.js.map +0 -1
- package/lib/esm/utils/renderer/insertImport.js.map +0 -1
- package/lib/esm/utils/resolveConfiguration.js.map +0 -1
- package/lib/esm/utils/streamToObservable.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __decorate
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { classOf } from "@tsed/core";
|
|
3
|
-
import {
|
|
3
|
+
import { $emit, configuration, constant, destroyInjector, DIContext, getContext, inject, Injectable, injector, logger, Provider, runInContext } from "@tsed/di";
|
|
4
4
|
import { Argument, Command } from "commander";
|
|
5
5
|
import Inquirer from "inquirer";
|
|
6
6
|
// @ts-ignore
|
|
@@ -10,16 +10,20 @@ import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
|
10
10
|
import { PackageManagersModule } from "../packageManagers/index.js";
|
|
11
11
|
import { createSubTasks, createTasksRunner } from "../utils/createTasksRunner.js";
|
|
12
12
|
import { getCommandMetadata } from "../utils/getCommandMetadata.js";
|
|
13
|
+
import { mapCommanderOptions } from "../utils/index.js";
|
|
13
14
|
import { mapCommanderArgs } from "../utils/mapCommanderArgs.js";
|
|
14
|
-
import { mapCommanderOptions } from "../utils/mapCommanderOptions.js";
|
|
15
15
|
import { parseOption } from "../utils/parseOption.js";
|
|
16
16
|
import { CliHooks } from "./CliHooks.js";
|
|
17
17
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
18
18
|
Inquirer.registerPrompt("autocomplete", inquirer_autocomplete_prompt);
|
|
19
19
|
let CliService = class CliService {
|
|
20
20
|
constructor() {
|
|
21
|
+
this.reinstallAfterRun = constant("project.reinstallAfterRun", false);
|
|
21
22
|
this.program = new Command();
|
|
22
|
-
this.
|
|
23
|
+
this.pkg = constant("pkg", { version: "1.0.0" });
|
|
24
|
+
this.hooks = inject(CliHooks);
|
|
25
|
+
this.projectPkg = inject(ProjectPackageJson);
|
|
26
|
+
this.packageManagers = inject(PackageManagersModule);
|
|
23
27
|
this.commands = new Map();
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
@@ -40,7 +44,7 @@ let CliService = class CliService {
|
|
|
40
44
|
*/
|
|
41
45
|
runLifecycle(cmdName, data = {}, $ctx) {
|
|
42
46
|
return runInContext($ctx, async () => {
|
|
43
|
-
await
|
|
47
|
+
await $emit("$loadPackageJson");
|
|
44
48
|
data = await this.beforePrompt(cmdName, data);
|
|
45
49
|
$ctx.set("data", data);
|
|
46
50
|
data = await this.prompt(cmdName, data);
|
|
@@ -54,12 +58,12 @@ let CliService = class CliService {
|
|
|
54
58
|
await this.exec(cmdName, data, $ctx);
|
|
55
59
|
}
|
|
56
60
|
catch (er) {
|
|
57
|
-
await
|
|
58
|
-
await
|
|
61
|
+
await $emit("$onFinish", er);
|
|
62
|
+
await destroyInjector();
|
|
59
63
|
throw er;
|
|
60
64
|
}
|
|
61
|
-
await
|
|
62
|
-
await
|
|
65
|
+
await $emit("$onFinish");
|
|
66
|
+
await destroyInjector();
|
|
63
67
|
}
|
|
64
68
|
async exec(cmdName, data, $ctx) {
|
|
65
69
|
const initialTasks = await this.getTasks(cmdName, data);
|
|
@@ -83,7 +87,7 @@ let CliService = class CliService {
|
|
|
83
87
|
*/
|
|
84
88
|
async beforePrompt(cmdName, ctx = {}) {
|
|
85
89
|
const provider = this.commands.get(cmdName);
|
|
86
|
-
const instance =
|
|
90
|
+
const instance = inject(provider.useClass);
|
|
87
91
|
const verbose = ctx.verbose;
|
|
88
92
|
if (instance.$beforePrompt) {
|
|
89
93
|
ctx = await instance.$beforePrompt(JSON.parse(JSON.stringify(ctx)));
|
|
@@ -98,7 +102,7 @@ let CliService = class CliService {
|
|
|
98
102
|
*/
|
|
99
103
|
async prompt(cmdName, ctx = {}) {
|
|
100
104
|
const provider = this.commands.get(cmdName);
|
|
101
|
-
const instance =
|
|
105
|
+
const instance = inject(provider.useClass);
|
|
102
106
|
if (instance.$prompt) {
|
|
103
107
|
const questions = [
|
|
104
108
|
...(await instance.$prompt(ctx)),
|
|
@@ -121,7 +125,7 @@ let CliService = class CliService {
|
|
|
121
125
|
async getTasks(cmdName, data) {
|
|
122
126
|
const $ctx = getContext();
|
|
123
127
|
const provider = this.commands.get(cmdName);
|
|
124
|
-
const instance =
|
|
128
|
+
const instance = inject(provider.token);
|
|
125
129
|
data = this.mapData(cmdName, data, $ctx);
|
|
126
130
|
if (instance.$beforeExec) {
|
|
127
131
|
await instance.$beforeExec(data);
|
|
@@ -130,7 +134,7 @@ let CliService = class CliService {
|
|
|
130
134
|
}
|
|
131
135
|
async getPostInstallTasks(cmdName, data) {
|
|
132
136
|
const provider = this.commands.get(cmdName);
|
|
133
|
-
const instance =
|
|
137
|
+
const instance = inject(provider.useClass);
|
|
134
138
|
data = this.mapData(cmdName, data, getContext());
|
|
135
139
|
return [
|
|
136
140
|
...(instance.$postInstall ? await instance.$postInstall(data) : []),
|
|
@@ -144,10 +148,10 @@ let CliService = class CliService {
|
|
|
144
148
|
return this.commands.get(name).command;
|
|
145
149
|
}
|
|
146
150
|
let cmd = this.program.command(name);
|
|
147
|
-
const onAction = (
|
|
151
|
+
const onAction = (commandName) => {
|
|
148
152
|
const [, ...rawArgs] = cmd.args;
|
|
149
|
-
const mappedArgs = mapCommanderArgs(args,
|
|
150
|
-
const allOpts = mapCommanderOptions(this.program.commands);
|
|
153
|
+
const mappedArgs = mapCommanderArgs(args, this.program.args.filter((arg) => commandName === arg));
|
|
154
|
+
const allOpts = mapCommanderOptions(commandName, this.program.commands);
|
|
151
155
|
const data = {
|
|
152
156
|
...allOpts,
|
|
153
157
|
verbose: !!this.program.opts().verbose,
|
|
@@ -157,15 +161,15 @@ let CliService = class CliService {
|
|
|
157
161
|
};
|
|
158
162
|
const $ctx = new DIContext({
|
|
159
163
|
id: v4(),
|
|
160
|
-
injector:
|
|
161
|
-
logger:
|
|
162
|
-
level:
|
|
164
|
+
injector: injector(),
|
|
165
|
+
logger: logger(),
|
|
166
|
+
level: logger().level,
|
|
163
167
|
maxStackSize: 0,
|
|
164
168
|
platform: "CLI"
|
|
165
169
|
});
|
|
166
170
|
$ctx.set("data", data);
|
|
167
171
|
$ctx.set("command", metadata);
|
|
168
|
-
|
|
172
|
+
configuration().set("command.metadata", metadata);
|
|
169
173
|
return this.runLifecycle(name, data, $ctx);
|
|
170
174
|
};
|
|
171
175
|
if (alias) {
|
|
@@ -180,21 +184,23 @@ let CliService = class CliService {
|
|
|
180
184
|
return cmd;
|
|
181
185
|
}
|
|
182
186
|
load() {
|
|
183
|
-
|
|
187
|
+
injector()
|
|
188
|
+
.getProviders("command")
|
|
189
|
+
.forEach((provider) => this.build(provider));
|
|
184
190
|
}
|
|
185
191
|
mapData(cmdName, data, $ctx) {
|
|
186
192
|
const provider = this.commands.get(cmdName);
|
|
187
|
-
const instance =
|
|
193
|
+
const instance = inject(provider.useClass);
|
|
188
194
|
const verbose = data.verbose;
|
|
189
195
|
if (instance.$mapContext) {
|
|
190
196
|
data = instance.$mapContext(JSON.parse(JSON.stringify(data)));
|
|
191
197
|
data.verbose = verbose;
|
|
192
198
|
}
|
|
193
199
|
if (data.verbose) {
|
|
194
|
-
|
|
200
|
+
logger().level = "debug";
|
|
195
201
|
}
|
|
196
202
|
else {
|
|
197
|
-
|
|
203
|
+
logger().level = "info";
|
|
198
204
|
}
|
|
199
205
|
data.bindLogger = $ctx.get("command").bindLogger;
|
|
200
206
|
$ctx.set("data", data);
|
|
@@ -249,32 +255,7 @@ let CliService = class CliService {
|
|
|
249
255
|
}, cmd);
|
|
250
256
|
}
|
|
251
257
|
};
|
|
252
|
-
__decorate([
|
|
253
|
-
Constant("project.reinstallAfterRun", false),
|
|
254
|
-
__metadata("design:type", Object)
|
|
255
|
-
], CliService.prototype, "reinstallAfterRun", void 0);
|
|
256
|
-
__decorate([
|
|
257
|
-
Constant("pkg", { version: "1.0.0" }),
|
|
258
|
-
__metadata("design:type", Object)
|
|
259
|
-
], CliService.prototype, "pkg", void 0);
|
|
260
|
-
__decorate([
|
|
261
|
-
Inject(),
|
|
262
|
-
__metadata("design:type", InjectorService)
|
|
263
|
-
], CliService.prototype, "injector", void 0);
|
|
264
|
-
__decorate([
|
|
265
|
-
Inject(),
|
|
266
|
-
__metadata("design:type", CliHooks)
|
|
267
|
-
], CliService.prototype, "hooks", void 0);
|
|
268
|
-
__decorate([
|
|
269
|
-
Inject(),
|
|
270
|
-
__metadata("design:type", ProjectPackageJson)
|
|
271
|
-
], CliService.prototype, "projectPkg", void 0);
|
|
272
|
-
__decorate([
|
|
273
|
-
Inject(PackageManagersModule),
|
|
274
|
-
__metadata("design:type", PackageManagersModule)
|
|
275
|
-
], CliService.prototype, "packageManagers", void 0);
|
|
276
258
|
CliService = __decorate([
|
|
277
259
|
Injectable()
|
|
278
260
|
], CliService);
|
|
279
261
|
export { CliService };
|
|
280
|
-
//# sourceMappingURL=CliService.js.map
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { __decorate
|
|
2
|
-
import {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { inject, Injectable } from "@tsed/di";
|
|
3
3
|
import JsYaml from "js-yaml";
|
|
4
4
|
import { CliFs } from "./CliFs.js";
|
|
5
5
|
let CliYaml = class CliYaml {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.fs = inject(CliFs);
|
|
8
|
+
}
|
|
6
9
|
async read(path) {
|
|
7
10
|
const content = await this.fs.readFile(path, { encoding: "utf8" });
|
|
8
11
|
return JsYaml.load(content);
|
|
@@ -12,12 +15,7 @@ let CliYaml = class CliYaml {
|
|
|
12
15
|
return this.fs.writeFile(path, content, { encoding: "utf8" });
|
|
13
16
|
}
|
|
14
17
|
};
|
|
15
|
-
__decorate([
|
|
16
|
-
Inject(),
|
|
17
|
-
__metadata("design:type", CliFs)
|
|
18
|
-
], CliYaml.prototype, "fs", void 0);
|
|
19
18
|
CliYaml = __decorate([
|
|
20
19
|
Injectable()
|
|
21
20
|
], CliYaml);
|
|
22
21
|
export { CliYaml };
|
|
23
|
-
//# sourceMappingURL=CliYaml.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var NpmRegistryClient_1;
|
|
2
|
-
import { __decorate
|
|
3
|
-
import {
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { inject, Injectable } from "@tsed/di";
|
|
4
4
|
import registry_url from "registry-url";
|
|
5
5
|
import url from "url";
|
|
6
6
|
import { CliHttpClient } from "./CliHttpClient.js";
|
|
@@ -15,6 +15,9 @@ export function addSuffix(pattern, suffix) {
|
|
|
15
15
|
}
|
|
16
16
|
export const SCOPE_SEPARATOR = "%2f";
|
|
17
17
|
let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.httpClient = inject(CliHttpClient);
|
|
20
|
+
}
|
|
18
21
|
static escapeName(name) {
|
|
19
22
|
// scoped packages contain slashes and the npm registry expects them to be escaped
|
|
20
23
|
return name.replace("/", SCOPE_SEPARATOR);
|
|
@@ -106,12 +109,7 @@ let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
|
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
};
|
|
109
|
-
__decorate([
|
|
110
|
-
Inject(CliHttpClient),
|
|
111
|
-
__metadata("design:type", CliHttpClient)
|
|
112
|
-
], NpmRegistryClient.prototype, "httpClient", void 0);
|
|
113
112
|
NpmRegistryClient = NpmRegistryClient_1 = __decorate([
|
|
114
113
|
Injectable()
|
|
115
114
|
], NpmRegistryClient);
|
|
116
115
|
export { NpmRegistryClient };
|
|
117
|
-
//# sourceMappingURL=NpmRegistryClient.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __decorate, __metadata
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { getValue, setValue } from "@tsed/core";
|
|
3
|
-
import {
|
|
3
|
+
import { configuration, constant, inject, Injectable } from "@tsed/di";
|
|
4
4
|
import { dirname, join } from "path";
|
|
5
5
|
import { readPackageUpSync } from "read-pkg-up";
|
|
6
6
|
import { isValidVersion } from "../utils/isValidVersion.js";
|
|
@@ -29,11 +29,10 @@ function mapPackages(deps) {
|
|
|
29
29
|
}, { valid: {}, invalid: {} });
|
|
30
30
|
}
|
|
31
31
|
let ProjectPackageJson = class ProjectPackageJson {
|
|
32
|
-
constructor(
|
|
33
|
-
this.configuration = configuration;
|
|
34
|
-
this.fs = fs;
|
|
32
|
+
constructor() {
|
|
35
33
|
this.rewrite = false;
|
|
36
34
|
this.reinstall = false;
|
|
35
|
+
this.fs = inject(CliFs);
|
|
37
36
|
this.setRaw({
|
|
38
37
|
name: "",
|
|
39
38
|
version: "1.0.0",
|
|
@@ -48,10 +47,10 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
48
47
|
return join(this.dir, "package.json");
|
|
49
48
|
}
|
|
50
49
|
get dir() {
|
|
51
|
-
return String(
|
|
50
|
+
return String(constant("project.rootDir"));
|
|
52
51
|
}
|
|
53
52
|
set dir(dir) {
|
|
54
|
-
|
|
53
|
+
configuration().project.rootDir = dir;
|
|
55
54
|
this.read();
|
|
56
55
|
}
|
|
57
56
|
get name() {
|
|
@@ -83,7 +82,7 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
84
|
get preferences() {
|
|
86
|
-
return this.raw[
|
|
85
|
+
return this.raw[constant("name")];
|
|
87
86
|
}
|
|
88
87
|
$loadPackageJson() {
|
|
89
88
|
return this.read();
|
|
@@ -97,11 +96,12 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
97
96
|
return this;
|
|
98
97
|
}
|
|
99
98
|
setRaw(pkg) {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
99
|
+
const config = configuration();
|
|
100
|
+
const projectPreferences = config.defaultProjectPreferences;
|
|
101
|
+
const preferences = getValue(pkg, config.name);
|
|
102
102
|
this.raw = {
|
|
103
103
|
...pkg,
|
|
104
|
-
[
|
|
104
|
+
[config.name]: {
|
|
105
105
|
...(projectPreferences && projectPreferences(pkg)),
|
|
106
106
|
...preferences
|
|
107
107
|
}
|
|
@@ -150,7 +150,7 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
150
150
|
return this;
|
|
151
151
|
}
|
|
152
152
|
setPreference(key, value) {
|
|
153
|
-
setValue(this.raw, `${
|
|
153
|
+
setValue(this.raw, `${constant("name")}.${key}`, value);
|
|
154
154
|
this.rewrite = true;
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
@@ -212,7 +212,7 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
212
212
|
refresh() {
|
|
213
213
|
this.reinstall = false;
|
|
214
214
|
this.rewrite = false;
|
|
215
|
-
const cwd =
|
|
215
|
+
const cwd = constant("project.rootDir");
|
|
216
216
|
const pkgPath = join(String(cwd), "package.json");
|
|
217
217
|
const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
|
|
218
218
|
pkg.scripts = {
|
|
@@ -227,17 +227,18 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
227
227
|
...this.raw.devDependencies,
|
|
228
228
|
...pkg.devDependencies
|
|
229
229
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
...
|
|
230
|
+
const name = constant("name");
|
|
231
|
+
pkg[name] = {
|
|
232
|
+
...this.raw[name],
|
|
233
|
+
...pkg[name]
|
|
233
234
|
};
|
|
234
235
|
this.raw = pkg;
|
|
235
236
|
return this;
|
|
236
237
|
}
|
|
237
238
|
getPackageJson() {
|
|
238
|
-
const cwd =
|
|
239
|
-
const disableReadUpPkg =
|
|
240
|
-
const name =
|
|
239
|
+
const cwd = constant("project.rootDir");
|
|
240
|
+
const disableReadUpPkg = constant("command.metadata.disableReadUpPkg");
|
|
241
|
+
const name = constant("name");
|
|
241
242
|
const pkgPath = join(String(cwd), "package.json");
|
|
242
243
|
const fileExists = this.fs.exists(pkgPath);
|
|
243
244
|
if (!disableReadUpPkg && !fileExists) {
|
|
@@ -246,14 +247,14 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
246
247
|
});
|
|
247
248
|
if (result && result.path) {
|
|
248
249
|
const pkgPath = dirname(result.path);
|
|
249
|
-
|
|
250
|
+
configuration().set("project.root", pkgPath);
|
|
250
251
|
const pkg = this.fs.readJsonSync(result.path, { encoding: "utf8" });
|
|
251
252
|
return { ...this.getEmptyPackageJson(name), ...pkg };
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
if (disableReadUpPkg && fileExists) {
|
|
255
256
|
const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
|
|
256
|
-
|
|
257
|
+
configuration().set("project.root", pkgPath);
|
|
257
258
|
return { ...this.getEmptyPackageJson(name), ...pkg };
|
|
258
259
|
}
|
|
259
260
|
return this.getEmptyPackageJson(name);
|
|
@@ -271,8 +272,6 @@ let ProjectPackageJson = class ProjectPackageJson {
|
|
|
271
272
|
};
|
|
272
273
|
ProjectPackageJson = __decorate([
|
|
273
274
|
Injectable({}),
|
|
274
|
-
|
|
275
|
-
__metadata("design:paramtypes", [Object, CliFs])
|
|
275
|
+
__metadata("design:paramtypes", [])
|
|
276
276
|
], ProjectPackageJson);
|
|
277
277
|
export { ProjectPackageJson };
|
|
278
|
-
//# sourceMappingURL=ProjectPackageJson.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { __decorate
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import "../utils/hbs/index.js";
|
|
3
3
|
import { isString } from "@tsed/core";
|
|
4
|
-
import { Configuration,
|
|
4
|
+
import { Configuration, constant, inject, Injectable } from "@tsed/di";
|
|
5
5
|
import { normalizePath } from "@tsed/normalize-path";
|
|
6
6
|
import Consolidate from "consolidate";
|
|
7
7
|
import fs from "fs-extra";
|
|
@@ -14,7 +14,10 @@ import { insertImport } from "../utils/renderer/insertImport.js";
|
|
|
14
14
|
import { CliFs } from "./CliFs.js";
|
|
15
15
|
export class Renderer {
|
|
16
16
|
constructor() {
|
|
17
|
+
this.templateDir = constant("templateDir", "");
|
|
18
|
+
this.fs = inject(CliFs);
|
|
17
19
|
this.cache = new Set();
|
|
20
|
+
this.configuration = inject(Configuration);
|
|
18
21
|
}
|
|
19
22
|
async loadPartials(cwd) {
|
|
20
23
|
if (this.cache.has(cwd)) {
|
|
@@ -131,18 +134,6 @@ export class Renderer {
|
|
|
131
134
|
return { output, templateDir, rootDir };
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
|
-
__decorate([
|
|
135
|
-
Constant("templateDir"),
|
|
136
|
-
__metadata("design:type", String)
|
|
137
|
-
], Renderer.prototype, "templateDir", void 0);
|
|
138
|
-
__decorate([
|
|
139
|
-
Inject(),
|
|
140
|
-
__metadata("design:type", CliFs)
|
|
141
|
-
], Renderer.prototype, "fs", void 0);
|
|
142
|
-
__decorate([
|
|
143
|
-
Configuration(),
|
|
144
|
-
__metadata("design:type", Object)
|
|
145
|
-
], Renderer.prototype, "configuration", void 0);
|
|
146
137
|
let RootRendererService = class RootRendererService extends Renderer {
|
|
147
138
|
get rootDir() {
|
|
148
139
|
return this.configuration.project?.rootDir;
|
|
@@ -170,4 +161,3 @@ ScriptsRendererService = __decorate([
|
|
|
170
161
|
Injectable()
|
|
171
162
|
], ScriptsRendererService);
|
|
172
163
|
export { ScriptsRendererService };
|
|
173
|
-
//# sourceMappingURL=Renderer.js.map
|
package/lib/esm/utils/coerce.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InjectorService } from "@tsed/di";
|
|
1
|
+
import { injector, InjectorService } from "@tsed/di";
|
|
2
2
|
import { Logger } from "@tsed/logger";
|
|
3
3
|
import { CliConfiguration } from "../services/CliConfiguration.js";
|
|
4
4
|
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
@@ -11,19 +11,19 @@ function createConfiguration(injector) {
|
|
|
11
11
|
return injector.invoke(CliConfiguration);
|
|
12
12
|
}
|
|
13
13
|
export function createInjector(settings = {}) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
logger =
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const inj = injector();
|
|
15
|
+
inj.settings = createConfiguration(inj);
|
|
16
|
+
logger = inj.logger = new Logger(settings.name || "CLI");
|
|
17
|
+
inj.addProvider(ProjectPackageJson);
|
|
18
|
+
inj.settings.set(settings);
|
|
19
19
|
/* istanbul ignore next */
|
|
20
|
-
if (
|
|
21
|
-
|
|
20
|
+
if (inj.settings.env === "test") {
|
|
21
|
+
inj.logger.stop();
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
/* istanbul ignore next */
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
inj.logger.level = inj.settings.logger?.level || "warn";
|
|
26
|
+
inj.logger.appenders
|
|
27
27
|
.set("stdout", {
|
|
28
28
|
type: "stdout",
|
|
29
29
|
layout: {
|
|
@@ -41,6 +41,5 @@ export function createInjector(settings = {}) {
|
|
|
41
41
|
levels: ["trace", "fatal", "error", "warn"]
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
return
|
|
44
|
+
return inj;
|
|
45
45
|
}
|
|
46
|
-
//# sourceMappingURL=createInjector.js.map
|
|
@@ -19,7 +19,7 @@ function getOptions({ bindLogger = true, ...ctx }) {
|
|
|
19
19
|
renderer: useRawRenderer ? VerboseRenderer : DefaultRenderer,
|
|
20
20
|
rendererOptions: useRawRenderer && bindLogger
|
|
21
21
|
? {
|
|
22
|
-
logger: CustomLogger
|
|
22
|
+
logger: new CustomLogger()
|
|
23
23
|
}
|
|
24
24
|
: undefined
|
|
25
25
|
};
|
|
@@ -38,4 +38,3 @@ export function createSubTasks(tasks, opts) {
|
|
|
38
38
|
export function createTasksRunner(tasks, ctx) {
|
|
39
39
|
return createTasks(tasks, ctx).run(ctx);
|
|
40
40
|
}
|
|
41
|
-
//# sourceMappingURL=createTasksRunner.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Store
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
2
|
import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
3
3
|
export function getCommandMetadata(token) {
|
|
4
4
|
const { name, alias, args = {}, allowUnknownOption, description, options = {}, enableFeatures, disableReadUpPkg, bindLogger = true, ...opts } = Store.from(token)?.get(CommandStoreKeys.COMMAND);
|
|
@@ -15,4 +15,3 @@ export function getCommandMetadata(token) {
|
|
|
15
15
|
...opts
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=getCommandMetadata.js.map
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { GlobalProviders,
|
|
1
|
+
import { GlobalProviders, injector, logger } from "@tsed/di";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import figures from "figures";
|
|
4
4
|
import { CliFs } from "../services/CliFs.js";
|
|
5
5
|
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
6
6
|
const all = (promises) => Promise.all(promises);
|
|
7
|
-
export async function loadPlugins(
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
7
|
+
export async function loadPlugins() {
|
|
8
|
+
const $inj = injector();
|
|
9
|
+
const name = $inj.settings.get("name");
|
|
10
|
+
const rootDir = $inj.settings.get("project.rootDir");
|
|
11
|
+
const projectPackageJson = $inj.invoke(ProjectPackageJson);
|
|
12
|
+
const fs = $inj.invoke(CliFs);
|
|
12
13
|
const promises = Object.keys(projectPackageJson.allDependencies)
|
|
13
14
|
.filter((mod) => mod.startsWith(`@${name}/cli-plugin`) || mod.includes(`${name}-cli-plugin`))
|
|
14
15
|
.map(async (mod) => {
|
|
15
16
|
try {
|
|
16
17
|
const { default: plugin } = await fs.importModule(mod, rootDir);
|
|
17
|
-
if (
|
|
18
|
+
if (!$inj.has(plugin)) {
|
|
18
19
|
const provider = GlobalProviders.get(plugin)?.clone();
|
|
19
20
|
if (provider?.imports.length) {
|
|
20
21
|
await all(provider.imports.map(async (token) => {
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
await
|
|
22
|
+
$inj.add(token, GlobalProviders.get(token)?.clone());
|
|
23
|
+
if ($inj.settings.get("loaded")) {
|
|
24
|
+
await $inj.invoke(token);
|
|
24
25
|
}
|
|
25
26
|
}));
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
await
|
|
28
|
+
$inj.add(plugin, provider);
|
|
29
|
+
if ($inj.settings.get("loaded")) {
|
|
30
|
+
await $inj.invoke(plugin);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
logger().info(chalk.green(figures.tick), mod, "module loaded");
|
|
33
34
|
}
|
|
34
35
|
catch (er) {
|
|
35
|
-
|
|
36
|
+
logger().warn(chalk.red(figures.cross), "Fail to load plugin", mod);
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
await all(promises);
|
|
39
40
|
}
|
|
40
|
-
//# sourceMappingURL=loadPlugins.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export function mapCommanderOptions(commands) {
|
|
1
|
+
export function mapCommanderOptions(commandName, commands) {
|
|
2
2
|
const options = {};
|
|
3
3
|
commands.forEach((command) => {
|
|
4
|
+
if (command.name() !== commandName) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
4
7
|
Object.entries(command.opts())
|
|
5
8
|
.filter(([key]) => !key.startsWith("_") && !["commands", "options", "parent", "rawArgs", "args"].includes(key))
|
|
6
9
|
.forEach(([key, value]) => {
|
|
@@ -9,4 +12,3 @@ export function mapCommanderOptions(commands) {
|
|
|
9
12
|
});
|
|
10
13
|
return options;
|
|
11
14
|
}
|
|
12
|
-
//# sourceMappingURL=mapCommanderOptions.js.map
|