|
| 1 | +#!/usr/bin/env node |
| 2 | + |
1 | 3 | import { Command } from "commander";
|
2 | 4 | import path from "path";
|
3 | 5 | import { promises as fs } from "fs";
|
@@ -54,6 +56,21 @@ async function init(projectName: string, cwd: string, template: string) {
|
54 | 56 | // Rewrite package.json in client directory
|
55 | 57 | await rewritePackageJson(projectName, clientPath);
|
56 | 58 |
|
| 59 | + console.log(`Cloning dojo-starter repository...`); |
| 60 | + const gitCloneResult = spawn.sync( |
| 61 | + "git", |
| 62 | + [ |
| 63 | + "clone", |
| 64 | + "https://github.com/dojoengine/dojo-starter.git", |
| 65 | + dojoStarterPath, |
| 66 | + ], |
| 67 | + { stdio: "inherit" } |
| 68 | + ); |
| 69 | + |
| 70 | + if (gitCloneResult.status !== 0) { |
| 71 | + throw new Error(`Failed to clone dojo-starter repository.`); |
| 72 | + } |
| 73 | + |
57 | 74 | // Clone dojo-starter
|
58 | 75 | console.log(`Downloading dojo-starter...`);
|
59 | 76 | spawn.sync("npx", ["degit", `dojoengine/dojo-starter`, dojoStarterPath], {
|
@@ -120,14 +137,31 @@ export const start = new Command()
|
120 | 137 | .name("start")
|
121 | 138 | .description("initialize a new project with a selected template")
|
122 | 139 | .option("-c, --cwd <cwd>", "the working directory", process.cwd())
|
| 140 | + .option("-t, --template <template>", "specify the template to use") |
123 | 141 | .action(async (options) => {
|
124 | 142 | try {
|
125 | 143 | const cwd = path.resolve(options.cwd);
|
126 |
| - |
127 |
| - const template = await select({ |
128 |
| - message: "Select a template", |
129 |
| - choices: templates, |
130 |
| - }); |
| 144 | + let template: string; |
| 145 | + |
| 146 | + if (options.template) { |
| 147 | + const selectedTemplate = templates.find( |
| 148 | + (tpl) => tpl.value === options.template |
| 149 | + ); |
| 150 | + if (!selectedTemplate) { |
| 151 | + console.error( |
| 152 | + `Template "${options.template}" not found. Available templates are: ${templates |
| 153 | + .map((tpl) => tpl.value) |
| 154 | + .join(", ")}` |
| 155 | + ); |
| 156 | + process.exit(1); |
| 157 | + } |
| 158 | + template = selectedTemplate.value; |
| 159 | + } else { |
| 160 | + template = await select({ |
| 161 | + message: "Select a template", |
| 162 | + choices: templates, |
| 163 | + }); |
| 164 | + } |
131 | 165 |
|
132 | 166 | const projectName = await input({
|
133 | 167 | message: "Project name ",
|
|
0 commit comments