Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"peerDependencies": {
"@proto-kit/api": "*",
"@proto-kit/common": "*",
"@proto-kit/indexer": "*",
"@proto-kit/library": "*",
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -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);
}
},
};
2 changes: 2 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -26,6 +27,7 @@ await yargs(hideBin(process.argv))
.command(settlementCommand)
.command(lightnetCommand)
.command(bridgeCommand)
.command(initCommand)
.command(circuitSummaryCommand)
.demandCommand(
1,
Expand Down
34 changes: 34 additions & 0 deletions packages/cli/src/scripts/init.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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;
}
}
Loading