Skip to content

Commit

Permalink
Refactor #1272: just a little bit refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Sep 10, 2024
1 parent b5d5dcb commit 64fca5d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/executable/TypiaSetupWizard.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import fs from "fs";
import path from "path";
import { DetectResult, detect } from "package-manager-detector";

import { ArgumentParser } from "./setup/ArgumentParser";
import { CommandExecutor } from "./setup/CommandExecutor";
import { PackageManager } from "./setup/PackageManager";
import { PluginConfigurator } from "./setup/PluginConfigurator";

const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../../package.json"), "utf-8"));

export namespace TypiaSetupWizard {
export interface IArguments {
manager: "npm" | "pnpm" | "yarn" | "bun";
project: string | null;
}

export async function setup(): Promise<void> {
export const setup = async (): Promise<void> => {
console.log("----------------------------------------");
console.log(" Typia Setup Wizard");
console.log("----------------------------------------");
Expand All @@ -25,7 +22,11 @@ export namespace TypiaSetupWizard {
const args: IArguments = await ArgumentParser.parse(pack)(inquiry);

// INSTALL TYPESCRIPT COMPILERS
pack.install({ dev: true, modulo: "typescript", version: pkg.devDependencies.typescript as string });
pack.install({
dev: true,
modulo: "typescript",
version: await getTypeScriptVersion(),
});
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
args.project ??= (() => {
const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
Expand Down Expand Up @@ -71,7 +72,7 @@ export namespace TypiaSetupWizard {
// CONFIGURE TYPIA
await PluginConfigurator.configure(args);
CommandExecutor.run(`${pack.manager} run prepare`);
}
};

const inquiry: ArgumentParser.Inquiry<IArguments> = async (
pack,
Expand Down Expand Up @@ -160,4 +161,14 @@ export namespace TypiaSetupWizard {
if (result?.name === "npm") return null; // NPM case is still selectable
return result?.name ?? null;
};

const getTypeScriptVersion = async (): Promise<string> => {
const content: string = await fs.promises.readFile(
`${__dirname}/package.json`,
"utf-8",
);
const json: { devDependencies: { typescript: string } } =
JSON.parse(content);
return json.devDependencies.typescript;
};
}

0 comments on commit 64fca5d

Please sign in to comment.