@rokkit/cli 1.0.0-next.150 → 1.0.0-next.152
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/dist/src/init.d.ts +13 -1
- package/package.json +1 -1
- package/src/doctor.js +60 -5
- package/src/init.js +72 -4
- package/src/upgrade.js +2 -1
package/dist/src/init.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Build the chart config section from user prompt answers.
|
|
3
|
+
* @param {{ chartColors: string, chartShades: string }} opts
|
|
4
|
+
* @returns {Record<string, unknown>}
|
|
5
|
+
*/
|
|
6
|
+
export function generateChartConfig({ chartColors, chartShades }: {
|
|
7
|
+
chartColors: string;
|
|
8
|
+
chartShades: string;
|
|
9
|
+
}): Record<string, unknown>;
|
|
10
|
+
export function generateConfig({ palette, customColors, icons, iconPath, themes, defaultTheme, switcher, includeChart, chartColors, chartShades }: {
|
|
2
11
|
palette: any;
|
|
3
12
|
customColors: any;
|
|
4
13
|
icons: any;
|
|
@@ -6,6 +15,9 @@ export function generateConfig({ palette, customColors, icons, iconPath, themes,
|
|
|
6
15
|
themes: any;
|
|
7
16
|
defaultTheme: any;
|
|
8
17
|
switcher: any;
|
|
18
|
+
includeChart: any;
|
|
19
|
+
chartColors: any;
|
|
20
|
+
chartShades: any;
|
|
9
21
|
}): {
|
|
10
22
|
colors: Record<string, unknown>;
|
|
11
23
|
themes: any;
|
package/package.json
CHANGED
package/src/doctor.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
3
3
|
import { resolve } from 'path'
|
|
4
|
-
import { generateUnoConfig, generateAppCssImports, generateInitScript } from './init.js'
|
|
4
|
+
import { generateUnoConfig, generateAppCssImports, generateInitScript, generateChartConfig } from './init.js'
|
|
5
5
|
|
|
6
6
|
const KNOWN_THEMES = [
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
'rokkit',
|
|
8
|
+
'minimal',
|
|
9
|
+
'material',
|
|
10
|
+
'frosted',
|
|
11
|
+
'grada-ui',
|
|
12
|
+
'shadcn',
|
|
13
|
+
'daisy-ui',
|
|
14
|
+
'bits-ui',
|
|
15
|
+
'carbon',
|
|
16
|
+
'ant-design'
|
|
9
17
|
]
|
|
10
18
|
|
|
11
19
|
/**
|
|
@@ -84,6 +92,26 @@ function checkCssTheme(fs) {
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Check rokkit.config.js has a chart section.
|
|
97
|
+
* Missing chart config is a warning (not failure) — defaults work without it.
|
|
98
|
+
* @param {Object} fs
|
|
99
|
+
* @returns {Object}
|
|
100
|
+
*/
|
|
101
|
+
function checkChartConfig(fs) {
|
|
102
|
+
const configPath = fs.resolve('rokkit.config.js')
|
|
103
|
+
const configExists = fs.exists(configPath)
|
|
104
|
+
const hasChart = configExists && /\bchart\s*:/.test(fs.read(configPath))
|
|
105
|
+
return {
|
|
106
|
+
id: 'chart-config',
|
|
107
|
+
label: 'rokkit.config.js has chart configuration',
|
|
108
|
+
status: hasChart ? 'pass' : 'warn',
|
|
109
|
+
fixable: configExists,
|
|
110
|
+
fix: 'Add a chart section to rokkit.config.js (see docs/design/17-chart-preset.md)',
|
|
111
|
+
autoFix: 'patch-chart-config'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
87
115
|
/**
|
|
88
116
|
* Check app.html has init script
|
|
89
117
|
* @param {Object} fs
|
|
@@ -111,7 +139,14 @@ function checkHtmlScript(fs) {
|
|
|
111
139
|
* @returns {Array<{ id: string, label: string, status: 'pass'|'fail', fixable: boolean, fix: string, autoFix?: string }>}
|
|
112
140
|
*/
|
|
113
141
|
export function runChecks(fs) {
|
|
114
|
-
return [
|
|
142
|
+
return [
|
|
143
|
+
checkConfig(fs),
|
|
144
|
+
checkUnoPreset(fs),
|
|
145
|
+
checkCssImports(fs),
|
|
146
|
+
checkCssTheme(fs),
|
|
147
|
+
checkHtmlScript(fs),
|
|
148
|
+
checkChartConfig(fs)
|
|
149
|
+
]
|
|
115
150
|
}
|
|
116
151
|
|
|
117
152
|
/**
|
|
@@ -173,6 +208,25 @@ function applyPatchHtml(cwd, label) {
|
|
|
173
208
|
return true
|
|
174
209
|
}
|
|
175
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Patch rokkit.config.js to add a default chart section.
|
|
213
|
+
* @param {string} cwd
|
|
214
|
+
* @param {string} label
|
|
215
|
+
*/
|
|
216
|
+
function applyPatchChartConfig(cwd, label) {
|
|
217
|
+
const configPath = resolve(cwd, 'rokkit.config.js')
|
|
218
|
+
if (!existsSync(configPath)) return false
|
|
219
|
+
const content = readFileSync(configPath, 'utf-8')
|
|
220
|
+
if (/\bchart\s*:/.test(content)) return false
|
|
221
|
+
const chartConfig = generateChartConfig({ chartColors: 'default', chartShades: 'standard' })
|
|
222
|
+
const chartJson = JSON.stringify(chartConfig, null, 2).replace(/\n/g, '\n ')
|
|
223
|
+
// Inject before the last closing brace of the export default object
|
|
224
|
+
const patched = content.replace(/(\n?}\s*\n?)$/, `,\n chart: ${chartJson}\n}\n`)
|
|
225
|
+
writeFileSync(configPath, patched)
|
|
226
|
+
console.info(` Fixed: ${label}`)
|
|
227
|
+
return true
|
|
228
|
+
}
|
|
229
|
+
|
|
176
230
|
/** @type {Record<string, (cwd: string, label: string) => boolean|void>} */
|
|
177
231
|
const FIX_HANDLERS = {
|
|
178
232
|
'generate-config': (cwd, label) => {
|
|
@@ -183,7 +237,8 @@ const FIX_HANDLERS = {
|
|
|
183
237
|
applyPatchCss(cwd, label)
|
|
184
238
|
return true
|
|
185
239
|
},
|
|
186
|
-
'patch-html': (cwd, label) => applyPatchHtml(cwd, label)
|
|
240
|
+
'patch-html': (cwd, label) => applyPatchHtml(cwd, label),
|
|
241
|
+
'patch-chart-config': (cwd, label) => applyPatchChartConfig(cwd, label)
|
|
187
242
|
}
|
|
188
243
|
|
|
189
244
|
/**
|
package/src/init.js
CHANGED
|
@@ -3,6 +3,19 @@ import prompts from 'prompts'
|
|
|
3
3
|
import { writeFileSync, readFileSync, existsSync } from 'fs'
|
|
4
4
|
import { resolve } from 'path'
|
|
5
5
|
|
|
6
|
+
const CHART_COLOR_SETS = {
|
|
7
|
+
default: ['blue', 'emerald', 'rose', 'amber', 'violet', 'sky', 'pink', 'teal',
|
|
8
|
+
'orange', 'indigo', 'lime', 'cyan', 'gold', 'lavender'],
|
|
9
|
+
warm: ['rose', 'orange', 'amber', 'pink', 'red', 'yellow', 'gold', 'fuchsia'],
|
|
10
|
+
cool: ['sky', 'teal', 'blue', 'indigo', 'cyan', 'violet', 'lavender', 'slate']
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CHART_SHADE_PRESETS = {
|
|
14
|
+
standard: { light: { fill: '300', stroke: '700' }, dark: { fill: '500', stroke: '200' } },
|
|
15
|
+
high: { light: { fill: '200', stroke: '800' }, dark: { fill: '400', stroke: '100' } },
|
|
16
|
+
soft: { light: { fill: '400', stroke: '600' }, dark: { fill: '600', stroke: '300' } }
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
const SKIN_PRESETS = {
|
|
7
20
|
default: { primary: 'orange', secondary: 'pink', accent: 'sky', surface: 'slate' },
|
|
8
21
|
vibrant: { primary: 'blue', secondary: 'purple', accent: 'sky', surface: 'slate' },
|
|
@@ -41,7 +54,30 @@ function resolveColors(palette, customColors) {
|
|
|
41
54
|
return { ...DEFAULT_COLORS, ...(SKIN_PRESETS[palette] || {}) }
|
|
42
55
|
}
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Build the chart config section from user prompt answers.
|
|
59
|
+
* @param {{ chartColors: string, chartShades: string }} opts
|
|
60
|
+
* @returns {Record<string, unknown>}
|
|
61
|
+
*/
|
|
62
|
+
export function generateChartConfig({ chartColors, chartShades }) {
|
|
63
|
+
return {
|
|
64
|
+
colors: CHART_COLOR_SETS[chartColors] ?? CHART_COLOR_SETS.default,
|
|
65
|
+
shades: CHART_SHADE_PRESETS[chartShades] ?? CHART_SHADE_PRESETS.standard
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function generateConfig({
|
|
70
|
+
palette,
|
|
71
|
+
customColors,
|
|
72
|
+
icons,
|
|
73
|
+
iconPath,
|
|
74
|
+
themes,
|
|
75
|
+
defaultTheme,
|
|
76
|
+
switcher,
|
|
77
|
+
includeChart,
|
|
78
|
+
chartColors,
|
|
79
|
+
chartShades
|
|
80
|
+
}) {
|
|
45
81
|
const config = {
|
|
46
82
|
colors: resolveColors(palette, customColors),
|
|
47
83
|
themes,
|
|
@@ -54,6 +90,10 @@ export function generateConfig({ palette, customColors, icons, iconPath, themes,
|
|
|
54
90
|
config.icons = { custom: iconPath }
|
|
55
91
|
}
|
|
56
92
|
|
|
93
|
+
if (includeChart) {
|
|
94
|
+
config.chart = generateChartConfig({ chartColors, chartShades })
|
|
95
|
+
}
|
|
96
|
+
|
|
57
97
|
return config
|
|
58
98
|
}
|
|
59
99
|
|
|
@@ -95,7 +135,8 @@ export function generateAppCssImports(themes) {
|
|
|
95
135
|
export function generateInitScript(switcher, storageKey = 'rokkit-theme', defaultStyle = 'rokkit') {
|
|
96
136
|
if (switcher === 'system') return null
|
|
97
137
|
|
|
98
|
-
const setStyle =
|
|
138
|
+
const setStyle =
|
|
139
|
+
switcher === 'full' ? `b.dataset.style = t.style || '${defaultStyle}'\n ` : ''
|
|
99
140
|
|
|
100
141
|
return ` <script>
|
|
101
142
|
(function () {
|
|
@@ -167,7 +208,7 @@ const PROMPTS_CONFIG = [
|
|
|
167
208
|
{ title: 'Rokkit', value: 'rokkit', selected: true },
|
|
168
209
|
{ title: 'Minimal', value: 'minimal' },
|
|
169
210
|
{ title: 'Material', value: 'material' },
|
|
170
|
-
{ title: 'Glass', value: '
|
|
211
|
+
{ title: 'Glass', value: 'frosted' },
|
|
171
212
|
{ title: 'Grada UI', value: 'grada-ui' },
|
|
172
213
|
{ value: 'shadcn', title: 'shadcn', hint: 'flat borders + ring focus' },
|
|
173
214
|
{ value: 'daisy-ui', title: 'daisy-ui', hint: 'rounded-full + bold fills' },
|
|
@@ -181,7 +222,8 @@ const PROMPTS_CONFIG = [
|
|
|
181
222
|
type: (prev) => (prev?.length > 1 ? 'select' : null),
|
|
182
223
|
name: 'defaultTheme',
|
|
183
224
|
message: 'Default theme style',
|
|
184
|
-
choices: (prev) =>
|
|
225
|
+
choices: (prev) =>
|
|
226
|
+
prev.map((t) => ({ title: t.charAt(0).toUpperCase() + t.slice(1), value: t }))
|
|
185
227
|
},
|
|
186
228
|
{
|
|
187
229
|
type: 'select',
|
|
@@ -192,6 +234,32 @@ const PROMPTS_CONFIG = [
|
|
|
192
234
|
{ title: 'Manual (light/dark toggle)', value: 'manual' },
|
|
193
235
|
{ title: 'Full (light/dark + style variants)', value: 'full' }
|
|
194
236
|
]
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: 'confirm',
|
|
240
|
+
name: 'includeChart',
|
|
241
|
+
message: 'Include chart configuration?',
|
|
242
|
+
initial: true
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
type: (prev) => (prev ? 'select' : null),
|
|
246
|
+
name: 'chartColors',
|
|
247
|
+
message: 'Chart color set',
|
|
248
|
+
choices: [
|
|
249
|
+
{ title: 'Default series (blue/emerald/rose/amber…)', value: 'default' },
|
|
250
|
+
{ title: 'Warm (rose/orange/amber/pink…)', value: 'warm' },
|
|
251
|
+
{ title: 'Cool (sky/teal/blue/indigo…)', value: 'cool' }
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
type: (_, values) => (values.includeChart ? 'select' : null),
|
|
256
|
+
name: 'chartShades',
|
|
257
|
+
message: 'Shade contrast',
|
|
258
|
+
choices: [
|
|
259
|
+
{ title: 'Standard (fill 300 / stroke 700)', value: 'standard' },
|
|
260
|
+
{ title: 'High (fill 200 / stroke 800)', value: 'high' },
|
|
261
|
+
{ title: 'Soft (fill 400 / stroke 600)', value: 'soft' }
|
|
262
|
+
]
|
|
195
263
|
}
|
|
196
264
|
]
|
|
197
265
|
|
package/src/upgrade.js
CHANGED
|
@@ -64,7 +64,8 @@ function resolveUpgradeAdapters(adapters) {
|
|
|
64
64
|
return null
|
|
65
65
|
}
|
|
66
66
|
}),
|
|
67
|
-
runInstall:
|
|
67
|
+
runInstall:
|
|
68
|
+
adapters.runInstall ?? ((bin, args) => execFileSync(bin, args, { stdio: 'inherit' }))
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|