@tsed/cli
Version:
CLI to bootstrap your Ts.ED project
55 lines (54 loc) • 2.21 kB
JavaScript
import { __decorate, __metadata, __param } from "tslib";
import { PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
import { Inject, inject, Module } from "@tsed/di";
import { BabelRuntime } from "./supports/BabelRuntime.js";
import { BaseRuntime } from "./supports/BaseRuntime.js";
import { BunRuntime } from "./supports/BunRuntime.js";
import { NodeRuntime } from "./supports/NodeRuntime.js";
import { WebpackRuntime } from "./supports/WebpackRuntime.js";
let RuntimesModule = class RuntimesModule {
constructor(runtimes) {
this.runtimes = runtimes;
this.projectPackageJson = inject(ProjectPackageJson);
this.packagesManager = inject(PackageManagersModule);
this.runtimes = runtimes.filter((manager) => manager.has());
}
init(ctx) {
ctx.runtime = ctx.runtime || this.get().name;
if (ctx.runtime === "bun") {
ctx.packageManager = "bun";
}
}
list() {
return this.runtimes.sort((a, b) => a.order - b.order).map((manager) => manager.name);
}
get(name) {
if (this.projectPackageJson.preferences.runtime) {
name = this.projectPackageJson.preferences.runtime;
}
name = name || "node";
let selected = this.runtimes.find((runtime) => runtime.name === name);
if (!selected) {
selected = this.runtimes.find((manager) => manager.name === "node");
}
this.projectPackageJson.setPreference("runtime", selected.name);
return selected;
}
scripts(ctx) {
const runtime = this.get(ctx.runtime);
return {
build: `${runtime.run("barrels")} && ${runtime.compile("src/index.ts", "dist/index.js")}`,
barrels: "barrels",
start: `${runtime.run("barrels")} && ${runtime.startDev("src/index.ts")}`,
"start:prod": `cross-env NODE_ENV=production ${runtime.startProd("dist/index.js")}`
};
}
};
RuntimesModule = __decorate([
Module({
imports: [NodeRuntime, BabelRuntime, WebpackRuntime, BunRuntime]
}),
__param(0, Inject("runtime")),
__metadata("design:paramtypes", [Array])
], RuntimesModule);
export { RuntimesModule };