create-sks-admin 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/bin/cli.js +92 -31
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -4,6 +4,7 @@ import { execSync } from 'child_process'
4
4
  import fs from 'fs'
5
5
  import path from 'path'
6
6
  import { fileURLToPath } from 'url'
7
+ import prompts from 'prompts'
7
8
 
8
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
10
 
@@ -13,6 +14,7 @@ const colors = {
13
14
  blue: (t) => `\x1b[34m${t}\x1b[0m`,
14
15
  yellow: (t) => `\x1b[33m${t}\x1b[0m`,
15
16
  red: (t) => `\x1b[31m${t}\x1b[0m`,
17
+ cyan: (t) => `\x1b[36m${t}\x1b[0m`,
16
18
  }
17
19
 
18
20
  const log = {
@@ -27,19 +29,53 @@ const projectName = process.argv[2] || 'sks-admin-test'
27
29
 
28
30
  console.log(`
29
31
  ╔═══════════════════════════════════════╗
30
- ║ @sks/create-admin CLI ║
32
+ ${colors.cyan('@sks/create-admin CLI')}
31
33
  ║ Creating: ${projectName.padEnd(22)}║
32
34
  ╚═══════════════════════════════════════╝
33
35
  `)
34
36
 
35
37
  const projectPath = path.resolve(process.cwd(), projectName)
38
+ const isCurrentDir = projectName === '.'
36
39
 
37
- // Check if folder exists
38
- if (fs.existsSync(projectPath)) {
40
+ // Check if folder exists (skip for current dir)
41
+ if (!isCurrentDir && fs.existsSync(projectPath)) {
39
42
  log.error(`Folder "${projectName}" already exists!`)
40
43
  process.exit(1)
41
44
  }
42
45
 
46
+ // For current directory, check if it's empty (allow .git and other hidden files)
47
+ if (isCurrentDir) {
48
+ const files = fs.readdirSync(projectPath).filter(f => !f.startsWith('.'))
49
+ if (files.length > 0) {
50
+ log.error('Current directory is not empty! Use an empty folder or provide a project name.')
51
+ process.exit(1)
52
+ }
53
+ }
54
+
55
+ // Ask for token
56
+ console.log('')
57
+ console.log(colors.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
58
+ console.log(colors.yellow(' Premium Admin Panel Components'))
59
+ console.log(colors.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
60
+ console.log('')
61
+
62
+ const response = await prompts({
63
+ type: 'password',
64
+ name: 'token',
65
+ message: 'Enter access token (or press Enter to skip):',
66
+ })
67
+
68
+ const hasToken = response.token && response.token.trim().length > 0
69
+ const authToken = response.token?.trim()
70
+
71
+ if (hasToken) {
72
+ log.success('Token received - Premium components will be installed')
73
+ } else {
74
+ log.info('No token - Basic template will be created')
75
+ }
76
+
77
+ console.log('')
78
+
43
79
  try {
44
80
  // Step 1: Create Next.js app
45
81
  log.info('Creating Next.js app...')
@@ -52,24 +88,40 @@ try {
52
88
  // Step 2: Navigate to project
53
89
  process.chdir(projectPath)
54
90
 
55
- // Step 3: Create .npmrc for GitHub Packages
91
+ // Step 3: Create .npmrc for GitHub Packages (with token if provided)
56
92
  log.info('Configuring npm registry...')
57
- fs.writeFileSync(
58
- '.npmrc',
59
- `@sks:registry=https://npm.pkg.github.com
60
- //npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}
93
+ if (hasToken) {
94
+ fs.writeFileSync(
95
+ '.npmrc',
96
+ `@sks:registry=https://npm.pkg.github.com
97
+ //npm.pkg.github.com/:_authToken=${authToken}
61
98
  `
62
- )
99
+ )
100
+ } else {
101
+ fs.writeFileSync(
102
+ '.npmrc',
103
+ `@sks:registry=https://npm.pkg.github.com
104
+ # Add your token here to install premium packages:
105
+ # //npm.pkg.github.com/:_authToken=YOUR_TOKEN
106
+ `
107
+ )
108
+ }
63
109
  log.success('.npmrc created')
64
110
 
65
- // Step 4: Install @sks packages (will fail if not published yet, that's OK)
66
- log.info('Installing @sks packages...')
67
- try {
68
- execSync('npm install @sks/admin-core @sks/admin-ui', { stdio: 'inherit' })
69
- log.success('@sks packages installed')
70
- } catch {
71
- log.warn('@sks packages not published yet - skipping')
72
- log.info('Run "npm install @sks/admin-core @sks/admin-ui" after publishing')
111
+ // Step 4: Install @sks packages only if token provided
112
+ let packagesInstalled = false
113
+ if (hasToken) {
114
+ log.info('Installing @sks premium packages...')
115
+ try {
116
+ execSync('npm install @sks/admin-core @sks/admin-ui', { stdio: 'inherit' })
117
+ log.success('@sks packages installed')
118
+ packagesInstalled = true
119
+ } catch {
120
+ log.warn('Could not install @sks packages - token may be invalid')
121
+ log.info('Check your token and run: npm install @sks/admin-core @sks/admin-ui')
122
+ }
123
+ } else {
124
+ log.info('Skipping premium packages (no token)')
73
125
  }
74
126
 
75
127
  // Step 5: Create lib/dal.ts
@@ -165,20 +217,29 @@ export default function AdminLayout({
165
217
  log.success('Boilerplate files created')
166
218
 
167
219
  // Done!
168
- console.log(`
169
- ${colors.green('✓ Project created successfully!')}
170
-
171
- ${colors.blue('Next steps:')}
172
- cd ${projectName}
173
- npm run dev
174
-
175
- ${colors.blue('Admin panel:')}
176
- http://localhost:3000/admin
177
-
178
- ${colors.yellow('After publishing @sks packages:')}
179
- npm install @sks/admin-core @sks/admin-ui
180
- Then uncomment imports in lib/dal.ts and app/admin/layout.tsx
181
- `)
220
+ console.log('')
221
+ console.log(colors.green('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
222
+ console.log(colors.green(' ✓ Project created successfully!'))
223
+ console.log(colors.green('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'))
224
+ console.log('')
225
+
226
+ console.log(colors.blue('Next steps:'))
227
+ console.log(` cd ${isCurrentDir ? '.' : projectName}`)
228
+ console.log(' npm run dev')
229
+ console.log('')
230
+ console.log(colors.blue('Admin panel:'))
231
+ console.log(' http://localhost:3000/admin')
232
+ console.log('')
233
+
234
+ if (packagesInstalled) {
235
+ console.log(colors.green('Premium packages installed! Full admin panel ready.'))
236
+ } else {
237
+ console.log(colors.yellow('To unlock premium features:'))
238
+ console.log(' 1. Get your access token from admin')
239
+ console.log(' 2. Run: npx create-sks-admin my-app')
240
+ console.log(' 3. Enter token when prompted')
241
+ }
242
+ console.log('')
182
243
 
183
244
  } catch (error) {
184
245
  log.error('Failed to create project')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sks-admin",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "CLI to scaffold SKS Admin projects",
5
5
  "type": "module",
6
6
  "bin": {