@svgrid/create-studio 0.1.1 → 0.1.3
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/README.md +16 -1
- package/index.mjs +89 -2
- package/package.json +2 -2
- package/templates/default/src/app.css +6 -2
package/README.md
CHANGED
|
@@ -39,11 +39,26 @@ and generate the exact screens + blocks you arranged:
|
|
|
39
39
|
npm create @svgrid/studio@latest my-app -- --project ./studio.config.json
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## Pick a theme
|
|
43
|
+
|
|
44
|
+
Running interactively, you'll be asked to pick a theme (one of `@svgrid/grid`'s
|
|
45
|
+
19 built-in presets - shadcn, Tailwind, Material, Excel, Fluent, and more) and
|
|
46
|
+
whether to start in light or dark mode. Both are also available as flags for
|
|
47
|
+
scripted use:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm create @svgrid/studio@latest my-app -- --theme material --dark
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Skipped when generating `--project ./studio.config.json` - that export already
|
|
54
|
+
carries the theme you chose in the designer.
|
|
55
|
+
|
|
42
56
|
## What you get
|
|
43
57
|
|
|
44
58
|
A full [SvelteKit](https://svelte.dev/docs/kit) app - not a snippet - wired end to end:
|
|
45
59
|
|
|
46
|
-
- **Nav shell +
|
|
60
|
+
- **Nav shell + theme** (plain CSS, light/dark aware, no Tailwind) - your pick
|
|
61
|
+
from `@svgrid/grid`'s built-in presets.
|
|
47
62
|
- **Two linked entities** - Customers and Orders - where an order references a
|
|
48
63
|
customer through a **searchable lookup** field.
|
|
49
64
|
- **Grid + modal CRUD** on every screen: sort, filter, global search, paging,
|
package/index.mjs
CHANGED
|
@@ -41,7 +41,7 @@ const c = {
|
|
|
41
41
|
const color = stdout.isTTY ? (k, s) => `${c[k]}${s}${c.reset}` : (_k, s) => s
|
|
42
42
|
|
|
43
43
|
function parseArgs(argv) {
|
|
44
|
-
const args = { _: [], force: false, help: false, from: null, project: null }
|
|
44
|
+
const args = { _: [], force: false, help: false, from: null, project: null, theme: null, dark: false }
|
|
45
45
|
for (let i = 0; i < argv.length; i++) {
|
|
46
46
|
const a = argv[i]
|
|
47
47
|
if (a === '--help' || a === '-h') args.help = true
|
|
@@ -50,6 +50,9 @@ function parseArgs(argv) {
|
|
|
50
50
|
else if (a.startsWith('--from=')) args.from = a.slice('--from='.length)
|
|
51
51
|
else if (a === '--project') args.project = argv[++i]
|
|
52
52
|
else if (a.startsWith('--project=')) args.project = a.slice('--project='.length)
|
|
53
|
+
else if (a === '--theme') args.theme = argv[++i]
|
|
54
|
+
else if (a.startsWith('--theme=')) args.theme = a.slice('--theme='.length)
|
|
55
|
+
else if (a === '--dark') args.dark = true
|
|
53
56
|
else if (!a.startsWith('-')) args._.push(a)
|
|
54
57
|
}
|
|
55
58
|
return args
|
|
@@ -72,6 +75,8 @@ ${color('bold', 'Options')}
|
|
|
72
75
|
schema instead of the seeded example (auto-detected).
|
|
73
76
|
--project <path> Generate the app from a studio.config.json exported by the
|
|
74
77
|
visual designer (screens + blocks, not just entities).
|
|
78
|
+
--theme <id> One of: ${THEME_IDS.join(', ')} (default: tailwind).
|
|
79
|
+
--dark Start the app in dark mode.
|
|
75
80
|
--force Scaffold into a non-empty directory.
|
|
76
81
|
|
|
77
82
|
${color('bold', 'Examples')}
|
|
@@ -79,9 +84,83 @@ ${color('bold', 'Examples')}
|
|
|
79
84
|
pnpm create @svgrid/studio my-data-app
|
|
80
85
|
npm create @svgrid/studio@latest my-app -- --from ./prisma/schema.prisma
|
|
81
86
|
npm create @svgrid/studio@latest my-app -- --project ./studio.config.json
|
|
87
|
+
npm create @svgrid/studio@latest my-app -- --theme material --dark
|
|
82
88
|
`)
|
|
83
89
|
}
|
|
84
90
|
|
|
91
|
+
const THEME_IDS = [
|
|
92
|
+
'shadcn', 'tailwind', 'material', 'excel', 'fluent', 'carbon', 'sap',
|
|
93
|
+
'salesforce', 'atlassian', 'github', 'antd', 'ag-alpine', 'bootstrap',
|
|
94
|
+
'vercel', 'linear', 'notion', 'nord', 'dracula', 'catppuccin',
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the theme + mode to apply: from `--theme`/`--dark` flags, or (in a
|
|
99
|
+
* TTY) an interactive prompt; otherwise the default (tailwind, light). Reuses
|
|
100
|
+
* `@svgrid/enterprise/studio`'s own preset list, so the picker can never drift
|
|
101
|
+
* from the canonical set in `@svgrid/grid/themes`.
|
|
102
|
+
*/
|
|
103
|
+
async function promptTheme(args, ask, interactive) {
|
|
104
|
+
let studio
|
|
105
|
+
try {
|
|
106
|
+
studio = await import('@svgrid/enterprise/studio')
|
|
107
|
+
} catch {
|
|
108
|
+
return null // theming is best-effort; the template's own default stands in.
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let themeId = args.theme ? args.theme.trim().toLowerCase() : null
|
|
112
|
+
if (themeId && !studio.getStudioTheme(themeId)) {
|
|
113
|
+
stdout.write(`${color('yellow', '!')} Unknown theme "${themeId}" - using tailwind. (${THEME_IDS.join(', ')})\n`)
|
|
114
|
+
themeId = null
|
|
115
|
+
}
|
|
116
|
+
if (!themeId && interactive) {
|
|
117
|
+
const list = studio.studioThemes.map((t, i) => ` ${i + 1}. ${t.name} ${color('dim', `(${t.id})`)}`).join('\n')
|
|
118
|
+
stdout.write(`\n${color('bold', 'Theme')}\n${list}\n`)
|
|
119
|
+
const choice = await ask('Pick a number or id:', 'tailwind')
|
|
120
|
+
const byIndex = studio.studioThemes[Number(choice) - 1]
|
|
121
|
+
themeId = byIndex ? byIndex.id : (studio.getStudioTheme(choice.trim().toLowerCase())?.id ?? 'tailwind')
|
|
122
|
+
}
|
|
123
|
+
themeId ??= 'tailwind'
|
|
124
|
+
|
|
125
|
+
let dark = args.dark
|
|
126
|
+
if (!dark && interactive) {
|
|
127
|
+
const a = await ask('Start in dark mode? (y/N)', 'N')
|
|
128
|
+
dark = /^y(es)?$/i.test(a)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return { themeId, dark, name: studio.getStudioTheme(themeId)?.name ?? themeId, studio }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Rewrite the template's `app.css` (between the `svgrid-theme` markers) with
|
|
135
|
+
* the resolved `--sg-*` tokens for the chosen theme + mode, and set
|
|
136
|
+
* `data-theme="dark"` on `<html>` when dark mode was picked. */
|
|
137
|
+
async function applyTheme(destDir, choice) {
|
|
138
|
+
if (!choice) return
|
|
139
|
+
const { themeId, dark, studio } = choice
|
|
140
|
+
const light = studio.resolveThemeTokens({ preset: themeId, mode: 'light' })
|
|
141
|
+
const darkTokens = studio.resolveThemeTokens({ preset: themeId, mode: 'dark' })
|
|
142
|
+
const block = (selector, tokens, scheme) => {
|
|
143
|
+
const lines = Object.entries(tokens).map(([k, v]) => ` ${k}: ${v};`).join('\n')
|
|
144
|
+
return `${selector} {\n${lines}\n color-scheme: ${scheme};\n}`
|
|
145
|
+
}
|
|
146
|
+
const css = `${block(':root', light, 'light')}\n${block(":root[data-theme='dark']", darkTokens, 'dark')}`
|
|
147
|
+
|
|
148
|
+
const cssPath = join(destDir, 'src', 'app.css')
|
|
149
|
+
const cssText = await readFile(cssPath, 'utf8')
|
|
150
|
+
const marked = /\/\* svgrid-theme:start \*\/[\s\S]*?\/\* svgrid-theme:end \*\//
|
|
151
|
+
if (marked.test(cssText)) {
|
|
152
|
+
await writeFile(cssPath, cssText.replace(marked, `/* svgrid-theme:start */\n${css}\n/* svgrid-theme:end */`))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (dark) {
|
|
156
|
+
const htmlPath = join(destDir, 'src', 'app.html')
|
|
157
|
+
const htmlText = await readFile(htmlPath, 'utf8').catch(() => null)
|
|
158
|
+
if (htmlText && !/data-theme=/.test(htmlText)) {
|
|
159
|
+
await writeFile(htmlPath, htmlText.replace('<html lang="en">', '<html lang="en" data-theme="dark">'))
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
85
164
|
/**
|
|
86
165
|
* Generate the app from a studio.config.json (the visual designer's export):
|
|
87
166
|
* parse it, emit each screen's composed blocks, and replace the seeded example.
|
|
@@ -265,11 +344,16 @@ async function main() {
|
|
|
265
344
|
process.exit(1)
|
|
266
345
|
}
|
|
267
346
|
|
|
347
|
+
// 2b. Theme + light/dark mode. Skipped for --project - a designer export
|
|
348
|
+
// already carries its own theme, applied straight into +layout.svelte.
|
|
349
|
+
const themeChoice = args.project ? null : await promptTheme(args, ask, interactive)
|
|
350
|
+
if (rl) rl.close()
|
|
351
|
+
|
|
268
352
|
// 3. Scaffold.
|
|
269
353
|
await mkdir(destDir, { recursive: true })
|
|
270
354
|
await copyTemplate(TEMPLATE_DIR, destDir)
|
|
271
355
|
await setProjectName(destDir, projectName)
|
|
272
|
-
|
|
356
|
+
await applyTheme(destDir, themeChoice)
|
|
273
357
|
|
|
274
358
|
// 3b. Generate from a designer project (--project) or a schema file (--from).
|
|
275
359
|
let entities = null
|
|
@@ -290,6 +374,9 @@ async function main() {
|
|
|
290
374
|
// 4. Next steps.
|
|
291
375
|
const rel = isAbsolute(target) || target.startsWith('.') ? target : `./${target}`
|
|
292
376
|
stdout.write(`\n${color('green', '✔')} Scaffolded ${color('bold', projectName)} into ${rel}\n`)
|
|
377
|
+
if (themeChoice) {
|
|
378
|
+
stdout.write(` ${color('dim', 'theme')} ${themeChoice.name}${themeChoice.dark ? ' (dark)' : ''}\n`)
|
|
379
|
+
}
|
|
293
380
|
if (entities) {
|
|
294
381
|
stdout.write(` ${color('dim', 'from')} ${source} ${color('dim', '->')} ${entities.join(', ')}\n`)
|
|
295
382
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svgrid/create-studio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Scaffold a runnable SvGrid Studio data app in one command: npm create @svgrid/studio@latest",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"node": ">=18"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@svgrid/enterprise": "^2.0.
|
|
40
|
+
"@svgrid/enterprise": "^2.0.2"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/* App theme + chrome. The grid ships its own styles; these tokens drive the
|
|
2
|
-
* accent + surfaces (light / dark friendly), the nav shell, and the buttons.
|
|
2
|
+
* accent + surfaces (light / dark friendly), the nav shell, and the buttons.
|
|
3
|
+
* The block between the markers is rewritten by create-studio's CLI to match
|
|
4
|
+
* the theme + mode you pick when scaffolding - edit freely afterwards. */
|
|
5
|
+
/* svgrid-theme:start */
|
|
3
6
|
:root {
|
|
4
7
|
--sg-accent: #4f46e5;
|
|
5
8
|
color-scheme: light dark;
|
|
6
9
|
}
|
|
10
|
+
/* svgrid-theme:end */
|
|
7
11
|
|
|
8
12
|
* { box-sizing: border-box; }
|
|
9
13
|
html, body { margin: 0; height: 100%; }
|
|
10
14
|
body {
|
|
11
|
-
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
15
|
+
font-family: var(--sg-font, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
|
|
12
16
|
color: var(--sg-fg, #0f172a);
|
|
13
17
|
background: var(--sg-bg, #ffffff);
|
|
14
18
|
}
|