Skip to content

Commit

Permalink
Merge pull request #1269 from samchon/feature/cli
Browse files Browse the repository at this point in the history
CLI detects package manager automatically.
  • Loading branch information
samchon authored Sep 9, 2024
2 parents 04c1cbd + 72ffc86 commit efd1039
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
!/bin
lib/
node_modules/

Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 5 additions & 0 deletions bin/typia.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { cli } from '../lib/cli/index.js'

await cli()
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-json/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
31 changes: 20 additions & 11 deletions src/executable/TypiaSetupWizard.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
};
}
26 changes: 13 additions & 13 deletions src/executable/setup/PackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Manager, string>;
const devOptionTable = {
npm: "--save-dev",
pnpm: "--save-dev",
yarn: "--dev",
bun: "--dev",
} as const satisfies Record<Manager, string>;

export class PackageManager {
public manager: Manager = "npm";
public get file(): string {
Expand Down Expand Up @@ -84,3 +71,16 @@ export namespace Package {
devDependencies?: Record<string, string>;
}
}

const installCmdTable = {
npm: "install",
pnpm: "add",
yarn: "add",
bun: "add",
} as const satisfies Record<Manager, string>;
const devOptionTable = {
npm: "--save-dev",
pnpm: "--save-dev",
yarn: "--dev",
bun: "--dev",
} as const satisfies Record<Manager, string>;
2 changes: 1 addition & 1 deletion test-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
9 changes: 9 additions & 0 deletions tsconfig.cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"sourceMap": false
},
"include": ["src/cli"],
"exclude": []
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit efd1039

Please sign in to comment.