create-rasti 0.1.0-alpha.3 → 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/README.md +3 -1
- package/extras/rasti-icons/README.md +4 -4
- package/extras/rasti-icons/bin/rasti-icons.js +1 -1
- package/extras/rasti-icons/src/generate.js +44 -16
- package/package.json +3 -3
- package/src/cli.js +16 -15
- package/src/utils/template.js +8 -1
- package/src/versions.js +2 -2
- package/templates/AGENTS.md +1 -1
- package/templates/spa/_gitignore +21 -0
- package/templates/ssr/_gitignore +21 -0
- package/templates/ssr/app.js +1 -1
- package/templates/ssr/src/entry-server.js +6 -4
- package/templates/ssr/src/entry-server.ts +6 -2
package/README.md
CHANGED
|
@@ -14,9 +14,11 @@ npm create rasti my-app # SPA, non-interactive
|
|
|
14
14
|
Create a server-rendered project with routing and Tailwind:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm create rasti my-app --ssr --router --tailwind
|
|
17
|
+
npm create rasti my-app -- --ssr --router --tailwind
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
npm needs the `--` to pass the options on to create-rasti; without it they are dropped silently. `npx create-rasti`, `pnpm create rasti` and `yarn create rasti` take them directly.
|
|
21
|
+
|
|
20
22
|
## Templates
|
|
21
23
|
|
|
22
24
|
- **SPA** *(default)*: Rasti + Vite for client-rendered applications.
|
|
@@ -7,9 +7,9 @@ This tool is used by `create-rasti --icons`, and it can also run directly when a
|
|
|
7
7
|
## With create-rasti
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm create rasti my-app --icons
|
|
11
|
-
npm create rasti my-app --icons pixelarticons
|
|
12
|
-
npm create rasti my-app --icons heroicons-outline,heroicons-solid
|
|
10
|
+
npm create rasti my-app -- --icons
|
|
11
|
+
npm create rasti my-app -- --icons pixelarticons
|
|
12
|
+
npm create rasti my-app -- --icons heroicons-outline,heroicons-solid
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
The default preset is `heroicons-outline`. A single preset writes components to `src/icons/`; multiple presets write each set to `src/icons/<preset>/`.
|
|
@@ -38,7 +38,7 @@ node bin/rasti-icons.js \
|
|
|
38
38
|
--output ./icons
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
`--source` must be a GitHub API directory
|
|
41
|
+
`--source` must be a GitHub contents API URL of the directory (`https://api.github.com/repos/<owner>/<repo>/contents/<path>`), with an optional `?ref=<branch|tag|sha>` (default `HEAD`). The directory is listed with the Git Trees API, so sets past the contents API's 1000-entry limit come complete, and the SVG files are downloaded from `raw.githubusercontent.com`. `--license` is optional. Custom source output defaults to `./icons`.
|
|
42
42
|
|
|
43
43
|
## Generated components
|
|
44
44
|
|
|
@@ -26,7 +26,7 @@ Usage:
|
|
|
26
26
|
|
|
27
27
|
Options:
|
|
28
28
|
--preset <name> Built-in preset (see below)
|
|
29
|
-
--source <url> GitHub API URL
|
|
29
|
+
--source <url> GitHub contents API URL of a directory of SVG files (optional ?ref=)
|
|
30
30
|
--license <url> Raw URL for the license file (optional)
|
|
31
31
|
--output <dir> Output directory (default: ./icons/<preset> or ./icons)
|
|
32
32
|
|
|
@@ -127,10 +127,42 @@ export function buildComponent(name, svgContent) {
|
|
|
127
127
|
].join('\n');
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* List the SVG files of a GitHub directory with the Git Trees API, which returns every
|
|
132
|
+
* entry of the directory (the contents API stops at 1000).
|
|
133
|
+
* @param {string} source - GitHub contents API URL of the directory, e.g.
|
|
134
|
+
* `https://api.github.com/repos/owner/repo/contents/svg`, with an optional `?ref=` (default `HEAD`)
|
|
135
|
+
* @returns {Promise<Array<{ name : string, url : string }>>} File names and raw download URLs
|
|
136
|
+
*/
|
|
137
|
+
export async function listSvgFiles(source) {
|
|
138
|
+
const url = new URL(source);
|
|
139
|
+
const match = url.pathname.match(/^\/repos\/([^/]+)\/([^/]+)\/contents\/(.+?)\/?$/);
|
|
140
|
+
if (url.hostname !== 'api.github.com' || !match) {
|
|
141
|
+
throw new Error(`Source must be a GitHub contents API URL (https://api.github.com/repos/owner/repo/contents/path). Got: ${source}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const [, owner, repo, dir] = match;
|
|
145
|
+
const ref = url.searchParams.get('ref') || 'HEAD';
|
|
146
|
+
|
|
147
|
+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(`${ref}:${dir}`)}`);
|
|
148
|
+
if (!res.ok) throw new Error(`Source fetch failed: ${res.status}`);
|
|
149
|
+
const { tree, truncated } = await res.json();
|
|
150
|
+
|
|
151
|
+
if (!Array.isArray(tree)) throw new Error(`Unexpected response from source URL: no tree for ${dir}`);
|
|
152
|
+
if (truncated) throw new Error(`The listing of ${dir} is truncated by GitHub`);
|
|
153
|
+
|
|
154
|
+
return tree
|
|
155
|
+
.filter(entry => entry.type === 'blob' && entry.path.endsWith('.svg'))
|
|
156
|
+
.map(entry => ({
|
|
157
|
+
name : entry.path,
|
|
158
|
+
url : `https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${dir}/${entry.path}`
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
|
|
130
162
|
/**
|
|
131
163
|
* Generate Rasti icon components from a GitHub-hosted SVG directory.
|
|
132
164
|
* @param {object} options
|
|
133
|
-
* @param {string} options.source - GitHub API URL
|
|
165
|
+
* @param {string} options.source - GitHub contents API URL of the directory (see `listSvgFiles`)
|
|
134
166
|
* @param {string} [options.license] - Raw URL for license file (optional)
|
|
135
167
|
* @param {string} options.output - Absolute path to output directory
|
|
136
168
|
* @returns {Promise<number>} Number of icons generated
|
|
@@ -144,23 +176,19 @@ export async function generateIcons({ source, license, output }) {
|
|
|
144
176
|
fs.writeFileSync(path.join(output, 'LICENSE.txt'), await licRes.text());
|
|
145
177
|
}
|
|
146
178
|
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (!Array.isArray(files)) {
|
|
152
|
-
throw new Error(`Unexpected response from source URL. Got: ${JSON.stringify(files).slice(0, 100)}`);
|
|
153
|
-
}
|
|
179
|
+
const files = await listSvgFiles(source);
|
|
180
|
+
// Names that differ only in case (akar-icons `linkedInV1-fill` / `linkedin-V1-fill`) would share
|
|
181
|
+
// a file on case-insensitive filesystems: the first one listed is kept, on every platform.
|
|
182
|
+
const written = new Set();
|
|
154
183
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
if (!svgRes.ok) throw new Error(`SVG fetch failed for ${item.name}: ${svgRes.status}`);
|
|
184
|
+
for (const file of files) {
|
|
185
|
+
const iconName = toPascalCase(file.name);
|
|
186
|
+
if (written.has(iconName.toLowerCase())) continue;
|
|
187
|
+
const svgRes = await fetch(file.url);
|
|
188
|
+
if (!svgRes.ok) throw new Error(`SVG fetch failed for ${file.name}: ${svgRes.status}`);
|
|
161
189
|
fs.writeFileSync(path.join(output, `${iconName}.js`), buildComponent(iconName, await svgRes.text()));
|
|
162
|
-
|
|
190
|
+
written.add(iconName.toLowerCase());
|
|
163
191
|
}
|
|
164
192
|
|
|
165
|
-
return
|
|
193
|
+
return written.size;
|
|
166
194
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-rasti",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Create Rasti projects with Vite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@clack/prompts": "^1.9.0",
|
|
44
|
-
"cssfun": "^0.4.0
|
|
45
|
-
"rasti": "^5.0.0
|
|
44
|
+
"cssfun": "^0.4.0",
|
|
45
|
+
"rasti": "^5.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@eslint/js": "^10.0.1",
|
package/src/cli.js
CHANGED
|
@@ -59,14 +59,14 @@ function showHelp() {
|
|
|
59
59
|
create-rasti - Create Rasti + Vite projects
|
|
60
60
|
|
|
61
61
|
Usage:
|
|
62
|
-
npm create rasti [project-name] [options]
|
|
62
|
+
npm create rasti [project-name] -- [options]
|
|
63
63
|
|
|
64
64
|
Options:
|
|
65
65
|
--ssr Use SSR template instead of SPA
|
|
66
66
|
--static Use Static template (SSR + pre-rendered static build)
|
|
67
67
|
--tailwind Add Tailwind CSS
|
|
68
68
|
--cssfun Add CSSFUN (CSS-in-JS with light and dark themes)
|
|
69
|
-
--icons [sets] Add rasti-icons (
|
|
69
|
+
--icons [sets] Add rasti-icons (default: ${DEFAULT_PRESET}). Presets: ${presetList}.
|
|
70
70
|
Repeat flag or use comma-separated list. Multiple sets are written under src/icons/<preset>/ each;
|
|
71
71
|
a single set uses src/icons/ directly.
|
|
72
72
|
--router Add micro-router (universal router, two pages and links)
|
|
@@ -74,20 +74,21 @@ Options:
|
|
|
74
74
|
--help Show this help message
|
|
75
75
|
|
|
76
76
|
Examples:
|
|
77
|
-
npm create rasti
|
|
78
|
-
npm create rasti my-app
|
|
79
|
-
npm create rasti my-app --ssr
|
|
80
|
-
npm create rasti my-app --static
|
|
81
|
-
npm create rasti my-app --tailwind
|
|
82
|
-
npm create rasti my-app --icons
|
|
83
|
-
npm create rasti my-app --icons heroicons-outline
|
|
84
|
-
npm create rasti my-app --icons akar-icons
|
|
85
|
-
npm create rasti my-app --icons feathericon
|
|
86
|
-
npm create rasti my-app --icons pixelarticons
|
|
87
|
-
npm create rasti my-app --icons heroicons-solid,heroicons-outline # Multiple sets in subfolders under src/icons
|
|
88
|
-
npm create rasti my-app --router
|
|
89
|
-
npm create rasti my-app --ssr --ts
|
|
77
|
+
npm create rasti # Interactive mode
|
|
78
|
+
npm create rasti my-app # Create SPA project
|
|
79
|
+
npm create rasti my-app -- --ssr # Create SSR project
|
|
80
|
+
npm create rasti my-app -- --static # Create static site (SSR + static build)
|
|
81
|
+
npm create rasti my-app -- --tailwind # Create SPA with Tailwind
|
|
82
|
+
npm create rasti my-app -- --icons # SPA with ${DEFAULT_PRESET} in src/icons
|
|
83
|
+
npm create rasti my-app -- --icons heroicons-outline # SPA with heroicons-outline in src/icons
|
|
84
|
+
npm create rasti my-app -- --icons akar-icons # SPA with akar-icons in src/icons
|
|
85
|
+
npm create rasti my-app -- --icons feathericon # SPA with feathericon in src/icons
|
|
86
|
+
npm create rasti my-app -- --icons pixelarticons # SPA with pixelarticons in src/icons
|
|
87
|
+
npm create rasti my-app -- --icons heroicons-solid,heroicons-outline # Multiple sets in subfolders under src/icons
|
|
88
|
+
npm create rasti my-app -- --router # SPA with two pages and universal router
|
|
89
|
+
npm create rasti my-app -- --ssr --ts # SSR project in TypeScript
|
|
90
90
|
|
|
91
91
|
Note: --tailwind and --cssfun are mutually exclusive.
|
|
92
|
+
npm needs "--" before the options to pass them on; npx create-rasti, pnpm create and yarn create don't.
|
|
92
93
|
`);
|
|
93
94
|
}
|
package/src/utils/template.js
CHANGED
|
@@ -108,6 +108,13 @@ export async function copyTemplateDir(templateName, targetDir, context = {}, opt
|
|
|
108
108
|
await copyDirRecursive(templateDir, targetDir, context, options.typescript ? '.ts' : '.js');
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Template files written under another name. npm leaves `.gitignore` out of published
|
|
113
|
+
* packages, so templates keep it as `_gitignore`.
|
|
114
|
+
* @type {Record<string, string>}
|
|
115
|
+
*/
|
|
116
|
+
const RENAMED_FILES = { '_gitignore' : '.gitignore' };
|
|
117
|
+
|
|
111
118
|
/**
|
|
112
119
|
* Recursively copy a directory, processing placeholders in text files.
|
|
113
120
|
* @param {string} src - Source directory
|
|
@@ -127,7 +134,7 @@ async function copyDirRecursive(src, dest, context, sourceExt) {
|
|
|
127
134
|
if (pair && ext !== sourceExt && names.has(entry.name.slice(0, -ext.length) + pair)) continue;
|
|
128
135
|
|
|
129
136
|
const srcPath = path.join(src, entry.name);
|
|
130
|
-
const destPath = path.join(dest, entry.name);
|
|
137
|
+
const destPath = path.join(dest, RENAMED_FILES[entry.name] ?? entry.name);
|
|
131
138
|
|
|
132
139
|
if (entry.isDirectory()) {
|
|
133
140
|
await copyDirRecursive(srcPath, destPath, context, sourceExt);
|
package/src/versions.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* path-to-regexp are mirrored in package.json files, kept in sync by test/versions.test.js).
|
|
5
5
|
*/
|
|
6
6
|
export const VERSIONS = {
|
|
7
|
-
rasti : '^5.0.0
|
|
7
|
+
rasti : '^5.0.0',
|
|
8
8
|
vite : '^8.3.8',
|
|
9
9
|
express : '^5.3.0',
|
|
10
10
|
compression : '^1.8.2',
|
|
@@ -12,7 +12,7 @@ export const VERSIONS = {
|
|
|
12
12
|
crossEnv : '^10.1.0',
|
|
13
13
|
tailwindcss : '^4.3.5',
|
|
14
14
|
tailwindVite : '^4.3.5',
|
|
15
|
-
cssfun : '^0.4.0
|
|
15
|
+
cssfun : '^0.4.0',
|
|
16
16
|
pathToRegexp : '^9.0.0',
|
|
17
17
|
typescript : '^7.0.2',
|
|
18
18
|
typesNode : '^22.20.5',
|
package/templates/AGENTS.md
CHANGED
|
@@ -38,7 +38,7 @@ Presentational components live in `src/components/` and are written with `Compon
|
|
|
38
38
|
Theming uses `src/theme.js` (light/dark via `data-color-scheme` on `<html>`; CSS variables prefixed `--fun-*`).
|
|
39
39
|
{{#endif}}
|
|
40
40
|
{{#if ROUTER}}
|
|
41
|
-
Routing is handled by `src/router-setup.{{SRC_EXT}}`: `route(url)` creates the model `App` renders and the router that sets its `location`, and the entry files await it before mounting. Rendering is synchronous, so a page kept in a chunk of its own (`lazy(() => import(...))`, like `About`) is loaded by its route action before the model changes.{{#if SSR}} The server loads every page `lazy` created before its first render (`loadPages`), so a new lazy page needs no other change.{{#endif}} Client-side links use the `data-router` attribute.
|
|
41
|
+
Routing is handled by `src/router-setup.{{SRC_EXT}}`: `route(url)` creates the model `App` renders and the router that sets its `location`, and the entry files await it before mounting. Rendering is synchronous, so a page kept in a chunk of its own (`lazy(() => import(...))`, like `About`) is loaded by its route action before the model changes.{{#if SSR}} The server loads every page `lazy` created before its first render (`loadPages`), so a new lazy page needs no other change. A URL no route matches leaves `location` null and gets a 404 response.{{#endif}} Client-side links use the `data-router` attribute.
|
|
42
42
|
{{#endif}}
|
|
43
43
|
{{#if STATIC}}
|
|
44
44
|
Routes to pre-render are listed in `static.config.js`.
|
package/templates/ssr/app.js
CHANGED
|
@@ -59,7 +59,7 @@ app.use('*all', async (req, res) => {
|
|
|
59
59
|
html = html.replace(/<title>[\s\S]*?<\/title>/, '<title>' + rendered.title + '</title>');
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
res.status(200).set({ 'Content-Type' : 'text/html' }).send(html);
|
|
62
|
+
res.status(rendered.status ?? 200).set({ 'Content-Type' : 'text/html' }).send(html);
|
|
63
63
|
} catch (error) {
|
|
64
64
|
const e = /** @type {Error} */ (error);
|
|
65
65
|
vite?.ssrFixStacktrace(e);
|
|
@@ -31,9 +31,9 @@ function serializeOptions(options) {
|
|
|
31
31
|
* Returns the pieces `app.js` injects into the `index.html` template.
|
|
32
32
|
* @param {string} {{#if ROUTER}}url{{#else}}_url{{#endif}} - Request URL
|
|
33
33
|
{{#if ROUTER}}
|
|
34
|
-
* @returns {Promise<{ html: string, head?: string, title?: string, bodyClassName?: string }>}
|
|
34
|
+
* @returns {Promise<{ html: string, head?: string, title?: string, bodyClassName?: string, status?: number }>}
|
|
35
35
|
{{#else}}
|
|
36
|
-
* @returns {{ html: string, head?: string, title?: string, bodyClassName?: string }}
|
|
36
|
+
* @returns {{ html: string, head?: string, title?: string, bodyClassName?: string, status?: number }}
|
|
37
37
|
{{#endif}}
|
|
38
38
|
*/
|
|
39
39
|
export {{#if ROUTER}}async {{#endif}}function render({{#if ROUTER}}url{{#else}}_url{{#endif}}) {
|
|
@@ -45,14 +45,16 @@ export {{#if ROUTER}}async {{#endif}}function render({{#if ROUTER}}url{{#else}}_
|
|
|
45
45
|
Component.resetUid();
|
|
46
46
|
{{#if ROUTER}}
|
|
47
47
|
const html = new App({ model, router }).toString();
|
|
48
|
+
// `location` is null for a URL no route matches.
|
|
49
|
+
const status = model.location ? 200 : 404;
|
|
48
50
|
const options = { url };
|
|
49
51
|
// The client hydrates with the same options.
|
|
50
52
|
const script = `<script>window.__APP_OPTIONS__=${serializeOptions(options)}</script>`;
|
|
51
53
|
{{#if CSSFUN}}
|
|
52
54
|
// <style> tags for every style sheet the app modules registered on import, theme and every page included.
|
|
53
|
-
return { html, head : StyleSheet.toString() + script, title : getTitleForUrl(url), bodyClassName : theme.classes.root };
|
|
55
|
+
return { html, head : StyleSheet.toString() + script, title : getTitleForUrl(url), bodyClassName : theme.classes.root, status };
|
|
54
56
|
{{#else}}
|
|
55
|
-
return { html, head : script, title : getTitleForUrl(url) };
|
|
57
|
+
return { html, head : script, title : getTitleForUrl(url), status };
|
|
56
58
|
{{#endif}}
|
|
57
59
|
{{#else}}
|
|
58
60
|
const html = new App().toString();
|
|
@@ -19,6 +19,8 @@ export interface RenderResult {
|
|
|
19
19
|
head?: string;
|
|
20
20
|
title?: string;
|
|
21
21
|
bodyClassName?: string;
|
|
22
|
+
/** HTTP status of the response, 200 when left out. */
|
|
23
|
+
status?: number;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
{{#if ROUTER}}
|
|
@@ -49,14 +51,16 @@ export {{#if ROUTER}}async {{#endif}}function render({{#if ROUTER}}url{{#else}}_
|
|
|
49
51
|
Component.resetUid();
|
|
50
52
|
{{#if ROUTER}}
|
|
51
53
|
const html = new App({ model, router }).toString();
|
|
54
|
+
// `location` is null for a URL no route matches.
|
|
55
|
+
const status = model.location ? 200 : 404;
|
|
52
56
|
const options = { url };
|
|
53
57
|
// The client hydrates with the same options.
|
|
54
58
|
const script = `<script>window.__APP_OPTIONS__=${serializeOptions(options)}</script>`;
|
|
55
59
|
{{#if CSSFUN}}
|
|
56
60
|
// <style> tags for every style sheet the app modules registered on import, theme and every page included.
|
|
57
|
-
return { html, head : StyleSheet.toString() + script, title : getTitleForUrl(url), bodyClassName : theme.classes.root };
|
|
61
|
+
return { html, head : StyleSheet.toString() + script, title : getTitleForUrl(url), bodyClassName : theme.classes.root, status };
|
|
58
62
|
{{#else}}
|
|
59
|
-
return { html, head : script, title : getTitleForUrl(url) };
|
|
63
|
+
return { html, head : script, title : getTitleForUrl(url), status };
|
|
60
64
|
{{#endif}}
|
|
61
65
|
{{#else}}
|
|
62
66
|
const html = new App().toString();
|