diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a4c3685d9..c0a847013 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,16 @@ version: 2 updates: +####################################################### - package-ecosystem: 'npm' - directory: '/packages/test' + directory: '/packages/cli' + schedule: + interval: 'daily' + open-pull-requests-limit: 25 + allow: + - dependency-name: typescript +####################################################### + - package-ecosystem: 'npm' + directory: 'test' schedule: interval: 'daily' versioning-strategy: increase diff --git a/packages/cli/package.json b/packages/cli/package.json index d028fb0ab..47c3e086d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "nestia", - "version": "6.0.2", + "version": "6.0.3-dev.20240910", "description": "Nestia CLI tool", "main": "bin/index.js", "bin": { @@ -33,7 +33,8 @@ "dependencies": { "commander": "^10.0.0", "comment-json": "^4.2.3", - "inquirer": "^8.2.5" + "inquirer": "^8.2.5", + "package-manager-detector": "^0.2.0" }, "devDependencies": { "@nestia/core": "^3.8.0", @@ -41,7 +42,7 @@ "@types/inquirer": "^9.0.3", "@types/node": "^18.11.16", "rimraf": "^3.0.2", - "typescript": "^5.5.3" + "typescript": "^5.6.2" }, "files": [ "bin", diff --git a/packages/cli/src/NestiaSetupWizard.ts b/packages/cli/src/NestiaSetupWizard.ts index 2b80e11f6..f7ca6907c 100644 --- a/packages/cli/src/NestiaSetupWizard.ts +++ b/packages/cli/src/NestiaSetupWizard.ts @@ -1,3 +1,5 @@ +import fs from "fs"; + import { ArgumentParser } from "./internal/ArgumentParser"; import { CommandExecutor } from "./internal/CommandExecutor"; import { PackageManager } from "./internal/PackageManager"; @@ -29,7 +31,11 @@ export namespace NestiaSetupWizard { // INSTALL TYPESCRIPT COMPILERS pack.install({ dev: true, modulo: "ts-patch", version: "latest" }); pack.install({ dev: true, modulo: "ts-node", version: "latest" }); - pack.install({ dev: true, modulo: "typescript", version: "5.5.2" }); + pack.install({ + dev: true, + modulo: "typescript", + version: await getTypeScriptVersion(), + }); args.project ??= (() => { const runner: string = pack.manager === "npm" ? "npx" : pack.manager; CommandExecutor.run(`${runner} tsc --init`); @@ -75,4 +81,14 @@ export namespace NestiaSetupWizard { // CONFIGURE PLUGIN await PluginConfigurator.configure(args); } + + const getTypeScriptVersion = async (): Promise => { + const content: string = await fs.promises.readFile( + `${__dirname}/../package.json`, + "utf-8", + ); + const json: { devDependencies: { typescript: string } } = + JSON.parse(content); + return json.devDependencies.typescript; + }; } diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index f59b17ee3..f3d7da418 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -10,7 +10,6 @@ npx nestia [command] [options?] 5. npx nestia init 6. npx nestia sdk 7. npx nestia swagger - 8. npx nestia openai 9. npx nestia e2e 10. npx nestia all `; @@ -45,7 +44,6 @@ async function main(): Promise { type === "dependencies" || type === "init" || type === "sdk" || - type === "openai" || type === "swagger" || type === "e2e" || type === "all" diff --git a/packages/cli/src/internal/ArgumentParser.ts b/packages/cli/src/internal/ArgumentParser.ts index 3ca2cf0cd..38561abed 100644 --- a/packages/cli/src/internal/ArgumentParser.ts +++ b/packages/cli/src/internal/ArgumentParser.ts @@ -1,12 +1,13 @@ import commander from "commander"; import fs from "fs"; import inquirer from "inquirer"; +import { DetectResult, detect } from "package-manager-detector"; import { PackageManager } from "./PackageManager"; export namespace ArgumentParser { export interface IArguments { - manager: "npm" | "pnpm" | "yarn"; + manager: "npm" | "pnpm" | "yarn" | "bun"; project: string | null; runtime: boolean; } @@ -85,14 +86,17 @@ export namespace ArgumentParser { // DO CONSTRUCT return action(async (options) => { - options.manager ??= await select("manager")("Package Manager")( - [ - "npm" as const, - "pnpm" as const, - "yarn (berry is not supported)" as "yarn", - ], - (value) => value.split(" ")[0] as "yarn", - ); + options.manager ??= + (await detectManager()) ?? + (await select("manager")("Package Manager")( + [ + "npm" as const, + "pnpm" as const, + "yarn (berry is not supported)" as "yarn", + "bun" as const, + ], + (value) => value.split(" ")[0] as "yarn", + )); pack.manager = options.manager; options.project ??= await configure(); options.runtime = @@ -106,4 +110,12 @@ export namespace ArgumentParser { return options as IArguments; }); } + + const detectManager = async (): Promise< + "npm" | "pnpm" | "yarn" | "bun" | null + > => { + const result: DetectResult | null = await detect({ cwd: process.cwd() }); + if (result?.name === "npm") return null; // NPM case is still selectable + return result?.name ?? null; + }; } diff --git a/packages/cli/src/internal/PackageManager.ts b/packages/cli/src/internal/PackageManager.ts index 24078b908..483254cc5 100644 --- a/packages/cli/src/internal/PackageManager.ts +++ b/packages/cli/src/internal/PackageManager.ts @@ -5,7 +5,7 @@ import { CommandExecutor } from "./CommandExecutor"; import { FileRetriever } from "./FileRetriever"; export class PackageManager { - public manager: string = "npm"; + public manager: Manager = "npm"; public get file(): string { return path.join(this.directory, "package.json"); } @@ -38,17 +38,20 @@ export class PackageManager { public install(props: { dev: boolean; modulo: string; - version?: `latest` | `next` | `${number}.${number}.${number}`; + version?: + | `latest` + | `next` + | `^${number}.${number}.${number}` + | (string & {}); force?: boolean; }): boolean { - const symbol: string = - this.manager === "yarn" - ? `add${props.dev ? " -D" : ""}` - : `install ${props.dev ? "--save-dev" : "--save"}`; + const cmd = installCmdTable[this.manager]; + const option = props.dev ? devOptionTable[this.manager] : ""; + const middle: string = `${cmd} ${option}` as const; CommandExecutor.run( - `${this.manager} ${symbol}${props.force === true ? " --force" : ""} ${ - props.modulo - }${props.version ? `@${props.version}` : ""}`, + `${this.manager} ${middle} ${props.modulo}${ + props.version ? `@${props.version}` : "" + }`, ); return true; } @@ -70,3 +73,19 @@ export namespace Package { devDependencies?: Record; } } + +type Manager = "npm" | "pnpm" | "yarn" | "bun"; + +const installCmdTable = { + npm: "install", + pnpm: "add", + yarn: "add", + bun: "add", +} as const satisfies Record; + +const devOptionTable = { + npm: "--save-dev", + pnpm: "--save-dev", + yarn: "--dev", + bun: "--dev", +} as const satisfies Record;