@tsed/cli 6.1.13 → 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/commands/generate/GenerateCmd.js +4 -9
- package/lib/esm/commands/init/InitCmd.js +2 -1
- package/lib/esm/commands/run/RunCmd.js +2 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/services/CliRunScript.js +22 -0
- package/lib/esm/services/Renderer.js +162 -0
- package/lib/esm/utils/hbs/array.js +515 -0
- package/lib/esm/utils/hbs/collection.js +60 -0
- package/lib/esm/utils/hbs/comparison.js +431 -0
- package/lib/esm/utils/hbs/index.js +11 -0
- package/lib/esm/utils/hbs/object.js +236 -0
- package/lib/esm/utils/hbs/switch.js +10 -0
- package/lib/esm/utils/renderer/insertAfter.js +12 -0
- package/lib/esm/utils/renderer/insertImport.js +11 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/generate/GenerateCmd.d.ts +2 -1
- package/lib/types/commands/init/InitCmd.d.ts +2 -1
- package/lib/types/commands/run/RunCmd.d.ts +2 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/CliRunScript.d.ts +3 -0
- package/lib/types/services/Renderer.d.ts +44 -0
- package/lib/types/utils/hbs/array.d.ts +1 -0
- package/lib/types/utils/hbs/collection.d.ts +1 -0
- package/lib/types/utils/hbs/comparison.d.ts +1 -0
- package/lib/types/utils/hbs/index.d.ts +1 -0
- package/lib/types/utils/hbs/object.d.ts +1 -0
- package/lib/types/utils/hbs/switch.d.ts +1 -0
- package/lib/types/utils/renderer/insertAfter.d.ts +1 -0
- package/lib/types/utils/renderer/insertImport.d.ts +1 -0
- package/package.json +9 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var GenerateCmd_1;
|
|
2
2
|
import { __decorate, __metadata } from "tslib";
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
|
-
import { Command, Inject,
|
|
4
|
+
import { Command, Inject, inject, ProjectPackageJson } from "@tsed/cli-core";
|
|
5
5
|
import { normalizePath } from "@tsed/normalize-path";
|
|
6
6
|
import { kebabCase, pascalCase } from "change-case";
|
|
7
7
|
import { globbySync } from "globby";
|
|
@@ -10,6 +10,7 @@ import { ClassNamePipe } from "../../pipes/ClassNamePipe.js";
|
|
|
10
10
|
import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
|
|
11
11
|
import { RoutePipe } from "../../pipes/RoutePipe.js";
|
|
12
12
|
import { ProvidersInfoService } from "../../services/ProvidersInfoService.js";
|
|
13
|
+
import { SrcRendererService } from "../../services/Renderer.js";
|
|
13
14
|
import { fillImports } from "../../utils/fillImports.js";
|
|
14
15
|
import { PROVIDER_TYPES } from "./ProviderTypes.js";
|
|
15
16
|
const DECORATOR_TYPES = [
|
|
@@ -34,6 +35,8 @@ const searchFactory = (list) => {
|
|
|
34
35
|
let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
|
|
35
36
|
constructor(providersList) {
|
|
36
37
|
this.providersList = providersList;
|
|
38
|
+
this.srcRenderService = inject(SrcRendererService);
|
|
39
|
+
this.projectPackageJson = inject(ProjectPackageJson);
|
|
37
40
|
PROVIDER_TYPES.forEach((info) => {
|
|
38
41
|
this.providersList.add({
|
|
39
42
|
...info
|
|
@@ -206,14 +209,6 @@ __decorate([
|
|
|
206
209
|
Inject(),
|
|
207
210
|
__metadata("design:type", RoutePipe)
|
|
208
211
|
], GenerateCmd.prototype, "routePipe", void 0);
|
|
209
|
-
__decorate([
|
|
210
|
-
Inject(),
|
|
211
|
-
__metadata("design:type", SrcRendererService)
|
|
212
|
-
], GenerateCmd.prototype, "srcRenderService", void 0);
|
|
213
|
-
__decorate([
|
|
214
|
-
Inject(),
|
|
215
|
-
__metadata("design:type", ProjectPackageJson)
|
|
216
|
-
], GenerateCmd.prototype, "projectPackageJson", void 0);
|
|
217
212
|
GenerateCmd = GenerateCmd_1 = __decorate([
|
|
218
213
|
Command({
|
|
219
214
|
name: "generate",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
|
-
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, CliService, Command, Configuration, createSubTasks, createTasksRunner, inject, PackageManager, PackageManagersModule, ProjectPackageJson
|
|
3
|
+
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, CliService, Command, Configuration, createSubTasks, createTasksRunner, inject, PackageManager, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
4
4
|
import { kebabCase, pascalCase } from "change-case";
|
|
5
5
|
import { DEFAULT_TSED_TAGS } from "../../constants/index.js";
|
|
6
6
|
import { ArchitectureConvention } from "../../interfaces/ArchitectureConvention.js";
|
|
@@ -11,6 +11,7 @@ import { InitPlatformsModule } from "../../platforms/InitPlatformsModule.js";
|
|
|
11
11
|
import { RuntimesModule } from "../../runtimes/RuntimesModule.js";
|
|
12
12
|
import { BunRuntime } from "../../runtimes/supports/BunRuntime.js";
|
|
13
13
|
import { NodeRuntime } from "../../runtimes/supports/NodeRuntime.js";
|
|
14
|
+
import { RootRendererService } from "../../services/Renderer.js";
|
|
14
15
|
import { fillImports } from "../../utils/fillImports.js";
|
|
15
16
|
import { FeaturesMap, FeatureType } from "./config/FeaturesPrompt.js";
|
|
16
17
|
import { InitFileSchema } from "./config/InitFileSchema.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { CliFs,
|
|
2
|
+
import { CliFs, Command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { CliRunScript } from "../../services/CliRunScript.js";
|
|
3
4
|
let RunCmd = class RunCmd {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.fs = inject(CliFs);
|
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { inject, Injectable } from "@tsed/di";
|
|
4
|
+
let CliRunScript = class CliRunScript {
|
|
5
|
+
async run(cmd, args, options = {}) {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const mod = await import("@npmcli/run-script");
|
|
8
|
+
return (mod.default || mod)({
|
|
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 };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import "../utils/hbs/index.js";
|
|
3
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
4
|
+
import { CliFs } from "@tsed/cli-core";
|
|
5
|
+
import { isString } from "@tsed/core";
|
|
6
|
+
import { constant, inject, Injectable } from "@tsed/di";
|
|
7
|
+
import { normalizePath } from "@tsed/normalize-path";
|
|
8
|
+
import Consolidate from "consolidate";
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import { globby } from "globby";
|
|
11
|
+
import handlebars from "handlebars";
|
|
12
|
+
import { Observable } from "rxjs";
|
|
13
|
+
import { insertAfter } from "../utils/renderer/insertAfter.js";
|
|
14
|
+
import { insertImport } from "../utils/renderer/insertImport.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 };
|