Skip to content

Commit e2222a3

Browse files
committed
Make the command functional
1 parent fdaead7 commit e2222a3

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

index.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
11
#!/usr/bin/env node
22

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();

package-lock.json

Lines changed: 27 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@
1111
"license": "MIT",
1212
"bin": {
1313
"create-stackbit-app": "./index.js"
14+
},
15+
"type": "module",
16+
"dependencies": {
17+
"chalk": "^5.0.0"
1418
}
1519
}

0 commit comments

Comments
 (0)