@tsed/cli-core 6.1.12 → 6.1.14
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/services/CliProxyAgent.js +5 -3
- package/lib/esm/services/index.js +0 -2
- package/lib/types/services/CliProxyAgent.d.ts +2 -0
- package/lib/types/services/index.d.ts +0 -2
- package/package.json +3 -9
- package/lib/esm/services/CliRunScript.js +0 -22
- package/lib/esm/services/Renderer.js +0 -162
- package/lib/esm/utils/hbs/array.js +0 -515
- package/lib/esm/utils/hbs/collection.js +0 -60
- package/lib/esm/utils/hbs/comparison.js +0 -431
- package/lib/esm/utils/hbs/index.js +0 -11
- package/lib/esm/utils/hbs/object.js +0 -236
- package/lib/esm/utils/hbs/switch.js +0 -10
- package/lib/esm/utils/renderer/insertAfter.js +0 -12
- package/lib/esm/utils/renderer/insertImport.js +0 -11
- package/lib/types/services/CliRunScript.d.ts +0 -3
- package/lib/types/services/Renderer.d.ts +0 -44
- package/lib/types/utils/hbs/array.d.ts +0 -1
- package/lib/types/utils/hbs/collection.d.ts +0 -1
- package/lib/types/utils/hbs/comparison.d.ts +0 -1
- package/lib/types/utils/hbs/index.d.ts +0 -1
- package/lib/types/utils/hbs/object.d.ts +0 -1
- package/lib/types/utils/hbs/switch.d.ts +0 -1
- package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
- package/lib/types/utils/renderer/insertImport.d.ts +0 -1
|
@@ -2,7 +2,6 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import { URL } from "node:url";
|
|
3
3
|
import { Configuration, Inject, inject, Injectable, refValue } from "@tsed/di";
|
|
4
4
|
import { camelCase } from "change-case";
|
|
5
|
-
import tunnel from "tunnel";
|
|
6
5
|
import { coerce } from "../utils/coerce.js";
|
|
7
6
|
import { CliExeca } from "./CliExeca.js";
|
|
8
7
|
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
@@ -12,6 +11,9 @@ let CliProxyAgent = class CliProxyAgent {
|
|
|
12
11
|
this.projectPackageJson = Inject(ProjectPackageJson);
|
|
13
12
|
this.cliExeca = inject(CliExeca);
|
|
14
13
|
}
|
|
14
|
+
async $onInit() {
|
|
15
|
+
this.tunnel = await import("tunnel");
|
|
16
|
+
}
|
|
15
17
|
hasProxy() {
|
|
16
18
|
return !!this.proxySettings.value.url;
|
|
17
19
|
}
|
|
@@ -29,8 +31,8 @@ let CliProxyAgent = class CliProxyAgent {
|
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
const method = camelCase([type, "over", protocol].join(" "));
|
|
32
|
-
if (tunnel[method]) {
|
|
33
|
-
return tunnel[method](options);
|
|
34
|
+
if (this.tunnel[method]) {
|
|
35
|
+
return this.tunnel[method](options);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
return null;
|
|
@@ -7,9 +7,7 @@ export * from "./CliLoadFile.js";
|
|
|
7
7
|
export * from "./CliPackageJson.js";
|
|
8
8
|
export * from "./CliPlugins.js";
|
|
9
9
|
export * from "./CliProxyAgent.js";
|
|
10
|
-
export * from "./CliRunScript.js";
|
|
11
10
|
export * from "./CliService.js";
|
|
12
11
|
export * from "./CliYaml.js";
|
|
13
12
|
export * from "./NpmRegistryClient.js";
|
|
14
13
|
export * from "./ProjectPackageJson.js";
|
|
15
|
-
export * from "./Renderer.js";
|
|
@@ -9,6 +9,8 @@ export declare class CliProxyAgent {
|
|
|
9
9
|
};
|
|
10
10
|
protected projectPackageJson: any;
|
|
11
11
|
protected cliExeca: CliExeca;
|
|
12
|
+
protected tunnel: typeof import("tunnel");
|
|
13
|
+
$onInit(): Promise<void>;
|
|
12
14
|
hasProxy(): boolean;
|
|
13
15
|
get(type: "http" | "https"): any;
|
|
14
16
|
resolveProxySettings(): Promise<void>;
|
|
@@ -7,9 +7,7 @@ export * from "./CliLoadFile.js";
|
|
|
7
7
|
export * from "./CliPackageJson.js";
|
|
8
8
|
export * from "./CliPlugins.js";
|
|
9
9
|
export * from "./CliProxyAgent.js";
|
|
10
|
-
export * from "./CliRunScript.js";
|
|
11
10
|
export * from "./CliService.js";
|
|
12
11
|
export * from "./CliYaml.js";
|
|
13
12
|
export * from "./NpmRegistryClient.js";
|
|
14
13
|
export * from "./ProjectPackageJson.js";
|
|
15
|
-
export * from "./Renderer.js";
|
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": "6.1.
|
|
4
|
+
"version": "6.1.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -31,25 +31,19 @@
|
|
|
31
31
|
"listr"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@npmcli/run-script": "9.0.0",
|
|
35
34
|
"@tsed/logger": ">=7.0.1",
|
|
36
35
|
"@tsed/normalize-path": ">=7.14.2",
|
|
37
|
-
"@types/fs-extra": "^11.0.4",
|
|
38
36
|
"@types/inquirer": "^9.0.7",
|
|
39
37
|
"ajv": "^8.17.1",
|
|
40
38
|
"axios": "^1.7.7",
|
|
41
39
|
"chalk": "^5.3.0",
|
|
42
40
|
"change-case": "^5.4.4",
|
|
43
41
|
"commander": "^12.1.0",
|
|
44
|
-
"consolidate": "^1.0.4",
|
|
45
|
-
"create-frame": "^1.0.0",
|
|
46
42
|
"enquirer": "^2.4.1",
|
|
47
43
|
"execa": "^8.0.1",
|
|
48
44
|
"figures": "^6.1.0",
|
|
49
45
|
"fs-extra": "^11.2.0",
|
|
50
46
|
"globby": "^14.0.2",
|
|
51
|
-
"handlebars": "^4.7.8",
|
|
52
|
-
"handlebars-utils": "^1.0.6",
|
|
53
47
|
"inquirer": "^9.3.7",
|
|
54
48
|
"inquirer-autocomplete-prompt": "^3.0.1",
|
|
55
49
|
"js-yaml": "^4.1.0",
|
|
@@ -66,10 +60,10 @@
|
|
|
66
60
|
"uuid": "^10.0.0"
|
|
67
61
|
},
|
|
68
62
|
"devDependencies": {
|
|
69
|
-
"@tsed/typescript": "6.1.
|
|
63
|
+
"@tsed/typescript": "6.1.14",
|
|
70
64
|
"@types/commander": "2.12.2",
|
|
71
|
-
"@types/consolidate": "0.14.4",
|
|
72
65
|
"@types/figures": "3.0.1",
|
|
66
|
+
"@types/fs-extra": "^11.0.4",
|
|
73
67
|
"@types/globby": "9.1.0",
|
|
74
68
|
"@types/js-yaml": "4.0.9",
|
|
75
69
|
"@types/semver": "7.5.8",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import runScript from "@npmcli/run-script";
|
|
4
|
-
import { inject, Injectable } from "@tsed/di";
|
|
5
|
-
import { ProjectPackageJson } from "./ProjectPackageJson.js";
|
|
6
|
-
let CliRunScript = class CliRunScript {
|
|
7
|
-
run(cmd, args, options = {}) {
|
|
8
|
-
return runScript({
|
|
9
|
-
event: "run",
|
|
10
|
-
...options,
|
|
11
|
-
cmd: `${cmd} ${args.join(" ")}`,
|
|
12
|
-
path: options.cwd || inject(ProjectPackageJson).dir,
|
|
13
|
-
env: options.env || {},
|
|
14
|
-
stdio: options.stdio || "inherit",
|
|
15
|
-
banner: false
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
CliRunScript = __decorate([
|
|
20
|
-
Injectable()
|
|
21
|
-
], CliRunScript);
|
|
22
|
-
export { CliRunScript };
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
import "../utils/hbs/index.js";
|
|
3
|
-
import { basename, dirname, join, relative } from "node:path";
|
|
4
|
-
import { isString } from "@tsed/core";
|
|
5
|
-
import { constant, inject, Injectable } from "@tsed/di";
|
|
6
|
-
import { normalizePath } from "@tsed/normalize-path";
|
|
7
|
-
import Consolidate from "consolidate";
|
|
8
|
-
import fs from "fs-extra";
|
|
9
|
-
import { globby } from "globby";
|
|
10
|
-
import handlebars from "handlebars";
|
|
11
|
-
import { Observable } from "rxjs";
|
|
12
|
-
import { insertAfter } from "../utils/renderer/insertAfter.js";
|
|
13
|
-
import { insertImport } from "../utils/renderer/insertImport.js";
|
|
14
|
-
import { CliFs } from "./CliFs.js";
|
|
15
|
-
export class Renderer {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.templateDir = constant("templateDir", "");
|
|
18
|
-
this.fs = inject(CliFs);
|
|
19
|
-
this.cache = new Set();
|
|
20
|
-
}
|
|
21
|
-
async loadPartials(cwd) {
|
|
22
|
-
if (this.cache.has(cwd)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const files = await globby("**/_partials/*.hbs", {
|
|
26
|
-
cwd
|
|
27
|
-
});
|
|
28
|
-
files.forEach((filename) => {
|
|
29
|
-
let template = this.fs.readFileSync(join(cwd, filename), "utf8");
|
|
30
|
-
const name = basename(filename).replace(".hbs", "");
|
|
31
|
-
handlebars.registerPartial(name, template);
|
|
32
|
-
});
|
|
33
|
-
this.cache.add(cwd);
|
|
34
|
-
}
|
|
35
|
-
async render(path, data, options = {}) {
|
|
36
|
-
const { output, templateDir, rootDir } = this.mapOptions(path, options);
|
|
37
|
-
let content = "";
|
|
38
|
-
const file = normalizePath(join(templateDir, path));
|
|
39
|
-
options.baseDir && (await this.loadPartials(join(templateDir, options.baseDir)));
|
|
40
|
-
if (path.endsWith(".hbs")) {
|
|
41
|
-
content = await Consolidate.handlebars(file, data);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
content = await this.fs.readFile(file, { encoding: "utf8" });
|
|
45
|
-
}
|
|
46
|
-
return this.write(content, { output, rootDir });
|
|
47
|
-
}
|
|
48
|
-
renderAll(paths, data, options = {}) {
|
|
49
|
-
let count = 0;
|
|
50
|
-
const mapOptions = (opts) => {
|
|
51
|
-
if (isString(opts)) {
|
|
52
|
-
return { ...options, path: opts };
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
...options,
|
|
56
|
-
...opts
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
return new Observable((observer) => {
|
|
60
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
61
|
-
const promises = paths
|
|
62
|
-
.filter(Boolean)
|
|
63
|
-
.map(mapOptions)
|
|
64
|
-
.map(async ({ path, ...opts }) => {
|
|
65
|
-
await this.render(path, data, opts);
|
|
66
|
-
count++;
|
|
67
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
68
|
-
});
|
|
69
|
-
Promise.all(promises)
|
|
70
|
-
.then(() => {
|
|
71
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
72
|
-
observer.complete();
|
|
73
|
-
})
|
|
74
|
-
.catch((err) => {
|
|
75
|
-
observer.error(err);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async write(content, options) {
|
|
80
|
-
const { output, rootDir = this.rootDir } = options;
|
|
81
|
-
const outputFile = join(...[rootDir, output].filter(Boolean));
|
|
82
|
-
await this.fs.ensureDir(dirname(outputFile));
|
|
83
|
-
return this.fs.writeFile(outputFile, content, { encoding: "utf8" });
|
|
84
|
-
}
|
|
85
|
-
templateExists(path, options = {}) {
|
|
86
|
-
const { templateDir } = this.mapOptions(path, options);
|
|
87
|
-
return fs.existsSync(join(templateDir, path));
|
|
88
|
-
}
|
|
89
|
-
async scan(pattern, options = {}) {
|
|
90
|
-
const result = await globby(pattern.map((s) => normalizePath(s)), {
|
|
91
|
-
...options,
|
|
92
|
-
objectMode: true,
|
|
93
|
-
cwd: this.rootDir
|
|
94
|
-
});
|
|
95
|
-
return result.map((entry) => entry.path);
|
|
96
|
-
}
|
|
97
|
-
relativeFrom(path) {
|
|
98
|
-
return relative(dirname(join(this.rootDir, path)), this.rootDir);
|
|
99
|
-
}
|
|
100
|
-
async update(path, actions) {
|
|
101
|
-
path = join(this.rootDir, path);
|
|
102
|
-
if (!this.fs.exists(path)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const content = actions.reduce((fileContent, action) => {
|
|
106
|
-
switch (action.type) {
|
|
107
|
-
case "import":
|
|
108
|
-
return insertImport(fileContent, action.content);
|
|
109
|
-
case "insert-after":
|
|
110
|
-
return insertAfter(fileContent, action.content, action.pattern);
|
|
111
|
-
default:
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
return fileContent;
|
|
115
|
-
}, await this.fs.readFile(path, { encoding: "utf8" }));
|
|
116
|
-
return this.fs.writeFile(path, content, { encoding: "utf8" });
|
|
117
|
-
}
|
|
118
|
-
mapOptions(path, options) {
|
|
119
|
-
const { templateDir = this.templateDir, rootDir = this.rootDir } = options;
|
|
120
|
-
let { output = path } = options;
|
|
121
|
-
if (options.baseDir) {
|
|
122
|
-
output = normalizePath(join("/", relative(options.baseDir, path)));
|
|
123
|
-
}
|
|
124
|
-
if (options.basename) {
|
|
125
|
-
output = normalizePath(join(dirname(output), options.basename));
|
|
126
|
-
}
|
|
127
|
-
output = output.replace(/\.hbs$/, "");
|
|
128
|
-
if (options.replaces) {
|
|
129
|
-
options.replaces.filter(Boolean).forEach((replace) => {
|
|
130
|
-
output = output.replace(replace, "");
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return { output, templateDir, rootDir };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let RootRendererService = class RootRendererService extends Renderer {
|
|
137
|
-
get rootDir() {
|
|
138
|
-
return constant("project.rootDir", "");
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
RootRendererService = __decorate([
|
|
142
|
-
Injectable()
|
|
143
|
-
], RootRendererService);
|
|
144
|
-
export { RootRendererService };
|
|
145
|
-
let SrcRendererService = class SrcRendererService extends Renderer {
|
|
146
|
-
get rootDir() {
|
|
147
|
-
return join(...[constant("project.rootDir"), constant("project.srcDir")].filter(Boolean));
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
SrcRendererService = __decorate([
|
|
151
|
-
Injectable()
|
|
152
|
-
], SrcRendererService);
|
|
153
|
-
export { SrcRendererService };
|
|
154
|
-
let ScriptsRendererService = class ScriptsRendererService extends Renderer {
|
|
155
|
-
get rootDir() {
|
|
156
|
-
return join(...[constant("project.rootDir"), constant("project.scriptsDir")].filter(Boolean));
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
ScriptsRendererService = __decorate([
|
|
160
|
-
Injectable()
|
|
161
|
-
], ScriptsRendererService);
|
|
162
|
-
export { ScriptsRendererService };
|