create-rasti 0.1.0-alpha.2 → 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 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.
@@ -46,7 +48,7 @@ Without either flag, the generated project uses plain CSS.
46
48
 
47
49
  ### `--router`
48
50
 
49
- Adds a small universal router built on [path-to-regexp](https://github.com/pillarjs/path-to-regexp). It is copied into the generated project as `src/lib/router.js`, then wired through `src/router-setup.js`, example pages, and an App shell with navigation.
51
+ Adds a small universal router built on [path-to-regexp](https://github.com/pillarjs/path-to-regexp). It is copied into the generated project as `src/lib/router.js`, then wired through `src/router-setup.js`, example pages, and an App shell with navigation. The project routes before mounting `App`, so a route can load its page as a chunk of its own: the example `About` page is code-split, and the hydrating client waits for it before rendering. The server loads every code-split page before its first render, so each response renders the same way whatever pages earlier requests loaded (with CSSFUN, every page embeds the style sheets of all of them).
50
52
 
51
53
  The router is intentionally narrow: route matching, URL creation, browser history, and delegated `a[data-router]` links. It works with SPA, SSR, and Static templates.
52
54
 
@@ -46,14 +46,14 @@ In the browser, links opt in to client-side navigation with `data-router`:
46
46
 
47
47
  | Method | Description |
48
48
  |---|---|
49
- | `navigate(url, options?)` | Matches `url`, updates browser history when available, invokes the matched route's `action(location)`, and returns the action result. Async actions return a Promise. Options: `{ addToHistory = true, replaceHistory = false, resetScroll = true }`. A navigation that adds or replaces a history entry scrolls to the top; pass `resetScroll : false` to keep the position, e.g. for a tab switch that only updates the query. |
49
+ | `navigate(url, options?)` | Matches `url`, updates browser history when available, invokes the matched route's `action(location, { signal })`, and returns the action result. Async actions return a Promise. Options: `{ addToHistory = true, replaceHistory = false, resetScroll = true }`. A navigation that adds or replaces a history entry scrolls once the action is done: to the element the URL hash names, or to the top. Pass `resetScroll : false` to keep the position, e.g. for a tab switch that only updates the query. |
50
50
  | `createUrl(path, params?, query?)` | Builds a URL from a route path, route params, and query params. |
51
- | `delegateNavigation(rootElement)` | Intercepts left-clicks on descendant `a[data-router]` links and routes them through `navigate`. Returns a cleanup function. |
52
- | `bindHistory()` | Listens for `popstate` and navigates to the current URL without pushing a new history entry or scrolling, so the browser restores the position. A `popstate` that keeps the path and query — a jump to an in-page anchor — is ignored. Returns a cleanup function. |
51
+ | `delegateNavigation(rootElement)` | Intercepts left-clicks on descendant `a[data-router]` links and routes them through `navigate`, hash included. If the action rejects, the link is followed with a full page load. Returns a cleanup function. |
52
+ | `bindHistory()` | Listens for `popstate` and navigates to the current URL without pushing a new history entry or scrolling, so the browser restores the position. A `popstate` that keeps the path and query — a jump to an in-page anchor — is ignored. If the action rejects, the page is reloaded. Returns a cleanup function. |
53
53
 
54
54
  **Options:** `{ baseUrl?: string }` — prepended to generated URLs and stripped before matching. It is only stripped as a prefix, on a path segment boundary: with `baseUrl: '/app'`, `/app/about` matches `/about` while `/application/x` and `/en/app-store/x` are left alone.
55
55
 
56
- **Route:** `{ path: string, action: (location) => any }`.
56
+ **Route:** `{ path: string, action: (location, context) => any }`. `context` is `{ signal: AbortSignal }`.
57
57
 
58
58
  **Location:** `{ path, params, query, test(url): boolean }` — `params` and `query` are plain objects; `test(url)` reports whether a URL matches the same route. Wildcard params (`/files/*rest`) are arrays of path segments, matching what `path-to-regexp` produces and what `createUrl` expects back.
59
59
 
@@ -87,9 +87,31 @@ Note that a param matches any single segment: `/user/:id` matches `/user/abc` as
87
87
 
88
88
  Without `replaceHistory`, the redirect leaves `/admin` in the back stack and the back button lands on a route that redirects again.
89
89
 
90
+ ## Async actions
91
+
92
+ An action may return a Promise, e.g. to import the module of a page before rendering it. `navigate` returns that Promise, and the scroll waits for it, so a hash target rendered by the page is there to scroll to.
93
+
94
+ A slow action can finish after the reader has moved on. Each action receives a `signal`, aborted as soon as a newer navigation starts — a click, a `popstate`, or a redirect from the action itself. Check it before rendering, so a late page does not replace the current one:
95
+
96
+ ```javascript
97
+ {
98
+ path : '/reports',
99
+ action : async (location, { signal }) => {
100
+ // The page is a chunk of its own, loaded on first visit.
101
+ const { default : Reports } = await import('./Reports.js');
102
+ if (signal.aborted) return;
103
+ model.page = Reports;
104
+ }
105
+ }
106
+ ```
107
+
108
+ The signal can also be handed to the requests the action makes, e.g. `fetch(url, { signal })`, to cancel them.
109
+
110
+ A rejected action rejects the Promise `navigate` returns, unless a newer navigation replaced it: then it resolves to `undefined`. Navigations the router starts on its own recover with a full page load instead: a link click loads its URL, and a `popstate` reloads the page. That covers a chunk that no longer exists after a new deploy.
111
+
90
112
  ## Links
91
113
 
92
- `delegateNavigation` only takes over a link it can own. It leaves the browser's default handling in place — no `preventDefault` — for cross-origin hrefs, `target` other than `_self`, `download`, and `rel="external"`. Modified and non-left clicks are ignored as usual.
114
+ `delegateNavigation` only takes over a link it can own. It leaves the browser's default handling in place — no `preventDefault` — for cross-origin hrefs, `target` other than `_self`, `download`, and `rel="external"`. Modified and non-left clicks are ignored as usual. A link to an anchor on the current page (same path and query, with a hash) is also left to the browser, which jumps to it without routing the page again.
93
115
 
94
116
  ## Copy model
95
117
 
@@ -13,17 +13,22 @@ import { match, compile } from 'path-to-regexp';
13
13
  * @property {(url: string) => boolean} test - A function to test if a given URL matches this route. Returns `true` if the URL matches the route, `false` otherwise.
14
14
  */
15
15
 
16
+ /**
17
+ * @typedef {Object} ActionContext
18
+ * @property {AbortSignal} signal - Aborted when a newer navigation starts, so an async action can skip rendering a page that is no longer current.
19
+ */
20
+
16
21
  /**
17
22
  * @typedef {Object} Route
18
23
  * @property {string} path - The route path pattern (e.g., `/user/:id`).
19
- * @property {(location: Location) => *} action - The action function to call when the route matches. Receives a `Location` object as parameter.
24
+ * @property {(location: Location, context: ActionContext) => *} action - The action function to call when the route matches. Receives a `Location` object and an `ActionContext`. It may return a Promise, e.g. to load the page before rendering it.
20
25
  */
21
26
 
22
27
  /**
23
28
  * @typedef {Object} NavigateOptions
24
29
  * @property {boolean} [addToHistory=true] - Whether to add the navigation to the browser's history.
25
30
  * @property {boolean} [replaceHistory=false] - Whether to replace the current history entry instead of adding a new one.
26
- * @property {boolean} [resetScroll=true] - Whether to scroll to the top when the navigation adds or replaces a history entry. A `popstate` never scrolls: the browser restores the position.
31
+ * @property {boolean} [resetScroll=true] - Whether to scroll when the navigation adds or replaces a history entry: to the element the URL hash names, or to the top. It happens once the action is done. A `popstate` never scrolls: the browser restores the position.
27
32
  */
28
33
 
29
34
  /**
@@ -54,6 +59,12 @@ export default function createRouter(routes, routerOptions = {}) {
54
59
  */
55
60
  const matchers = new Map();
56
61
 
62
+ /**
63
+ * Controller of the navigation in progress, aborted when a newer one starts.
64
+ * @type {AbortController|null}
65
+ */
66
+ let controller = null;
67
+
57
68
  /**
58
69
  * Path and query of the last URL routed, to tell a new page from an in-page anchor jump.
59
70
  * @type {string|null}
@@ -117,7 +128,7 @@ export default function createRouter(routes, routerOptions = {}) {
117
128
  /**
118
129
  * Matches a given url against the routes.
119
130
  * @param {string} url - The url to match.
120
- * @returns {(() => *)|null} - A function that calls the matched route's action with a `Location` object, or `null` if no match is found.
131
+ * @returns {({ route: Route, location: Location })|null} - The matched route and its `Location`, or `null` if no match is found.
121
132
  * @private
122
133
  */
123
134
  const matchRoute = (url) => {
@@ -135,7 +146,7 @@ export default function createRouter(routes, routerOptions = {}) {
135
146
  test : (url) => !!getMatch(getUrlParts(url).pathname, route.path)
136
147
  };
137
148
 
138
- return () => route.action(location);
149
+ return { route, location };
139
150
  }
140
151
  }
141
152
 
@@ -143,37 +154,96 @@ export default function createRouter(routes, routerOptions = {}) {
143
154
  };
144
155
 
145
156
  /**
146
- * Navigates to a given path, matches a route, and calls its action with a `Location` object.
147
- *
148
- * History is updated before the action runs, so an action that redirects can
149
- * replace the entry it was reached through: `navigate('/login', { replaceHistory : true })`.
150
- * The page scrolls to the top along with the history update, unless `resetScroll` is `false`.
151
- *
157
+ * Scrolls to the element the url hash names, or to the top of the page.
158
+ * @param {string} url - The url navigated to.
159
+ * @private
160
+ */
161
+ const scrollToUrl = (url) => {
162
+ const hash = url.split('#')[1];
163
+ let id = hash;
164
+ if (hash) {
165
+ try {
166
+ id = decodeURIComponent(hash);
167
+ } catch {
168
+ // A malformed escape names the element as written.
169
+ }
170
+ }
171
+ const target = id ? document.getElementById(id) : null;
172
+ if (target) target.scrollIntoView({ behavior : 'instant' });
173
+ else window.scrollTo({ top : 0, behavior : 'instant' });
174
+ };
175
+
176
+ /**
177
+ * Navigates to a url, calling `onError` if an async action rejects.
152
178
  * @param {string} url - The path to navigate to, including query string.
153
- * @param {NavigateOptions} [options={}] - Options for navigation.
154
- * @returns {*} The matched route action result, or `undefined` if no route matches. Async actions return a Promise.
179
+ * @param {NavigateOptions} options - Options for navigation.
180
+ * @param {(error: *) => *} [onError] - Handles a rejected action. Without it, the returned promise rejects.
181
+ * @returns {*} The matched route action result, or `undefined` if no route matches.
182
+ * @private
155
183
  */
156
- const navigate = (url, options = {}) => {
184
+ const go = (url, options, onError) => {
157
185
  const { addToHistory = true, replaceHistory = false, resetScroll = true } = options;
158
186
  // Match the route and query
159
187
  const matched = matchRoute(url);
160
188
 
161
- if (matched) {
162
- currentUrl = url.split('#')[0];
163
- // Handle browser history
164
- if (addToHistory && typeof window !== 'undefined') {
165
- window.history[replaceHistory ? 'replaceState' : 'pushState']({}, '', url);
166
- if (resetScroll) window.scrollTo({ top : 0, behavior : 'instant' });
167
- }
168
- // Call the route's action
169
- return matched();
170
- } else {
189
+ if (!matched) {
171
190
  console.error('No route matched:', url);
191
+ return undefined;
172
192
  }
173
193
 
174
- return undefined;
194
+ // A newer navigation supersedes the one in progress
195
+ controller?.abort();
196
+ const navigation = controller = new AbortController();
197
+ const { signal } = navigation;
198
+
199
+ currentUrl = url.split('#')[0];
200
+ // Handle browser history
201
+ if (addToHistory && typeof window !== 'undefined') {
202
+ window.history[replaceHistory ? 'replaceState' : 'pushState']({}, '', url);
203
+ }
204
+
205
+ // Scroll once the page is rendered, unless a newer navigation took over (e.g. a redirect)
206
+ const scroll = () => {
207
+ if (addToHistory && resetScroll && !signal.aborted && typeof window !== 'undefined') scrollToUrl(url);
208
+ };
209
+
210
+ // Call the route's action
211
+ const result = matched.route.action(matched.location, { signal });
212
+
213
+ if (!result || typeof result.then !== 'function') {
214
+ scroll();
215
+ return result;
216
+ }
217
+
218
+ return Promise.resolve(result).then(
219
+ (value) => {
220
+ scroll();
221
+ return value;
222
+ },
223
+ (error) => {
224
+ if (signal.aborted) return undefined;
225
+ if (onError) return onError(error);
226
+ throw error;
227
+ }
228
+ );
175
229
  };
176
230
 
231
+ /**
232
+ * Navigates to a given path, matches a route, and calls its action with a `Location` object.
233
+ *
234
+ * History is updated before the action runs, so an action that redirects can
235
+ * replace the entry it was reached through: `navigate('/login', { replaceHistory : true })`.
236
+ *
237
+ * The action receives a `signal` that is aborted when a newer navigation starts. When
238
+ * the action returns a Promise, `navigate` returns it, and the scroll waits for it. A
239
+ * superseded navigation that rejects resolves to `undefined` instead.
240
+ *
241
+ * @param {string} url - The path to navigate to, including query string.
242
+ * @param {NavigateOptions} [options={}] - Options for navigation.
243
+ * @returns {*} The matched route action result, or `undefined` if no route matches. Async actions return a Promise.
244
+ */
245
+ const navigate = (url, options = {}) => go(url, options);
246
+
177
247
  /**
178
248
  * Creates a URL from a route path, parameters, and query string.
179
249
  * @param {string} path - The route path (e.g., `/user/:id`).
@@ -192,7 +262,8 @@ export default function createRouter(routes, routerOptions = {}) {
192
262
  /**
193
263
  * Delegates navigation events for links with `data-router` attributes.
194
264
  * Links the router cannot own (cross-origin, `target`, `download`, `rel="external"`)
195
- * are left to the browser's default handling.
265
+ * are left to the browser's default handling, and so is an anchor on the current
266
+ * page. If the action rejects, the link is followed with a full page load.
196
267
  * @param {HTMLElement} rootElement - The root element to listen for click events.
197
268
  * @returns {() => void} - A function to undelegate the event listener.
198
269
  */
@@ -234,8 +305,12 @@ export default function createRouter(routes, routerOptions = {}) {
234
305
 
235
306
  if (url.origin !== window.location.origin) return;
236
307
 
308
+ const path = url.pathname + url.search;
309
+ // An anchor on the current page is a jump the browser already does.
310
+ if (url.hash && path === currentUrl) return;
311
+
237
312
  event.preventDefault();
238
- navigate(url.pathname + url.search);
313
+ go(path + url.hash, {}, () => window.location.replace(url.href));
239
314
  };
240
315
  // Bind the click event to the root element.
241
316
  rootElement.addEventListener('click', handleClick);
@@ -248,7 +323,7 @@ export default function createRouter(routes, routerOptions = {}) {
248
323
  /**
249
324
  * Binds browser history changes to the navigation logic.
250
325
  * A `popstate` that keeps the routed path and query, such as a jump to an in-page
251
- * anchor, is ignored. No-op outside the browser.
326
+ * anchor, is ignored. If the action rejects, the page is reloaded. No-op outside the browser.
252
327
  * @returns {() => void} - A function to unbind the `popstate` event listener.
253
328
  */
254
329
  const bindHistory = () => {
@@ -259,7 +334,7 @@ export default function createRouter(routes, routerOptions = {}) {
259
334
  // Routing the same URL again would re-render the page under the reader.
260
335
  if (url === currentUrl) return;
261
336
  // On popstate, navigate to the current URL
262
- navigate(url, { addToHistory : false });
337
+ go(url, { addToHistory : false }, () => window.location.reload());
263
338
  };
264
339
 
265
340
  window.addEventListener('popstate', handlePopState);
@@ -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 listing URL that returns a JSON array of file objects with `download_url`. `--license` is optional. Custom source output defaults to `./icons`.
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 for a directory listing of SVG files
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 for directory listing
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 listRes = await fetch(source);
148
- if (!listRes.ok) throw new Error(`Source fetch failed: ${listRes.status}`);
149
- const files = await listRes.json();
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
- let count = 0;
156
- for (const item of files) {
157
- if (item.type !== 'file' || !item.name.endsWith('.svg')) continue;
158
- const iconName = toPascalCase(item.name);
159
- const svgRes = await fetch(item.download_url);
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
- count++;
190
+ written.add(iconName.toLowerCase());
163
191
  }
164
192
 
165
- return count;
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-alpha.2",
3
+ "version": "0.1.0",
4
4
  "description": "Create Rasti projects with Vite",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,16 +40,16 @@
40
40
  "author": "Alberto Masuelli <alberto.masuelli@gmail.com> (https://github.com/8tentaculos)",
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "@clack/prompts": "^1.8.1",
44
- "cssfun": "^0.4.0-alpha.0",
45
- "rasti": "^5.0.0-alpha.4"
43
+ "@clack/prompts": "^1.9.0",
44
+ "cssfun": "^0.4.0",
45
+ "rasti": "^5.0.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@eslint/js": "^10.0.1",
49
- "eslint": "^10.13.0",
50
- "globals": "^17.13.0",
49
+ "eslint": "^10.15.0",
50
+ "globals": "^17.14.0",
51
51
  "path-to-regexp": "^9.0.0",
52
- "vitest": "^5.0.5"
52
+ "vitest": "^5.1.1"
53
53
  },
54
54
  "engines": {
55
55
  "node": ">=22"
@@ -17,7 +17,8 @@ function getRouterContext(plan) {
17
17
  ROUTE_ABOUT : routeAbout,
18
18
  CSSFUN : plan.features.cssfun ? 'true' : '',
19
19
  TAILWIND : plan.features.tailwind ? 'true' : '',
20
- ROUTER : 'true'
20
+ ROUTER : 'true',
21
+ SSR : plan.base === 'ssr' || plan.base === 'static' ? 'true' : ''
21
22
  };
22
23
  }
23
24
 
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 (preset ids: ${DEFAULT_PRESET} (default), ${presetList}).
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 # 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
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
  }
@@ -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,15 +4,15 @@
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-alpha.4',
8
- vite : '^8.3.5',
7
+ rasti : '^5.0.0',
8
+ vite : '^8.3.8',
9
9
  express : '^5.3.0',
10
10
  compression : '^1.8.2',
11
11
  sirv : '^3.0.2',
12
12
  crossEnv : '^10.1.0',
13
- tailwindcss : '^4.3.3',
14
- tailwindVite : '^4.3.3',
15
- cssfun : '^0.4.0-alpha.0',
13
+ tailwindcss : '^4.3.5',
14
+ tailwindVite : '^4.3.5',
15
+ cssfun : '^0.4.0',
16
16
  pathToRegexp : '^9.0.0',
17
17
  typescript : '^7.0.2',
18
18
  typesNode : '^22.20.5',
@@ -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.js` — routes update `state.location`; 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`.
@@ -58,6 +58,11 @@ Icon components generated from SVG live in `src/icons/`.
58
58
  - Spaces around colons in objects: `{ key : value }`
59
59
  - Component files are PascalCase; utilities are camelCase
60
60
  - Name callback props `handle*` (`handleIncrement`), never `on*`: those names belong to DOM events and lifecycle hooks
61
+ {{#if CSSFUN}}
62
+ {{#if ROUTER}}
63
+ - `@global` rules and the theme go in modules the entry imports (`App`, `theme.js`), never in a lazy page: once it loads, its global rules apply to every page
64
+ {{#endif}}
65
+ {{#endif}}
61
66
 
62
67
  ## Agent skills
63
68