create-better-system 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +53 -12
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -5,6 +5,16 @@ import { execa } from 'execa'
5
5
  import fs from 'fs-extra'
6
6
  import path from 'path'
7
7
  import crypto from 'crypto'
8
+ import ora from 'ora'
9
+
10
+ // ─── Node version check ───────────────────────────────────────────────────────
11
+
12
+ const MIN_NODE = 20
13
+ const currentMajor = parseInt(process.versions.node.split('.')[0], 10)
14
+ if (currentMajor < MIN_NODE) {
15
+ console.error(`\n❌ Node.js ${MIN_NODE}+ required. You are running ${process.versions.node}.\n`)
16
+ process.exit(1)
17
+ }
8
18
 
9
19
  const THEME_PRESETS = {
10
20
  dark: {
@@ -108,14 +118,20 @@ const headingFontVarName = toVarName(answers.headingFont) + 'Font'
108
118
 
109
119
  // ─── Clone template ───────────────────────────────────────────────────────────
110
120
 
111
- console.log('\n📦 Cloning Better System template...')
112
- await execa('npx', ['degit', 'brunogilferro/better-system', projectName], {
113
- stdio: 'inherit',
114
- })
121
+ const spinnerClone = ora('Cloning Better System template...').start()
122
+ try {
123
+ await execa('npx', ['degit', 'brunogilferro/better-system', projectName], {
124
+ stdio: 'pipe',
125
+ })
126
+ spinnerClone.succeed('Template cloned')
127
+ } catch (err) {
128
+ spinnerClone.fail('Failed to clone template')
129
+ throw err
130
+ }
115
131
 
116
132
  // ─── Update layout.tsx with heading font ─────────────────────────────────────
117
133
 
118
- console.log('🔤 Configuring fonts...')
134
+ const spinnerSetup = ora('Configuring project...').start()
119
135
 
120
136
  const layoutPath = path.join(projectPath, 'apps', 'frontend', 'app', 'layout.tsx')
121
137
  let layout = await fs.readFile(layoutPath, 'utf-8')
@@ -137,10 +153,10 @@ layout = layout
137
153
  .replaceAll('__PROJECT_NAME__', projectName)
138
154
 
139
155
  await fs.writeFile(layoutPath, layout)
156
+ spinnerSetup.text = 'Configuring CSS variables...'
140
157
 
141
158
  // ─── Fill globals.css placeholders ───────────────────────────────────────────
142
159
 
143
- console.log('💅 Configuring CSS variables...')
144
160
 
145
161
  const cssPath = path.join(projectPath, 'apps', 'frontend', 'app', 'globals.css')
146
162
  let css = await fs.readFile(cssPath, 'utf-8')
@@ -186,10 +202,10 @@ if (isBoth) {
186
202
  }
187
203
 
188
204
  await fs.writeFile(cssPath, css)
205
+ spinnerSetup.text = 'Configuring design tokens...'
189
206
 
190
207
  // ─── Fill figma-design-rules.md placeholders ─────────────────────────────────
191
208
 
192
- console.log('🎨 Configuring design tokens...')
193
209
 
194
210
  const figmaRulesPath = path.join(projectPath, 'docs', 'figma-design-rules.md')
195
211
  let figmaRules = await fs.readFile(figmaRulesPath, 'utf-8')
@@ -226,10 +242,10 @@ for (const [placeholder, value] of Object.entries(figmaReplacements)) {
226
242
  }
227
243
 
228
244
  await fs.writeFile(figmaRulesPath, figmaRules)
245
+ spinnerSetup.text = 'Generating APP_KEY...'
229
246
 
230
247
  // ─── Setup backend .env ───────────────────────────────────────────────────────
231
248
 
232
- console.log('🔑 Generating APP_KEY...')
233
249
 
234
250
  const backendPath = path.join(projectPath, 'apps', 'backend')
235
251
  const envExamplePath = path.join(backendPath, '.env.example')
@@ -242,23 +258,49 @@ const generatedKey = crypto.randomBytes(32).toString('base64url')
242
258
  let envContent = await fs.readFile(envPath, 'utf-8')
243
259
  envContent = envContent.replace('APP_KEY=', `APP_KEY=${generatedKey}`)
244
260
  await fs.writeFile(envPath, envContent)
261
+ spinnerSetup.text = 'Updating package.json...'
245
262
 
246
263
  // ─── Update root package.json ─────────────────────────────────────────────────
247
264
 
248
- console.log('📝 Updating package.json...')
249
265
 
250
266
  const rootPkgPath = path.join(projectPath, 'package.json')
251
267
  const rootPkg = await fs.readJson(rootPkgPath)
252
268
  rootPkg.name = projectName
253
269
  await fs.writeJson(rootPkgPath, rootPkg, { spaces: 2 })
270
+ spinnerSetup.succeed('Project configured')
254
271
 
255
272
  // ─── Git init ─────────────────────────────────────────────────────────────────
256
273
 
257
- console.log('🗂️ Initializing git repository...')
258
-
274
+ const spinnerGit = ora('Initializing git repository...').start()
259
275
  await execa('git', ['init'], { cwd: projectPath })
260
276
  await execa('git', ['add', '.'], { cwd: projectPath })
261
277
  await execa('git', ['commit', '-m', 'init: better system'], { cwd: projectPath })
278
+ spinnerGit.succeed('Git repository initialized')
279
+
280
+ // ─── Ensure pnpm is available ─────────────────────────────────────────────────
281
+
282
+ try {
283
+ await execa('pnpm', ['--version'], { stdio: 'pipe' })
284
+ } catch {
285
+ const spinnerPnpm = ora('pnpm not found — installing via npm...').start()
286
+ try {
287
+ await execa('npm', ['install', '-g', 'pnpm'], { stdio: 'pipe' })
288
+ spinnerPnpm.succeed('pnpm installed')
289
+ } catch {
290
+ spinnerPnpm.fail('Could not install pnpm. Install it manually: npm install -g pnpm')
291
+ process.exit(1)
292
+ }
293
+ }
294
+
295
+ // ─── pnpm install ─────────────────────────────────────────────────────────────
296
+
297
+ const spinnerInstall = ora('Installing dependencies...').start()
298
+ try {
299
+ await execa('pnpm', ['install'], { cwd: projectPath, stdio: 'pipe' })
300
+ spinnerInstall.succeed('Dependencies installed')
301
+ } catch {
302
+ spinnerInstall.fail('pnpm install failed — run it manually: cd ' + projectName + ' && pnpm install')
303
+ }
262
304
 
263
305
  // ─── Done ─────────────────────────────────────────────────────────────────────
264
306
 
@@ -271,7 +313,6 @@ if (isBoth) {
271
313
 
272
314
  console.log(`\nNext steps:`)
273
315
  console.log(` cd ${projectName}`)
274
- console.log(` pnpm install`)
275
316
  console.log(` pnpm dev`)
276
317
  console.log(`\nTo push to GitHub:`)
277
318
  console.log(` gh repo create ${projectName} --private --source=. --push\n`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-system",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "bin": {
5
5
  "create-better-system": "index.js"
6
6
  },
@@ -8,6 +8,7 @@
8
8
  "dependencies": {
9
9
  "inquirer": "^9.0.0",
10
10
  "execa": "^8.0.0",
11
- "fs-extra": "^11.0.0"
11
+ "fs-extra": "^11.0.0",
12
+ "ora": "^8.0.0"
12
13
  }
13
14
  }