Skip to content

Commit a5be22c

Browse files
committed
Format
1 parent b0a174a commit a5be22c

File tree

2 files changed

+53
-64
lines changed

2 files changed

+53
-64
lines changed

config.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
const starters = [
22
{
3-
name: "nextjs",
4-
repoUrl: "https://github.com/stackbit-themes/nextjs-starter",
3+
name: 'nextjs',
4+
repoUrl: 'https://github.com/stackbit-themes/nextjs-starter',
55
},
66
{
7-
name: "ts-nextjs",
8-
repoUrl: "https://github.com/stackbit-themes/ts-mui-nextjs-starter",
7+
name: 'ts-nextjs',
8+
repoUrl: 'https://github.com/stackbit-themes/ts-mui-nextjs-starter',
99
},
1010
{
11-
name: "contentful",
12-
repoUrl: "https://github.com/stackbit-themes/contentful-starter",
11+
name: 'contentful',
12+
repoUrl: 'https://github.com/stackbit-themes/contentful-starter',
1313
},
1414
{
15-
name: "full-nextjs",
16-
repoUrl: "https://github.com/stackbit-themes/starter-nextjs-theme",
15+
name: 'full-nextjs',
16+
repoUrl: 'https://github.com/stackbit-themes/starter-nextjs-theme',
1717
},
1818
{
19-
name: "small-biz-nextjs",
20-
repoUrl: "https://github.com/stackbit-themes/small-business-nextjs-theme",
19+
name: 'small-biz-nextjs',
20+
repoUrl: 'https://github.com/stackbit-themes/small-business-nextjs-theme',
2121
},
2222
{
23-
name: "personal-nextjs",
24-
repoUrl: "https://github.com/stackbit-themes/personal-nextjs-theme",
23+
name: 'personal-nextjs',
24+
repoUrl: 'https://github.com/stackbit-themes/personal-nextjs-theme',
2525
},
2626
];
2727

2828
const examples = {
29-
repoUrl: "https://github.com/stackbit-themes/stackbit-examples",
29+
repoUrl: 'https://github.com/stackbit-themes/stackbit-examples',
3030
directories: [
31-
"algolia-search",
32-
"angular-contentful",
33-
"chakra-ui",
34-
"cloudinary-contentful",
35-
"hydrogen-contentful-demo-store",
36-
"ninetailed-personalization",
37-
"onboarding-webapp",
38-
"sveltekit-contentful",
39-
"tutorial-nextjs-contentful",
40-
"tutorial-nextjs-files",
31+
'algolia-search',
32+
'angular-contentful',
33+
'chakra-ui',
34+
'cloudinary-contentful',
35+
'hydrogen-contentful-demo-store',
36+
'ninetailed-personalization',
37+
'onboarding-webapp',
38+
'sveltekit-contentful',
39+
'tutorial-nextjs-contentful',
40+
'tutorial-nextjs-files',
4141
],
4242
};
4343

4444
export default {
45-
defaults: { dirName: "my-stackbit-site", starter: starters[0] },
46-
minGitVersion: "2.25.0",
45+
defaults: { dirName: 'my-stackbit-site', starter: starters[0] },
46+
minGitVersion: '2.25.0',
4747
examples,
4848
starters,
4949
};

index.js

+28-39
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env node
22

3-
import chalk from "chalk";
4-
import { exec } from "child_process";
5-
import fs from "fs";
6-
import path from "path";
7-
import readline from "readline";
8-
import util from "util";
9-
import yargs from "yargs";
10-
import { hideBin } from "yargs/helpers";
3+
import chalk from 'chalk';
4+
import { exec } from 'child_process';
5+
import fs from 'fs';
6+
import path from 'path';
7+
import readline from 'readline';
8+
import util from 'util';
9+
import yargs from 'yargs';
10+
import { hideBin } from 'yargs/helpers';
1111

12-
import config from "./config.js";
12+
import config from './config.js';
1313

1414
/* --- Helpers --- */
1515

