diff --git a/.gitignore b/.gitignore index edba8dc08c..5282d49496 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin/ +!/bin lib/ node_modules/ diff --git a/benchmark/package.json b/benchmark/package.json index c9e0d17720..ac4433e060 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -72,6 +72,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.10.0-dev.20240910.tgz" + "typia": "../typia-6.10.0-dev.20240910-2.tgz" } } \ No newline at end of file diff --git a/bin/typia.mjs b/bin/typia.mjs new file mode 100644 index 0000000000..3290f93784 --- /dev/null +++ b/bin/typia.mjs @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { cli } from '../lib/cli/index.js' + +await cli() diff --git a/errors/package.json b/errors/package.json index 1483e12a6a..d05d0f2f33 100644 --- a/errors/package.json +++ b/errors/package.json @@ -32,6 +32,6 @@ "typescript": "^5.3.2" }, "dependencies": { - "typia": "../typia-6.10.0-dev.20240910.tgz" + "typia": "../typia-6.10.0-dev.20240910-2.tgz" } } \ No newline at end of file diff --git a/package.json b/package.json index 4af099a4e4..bfc672b0aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "6.10.0-dev.20240910", + "version": "6.10.0-dev.20240910-2", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -71,6 +71,7 @@ "commander": "^10.0.0", "comment-json": "^4.2.3", "inquirer": "^8.2.5", + "package-manager-detector": "^0.2.0", "randexp": "^0.5.3" }, "peerDependencies": { diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index f45f8f73b5..7ef36d9fcc 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,6 +1,6 @@ { "name": "typescript-json", - "version": "6.10.0-dev.20240910", + "version": "6.10.0-dev.20240910-2", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -63,7 +63,7 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "6.10.0-dev.20240910" + "typia": "6.10.0-dev.20240910-2" }, "peerDependencies": { "typescript": ">=4.8.0 <5.6.0" diff --git a/packages/typescript-json/tsconfig.json b/packages/typescript-json/tsconfig.json index 2e9fb09c29..f3914ece9a 100644 --- a/packages/typescript-json/tsconfig.json +++ b/packages/typescript-json/tsconfig.json @@ -101,5 +101,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src"] + "include": ["src"], + "exclude": ["src/cli"] } diff --git a/src/executable/TypiaSetupWizard.ts b/src/executable/TypiaSetupWizard.ts index 6f4ba9319f..a1da1cb641 100644 --- a/src/executable/TypiaSetupWizard.ts +++ b/src/executable/TypiaSetupWizard.ts @@ -1,4 +1,5 @@ import fs from "fs"; +import { DetectResult, detect } from "package-manager-detector"; import { ArgumentParser } from "./setup/ArgumentParser"; import { CommandExecutor } from "./setup/CommandExecutor"; @@ -131,21 +132,29 @@ export namespace TypiaSetupWizard { // DO CONSTRUCT return action(async (options) => { - pack.manager = options.manager ??= await select("manager")( - "Package Manager", - )( - [ - "npm" as const, - "pnpm" as const, - "bun" as const, - "yarn (berry is not supported)" as "yarn", - ], - (value) => value.split(" ")[0] as "yarn", - ); + pack.manager = options.manager ??= + (await detectManager()) ?? + (await select("manager")("Package Manager")( + [ + "npm" as const, + "pnpm" as const, + "bun" as const, + "yarn (berry is not supported)" as "yarn", + ], + (value) => value.split(" ")[0] as "yarn", + )); options.project ??= await configure(); if (questioned.value) console.log(""); 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/src/executable/setup/PackageManager.ts b/src/executable/setup/PackageManager.ts index 4963c6f5e4..fd4401fc74 100644 --- a/src/executable/setup/PackageManager.ts +++ b/src/executable/setup/PackageManager.ts @@ -7,19 +7,6 @@ import { FileRetriever } from "./FileRetriever"; const managers = ["npm", "pnpm", "yarn", "bun"] as const; type Manager = (typeof managers)[number]; -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; - export class PackageManager { public manager: Manager = "npm"; public get file(): string { @@ -84,3 +71,16 @@ export namespace Package { devDependencies?: Record; } } + +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; diff --git a/test-esm/package.json b/test-esm/package.json index 418a3f92df..e688ccb6f9 100644 --- a/test-esm/package.json +++ b/test-esm/package.json @@ -36,6 +36,6 @@ "typescript": "^5.4.5" }, "dependencies": { - "typia": "../typia-6.10.0-dev.20240910.tgz" + "typia": "../typia-6.10.0-dev.20240910-2.tgz" } } \ No newline at end of file diff --git a/test/package.json b/test/package.json index 6a16627ff0..b9a7515113 100644 --- a/test/package.json +++ b/test/package.json @@ -52,6 +52,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.10.0-dev.20240910.tgz" + "typia": "../typia-6.10.0-dev.20240910-2.tgz" } } \ No newline at end of file diff --git a/tsconfig.cli.json b/tsconfig.cli.json new file mode 100644 index 0000000000..5c03b36316 --- /dev/null +++ b/tsconfig.cli.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": false, + "sourceMap": false + }, + "include": ["src/cli"], + "exclude": [] +} diff --git a/tsconfig.json b/tsconfig.json index 2e9fb09c29..f3914ece9a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -101,5 +101,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src"] + "include": ["src"], + "exclude": ["src/cli"] }