@tsed/cli 7.3.4 → 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
|
}
|