From c9217e2837e2a90517c7bffe1963f001b462584c Mon Sep 17 00:00:00 2001 From: stanlou Date: Wed, 11 Mar 2026 00:14:22 -0300 Subject: [PATCH 1/4] feat(cli): add init command --- packages/cli/src/commands/init.ts | 24 ++++++++++++++++++ packages/cli/src/index.ts | 2 ++ packages/cli/src/scripts/init.ts | 42 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 packages/cli/src/commands/init.ts create mode 100644 packages/cli/src/scripts/init.ts 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 7f60b14b9..89793e55c 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"; process.removeAllListeners("warning"); process.env.NODE_NO_WARNINGS = "1"; @@ -25,6 +26,7 @@ await yargs(hideBin(process.argv)) .command(settlementCommand) .command(lightnetCommand) .command(bridgeCommand) + .command(initCommand) .demandCommand( 1, "You must specify a command. Use --help to see available commands." diff --git a/packages/cli/src/scripts/init.ts b/packages/cli/src/scripts/init.ts new file mode 100644 index 000000000..bf5caeb73 --- /dev/null +++ b/packages/cli/src/scripts/init.ts @@ -0,0 +1,42 @@ +import { spawn } from "child_process"; + +const STARTER_KIT_REPO = "https://github.com/proto-kit/starter-kit.git"; + +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`); + + return await new Promise((resolve, reject) => { + const child = spawn("git", ["clone", STARTER_KIT_REPO, targetDir], { + stdio: "inherit", + }); + + child.on("error", (error) => { + console.error("Failed to clone starter-kit:", error); + reject(error); + }); + + child.on("exit", (code) => { + if (code !== null && code !== 0) { + reject(new Error(`git clone failed with exit code ${code}`)); + } else { + 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" + ); + resolve(); + } + }); + }); +} From e516d981869f47a45f76375a8b87e49c0fbd4553 Mon Sep 17 00:00:00 2001 From: stanlou Date: Mon, 13 Apr 2026 12:52:56 +0100 Subject: [PATCH 2/4] use degit to initialize project --- package-lock.json | 21 ++++++++++++ packages/cli/package.json | 4 ++- packages/cli/src/scripts/init.ts | 57 +++++++++++++++++--------------- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8c0b7475a..a1d93e48f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6598,6 +6598,13 @@ "@types/node": "*" } }, + "node_modules/@types/degit": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/@types/degit/-/degit-2.8.6.tgz", + "integrity": "sha512-y0M7sqzsnHB6cvAeTCBPrCQNQiZe8U4qdzf8uBVmOWYap5MMTN/gB2iEqrIqFiYcsyvP74GnGD5tgsHttielFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/express": { "version": "5.0.6", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", @@ -11205,6 +11212,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/degit": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/degit/-/degit-2.8.4.tgz", + "integrity": "sha512-vqYuzmSA5I50J882jd+AbAhQtgK6bdKUJIex1JNfEUPENCgYsxugzKVZlFyMwV4i06MmnV47/Iqi5Io86zf3Ng==", + "license": "MIT", + "bin": { + "degit": "degit" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/del": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz", @@ -28981,6 +29000,7 @@ "license": "ISC", "dependencies": { "@inquirer/figures": "^2.0.3", + "degit": "^2.8.4", "dotenv": "^17.2.3", "inquirer": "^9.3.0", "kleur": "^4.1.5", @@ -28995,6 +29015,7 @@ "protokit": "bin/protokit-cli.js" }, "devDependencies": { + "@types/degit": "^2.8.6", "@types/inquirer": "^9.0.9", "@types/node": "^20.19.24", "@types/yargs": "17.0.32" diff --git a/packages/cli/package.json b/packages/cli/package.json index d82d43526..22953763b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -22,6 +22,7 @@ "license": "ISC", "dependencies": { "@inquirer/figures": "^2.0.3", + "degit": "^2.8.4", "dotenv": "^17.2.3", "inquirer": "^9.3.0", "kleur": "^4.1.5", @@ -35,17 +36,18 @@ "peerDependencies": { "@proto-kit/api": "*", "@proto-kit/common": "*", + "@proto-kit/indexer": "*", "@proto-kit/library": "*", "@proto-kit/module": "*", "@proto-kit/protocol": "*", "@proto-kit/sdk": "*", "@proto-kit/sequencer": "*", "@proto-kit/stack": "*", - "@proto-kit/indexer": "*", "o1js": "^2.10.0", "tsyringe": "^4.10.0" }, "devDependencies": { + "@types/degit": "^2.8.6", "@types/inquirer": "^9.0.9", "@types/node": "^20.19.24", "@types/yargs": "17.0.32" diff --git a/packages/cli/src/scripts/init.ts b/packages/cli/src/scripts/init.ts index bf5caeb73..b22220636 100644 --- a/packages/cli/src/scripts/init.ts +++ b/packages/cli/src/scripts/init.ts @@ -1,6 +1,8 @@ -import { spawn } from "child_process"; +import { execSync } from "child_process"; -const STARTER_KIT_REPO = "https://github.com/proto-kit/starter-kit.git"; +import degit from "degit"; + +const STARTER_KIT_REPO = "proto-kit/starter-kit#develop"; export interface InitArgs { name?: string; @@ -11,32 +13,35 @@ export default async function (args: InitArgs): Promise { console.log(`\nCloning starter-kit into ./${targetDir}...\n`); - return await new Promise((resolve, reject) => { - const child = spawn("git", ["clone", STARTER_KIT_REPO, targetDir], { - stdio: "inherit", - }); + try { + const emitter = degit(STARTER_KIT_REPO); - child.on("error", (error) => { - console.error("Failed to clone starter-kit:", error); - reject(error); + emitter.on("info", (info) => { + console.log(info.message); }); - child.on("exit", (code) => { - if (code !== null && code !== 0) { - reject(new Error(`git clone failed with exit code ${code}`)); - } else { - 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" - ); - resolve(); - } + await emitter.clone(targetDir); + + execSync("git init -b develop", { cwd: targetDir, stdio: "ignore" }); + execSync("git add -A", { cwd: targetDir, stdio: "ignore" }); + // eslint-disable-next-line @typescript-eslint/quotes + execSync('git commit -m "initial commit"', { + cwd: targetDir, + stdio: "ignore", }); - }); + + 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; + } } From 7649820feeb3b8302477bcb265c0cb11610f9d8a Mon Sep 17 00:00:00 2001 From: stanlou Date: Thu, 16 Apr 2026 14:44:20 +0100 Subject: [PATCH 3/4] refactor: replace degit with git clone --- packages/cli/src/scripts/init.ts | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/packages/cli/src/scripts/init.ts b/packages/cli/src/scripts/init.ts index b22220636..66be329ce 100644 --- a/packages/cli/src/scripts/init.ts +++ b/packages/cli/src/scripts/init.ts @@ -1,8 +1,7 @@ import { execSync } from "child_process"; -import degit from "degit"; - -const STARTER_KIT_REPO = "proto-kit/starter-kit#develop"; +const STARTER_KIT_REPO = "https://github.com/proto-kit/starter-kit.git"; +const REPO_BRANCH = "develop"; export interface InitArgs { name?: string; @@ -14,21 +13,9 @@ export default async function (args: InitArgs): Promise { console.log(`\nCloning starter-kit into ./${targetDir}...\n`); try { - const emitter = degit(STARTER_KIT_REPO); - - emitter.on("info", (info) => { - console.log(info.message); - }); - - await emitter.clone(targetDir); - - execSync("git init -b develop", { cwd: targetDir, stdio: "ignore" }); - execSync("git add -A", { cwd: targetDir, stdio: "ignore" }); - // eslint-disable-next-line @typescript-eslint/quotes - execSync('git commit -m "initial commit"', { - cwd: targetDir, - stdio: "ignore", - }); + execSync( + `git clone --depth 1 --branch ${REPO_BRANCH} ${STARTER_KIT_REPO} ${targetDir}` + ); console.log(`\nProject created at ./${targetDir}`); console.log("\nNext steps:"); From 1250735b3d6075952a64c91315df84b6e4ab2d1b Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Mon, 20 Apr 2026 20:24:02 +0200 Subject: [PATCH 4/4] Removed degit dependency from package.json --- package-lock.json | 21 --------------------- packages/cli/package.json | 2 -- 2 files changed, 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index e2bf08870..480f793dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6170,13 +6170,6 @@ "@types/node": "*" } }, - "node_modules/@types/degit": { - "version": "2.8.6", - "resolved": "https://registry.npmjs.org/@types/degit/-/degit-2.8.6.tgz", - "integrity": "sha512-y0M7sqzsnHB6cvAeTCBPrCQNQiZe8U4qdzf8uBVmOWYap5MMTN/gB2iEqrIqFiYcsyvP74GnGD5tgsHttielFw==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/express": { "version": "5.0.6", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", @@ -10784,18 +10777,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/degit": { - "version": "2.8.4", - "resolved": "https://registry.npmjs.org/degit/-/degit-2.8.4.tgz", - "integrity": "sha512-vqYuzmSA5I50J882jd+AbAhQtgK6bdKUJIex1JNfEUPENCgYsxugzKVZlFyMwV4i06MmnV47/Iqi5Io86zf3Ng==", - "license": "MIT", - "bin": { - "degit": "degit" - }, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/del": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz", @@ -28576,7 +28557,6 @@ "license": "ISC", "dependencies": { "@inquirer/figures": "^2.0.3", - "degit": "^2.8.4", "dotenv": "^17.2.3", "inquirer": "^9.3.0", "kleur": "^4.1.5", @@ -28591,7 +28571,6 @@ "protokit": "bin/protokit-cli.js" }, "devDependencies": { - "@types/degit": "^2.8.6", "@types/inquirer": "^9.0.9", "@types/node": "^20.19.24", "@types/yargs": "17.0.32" diff --git a/packages/cli/package.json b/packages/cli/package.json index 625b8aabd..77f992e96 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -22,7 +22,6 @@ "license": "ISC", "dependencies": { "@inquirer/figures": "^2.0.3", - "degit": "^2.8.4", "dotenv": "^17.2.3", "inquirer": "^9.3.0", "kleur": "^4.1.5", @@ -49,7 +48,6 @@ "tsyringe": "^4.10.0" }, "devDependencies": { - "@types/degit": "^2.8.6", "@types/inquirer": "^9.0.9", "@types/node": "^20.19.24", "@types/yargs": "17.0.32"