create-rasti 0.0.2 → 0.1.0-alpha.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.
Files changed (56) hide show
  1. package/README.md +21 -2
  2. package/extras/cn/src/index.js +14 -1
  3. package/extras/micro-router/README.md +35 -3
  4. package/extras/micro-router/package.json +1 -1
  5. package/extras/micro-router/src/index.js +124 -44
  6. package/extras/rasti-icons/README.md +15 -5
  7. package/extras/rasti-icons/src/generate.js +95 -49
  8. package/package.json +9 -6
  9. package/src/apply/agents.js +68 -0
  10. package/src/apply/base.js +1 -1
  11. package/src/apply/description.js +2 -0
  12. package/src/apply/featuresInclude.js +3 -2
  13. package/src/apply/index.js +13 -37
  14. package/src/apply/router.js +2 -2
  15. package/src/apply/ssr.js +1 -1
  16. package/src/apply/typescript.js +38 -0
  17. package/src/args.js +3 -0
  18. package/src/cli.js +2 -0
  19. package/src/plan.js +2 -1
  20. package/src/prompts.js +17 -0
  21. package/src/utils/template.js +32 -15
  22. package/src/versions.js +16 -12
  23. package/templates/AGENTS.md +31 -8
  24. package/templates/_base/App-cssfun.js +40 -23
  25. package/templates/_base/App-cssfun.ts +107 -0
  26. package/templates/_base/App-tailwind.js +39 -22
  27. package/templates/_base/App-tailwind.ts +77 -0
  28. package/templates/_base/App.js +39 -22
  29. package/templates/_base/App.ts +77 -0
  30. package/templates/_base/components/Button-cssfun.ts +54 -0
  31. package/templates/_base/components/Button-tailwind.ts +55 -0
  32. package/templates/_base/components/Button.ts +25 -0
  33. package/templates/_base/components/Header-cssfun.ts +71 -0
  34. package/templates/_base/components/Header-tailwind.ts +19 -0
  35. package/templates/_base/components/Header.ts +19 -0
  36. package/templates/_base/components/Home-cssfun.ts +101 -0
  37. package/templates/_base/components/Home-tailwind.ts +38 -0
  38. package/templates/_base/components/Home.ts +38 -0
  39. package/templates/_extras/router/components/About-cssfun.ts +45 -0
  40. package/templates/_extras/router/components/About-tailwind.ts +16 -0
  41. package/templates/_extras/router/components/About.ts +18 -0
  42. package/templates/_extras/router/router-setup.js +21 -21
  43. package/templates/_extras/router/router-setup.ts +52 -0
  44. package/templates/_features/cssfun/index.html +1 -1
  45. package/templates/_features/typescript/tsconfig.json +30 -0
  46. package/templates/spa/index.html +1 -1
  47. package/templates/spa/src/main.js +1 -2
  48. package/templates/spa/src/main.ts +14 -0
  49. package/templates/ssr/app.js +10 -10
  50. package/templates/ssr/index.html +1 -1
  51. package/templates/ssr/package.json +1 -1
  52. package/templates/ssr/src/entry-client.js +2 -1
  53. package/templates/ssr/src/entry-client.ts +28 -0
  54. package/templates/ssr/src/entry-server.js +31 -25
  55. package/templates/ssr/src/entry-server.ts +62 -0
  56. package/templates/static/scripts/build-static.js +11 -1
@@ -0,0 +1,62 @@
1
+ import { Component } from 'rasti';
2
+ import App from './App.ts';
3
+ {{#if ROUTER}}
4
+ import type { AppProps } from './App.ts';
5
+ import { getTitleForUrl } from './router-setup.ts';
6
+ {{#endif}}
7
+ {{#if CSSFUN}}
8
+ import { theme } from './theme.js';
9
+ import { StyleSheet } from 'cssfun';
10
+ {{#endif}}
11
+
12
+ /** The pieces `app.js` injects into the `index.html` template. */
13
+ export interface RenderResult {
14
+ html: string;
15
+ head?: string;
16
+ title?: string;
17
+ bodyClassName?: string;
18
+ }
19
+
20
+ {{#if ROUTER}}
21
+ /**
22
+ * Serializes the render options for an inline `<script>`, as unicode escapes for the
23
+ * characters that could close the tag (`</script>`) or break older JavaScript parsers.
24
+ * @param options - Per-request options.
25
+ * @returns JSON safe to embed into an inline script.
26
+ */
27
+ function serializeOptions(options: AppProps): string {
28
+ return JSON.stringify(options).replace(
29
+ /[<>&\u2028\u2029]/g,
30
+ char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`
31
+ );
32
+ }
33
+
34
+ {{#endif}}
35
+ /**
36
+ * Server-side render function.
37
+ * @param {{#if ROUTER}}url{{#else}}_url{{#endif}} - Request URL
38
+ */
39
+ export function render({{#if ROUTER}}url{{#else}}_url{{#endif}}: string): RenderResult {
40
+ // Hydration matches elements by uid, so every request numbers them from the start.
41
+ Component.resetUid();
42
+ {{#if ROUTER}}
43
+ const options: AppProps = { url };
44
+ const html = new App(options).toString();
45
+ // The client hydrates with the same options.
46
+ const script = `<script>window.__APP_OPTIONS__=${serializeOptions(options)}</script>`;
47
+ {{#if CSSFUN}}
48
+ // <style> tags for every style sheet the app modules registered on import, theme included.
49
+ return { html, head : StyleSheet.toString() + script, title : getTitleForUrl(url), bodyClassName : theme.classes.root };
50
+ {{#else}}
51
+ return { html, head : script, title : getTitleForUrl(url) };
52
+ {{#endif}}
53
+ {{#else}}
54
+ const html = new App().toString();
55
+ {{#if CSSFUN}}
56
+ // <style> tags for every style sheet the app modules registered on import, theme included.
57
+ return { html, head : StyleSheet.toString(), bodyClassName : theme.classes.root };
58
+ {{#else}}
59
+ return { html };
60
+ {{#endif}}
61
+ {{#endif}}
62
+ }
@@ -10,6 +10,11 @@ const port = Number(process.env.PORT) || 37521;
10
10
 
11
11
  process.env.NODE_ENV = 'production';
12
12
 
13
+ /**
14
+ * Polls `baseUrl` until the server answers, for up to 6 seconds.
15
+ * @param {string} baseUrl
16
+ * @returns {Promise<boolean>} Whether the server answered.
17
+ */
13
18
  async function waitForServer(baseUrl) {
14
19
  for (let i = 0; i < 30; i++) {
15
20
  try {
@@ -23,6 +28,11 @@ async function waitForServer(baseUrl) {
23
28
  return false;
24
29
  }
25
30
 
31
+ /**
32
+ * Maps a page URL to its output file (`/about/` -> `about/index.html`).
33
+ * @param {string} fullUrl
34
+ * @returns {string}
35
+ */
26
36
  function urlToFilePath(fullUrl) {
27
37
  const pathname = fullUrl.replace(/\?.*$/, '').replace(/^https?:\/\/[^/]+/, '') || '/';
28
38
  const clean = pathname.replace(/^\//, '').replace(/\/$/, '') || 'index';
@@ -132,7 +142,7 @@ async function main() {
132
142
  resolved = entries.map((item) => resolveConfigEntry(item, baseUrl));
133
143
  } catch (err) {
134
144
  server.close();
135
- console.error(err.message || err);
145
+ console.error(err instanceof Error ? err.message : err);
136
146
  process.exit(1);
137
147
  }
138
148