Skip to content

Commit

Permalink
feat(cli-core): add BunManager
Browse files Browse the repository at this point in the history
BREAKING CHANGE: prompt has changed and can break the third parties like Intellij/Vscode extension to generate Ts.ED project
  • Loading branch information
Romakita committed Dec 22, 2023
1 parent c19ebd3 commit ca2df00
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
7 changes: 5 additions & 2 deletions packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {InitCmdContext} from "@tsed/cli";
import {Inject, Injectable, OnExec, OnPostInstall, ProjectPackageJson, RootRendererService} from "@tsed/cli-core";
import {Inject, Injectable, OnExec, OnPostInstall, PackageManagersModule, ProjectPackageJson, RootRendererService} from "@tsed/cli-core";
import {TEMPLATE_DIR} from "../utils/templateDir";

@Injectable()
export class EslintInitHook {
@Inject()
protected packageJson: ProjectPackageJson;

@Inject()
protected packageManagers: PackageManagersModule;

@Inject()
protected rootRenderer: RootRendererService;

Expand Down Expand Up @@ -65,7 +68,7 @@ export class EslintInitHook {
})
.write();

await this.packageJson.runScript("prepare");
await this.packageManagers.runScript("prepare");
}
}
];
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-plugin-jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
coverageThreshold: {
global: {
statements: 79.45,
branches: 40,
branches: 37.5,
functions: 60,
lines: 79.45
}
Expand Down
10 changes: 7 additions & 3 deletions packages/cli-plugin-jest/src/CliPluginJestModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Module, OnAdd, ProjectPackageJson} from "@tsed/cli-core";
import {RuntimesModule} from "@tsed/cli";
import {Inject} from "@tsed/di";
import {JestGenerateHook} from "./hooks/JestGenerateHook";
import {JestInitHook} from "./hooks/JestInitHook";
Expand All @@ -7,6 +8,9 @@ import {JestInitHook} from "./hooks/JestInitHook";
imports: [JestInitHook, JestGenerateHook]
})
export class CliPluginJestModule {
@Inject()
runtimes: RuntimesModule;

@Inject()
packageJson: ProjectPackageJson;

Expand All @@ -17,12 +21,12 @@ export class CliPluginJestModule {
}

addScripts() {
const runner = this.packageJson.getRunCmd();
const runtime = this.runtimes.get();

this.packageJson.addScripts({
test: `${runner} test:lint && ${runner} test:coverage`,
test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")} `,
"test:unit": "cross-env NODE_ENV=test jest",
"test:coverage": `${runner} test:unit`
"test:coverage": `${runtime.run("test:unit")} `
});
}

Expand Down
8 changes: 6 additions & 2 deletions packages/cli-plugin-mocha/src/CliPluginMochaModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import {Module, OnAdd, ProjectPackageJson} from "@tsed/cli-core";
import {Inject} from "@tsed/di";
import {MochaGenerateHook} from "./hooks/MochaGenerateHook";
import {MochaInitHook} from "./hooks/MochaInitHook";
import {RuntimesModule} from "@tsed/cli";

@Module({
imports: [MochaInitHook, MochaGenerateHook]
})
export class CliPluginMochaModule {
@Inject()
runtimes: RuntimesModule;

@Inject()
packageJson: ProjectPackageJson;

Expand All @@ -17,10 +21,10 @@ export class CliPluginMochaModule {
}

addScripts() {
const runner = this.packageJson.getRunCmd();
const runtime = this.runtimes.get();

this.packageJson.addScripts({
test: `${runner} test:unit && ${runner} test:coverage`,
test: `${runtime.run("test:unit")} && ${runtime.run("test:coverage")} `,
"test:unit": "cross-env NODE_ENV=test mocha",
"test:coverage": "cross-env NODE_ENV=test nyc mocha"
});
Expand Down
7 changes: 5 additions & 2 deletions packages/cli-plugin-prisma/src/hooks/PrismaInitHook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {InitCmdContext} from "@tsed/cli";
import {CliService, Inject, OnExec, ProjectPackageJson} from "@tsed/cli-core";
import {CliService, Inject, OnExec, PackageManagersModule, ProjectPackageJson} from "@tsed/cli-core";
import {Injectable} from "@tsed/di";
import {CliPrisma} from "../services/CliPrisma";

Expand All @@ -14,6 +14,9 @@ export class PrismaInitHook {
@Inject()
protected packageJson: ProjectPackageJson;

@Inject()
protected packageManagers: PackageManagersModule;

@OnExec("init")
onExec(ctx: InitCmdContext) {
this.addScripts();
Expand Down Expand Up @@ -60,7 +63,7 @@ export class PrismaInitHook {

$onFinish() {
return new Promise((resolve) => {
this.packageJson.runScript("prisma:generate").subscribe({
this.packageManagers.runScript("prisma:generate").subscribe({
complete() {
resolve([]);
},
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-testing/src/FakeCliFs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from "fs";
import {PathLike} from "fs";
import {EnsureOptions, WriteFileOptions} from "fs-extra";
import {normalizePath} from "./normalizePath";
import {isString} from "@tsed/core";

export class FakeCliFs {
static entries = new Map<any, string>();
Expand All @@ -26,6 +28,12 @@ export class FakeCliFs {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
readFileSync(file: string | Buffer | number, encoding?: any): string {
try {
if (isString(file) && file.match(/_partials/)) {
return fs.readFileSync(file, encoding) as any as string;
}
} catch (er) {}

return FakeCliFs.entries.get(normalizePath(file))!;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/runtimes/RuntimesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {BunRuntime} from "./supports/BunRuntime";
import {SWCRuntime} from "./supports/SWCRuntime";
import {BaseRuntime} from "./supports/BaseRuntime";

export interface InitOptions extends Record<string, unknown> {
export interface RuntimeInitOptions extends Record<string, unknown> {
runtime?: string;
}

Expand All @@ -25,7 +25,7 @@ export class RuntimesModule {
this.runtimes = runtimes.filter((manager) => manager.has());
}

init(ctx: InitOptions) {
init(ctx: RuntimeInitOptions) {
ctx.runtime = ctx.runtime || this.get().name;

if (ctx.runtime === "bun") {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class RuntimesModule {
return selected;
}

scripts(ctx: InitOptions) {
scripts(ctx: RuntimeInitOptions) {
const runtime = this.get(ctx.runtime);

return {
Expand Down

0 comments on commit ca2df00

Please sign in to comment.