@tsed/cli 6.2.0-beta.1 → 6.2.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/commands/generate/GenerateCmd.js +4 -9
- package/lib/esm/commands/init/InitCmd.js +2 -1
- package/lib/esm/commands/run/RunCmd.js +3 -3
- 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
- package/templates/init/nodemon.json.hbs +1 -1
|
@@ -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 { getFrameworksPrompt } from "../init/prompts/getFeaturesPrompt.js";
|
|
15
16
|
import { PROVIDER_TYPES } from "./ProviderTypes.js";
|
|
@@ -35,6 +36,8 @@ const searchFactory = (list) => {
|
|
|
35
36
|
let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
|
|
36
37
|
constructor(providersList) {
|
|
37
38
|
this.providersList = providersList;
|
|
39
|
+
this.srcRenderService = inject(SrcRendererService);
|
|
40
|
+
this.projectPackageJson = inject(ProjectPackageJson);
|
|
38
41
|
PROVIDER_TYPES.forEach((info) => {
|
|
39
42
|
this.providersList.add({
|
|
40
43
|
...info
|
|
@@ -208,14 +211,6 @@ __decorate([
|
|
|
208
211
|
Inject(),
|
|
209
212
|
__metadata("design:type", RoutePipe)
|
|
210
213
|
], GenerateCmd.prototype, "routePipe", void 0);
|
|
211
|
-
__decorate([
|
|
212
|
-
Inject(),
|
|
213
|
-
__metadata("design:type", SrcRendererService)
|
|
214
|
-
], GenerateCmd.prototype, "srcRenderService", void 0);
|
|
215
|
-
__decorate([
|
|
216
|
-
Inject(),
|
|
217
|
-
__metadata("design:type", ProjectPackageJson)
|
|
218
|
-
], GenerateCmd.prototype, "projectPackageJson", void 0);
|
|
219
214
|
GenerateCmd = GenerateCmd_1 = __decorate([
|
|
220
215
|
Command({
|
|
221
216
|
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,6 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { CliFs,
|
|
3
|
-
import {
|
|
2
|
+
import { CliFs, Command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { CliRunScript } from "../../services/CliRunScript.js";
|
|
4
4
|
let RunCmd = class RunCmd {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.fs = inject(CliFs);
|
|
@@ -9,7 +9,7 @@ let RunCmd = class RunCmd {
|
|
|
9
9
|
}
|
|
10
10
|
async $exec(ctx) {
|
|
11
11
|
const cmd = "node";
|
|
12
|
-
const args = ["--import", "@swc-node/register/register
|
|
12
|
+
const args = ["--import", "@swc-node/register/esm-register"];
|
|
13
13
|
const path = normalizePath("src/bin/index.ts");
|
|
14
14
|
await this.runScript.run(cmd, [...args, path, ctx.command, ...ctx.rawArgs], {
|
|
15
15
|
env: process.env
|
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 };
|