|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -console.log("HELLO WORLD 123"); |
| 3 | +import readline from "readline"; |
| 4 | +import { exec } from "child_process"; |
| 5 | +import util from "util"; |
| 6 | +import chalk from "chalk"; |
| 7 | + |
| 8 | +/* --- Helpers --- */ |
| 9 | + |
| 10 | +const rl = readline.createInterface({ |
| 11 | + input: process.stdin, |
| 12 | + output: process.stdout, |
| 13 | +}); |
| 14 | + |
| 15 | +function prompt(question, defaultAnswer) { |
| 16 | + return new Promise((resolve) => { |
| 17 | + const questionText = `${chalk.bold(question)} (${defaultAnswer}): `; |
| 18 | + rl.question(questionText, (input) => resolve(input || defaultAnswer)); |
| 19 | + }); |
| 20 | +} |
| 21 | + |
| 22 | +const run = util.promisify(exec); |
| 23 | + |
| 24 | +/* --- User Input --- */ |
| 25 | + |
| 26 | +const projectName = await prompt("Project Name", "my-stackbit-site"); |
| 27 | +const repoName = await prompt("GitHub Repo", "stackbit/nextjs-starter"); |
| 28 | + |
| 29 | +/* --- Run --- */ |
| 30 | + |
| 31 | +// Clone repo |
| 32 | +const repoUrl = `https://github.com/${repoName}`; |
| 33 | +const cloneCommand = `git clone --depth=1 ${repoUrl} ${projectName}`; |
| 34 | +console.log(`\nCloning into ${projectName} ...`); |
| 35 | +await run(cloneCommand); |
| 36 | + |
| 37 | +// Install dependencies |
| 38 | +console.log(`Installing dependencies ...`); |
| 39 | +await run(`cd ${projectName} && npm install`); |
| 40 | + |
| 41 | +// Output next steps: |
| 42 | +console.log(` |
| 43 | +🎉 ${chalk.bold("Welcome to Stackbit!")} 🎉 |
| 44 | +
|
| 45 | +Run the following commands: |
| 46 | +
|
| 47 | + cd ${projectName} |
| 48 | + npm run dev |
| 49 | +
|
| 50 | +When your dev server boots, you'll see an ${chalk.bgYellow.black.bold( |
| 51 | + " app.stackbit.com " |
| 52 | +)} URL in the logs. |
| 53 | +Open this URL in your browser and start building! |
| 54 | +`); |
| 55 | + |
| 56 | +/* --- Clean Up --- */ |
| 57 | + |
| 58 | +rl.close(); |
0 commit comments