diff --git a/packages/cli/package.json b/packages/cli/package.json index 303b005f1..77f992e96 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -35,6 +35,7 @@ "peerDependencies": { "@proto-kit/api": "*", "@proto-kit/common": "*", + "@proto-kit/indexer": "*", "@proto-kit/library": "*", "@proto-kit/module": "*", "@proto-kit/protocol": "*", diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts new file mode 100644 index 000000000..0fcfba12f --- /dev/null +++ b/packages/cli/src/commands/init.ts @@ -0,0 +1,24 @@ +import { CommandModule } from "yargs"; + +import type { InitArgs } from "../scripts/init"; + +export const initCommand: CommandModule<{}, InitArgs> = { + command: "init [name]", + describe: "Create a new Protokit project from the starter-kit template", + builder: (yarg) => + yarg.positional("name", { + type: "string", + default: "starter-kit", + describe: "Directory name for the new project", + }), + handler: async (args) => { + try { + const { default: init } = await import("../scripts/init"); + await init({ name: args.name }); + process.exit(0); + } catch (error) { + console.error("Failed to initialize project:", error); + process.exit(1); + } + }, +}; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index eece25a14..a9bb5f0f0 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -10,6 +10,7 @@ import { wizardCommand } from "./commands/wizard"; import { settlementCommand } from "./commands/settlement/settlement"; import { lightnetCommand } from "./commands/lightnet/lightnet"; import { bridgeCommand } from "./commands/bridge/bridge"; +import { initCommand } from "./commands/init"; import { circuitSummaryCommand } from "./commands/circuitSummary"; process.removeAllListeners("warning"); @@ -26,6 +27,7 @@ await yargs(hideBin(process.argv)) .command(settlementCommand) .command(lightnetCommand) .command(bridgeCommand) + .command(initCommand) .command(circuitSummaryCommand) .demandCommand( 1, diff --git a/packages/cli/src/scripts/init.ts b/packages/cli/src/scripts/init.ts new file mode 100644 index 000000000..66be329ce --- /dev/null +++ b/packages/cli/src/scripts/init.ts @@ -0,0 +1,34 @@ +import { execSync } from "child_process"; + +const STARTER_KIT_REPO = "https://github.com/proto-kit/starter-kit.git"; +const REPO_BRANCH = "develop"; + +export interface InitArgs { + name?: string; +} + +export default async function (args: InitArgs): Promise { + const targetDir = args.name ?? "starter-kit"; + + console.log(`\nCloning starter-kit into ./${targetDir}...\n`); + + try { + execSync( + `git clone --depth 1 --branch ${REPO_BRANCH} ${STARTER_KIT_REPO} ${targetDir}` + ); + + console.log(`\nProject created at ./${targetDir}`); + console.log("\nNext steps:"); + console.log(` cd ${targetDir}`); + console.log(" pnpm install"); + console.log(" pnpm env:development prisma:generate"); + console.log(" pnpm env:inmemory dev"); + console.log(" ✨ You're all set. Enjoy coding! ✨"); + console.log( + "\nFor more details, see the README.md in the project directory.\n" + ); + } catch (error) { + console.error("Failed to initialize project:", error); + throw error; + } +}