Skip to content

Commit

Permalink
Merge pull request #527 from samchon/features/yarn
Browse files Browse the repository at this point in the history
Fix samchon/typia#744 - change setup wizard to deprecate yarn berry
  • Loading branch information
samchon authored Aug 7, 2023
2 parents 7341c5a + cf8bf41 commit 16d9129
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestia",
"version": "4.3.2",
"version": "4.4.0",
"description": "Nestia CLI tool",
"main": "bin/index.js",
"bin": {
Expand All @@ -9,7 +9,7 @@
"scripts": {
"build": "rimraf bin && tsc",
"prettier": "prettier ./src/**/*.ts --write",
"package:next": "npm publish --access public --tag next"
"package:next": "npm run build && npm publish --access public --tag next"
},
"repository": {
"type": "git",
Expand All @@ -36,14 +36,14 @@
"inquirer": "^8.2.5"
},
"devDependencies": {
"@nestia/core": "^1.3.0",
"@nestia/sdk": "^1.3.0",
"@nestia/core": "^1.6.1",
"@nestia/sdk": "^1.6.1",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/inquirer": "^9.0.3",
"@types/node": "^18.11.16",
"prettier": "^2.8.7",
"rimraf": "^3.0.2",
"typescript": "^5.1.3"
"typescript": "^5.1.6"
},
"files": [
"bin",
Expand Down
30 changes: 22 additions & 8 deletions packages/cli/src/NestiaSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,37 @@ export namespace NestiaSetupWizard {
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
pack.install({ dev: true, modulo: "typescript", version: "latest" });
args.project ??= (() => {
CommandExecutor.run("npx tsc --init");
const runner: string =
pack.manager === "npm" ? "npx" : pack.manager;
CommandExecutor.run(`${runner} tsc --init`);
return (args.project = "tsconfig.json");
})();

// SETUP TRANSFORMER
await pack.save((data) => {
// COMPOSE POSTINSTALL COMMAND
data.scripts ??= {};
if (
typeof data.scripts.prepare === "string" &&
data.scripts.prepare.length
typeof data.scripts.postinstall === "string" &&
data.scripts.postinstall.trim().length
) {
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
data.scripts.prepare =
"ts-patch install && " + data.scripts.prepare;
} else data.scripts.prepare = "ts-patch install";
if (data.scripts.postinstall.indexOf("ts-patch install") === -1)
data.scripts.postinstall =
"ts-patch install && " + data.scripts.postinstall;
} else data.scripts.postinstall = "ts-patch install";

// FOR OLDER VERSIONS
if (typeof data.scripts.prepare === "string") {
data.scripts.prepare = data.scripts.prepare
.split("&&")
.map((str) => str.trim())
.filter((str) => str.indexOf("ts-patch install") === -1)
.join(" && ");
if (data.scripts.prepare.length === 0)
delete data.scripts.prepare;
}
});
CommandExecutor.run("npm run prepare");
CommandExecutor.run(`${pack.manager} run postinstall`);

// INSTALL AND CONFIGURE TYPIA + NESTIA
pack.install({ dev: false, modulo: "typia", version: "latest" });
Expand Down
17 changes: 11 additions & 6 deletions packages/cli/src/internal/ArgumentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export namespace ArgumentParser {

export async function parse(pack: PackageManager): Promise<IArguments> {
// PREPARE ASSETS
commander.program.option("--manager [manager", "package manager");
commander.program.option("--manager [manager]", "package manager");
commander.program.option(
"--project [project]",
"tsconfig.json file location",
Expand All @@ -39,6 +39,7 @@ export namespace ArgumentParser {
(message: string) =>
async <Choice extends string>(
choices: Choice[],
filter?: (value: string) => Choice,
): Promise<Choice> => {
questioned.value = true;
return (
Expand All @@ -47,6 +48,7 @@ export namespace ArgumentParser {
name: name,
message: message,
choices: choices,
filter,
})
)[name];
};
Expand Down Expand Up @@ -78,11 +80,14 @@ export namespace ArgumentParser {

// DO CONSTRUCT
return action(async (options) => {
options.manager ??= await select("manager")("Package Manager")([
"npm" as const,
"pnpm" as const,
"yarn" as const,
]);
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",
);
pack.manager = options.manager;
options.project ??= await configure();

Expand Down

0 comments on commit 16d9129

Please sign in to comment.