@@ -40,9 +40,7 @@ async function installDependencies(dirName) {
4040
async function initGit(dirName) {
4141
console.log(`Setting up Git ...`);
4242
await run(`rm -rf ${dirName}/.git`);
43-
await run(
44-
`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`
45-
);
43+
await run(`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`);
4644
}
4745

4846
/**
@@ -61,7 +59,7 @@ function compareVersion(version, control) {
6159
// Return 0 if the versions match.
6260
if (version === control) return returnValue;
6361
// Break the versions into arrays of integers.
64-
const getVersionParts = (str) => str.split(".").map((v) => parseInt(v));
62+
const getVersionParts = (str) => str.split('.').map((v) => parseInt(v));
6563
const versionParts = getVersionParts(version);
6664
const controlParts = getVersionParts(control);
6765
// Loop and compare each item.
@@ -78,24 +76,22 @@ function compareVersion(version, control) {
7876
/* --- Parse CLI Arguments */
7977

8078
const args = yargs(hideBin(process.argv))
81-
.option("starter", {
82-
alias: "s",
83-
describe: "Choose a starter",
79+
.option('starter', {
80+
alias: 's',
81+
describe: 'Choose a starter',
8482
choices: config.starters.map((s) => s.name),
8583
})
86-
.option("example", {
87-
alias: "e",
88-
describe: "Start from an example",
84+
.option('example', {
85+
alias: 'e',
86+
describe: 'Start from an example',
8987
choices: config.examples.directories,
9088
})
9189
.help()
9290
.parse();
9391

9492
/* --- References --- */
9593

96-
const starter = config.starters.find(
97-
(s) => s.name === (args.starter ?? config.defaults.starter.name)
98-
);
94+
const starter = config.starters.find((s) => s.name === (args.starter ?? config.defaults.starter.name));
9995

10096
// Current time in seconds.
10197
const timestamp = Math.round(new Date().getTime() / 1000);
@@ -117,7 +113,7 @@ async function cloneStarter() {
117113

118114
// Output next steps:
119115
console.log(`
120-
🎉 ${chalk.bold("Welcome to Stackbit!")} 🎉
116+
🎉 ${chalk.bold('Welcome to Stackbit!')} 🎉
121117
122118
Follow the instructions for getting Started here:
123119
@@ -128,23 +124,18 @@ Follow the instructions for getting Started here:
128124
/* --- New Project from Example --- */
129125

130126
async function cloneExample() {
131-
const gitResult = await run("git --version");
127+
const gitResult = await run('git --version');
132128
const gitVersionMatch = gitResult.stdout.match(/\d+\.\d+\.\d+/);
133129
if (!gitVersionMatch || !gitVersionMatch[0]) {
134130
console.error(
135131
`Cannot determine git version, which is required for starting from an example.`,
136132
`\nPlease report this:`,
137-
chalk.underline(
138-
"https://github.com/stackbit/create-stackbit-app/issues/new"
139-
)
133+
chalk.underline('https://github.com/stackbit/create-stackbit-app/issues/new'),
140134
);
141135
process.exit(1);
142136
}
143137
if (compareVersion(gitVersionMatch[0], config.minGitVersion) < 0) {
144-
console.error(
145-
`Starting from an example requires git version ${config.minGitVersion} or later.`,
146-
"Please upgrade"
147-
);
138+
console.error(`Starting from an example requires git version ${config.minGitVersion} or later.`, 'Please upgrade');
148139
process.exit(1);
149140
}
150141

@@ -154,9 +145,7 @@ async function cloneExample() {
154145

155146
try {
156147
// Sparse clone the monorepo.
157-
await run(
158-
`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`
159-
);
148+
await run(`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`);
160149
// Checkout just the example dir.
161150
await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`);
162151
// Copy out into a new directory within current working directory.
@@ -176,7 +165,7 @@ async function cloneExample() {
176165

177166
// Output next steps:
178167
console.log(`
179-
🎉 ${chalk.bold("Your example project is ready!")} 🎉
168+
🎉 ${chalk.bold('Your example project is ready!')} 🎉
180169
181170
Follow the instructions and learn more about the example here:
182171
@@ -190,9 +179,9 @@ async function integrateStackbit() {
190179
return new Promise(async (resolve) => {
191180
const integrate = await prompt(`
192181
This looks like an existing project.
193-
${chalk.bold("Would you like to install Stackbit in this project?")} [Y/n] `);
182+
${chalk.bold('Would you like to install Stackbit in this project?')} [Y/n] `);
194183

195-
if (!["yes", "y"].includes(integrate?.toLowerCase())) return resolve(false);
184+
if (!['yes', 'y'].includes(integrate?.toLowerCase())) return resolve(false);
196185

197186
console.log(`
198187
Visit the following URL to learn more about the integration process:
@@ -208,11 +197,11 @@ Visit the following URL to learn more about the integration process:
208197
async function doCreate() {
209198
// If the current directory has a package.json file, we assume we're in an
210199
// active project, and will not create a new project.
211-
const packageJsonFilePath = path.join(process.cwd(), "package.json");
200+
const packageJsonFilePath = path.join(process.cwd(), 'package.json');
212201
if (fs.existsSync(packageJsonFilePath)) return integrateStackbit();
213202
// If both starter and example were specified, throw an error message.
214203
if (args.starter && args.example) {
215-
console.error("[ERROR] Cannot specify a starter and an example.");
204+
console.error('[ERROR] Cannot specify a starter and an example.');
216205
process.exit(1);
217206
}
218207
// Start from an example if specified.

0 commit comments

Comments
 (0)