create-snappy 1.0.0 → 1.1.0
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.
- package/package.json +2 -1
- package/scripts/create-snappy/cli.js +39 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-snappy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The official installer for the SNAPPY stack.",
|
|
5
5
|
"main": "scripts/create-snappy/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"commander": "^14.0.3",
|
|
15
|
+
"ora": "^5.4.1",
|
|
15
16
|
"picocolors": "^1.1.1",
|
|
16
17
|
"prompts": "^2.4.2"
|
|
17
18
|
},
|
|
@@ -14,6 +14,16 @@ import os from 'os'
|
|
|
14
14
|
import { Command } from 'commander'
|
|
15
15
|
import prompts from 'prompts'
|
|
16
16
|
import pc from 'picocolors'
|
|
17
|
+
import ora from 'ora'
|
|
18
|
+
|
|
19
|
+
const SNAPPY_LOGO = `
|
|
20
|
+
███████╗███╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
|
|
21
|
+
██╔════╝████╗ ██║██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝
|
|
22
|
+
███████╗██╔██╗ ██║███████║██████╔╝██████╔╝ ╚████╔╝
|
|
23
|
+
╚════██║██║╚██╗██║██╔══██║██╔═══╝ ██╔═══╝ ╚██╔╝
|
|
24
|
+
███████║██║ ╚████║██║ ██║██║ ██║ ██║
|
|
25
|
+
╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
|
|
26
|
+
`
|
|
17
27
|
|
|
18
28
|
const __filename = fileURLToPath(import.meta.url)
|
|
19
29
|
const __dirname = path.dirname(__filename)
|
|
@@ -144,8 +154,17 @@ async function githubLogin() {
|
|
|
144
154
|
|
|
145
155
|
// --- Main CLI ---
|
|
146
156
|
|
|
157
|
+
function getPackageManager() {
|
|
158
|
+
const userAgent = process.env.npm_config_user_agent || ''
|
|
159
|
+
if (userAgent.startsWith('yarn')) return 'yarn'
|
|
160
|
+
if (userAgent.startsWith('pnpm')) return 'pnpm'
|
|
161
|
+
if (userAgent.startsWith('bun')) return 'bun'
|
|
162
|
+
return 'npm'
|
|
163
|
+
}
|
|
164
|
+
|
|
147
165
|
async function main() {
|
|
148
|
-
console.log(pc.cyan(
|
|
166
|
+
console.log(pc.cyan(SNAPPY_LOGO))
|
|
167
|
+
console.log(pc.cyan('🚀 Welcome to the SNAPPY Stack Installer!'))
|
|
149
168
|
console.log('------------------------------------------')
|
|
150
169
|
|
|
151
170
|
const program = new Command()
|
|
@@ -337,20 +356,24 @@ async function main() {
|
|
|
337
356
|
authenticatedUrl = repoUrl.replace('https://', `https://x-access-token:${token}@`)
|
|
338
357
|
}
|
|
339
358
|
|
|
340
|
-
|
|
359
|
+
const cloneSpinner = ora(`Cloning secure template (${selectedTemplate})...`).start()
|
|
341
360
|
try {
|
|
342
361
|
// Use branch as the template name
|
|
343
362
|
execSync(`git clone --depth 1 -b ${selectedTemplate} ${authenticatedUrl} "${targetDir}"`, {
|
|
344
|
-
stdio: '
|
|
363
|
+
stdio: 'ignore',
|
|
345
364
|
})
|
|
365
|
+
cloneSpinner.succeed('Project cloned successfully.')
|
|
346
366
|
} catch (cloneErr) {
|
|
367
|
+
cloneSpinner.stop()
|
|
347
368
|
if (!token) {
|
|
348
369
|
console.log(pc.yellow('\n🔐 This template might be private. Attempting login...'))
|
|
349
370
|
token = await githubLogin()
|
|
350
371
|
authenticatedUrl = repoUrl.replace('https://', `https://x-access-token:${token}@`)
|
|
372
|
+
const retrySpinner = ora(`Cloning secure template (${selectedTemplate})...`).start()
|
|
351
373
|
execSync(`git clone --depth 1 -b ${selectedTemplate} ${authenticatedUrl} "${targetDir}"`, {
|
|
352
|
-
stdio: '
|
|
374
|
+
stdio: 'ignore',
|
|
353
375
|
})
|
|
376
|
+
retrySpinner.succeed('Project cloned successfully.')
|
|
354
377
|
} else {
|
|
355
378
|
console.error(
|
|
356
379
|
pc.red("Clone failed. The branch might not exist, or you don't have access."),
|
|
@@ -405,19 +428,25 @@ PUBLIC_FRONTEND_URL="http://localhost:3000"
|
|
|
405
428
|
REQUIRE_LOGIN="yes"
|
|
406
429
|
`
|
|
407
430
|
fs.writeFileSync(path.join(targetDir, '.env'), envContent)
|
|
408
|
-
console.log(pc.green('✅ .env generated
|
|
431
|
+
console.log(pc.green('✅ .env generated.\n'))
|
|
409
432
|
|
|
410
433
|
if (process.env.SKIP_INSTALL !== 'true') {
|
|
411
|
-
|
|
434
|
+
const pm = getPackageManager()
|
|
435
|
+
const installCmd = pm === 'npm' ? 'npm install' : `${pm} install`
|
|
436
|
+
const installSpinner = ora(`Installing dependencies using ${pm}...`).start()
|
|
412
437
|
try {
|
|
413
|
-
execSync(
|
|
438
|
+
execSync(installCmd, { cwd: targetDir, stdio: 'ignore' })
|
|
439
|
+
installSpinner.succeed('Dependencies installed successfully.')
|
|
414
440
|
} catch (e) {
|
|
415
|
-
|
|
441
|
+
installSpinner.fail('Failed to install dependencies.')
|
|
442
|
+
console.warn(pc.yellow(`Warning: ${installCmd} failed.`))
|
|
416
443
|
}
|
|
417
444
|
}
|
|
418
445
|
|
|
419
|
-
|
|
420
|
-
|
|
446
|
+
const pmRun = getPackageManager() === 'npm' ? 'npm run dev' : `${getPackageManager()} run dev`
|
|
447
|
+
|
|
448
|
+
console.log(pc.green('\n✅ SNAPPY Stack is perfectly prepared and ready to launch!'))
|
|
449
|
+
console.log(`\nNext steps:\n cd ${pc.bold(projectName)}\n ${pmRun}\n`)
|
|
421
450
|
} catch (err) {
|
|
422
451
|
console.error(pc.red(`Installation failed: ${err.message || err}`))
|
|
423
452
|
} finally {
|