@ardly/bunext 1.0.4 → 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.
package/bin/cli.mjs CHANGED
@@ -2,15 +2,26 @@
2
2
 
3
3
  import { execSync } from 'child_process'
4
4
  import readline from 'readline'
5
+ import { createSpinner } from './utils.mjs'
6
+
7
+ // ANSI color codes for terminal output
8
+ const colors = {
9
+ reset: '\x1b[0m',
10
+ cyan: '\x1b[36m',
11
+ green: '\x1b[32m',
12
+ yellow: '\x1b[33m',
13
+ red: '\x1b[31m',
14
+ bold: '\x1b[1m',
15
+ dim: '\x1b[2m',
16
+ }
5
17
 
6
18
  const runCommand = (command) => {
7
19
  try {
8
20
  execSync(`${command}`, { stdio: 'inherit' })
21
+ return true
9
22
  } catch (error) {
10
- console.error(`Failed to run command: ${command}`, error)
11
23
  return false
12
24
  }
13
- return true
14
25
  }
15
26
 
16
27
  const rl = readline.createInterface({
@@ -18,85 +29,105 @@ const rl = readline.createInterface({
18
29
  output: process.stdout,
19
30
  })
20
31
 
32
+ const question = (query) =>
33
+ new Promise((resolve) => rl.question(query, resolve))
34
+
21
35
  let repoName = process.argv[2]
22
36
  const args = process.argv.slice(2)
23
37
  const useVSCode = args.includes('--vs')
24
38
  const useCursor = args.includes('--cursor')
25
39
 
26
- if (!repoName || repoName.startsWith('--')) {
27
- rl.question('Please enter a name for your project: ', (answer) => {
28
- repoName = answer
29
- initializeProject()
30
- })
31
- } else {
32
- initializeProject()
33
- }
34
-
35
- function initializeProject() {
36
- const gitCheckout = `git clone --depth 1 https://github.com/DarkidOP/Bunext.git ${repoName}`
37
- const removeGit = `cd ${repoName} && rm -rf .git`
38
- const initGit = `cd ${repoName} && git init && git add . && git commit -m "Initial commit"`
39
- const openVSCode = `cd ${repoName} && code .`
40
- const openCursor = `cd ${repoName} && cursor .`
40
+ async function initializeProject() {
41
+ console.log(
42
+ `\n${colors.cyan}${colors.bold}🚀 Bunext - Next.js Project Generator${colors.reset}\n`
43
+ )
41
44
 
42
- // Determine package manager based on how script was executed
43
- let packageManager = 'npm'
44
- if (process.env.npm_execpath?.includes('pnpm')) {
45
- packageManager = 'pnpm'
46
- } else if (process.env.npm_execpath?.includes('yarn')) {
47
- packageManager = 'yarn'
48
- } else if (process.argv[1].includes('bunx')) {
49
- packageManager = 'bun'
45
+ if (!repoName || repoName.startsWith('--')) {
46
+ repoName = await question(`${colors.yellow}? ${colors.reset}Project name: `)
47
+ if (!repoName) {
48
+ console.log(`${colors.red}✖ Project name is required${colors.reset}`)
49
+ process.exit(1)
50
+ }
50
51
  }
51
52
 
52
- const installDeps = `cd ${repoName} && ${packageManager} install`
53
+ const spinner = createSpinner()
53
54
 
54
- console.log(`Creating project template in ./${repoName}`)
55
+ // Clone repository
56
+ spinner.start('Creating project template')
57
+ const gitCheckout = `git clone --depth 1 https://github.com/DarkidOP/Bunext.git ${repoName}`
55
58
  const checkedOut = runCommand(gitCheckout)
56
59
  if (!checkedOut) {
57
- console.error(
58
- 'Failed to clone template repository "https://github.com/DarkidOP/Bunext.git"'
59
- )
60
+ spinner.fail('Failed to clone template repository')
60
61
  process.exit(1)
61
62
  }
63
+ spinner.succeed(`Project template created in ./${repoName}`)
62
64
 
63
- console.log('Removing Git history...')
65
+ // Remove git
66
+ spinner.start('Removing Git history')
67
+ const removeGit = `cd ${repoName} && rm -rf .git`
64
68
  const removedGit = runCommand(removeGit)
65
69
  if (!removedGit) {
66
- console.error('Failed to remove Git history')
70
+ spinner.fail('Failed to remove Git history')
67
71
  process.exit(1)
68
72
  }
73
+ spinner.succeed('Git history removed')
69
74
 
70
- console.log('Installing dependencies...')
75
+ // Detect package manager
76
+ let packageManager = 'npm'
77
+ if (process.env.npm_execpath?.includes('pnpm')) {
78
+ packageManager = 'pnpm'
79
+ } else if (process.env.npm_execpath?.includes('yarn')) {
80
+ packageManager = 'yarn'
81
+ } else if (process.argv[1].includes('bunx')) {
82
+ packageManager = 'bun'
83
+ }
84
+
85
+ // Install dependencies
86
+ spinner.start(`Installing dependencies using ${packageManager}`)
87
+ const installDeps = `cd ${repoName} && ${packageManager}${
88
+ packageManager === 'npm' ? ' install --legacy-peer-deps' : ' install'
89
+ }`
71
90
  const installedDeps = runCommand(installDeps)
72
91
  if (!installedDeps) {
73
- console.error('Failed to install dependencies')
92
+ spinner.fail('Failed to install dependencies')
74
93
  process.exit(1)
75
94
  }
95
+ spinner.succeed('Dependencies installed')
76
96
 
77
- rl.question(
78
- 'Would you like to initialize a new git repository? (y/n) ',
79
- (answer) => {
80
- if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
81
- console.log('Initializing Git repository...')
82
- const initializedGit = runCommand(initGit)
83
- if (!initializedGit) {
84
- console.error('Failed to initialize Git repository')
85
- process.exit(1)
86
- }
87
- console.log('Git repository initialized successfully!')
88
- }
89
-
90
- if (useVSCode) {
91
- console.log('Opening in Visual Studio Code...')
92
- runCommand(openVSCode)
93
- } else if (useCursor) {
94
- console.log('Opening in Cursor...')
95
- runCommand(openCursor)
96
- }
97
-
98
- console.log('\nHappy coding! 🎉')
99
- rl.close()
97
+ // Git init prompt
98
+ const initGit = await question(
99
+ `${colors.yellow}? ${colors.reset}Initialize Git repository? (y/N) `
100
+ )
101
+ if (initGit.toLowerCase() === 'y') {
102
+ spinner.start('Initializing Git repository')
103
+ const gitInit = `cd ${repoName} && git init && git add . && git commit -m "Initial commit"`
104
+ const initializedGit = runCommand(gitInit)
105
+ if (!initializedGit) {
106
+ spinner.fail('Failed to initialize Git repository')
107
+ process.exit(1)
100
108
  }
109
+ spinner.succeed('Git repository initialized')
110
+ }
111
+
112
+ // Open in editor if specified
113
+ if (useVSCode) {
114
+ runCommand(`cd ${repoName} && code .`)
115
+ console.log(`${colors.dim}Opening in Visual Studio Code...${colors.reset}`)
116
+ } else if (useCursor) {
117
+ runCommand(`cd ${repoName} && cursor .`)
118
+ console.log(`${colors.dim}Opening in Cursor...${colors.reset}`)
119
+ }
120
+
121
+ console.log(
122
+ `\n${colors.green}${colors.bold}✨ Success! Your project is ready.${colors.reset}`
123
+ )
124
+ console.log(`\n${colors.dim}To get started:${colors.reset}`)
125
+ console.log(`\n cd ${repoName}`)
126
+ console.log(
127
+ ` ${packageManager}${packageManager === 'npm' ? ' run' : ''} dev\n`
101
128
  )
129
+
130
+ rl.close()
102
131
  }
132
+
133
+ // Create utils.mjs for the spinner
package/bin/utils.mjs ADDED
@@ -0,0 +1,32 @@
1
+ const spinner = {
2
+ frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
3
+ interval: 80,
4
+ }
5
+
6
+ export function createSpinner() {
7
+ let currentFrame = 0
8
+ let intervalId
9
+ let text = ''
10
+
11
+ return {
12
+ start(message) {
13
+ text = message
14
+ process.stdout.write('\x1b[?25l') // Hide cursor
15
+ intervalId = setInterval(() => {
16
+ const frame = spinner.frames[currentFrame]
17
+ process.stdout.write(`\r${frame} ${text}`)
18
+ currentFrame = (currentFrame + 1) % spinner.frames.length
19
+ }, spinner.interval)
20
+ },
21
+ succeed(message) {
22
+ clearInterval(intervalId)
23
+ process.stdout.write('\r✓ ' + (message || text) + '\n')
24
+ process.stdout.write('\x1b[?25h') // Show cursor
25
+ },
26
+ fail(message) {
27
+ clearInterval(intervalId)
28
+ process.stdout.write('\r✖ ' + (message || text) + '\n')
29
+ process.stdout.write('\x1b[?25h') // Show cursor
30
+ },
31
+ }
32
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ardly/bunext",
3
3
  "description": "Bunext - A Next.js 15 template with Tailwind CSS, shadcn ui and Bun with some utilities built in",
4
4
  "author": "Ard Astroid <ardastroid@gmail.com>",
5
- "version": "1.0.4",
5
+ "version": "1.0.5",
6
6
  "bin": "./bin/cli.mjs",
7
7
  "keywords": [
8
8
  "next.js",