@tsed/cli-core 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.
@@ -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";
@@ -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.13",
4
+ "version": "6.1.14",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -31,7 +31,6 @@
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
36
  "@types/inquirer": "^9.0.7",
@@ -40,15 +39,11 @@
40
39
  "chalk": "^5.3.0",
41
40
  "change-case": "^5.4.4",
42
41
  "commander": "^12.1.0",
43
- "consolidate": "^1.0.4",
44
- "create-frame": "^1.0.0",
45
42
  "enquirer": "^2.4.1",
46
43
  "execa": "^8.0.1",
47
44
  "figures": "^6.1.0",
48
45
  "fs-extra": "^11.2.0",
49
46
  "globby": "^14.0.2",
50
- "handlebars": "^4.7.8",
51
- "handlebars-utils": "^1.0.6",
52
47
  "inquirer": "^9.3.7",
53
48
  "inquirer-autocomplete-prompt": "^3.0.1",
54
49
  "js-yaml": "^4.1.0",
@@ -65,9 +60,8 @@
65
60
  "uuid": "^10.0.0"
66
61
  },
67
62
  "devDependencies": {
68
- "@tsed/typescript": "6.1.13",
63
+ "@tsed/typescript": "6.1.14",
69
64
  "@types/commander": "2.12.2",
70
- "@types/consolidate": "0.14.4",
71
65
  "@types/figures": "3.0.1",
72
66
  "@types/fs-extra": "^11.0.4",
73
67
  "@types/globby": "9.1.0",
@@ -1,22 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { inject, Injectable } from "@tsed/di";
3
- import { ProjectPackageJson } from "./ProjectPackageJson.js";
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 };
@@ -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 };