create-sks-admin 0.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/bin/cli.js +187 -0
- package/package.json +28 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'child_process'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import { fileURLToPath } from 'url'
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
// Colors for terminal
|
|
11
|
+
const colors = {
|
|
12
|
+
green: (t) => `\x1b[32m${t}\x1b[0m`,
|
|
13
|
+
blue: (t) => `\x1b[34m${t}\x1b[0m`,
|
|
14
|
+
yellow: (t) => `\x1b[33m${t}\x1b[0m`,
|
|
15
|
+
red: (t) => `\x1b[31m${t}\x1b[0m`,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const log = {
|
|
19
|
+
info: (msg) => console.log(colors.blue('ℹ'), msg),
|
|
20
|
+
success: (msg) => console.log(colors.green('✓'), msg),
|
|
21
|
+
warn: (msg) => console.log(colors.yellow('⚠'), msg),
|
|
22
|
+
error: (msg) => console.log(colors.red('✗'), msg),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Get project name from args
|
|
26
|
+
const projectName = process.argv[2] || 'sks-admin-test'
|
|
27
|
+
|
|
28
|
+
console.log(`
|
|
29
|
+
╔═══════════════════════════════════════╗
|
|
30
|
+
║ @sks/create-admin CLI ║
|
|
31
|
+
║ Creating: ${projectName.padEnd(22)}║
|
|
32
|
+
╚═══════════════════════════════════════╝
|
|
33
|
+
`)
|
|
34
|
+
|
|
35
|
+
const projectPath = path.resolve(process.cwd(), projectName)
|
|
36
|
+
|
|
37
|
+
// Check if folder exists
|
|
38
|
+
if (fs.existsSync(projectPath)) {
|
|
39
|
+
log.error(`Folder "${projectName}" already exists!`)
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
// Step 1: Create Next.js app
|
|
45
|
+
log.info('Creating Next.js app...')
|
|
46
|
+
execSync(
|
|
47
|
+
`npx create-next-app@latest ${projectName} --typescript --tailwind --eslint --app --src-dir=false --import-alias="@/*" --turbopack`,
|
|
48
|
+
{ stdio: 'inherit' }
|
|
49
|
+
)
|
|
50
|
+
log.success('Next.js app created')
|
|
51
|
+
|
|
52
|
+
// Step 2: Navigate to project
|
|
53
|
+
process.chdir(projectPath)
|
|
54
|
+
|
|
55
|
+
// Step 3: Create .npmrc for GitHub Packages
|
|
56
|
+
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}
|
|
61
|
+
`
|
|
62
|
+
)
|
|
63
|
+
log.success('.npmrc created')
|
|
64
|
+
|
|
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')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Step 5: Create lib/dal.ts
|
|
76
|
+
log.info('Creating boilerplate files...')
|
|
77
|
+
|
|
78
|
+
fs.mkdirSync('lib', { recursive: true })
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
'lib/dal.ts',
|
|
81
|
+
`// Data Access Layer for Authentication
|
|
82
|
+
// Uncomment after installing @sks/admin-core
|
|
83
|
+
|
|
84
|
+
// import { createDAL } from '@sks/admin-core/auth'
|
|
85
|
+
// import { auth } from '@/auth'
|
|
86
|
+
|
|
87
|
+
// export const {
|
|
88
|
+
// verifySession,
|
|
89
|
+
// verifyAdminSession,
|
|
90
|
+
// redirectIfAuthenticated,
|
|
91
|
+
// } = createDAL({
|
|
92
|
+
// auth,
|
|
93
|
+
// loginPath: '/admin/login',
|
|
94
|
+
// adminRoles: ['ADMIN'],
|
|
95
|
+
// })
|
|
96
|
+
|
|
97
|
+
// Placeholder exports for now
|
|
98
|
+
export const verifySession = async () => ({ userId: '1', email: 'test@test.com', role: 'ADMIN' })
|
|
99
|
+
export const verifyAdminSession = verifySession
|
|
100
|
+
`
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
// Step 6: Create admin layout
|
|
104
|
+
fs.mkdirSync('app/admin', { recursive: true })
|
|
105
|
+
fs.writeFileSync(
|
|
106
|
+
'app/admin/layout.tsx',
|
|
107
|
+
`// Admin Layout with @sks/admin-ui
|
|
108
|
+
// Uncomment after installing packages
|
|
109
|
+
|
|
110
|
+
// import { AdminShell, ThemeProvider } from '@sks/admin-ui'
|
|
111
|
+
// import '@sks/admin-ui/themes/base.css'
|
|
112
|
+
|
|
113
|
+
export default function AdminLayout({
|
|
114
|
+
children,
|
|
115
|
+
}: {
|
|
116
|
+
children: React.ReactNode
|
|
117
|
+
}) {
|
|
118
|
+
return (
|
|
119
|
+
<div className="min-h-screen bg-gray-100">
|
|
120
|
+
{/* Replace with AdminShell after installing @sks/admin-ui */}
|
|
121
|
+
<aside className="fixed left-0 top-0 h-screen w-64 bg-gray-900 text-white p-4">
|
|
122
|
+
<h1 className="text-xl font-bold mb-8">Admin Panel</h1>
|
|
123
|
+
<nav className="space-y-2">
|
|
124
|
+
<a href="/admin" className="block p-2 rounded hover:bg-gray-800">Dashboard</a>
|
|
125
|
+
<a href="/admin/users" className="block p-2 rounded hover:bg-gray-800">Users</a>
|
|
126
|
+
<a href="/admin/settings" className="block p-2 rounded hover:bg-gray-800">Settings</a>
|
|
127
|
+
</nav>
|
|
128
|
+
</aside>
|
|
129
|
+
<main className="ml-64 p-8">
|
|
130
|
+
{children}
|
|
131
|
+
</main>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
`
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
// Step 7: Create admin dashboard page
|
|
139
|
+
fs.writeFileSync(
|
|
140
|
+
'app/admin/page.tsx',
|
|
141
|
+
`export default function AdminDashboard() {
|
|
142
|
+
return (
|
|
143
|
+
<div>
|
|
144
|
+
<h1 className="text-3xl font-bold mb-4">Dashboard</h1>
|
|
145
|
+
<div className="grid grid-cols-3 gap-4">
|
|
146
|
+
<div className="bg-white p-6 rounded-lg shadow">
|
|
147
|
+
<h2 className="text-gray-500">Total Users</h2>
|
|
148
|
+
<p className="text-3xl font-bold">1,234</p>
|
|
149
|
+
</div>
|
|
150
|
+
<div className="bg-white p-6 rounded-lg shadow">
|
|
151
|
+
<h2 className="text-gray-500">Revenue</h2>
|
|
152
|
+
<p className="text-3xl font-bold">$12,345</p>
|
|
153
|
+
</div>
|
|
154
|
+
<div className="bg-white p-6 rounded-lg shadow">
|
|
155
|
+
<h2 className="text-gray-500">Orders</h2>
|
|
156
|
+
<p className="text-3xl font-bold">567</p>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
log.success('Boilerplate files created')
|
|
166
|
+
|
|
167
|
+
// 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
|
+
`)
|
|
182
|
+
|
|
183
|
+
} catch (error) {
|
|
184
|
+
log.error('Failed to create project')
|
|
185
|
+
console.error(error)
|
|
186
|
+
process.exit(1)
|
|
187
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-sks-admin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI to scaffold SKS Admin projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-sks-admin": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"templates"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "node bin/cli.js",
|
|
15
|
+
"build": "echo 'No build needed'"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"prompts": "^2.4.2"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"admin",
|
|
22
|
+
"cli",
|
|
23
|
+
"nextjs",
|
|
24
|
+
"sks"
|
|
25
|
+
],
|
|
26
|
+
"author": "SKS",
|
|
27
|
+
"license": "MIT"
|
|
28
|
+
}
|