@tsed/cli 7.3.3 → 7.4.0
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as os from "node:os";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
|
-
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration, inject, PackageManager, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
4
4
|
import { tasks } from "@tsed/cli-tasks";
|
|
5
5
|
import { isString } from "@tsed/core";
|
|
6
6
|
import { constant } from "@tsed/di";
|
|
@@ -46,8 +46,16 @@ export class InitCmd {
|
|
|
46
46
|
if (initialOptions.skipPrompt) {
|
|
47
47
|
return [];
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
const
|
|
49
|
+
const forceBunRuntime = this.isLaunchedWithBunx();
|
|
50
|
+
const packageManagers = forceBunRuntime ? this.filterOnlyBun(this.packageManagers.list()) : this.packageManagers.list();
|
|
51
|
+
const runtimes = forceBunRuntime ? this.filterOnlyBun(this.runtimes.list()) : this.runtimes.list();
|
|
52
|
+
const promptOptions = forceBunRuntime
|
|
53
|
+
? {
|
|
54
|
+
...initialOptions,
|
|
55
|
+
runtime: "bun",
|
|
56
|
+
packageManager: PackageManager.BUN
|
|
57
|
+
}
|
|
58
|
+
: initialOptions;
|
|
51
59
|
return [
|
|
52
60
|
{
|
|
53
61
|
type: "input",
|
|
@@ -59,12 +67,16 @@ export class InitCmd {
|
|
|
59
67
|
return kebabCase(input);
|
|
60
68
|
}
|
|
61
69
|
},
|
|
62
|
-
...getFeaturesPrompt(runtimes, packageManagers.filter((o) => o !== "bun"),
|
|
70
|
+
...getFeaturesPrompt(runtimes, forceBunRuntime ? packageManagers : packageManagers.filter((o) => o !== "bun"), promptOptions)
|
|
63
71
|
];
|
|
64
72
|
}
|
|
65
73
|
$mapContext(ctx) {
|
|
66
74
|
this.resolveRootDir(ctx);
|
|
67
75
|
ctx = mapToContext(ctx);
|
|
76
|
+
if (this.isLaunchedWithBunx()) {
|
|
77
|
+
ctx.runtime = "bun";
|
|
78
|
+
ctx.packageManager = "bun";
|
|
79
|
+
}
|
|
68
80
|
this.runtimes.init(ctx);
|
|
69
81
|
this.runtimes.list().forEach((key) => {
|
|
70
82
|
ctx[key] = ctx.runtime === key;
|
|
@@ -78,6 +90,16 @@ export class InitCmd {
|
|
|
78
90
|
srcDir: constant("project.srcDir", "src")
|
|
79
91
|
};
|
|
80
92
|
}
|
|
93
|
+
isLaunchedWithBunx() {
|
|
94
|
+
return Boolean(globalThis.Bun);
|
|
95
|
+
}
|
|
96
|
+
filterOnlyBun(values) {
|
|
97
|
+
const filtered = values.filter((value) => value === "bun");
|
|
98
|
+
return filtered.length ? filtered : values;
|
|
99
|
+
}
|
|
100
|
+
async writeRcFiles(ctx) {
|
|
101
|
+
await Promise.all([render(".npmrc", ctx), render(".yarnrc", ctx)]);
|
|
102
|
+
}
|
|
81
103
|
preExec(ctx) {
|
|
82
104
|
this.fs.ensureDirSync(this.packageJson.cwd);
|
|
83
105
|
ctx.projectName && (this.packageJson.name = ctx.projectName);
|
|
@@ -91,9 +113,7 @@ export class InitCmd {
|
|
|
91
113
|
{
|
|
92
114
|
title: "Write RC files",
|
|
93
115
|
skip: () => !ctx.premium,
|
|
94
|
-
task: () =>
|
|
95
|
-
return Promise.all([render(".npmrc", ctx), render(".yarnrc", ctx)]);
|
|
96
|
-
}
|
|
116
|
+
task: () => this.writeRcFiles(ctx)
|
|
97
117
|
},
|
|
98
118
|
{
|
|
99
119
|
title: "Initialize package.json",
|
|
@@ -3,8 +3,11 @@ export function hasValue(expression, value) {
|
|
|
3
3
|
return (ctx) => [].concat(value).includes(getValue(expression, ctx));
|
|
4
4
|
}
|
|
5
5
|
export function hasFeature(feature) {
|
|
6
|
-
return (ctx) => !!ctx.features
|
|
6
|
+
return (ctx) => !!ctx.features?.find((item) => item === feature);
|
|
7
7
|
}
|
|
8
8
|
export function hasValuePremium() {
|
|
9
|
-
return (ctx) =>
|
|
9
|
+
return (ctx) => Object.entries(ctx)
|
|
10
|
+
.filter(([key]) => key.startsWith("features"))
|
|
11
|
+
.flatMap(([, value]) => [].concat(value))
|
|
12
|
+
.some((item) => typeof item === "string" && item.endsWith(":premium"));
|
|
10
13
|
}
|
|
@@ -40,8 +40,13 @@ export class ProjectClient extends Project {
|
|
|
40
40
|
async createSource(path, sourceFileText, options) {
|
|
41
41
|
path = join(this.rootDir, path);
|
|
42
42
|
if (path.endsWith(".ts") || path.endsWith(".mts")) {
|
|
43
|
+
await this.fs.mkdir(dirname(path));
|
|
44
|
+
if (typeof sourceFileText === "string") {
|
|
45
|
+
await this.fs.writeFile(path, sourceFileText, { encoding: "utf-8" });
|
|
46
|
+
return this.getSourceFile(path) || this.addSourceFileAtPath(path);
|
|
47
|
+
}
|
|
43
48
|
const source = this.createSourceFile(path, sourceFileText, options);
|
|
44
|
-
await source.
|
|
49
|
+
await this.fs.writeFile(path, source.getFullText(), { encoding: "utf-8" });
|
|
45
50
|
return source;
|
|
46
51
|
}
|
|
47
52
|
await this.fs.ensureDir(dirname(path));
|