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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rasti",
3
- "version": "0.0.2",
3
+ "version": "0.1.0-alpha.0",
4
4
  "description": "Create Rasti projects with Vite",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,13 +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": "^0.9.1"
43
+ "@clack/prompts": "^1.8.1",
44
+ "cssfun": "^0.4.0-alpha.0",
45
+ "rasti": "^5.0.0-alpha.0"
44
46
  },
45
47
  "devDependencies": {
46
- "@eslint/js": "^9.34.0",
47
- "eslint": "^9.34.0",
48
- "globals": "^16.3.0",
49
- "vitest": "^3.0.0"
48
+ "@eslint/js": "^10.0.1",
49
+ "eslint": "^10.13.0",
50
+ "globals": "^17.13.0",
51
+ "path-to-regexp": "^9.0.0",
52
+ "vitest": "^5.0.5"
50
53
  },
51
54
  "engines": {
52
55
  "node": ">=22"
@@ -0,0 +1,68 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
4
+ import { copyTemplateFile } from '../utils/template.js';
5
+ import { getBaseContext } from './description.js';
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ /**
10
+ * Get the Agent Skills to install for a plan.
11
+ * Each one ships in its npm package under `skills/<name>/`.
12
+ * @param {object} plan - Project plan
13
+ * @returns {string[]} Package names whose skill is installed
14
+ */
15
+ export function getSkills(plan) {
16
+ const skills = ['rasti'];
17
+ if (plan.features.cssfun) skills.push('cssfun');
18
+ return skills;
19
+ }
20
+
21
+ /**
22
+ * Copy a package's Agent Skill into `.agents/skills/<name>/` and link it from
23
+ * `.claude/skills/<name>`. The skill is read from this CLI's own dependency,
24
+ * kept on the same version range as the one written to the generated project.
25
+ * @param {string} name - Package (and skill) name
26
+ * @param {string} targetDir - Project root directory
27
+ */
28
+ async function installSkill(name, targetDir) {
29
+ const pkgDir = path.dirname(require.resolve(`${name}/package.json`));
30
+ const dest = path.join(targetDir, '.agents', 'skills', name);
31
+ await fs.cp(path.join(pkgDir, 'skills', name), dest, { recursive : true });
32
+
33
+ const link = path.join(targetDir, '.claude', 'skills', name);
34
+ await fs.mkdir(path.dirname(link), { recursive : true });
35
+
36
+ try {
37
+ // Relative, so the link survives moving or cloning the project.
38
+ await fs.symlink(path.relative(path.dirname(link), dest), link, 'dir');
39
+ } catch (error) {
40
+ // Windows without symlink privileges: fall back to a second copy.
41
+ if (error.code !== 'EPERM') throw error;
42
+ await fs.cp(dest, link, { recursive : true });
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Write the project's AGENTS.md and install the Agent Skills of its libraries.
48
+ * @param {object} ctx - Context with plan, targetDir
49
+ */
50
+ export async function applyAgents(ctx) {
51
+ const { plan, targetDir } = ctx;
52
+ const skills = getSkills(plan);
53
+
54
+ const context = {
55
+ ...getBaseContext(plan),
56
+ SSR : (plan.base === 'ssr' || plan.base === 'static') ? 'true' : '',
57
+ STATIC : plan.base === 'static' ? 'true' : '',
58
+ TAILWIND : plan.features.tailwind ? 'true' : '',
59
+ CSSFUN : plan.features.cssfun ? 'true' : '',
60
+ ROUTER : plan.features.router ? 'true' : '',
61
+ ICONS : plan.features.icons ? 'true' : ''
62
+ };
63
+ await copyTemplateFile('AGENTS.md', path.join(targetDir, 'AGENTS.md'), context);
64
+
65
+ for (const name of skills) {
66
+ await installSkill(name, targetDir);
67
+ }
68
+ }
package/src/apply/base.js CHANGED
@@ -18,7 +18,7 @@ export async function applyBase(ctx) {
18
18
  ROUTE_ABOUT : routeAbout
19
19
  };
20
20
 
21
- await copyTemplateDir('spa', targetDir, context);
21
+ await copyTemplateDir('spa', targetDir, context, { typescript : plan.features.typescript });
22
22
  await copyStyledTemplate('_base/App.js', path.join(targetDir, 'src', 'App.js'), context, plan);
23
23
  await copyStyledTemplate('_base/components/Button.js', path.join(targetDir, 'src', 'components', 'Button.js'), context, plan);
24
24
  await copyStyledTemplate('_base/components/Home.js', path.join(targetDir, 'src', 'components', 'Home.js'), context, plan);
@@ -15,6 +15,8 @@ const FAVICON_SRC = CDN_BASE + '/favicon.svg';
15
15
  export function getBaseContext(plan) {
16
16
  return {
17
17
  NAME : plan.name,
18
+ TS : plan.features.typescript ? 'true' : '',
19
+ SRC_EXT : plan.features.typescript ? 'ts' : 'js',
18
20
  DESCRIPTION : getDescription(plan),
19
21
  LOGO_SRC,
20
22
  LOGO_LIGHT_SRC,
@@ -58,8 +58,9 @@ export async function applyFeaturesInclude(ctx) {
58
58
  const { plan, targetDir } = ctx;
59
59
  const html = buildFeaturesHtml(plan);
60
60
 
61
- const homePath = path.join(targetDir, 'src', 'components', 'Home.js');
62
- await replaceInFile(homePath, html);
61
+ for (const ext of ['js', 'ts']) {
62
+ await replaceInFile(path.join(targetDir, 'src', 'components', `Home.${ext}`), html);
63
+ }
63
64
 
64
65
  const pagesDir = path.join(targetDir, 'src', 'pages');
65
66
  try {
@@ -1,30 +1,16 @@
1
1
  import path from 'node:path';
2
- import fs from 'node:fs/promises';
3
2
  import { applyBase } from './base.js';
4
3
  import { applySsr } from './ssr.js';
5
4
  import { applyStatic } from './static.js';
5
+ import { applyTypescript } from './typescript.js';
6
6
  import { applyTailwind } from './tailwind.js';
7
7
  import { applyCssfun } from './cssfun.js';
8
8
  import { applyIcons } from './icons.js';
9
9
  import { applyRouter } from './router.js';
10
10
  import { applyFeaturesInclude } from './featuresInclude.js';
11
- import { getBaseContext } from './description.js';
12
- import { copyTemplateFile } from '../utils/template.js';
11
+ import { applyAgents } from './agents.js';
13
12
  import { createSpinner, log } from '../utils/logger.js';
14
13
 
15
- const RASTI_AGENTS_MD_URL = 'https://raw.githubusercontent.com/8tentaculos/rasti/master/docs/AGENTS.md';
16
-
17
- /**
18
- * Fetch Rasti AGENTS.md and write to project root as AGENTS-RASTI.md.
19
- * @param {string} targetDir - Project root directory
20
- */
21
- async function fetchRastiAgentsMd(targetDir) {
22
- const res = await fetch(RASTI_AGENTS_MD_URL);
23
- if (!res.ok) throw new Error(`Failed to fetch AGENTS-RASTI.md: ${res.status}`);
24
- const text = await res.text();
25
- await fs.writeFile(path.join(targetDir, 'AGENTS-RASTI.md'), text, 'utf-8');
26
- }
27
-
28
14
  /**
29
15
  * Apply a project plan by copying templates and applying features.
30
16
  * @param {object} plan - Project plan object
@@ -53,6 +39,12 @@ export async function applyPlan(plan) {
53
39
 
54
40
  spinner.stop('Project created');
55
41
 
42
+ if (plan.features.typescript) {
43
+ spinner.start('Adding TypeScript...');
44
+ await applyTypescript(ctx);
45
+ spinner.stop('TypeScript added');
46
+ }
47
+
56
48
  if (plan.features.tailwind) {
57
49
  spinner.start('Adding Tailwind CSS...');
58
50
  await applyTailwind(ctx);
@@ -82,31 +74,14 @@ export async function applyPlan(plan) {
82
74
  await applyFeaturesInclude(ctx);
83
75
  spinner.stop('Features list written');
84
76
 
85
- spinner.start('Writing AGENTS.md...');
86
- const agentsContext = {
87
- ...getBaseContext(plan),
88
- SSR : (plan.base === 'ssr' || plan.base === 'static') ? 'true' : '',
89
- STATIC : plan.base === 'static' ? 'true' : '',
90
- TAILWIND : plan.features.tailwind ? 'true' : '',
91
- CSSFUN : plan.features.cssfun ? 'true' : '',
92
- ROUTER : plan.features.router ? 'true' : '',
93
- ICONS : plan.features.icons ? 'true' : '',
94
- };
95
- await copyTemplateFile('AGENTS.md', path.join(ctx.targetDir, 'AGENTS.md'), agentsContext);
96
- spinner.stop('AGENTS.md written');
97
-
98
- spinner.start('Adding Rasti AGENTS.md...');
99
- try {
100
- await fetchRastiAgentsMd(ctx.targetDir);
101
- spinner.stop('Rasti AGENTS.md added');
102
- } catch {
103
- spinner.stop('Could not fetch Rasti AGENTS.md (offline?) — skipped');
104
- }
77
+ spinner.start('Writing AGENTS.md and agent skills...');
78
+ await applyAgents(ctx);
79
+ spinner.stop('AGENTS.md and agent skills written');
105
80
 
106
81
  logSummary(plan);
107
82
 
108
83
  } catch (error) {
109
- spinner.stop('Failed');
84
+ spinner.error('Failed');
110
85
  throw error;
111
86
  }
112
87
  }
@@ -118,6 +93,7 @@ export async function applyPlan(plan) {
118
93
  function logSummary(plan) {
119
94
  const features = [];
120
95
 
96
+ if (plan.features.typescript) features.push('TypeScript');
121
97
  if (plan.features.tailwind) features.push('Tailwind CSS');
122
98
  if (plan.features.cssfun) features.push('CSSFUN');
123
99
  if (plan.features.icons) {
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs/promises';
3
- import { copyTemplateFile, copyStyledTemplate, copyExtraFile } from '../utils/template.js';
3
+ import { copyStyledTemplate, copyExtraFile } from '../utils/template.js';
4
4
  import { addDependencies } from '../utils/pkg.js';
5
5
  import { getBaseContext } from './description.js';
6
6
  import { VERSIONS } from '../versions.js';
@@ -29,7 +29,7 @@ export async function applyRouter(ctx) {
29
29
 
30
30
  await copyExtraFile('micro-router/src/index.js', path.join(targetDir, 'src', 'lib', 'router.js'));
31
31
 
32
- await copyTemplateFile('_extras/router/router-setup.js', path.join(targetDir, 'src', 'router-setup.js'), context);
32
+ await copyStyledTemplate('_extras/router/router-setup.js', path.join(targetDir, 'src', 'router-setup.js'), context, plan);
33
33
 
34
34
  const componentsDir = path.join(targetDir, 'src', 'components');
35
35
  await fs.mkdir(componentsDir, { recursive : true });
package/src/apply/ssr.js CHANGED
@@ -18,7 +18,7 @@ export async function applySsr(ctx) {
18
18
  ROUTE_ABOUT : routeAbout
19
19
  };
20
20
 
21
- await copyTemplateDir('ssr', targetDir, context);
21
+ await copyTemplateDir('ssr', targetDir, context, { typescript : plan.features.typescript });
22
22
  await copyStyledTemplate('_base/App.js', path.join(targetDir, 'src', 'App.js'), context, plan);
23
23
  await copyStyledTemplate('_base/components/Button.js', path.join(targetDir, 'src', 'components', 'Button.js'), context, plan);
24
24
  await copyStyledTemplate('_base/components/Home.js', path.join(targetDir, 'src', 'components', 'Home.js'), context, plan);
@@ -0,0 +1,38 @@
1
+ import path from 'node:path';
2
+ import { copyTemplateFile } from '../utils/template.js';
3
+ import { addDependencies, readPackageJson, mergeScripts } from '../utils/pkg.js';
4
+ import { VERSIONS } from '../versions.js';
5
+
6
+ /**
7
+ * Apply TypeScript tooling: `tsconfig.json`, the compiler and the type packages, and a
8
+ * type check before every build. The `.ts` sources themselves are picked by the base
9
+ * appliers through `copyStyledTemplate` and `copyTemplateDir`.
10
+ * @param {object} ctx - Context object with plan and targetDir
11
+ */
12
+ export async function applyTypescript(ctx) {
13
+ const { plan, targetDir } = ctx;
14
+ const isSsr = plan.base === 'ssr' || plan.base === 'static';
15
+
16
+ await addDependencies(targetDir, {
17
+ devDependencies : {
18
+ 'typescript' : VERSIONS.typescript,
19
+ ...(isSsr && {
20
+ '@types/compression' : VERSIONS.typesCompression,
21
+ '@types/express' : VERSIONS.typesExpress,
22
+ '@types/node' : VERSIONS.typesNode
23
+ })
24
+ }
25
+ });
26
+
27
+ await copyTemplateFile('_features/typescript/tsconfig.json', path.join(targetDir, 'tsconfig.json'), {
28
+ SSR : isSsr ? 'true' : '',
29
+ STATIC : plan.base === 'static' ? 'true' : ''
30
+ });
31
+
32
+ // Vite only strips types, so the build runs the type check first.
33
+ const { scripts } = await readPackageJson(targetDir);
34
+ await mergeScripts(targetDir, {
35
+ 'typecheck' : 'tsc',
36
+ 'build' : `tsc && ${scripts.build}`
37
+ });
38
+ }
package/src/args.js CHANGED
@@ -15,6 +15,7 @@ export function parseArgs(argv) {
15
15
  cssfun : false,
16
16
  icons : null,
17
17
  router : false,
18
+ typescript : false,
18
19
  help : false
19
20
  };
20
21
 
@@ -43,6 +44,8 @@ export function parseArgs(argv) {
43
44
  }
44
45
  } else if (arg === '--router') {
45
46
  args.router = true;
47
+ } else if (arg === '--ts' || arg === '--typescript') {
48
+ args.typescript = true;
46
49
  } else if (!arg.startsWith('-')) {
47
50
  // Positional argument - project name
48
51
  if (!args.name) {
package/src/cli.js CHANGED
@@ -70,6 +70,7 @@ Options:
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)
73
+ --ts Write the app in TypeScript (alias: --typescript)
73
74
  --help Show this help message
74
75
 
75
76
  Examples:
@@ -85,6 +86,7 @@ Examples:
85
86
  npm create rasti my-app --icons pixelarticons # SPA with pixelarticons in src/icons
86
87
  npm create rasti my-app --icons heroicons-solid,heroicons-outline # Multiple sets in subfolders under src/icons
87
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
88
90
 
89
91
  Note: --tailwind and --cssfun are mutually exclusive.
90
92
  `);
package/src/plan.js CHANGED
@@ -26,7 +26,8 @@ export function createPlan(options) {
26
26
  tailwind : options.tailwind || false,
27
27
  cssfun : options.cssfun || false,
28
28
  icons : normalizeIconSets(options.icons),
29
- router : options.router || false
29
+ router : options.router || false,
30
+ typescript : options.typescript || false
30
31
  },
31
32
  packageManager : detectPackageManager()
32
33
  };
package/src/prompts.js CHANGED
@@ -47,6 +47,23 @@ export async function runPrompts(defaults = {}) {
47
47
  options.ssr = base === 'ssr' || base === 'static';
48
48
  options.static = base === 'static';
49
49
 
50
+ // Language
51
+ const language = await p.select({
52
+ message : 'Select language',
53
+ options : [
54
+ { value : 'js', label : 'JavaScript', hint : 'Typed with JSDoc' },
55
+ { value : 'ts', label : 'TypeScript' }
56
+ ],
57
+ initialValue : defaults.typescript ? 'ts' : 'js'
58
+ });
59
+
60
+ if (p.isCancel(language)) {
61
+ p.cancel('Operation cancelled.');
62
+ return null;
63
+ }
64
+
65
+ options.typescript = language === 'ts';
66
+
50
67
  // Styling option
51
68
  const styling = await p.select({
52
69
  message : 'Select styling',
@@ -96,13 +96,16 @@ export async function copyTemplateFile(templatePath, destPath, context = {}) {
96
96
 
97
97
  /**
98
98
  * Copy a template directory to the target, processing placeholders in all files.
99
+ * Of a `File.js` / `File.ts` pair only the one in the project's language is copied.
99
100
  * @param {string} templateName - Name of the template directory (spa, ssr)
100
101
  * @param {string} targetDir - Target directory path
101
102
  * @param {object} context - Values to replace placeholders
103
+ * @param {object} [options]
104
+ * @param {boolean} [options.typescript=false] - Whether the project is written in TypeScript
102
105
  */
103
- export async function copyTemplateDir(templateName, targetDir, context = {}) {
106
+ export async function copyTemplateDir(templateName, targetDir, context = {}, options = {}) {
104
107
  const templateDir = path.join(TEMPLATES_DIR, templateName);
105
- await copyDirRecursive(templateDir, targetDir, context);
108
+ await copyDirRecursive(templateDir, targetDir, context, options.typescript ? '.ts' : '.js');
106
109
  }
107
110
 
108
111
  /**
@@ -110,18 +113,24 @@ export async function copyTemplateDir(templateName, targetDir, context = {}) {
110
113
  * @param {string} src - Source directory
111
114
  * @param {string} dest - Destination directory
112
115
  * @param {object} context - Values to replace placeholders
116
+ * @param {string} sourceExt - Extension kept from a `.js` / `.ts` pair
113
117
  */
114
- async function copyDirRecursive(src, dest, context) {
118
+ async function copyDirRecursive(src, dest, context, sourceExt) {
115
119
  await fs.mkdir(dest, { recursive : true });
116
120
 
117
121
  const entries = await fs.readdir(src, { withFileTypes : true });
122
+ const names = new Set(entries.map(entry => entry.name));
118
123
 
119
124
  for (const entry of entries) {
125
+ const ext = path.extname(entry.name);
126
+ const pair = { '.js' : '.ts', '.ts' : '.js' }[ext];
127
+ if (pair && ext !== sourceExt && names.has(entry.name.slice(0, -ext.length) + pair)) continue;
128
+
120
129
  const srcPath = path.join(src, entry.name);
121
130
  const destPath = path.join(dest, entry.name);
122
131
 
123
132
  if (entry.isDirectory()) {
124
- await copyDirRecursive(srcPath, destPath, context);
133
+ await copyDirRecursive(srcPath, destPath, context, sourceExt);
125
134
  } else {
126
135
  if (isTextFile(entry.name)) {
127
136
  let content = await fs.readFile(srcPath, 'utf-8');
@@ -157,30 +166,38 @@ function isTextFile(filename) {
157
166
  }
158
167
 
159
168
  /**
160
- * Copy a template file, auto-resolving styling variant by convention.
169
+ * Copy a template file, auto-resolving styling and language variants by convention.
161
170
  * Given `dir/File.js` and plan with tailwind, looks for `dir/File-tailwind.js` first.
162
171
  * Falls back to `dir/File-cssfun.js` if cssfun, then `dir/File.js`.
172
+ * For a TypeScript project the `.ts` variants are tried first, in the same order;
173
+ * a file with no `.ts` template stays JavaScript. The destination takes the extension
174
+ * of the template copied.
163
175
  * @param {string} templatePath - Base template path (e.g. '_extras/router/App.js')
164
176
  * @param {string} destPath - Absolute destination path
165
177
  * @param {object} context - Values to replace placeholders
166
- * @param {object} plan - Project plan (checks plan.features.tailwind / cssfun)
178
+ * @param {object} plan - Project plan (checks plan.features.tailwind / cssfun / typescript)
167
179
  */
168
180
  export async function copyStyledTemplate(templatePath, destPath, context, plan) {
169
181
  const ext = path.extname(templatePath);
170
182
  const base = templatePath.slice(0, -ext.length);
183
+ const style = plan.features.tailwind ? '-tailwind' : (plan.features.cssfun ? '-cssfun' : '');
184
+ const exts = plan.features.typescript ? ['.ts', ext] : [ext];
185
+ const candidates = exts.flatMap(candidateExt => [
186
+ ...(style ? [`${base}${style}${candidateExt}`] : []),
187
+ `${base}${candidateExt}`
188
+ ]);
171
189
 
172
190
  let resolvedPath = templatePath;
173
- if (plan.features.tailwind) {
174
- const candidate = `${base}-tailwind${ext}`;
175
- const full = path.join(TEMPLATES_DIR, candidate);
176
- try { await fs.access(full); resolvedPath = candidate; } catch { /* fallback to base */ }
177
- } else if (plan.features.cssfun) {
178
- const candidate = `${base}-cssfun${ext}`;
179
- const full = path.join(TEMPLATES_DIR, candidate);
180
- try { await fs.access(full); resolvedPath = candidate; } catch { /* fallback to base */ }
191
+ for (const candidate of candidates) {
192
+ try {
193
+ await fs.access(path.join(TEMPLATES_DIR, candidate));
194
+ resolvedPath = candidate;
195
+ break;
196
+ } catch { /* try the next candidate */ }
181
197
  }
182
198
 
183
- await copyTemplateFile(resolvedPath, destPath, context);
199
+ const resolvedDest = destPath.slice(0, -path.extname(destPath).length) + path.extname(resolvedPath);
200
+ await copyTemplateFile(resolvedPath, resolvedDest, context);
184
201
  }
185
202
 
186
203
  /**
package/src/versions.js CHANGED
@@ -1,17 +1,21 @@
1
1
  /**
2
2
  * Single source of truth for every version pinned in generated projects.
3
- * When bumping any of these, also follow docs/VERSIONS.md (e.g. path-to-regexp
4
- * is mirrored in extras/micro-router/package.json, kept in sync manually).
3
+ * When bumping any of these, also follow docs/VERSIONS.md (rasti, cssfun and
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 : '^4.1.0',
8
- vite : '^7.0.0',
9
- express : '^5.0.1',
10
- compression : '^1.8.1',
11
- sirv : '^3.0.0',
12
- crossEnv : '^7.0.3',
13
- tailwindcss : '^4.0.0',
14
- tailwindVite : '^4.0.0',
15
- cssfun : '^0.1.0',
16
- pathToRegexp : '^8.0.0'
7
+ rasti : '^5.0.0-alpha.0',
8
+ vite : '^8.3.5',
9
+ express : '^5.3.0',
10
+ compression : '^1.8.2',
11
+ sirv : '^3.0.2',
12
+ crossEnv : '^10.1.0',
13
+ tailwindcss : '^4.3.3',
14
+ tailwindVite : '^4.3.3',
15
+ cssfun : '^0.4.0-alpha.0',
16
+ pathToRegexp : '^9.0.0',
17
+ typescript : '^7.0.2',
18
+ typesNode : '^22.20.5',
19
+ typesExpress : '^5.0.6',
20
+ typesCompression : '^1.8.1'
17
21
  };
@@ -14,19 +14,26 @@ Single page app powered by [Rasti](https://rasti.js.org) {{RASTI_VERSION}} + [Vi
14
14
  npm run dev # development server (HMR)
15
15
  npm run build # production build
16
16
  npm run preview # preview production build
17
- {{#if SSR}}
18
- npm start # start Express server (requires npm run build first)
17
+ {{#if TS}}
18
+ npm run typecheck # type-check with tsc (also run by build)
19
19
  {{#endif}}
20
20
  {{#if STATIC}}
21
- npm run build:static # pre-render configured routes to dist/static/
22
- npm run serve:static # serve pre-rendered files locally
21
+ npm run build:static # pre-render configured routes to dist/static/
22
+ npm run preview:static # serve pre-rendered files locally
23
23
  {{#endif}}
24
24
  ```
25
25
 
26
26
  ## Architecture
27
27
 
28
- Components live in `src/components/` and are [Rasti components](./AGENTS-RASTI.md) defined with `Component.create`.
29
- `App` is the root component — it owns `this.state` and passes values and callbacks down as props. State is a [Rasti Model](./AGENTS-RASTI.md); mutations trigger re-renders automatically.
28
+ `App` (`src/App.{{SRC_EXT}}`) is the root component, written as a `Component` subclass: it owns `this.state` (a Rasti `Model`) and passes values and callbacks down as props. Mutating the state re-renders it.
29
+ {{#if TS}}
30
+ Presentational components live in `src/components/` and are also `Component` subclasses, the form that types best: `Component<Props, State>` types `this.props` and `this.state`.
31
+ {{#else}}
32
+ Presentational components live in `src/components/` and are written with `Component.create`.
33
+ {{#endif}}
34
+ {{#if SSR}}
35
+ `src/entry-server.{{SRC_EXT}}` renders `App` to HTML for each request and `src/entry-client.{{SRC_EXT}}` hydrates it in the browser; `app.js` is the Express server that joins them.
36
+ {{#endif}}
30
37
  {{#if CSSFUN}}
31
38
  Theming uses `src/theme.js` (light/dark via `data-color-scheme` on `<html>`; CSS variables prefixed `--fun-*`).
32
39
  {{#endif}}
@@ -36,13 +43,29 @@ Routing is handled by `src/router-setup.js` — routes update `state.location`;
36
43
  {{#if STATIC}}
37
44
  Routes to pre-render are listed in `static.config.js`.
38
45
  {{#endif}}
46
+ {{#if ICONS}}
47
+ Icon components generated from SVG live in `src/icons/`.
48
+ {{#endif}}
39
49
 
40
50
  ## Conventions
41
51
 
42
52
  - ESM throughout, 4-space indentation, single quotes, semicolons
53
+ {{#if TS}}
54
+ - TypeScript in `src/` (strict, type-stripped by Vite, checked by `tsc`); `src/lib/`, the Node server files and generated icons are JavaScript typed with JSDoc, which `tsc` checks too (`checkJs`)
55
+ - Relative imports name the real file, extension included (`./App.ts`, `./lib/router.js`)
56
+ - A field set in `onCreate` is declared with `declare`: `onCreate` runs inside the base constructor, and a field initializer would reset it
57
+ {{#endif}}
43
58
  - Spaces around colons in objects: `{ key : value }`
44
59
  - Component files are PascalCase; utilities are camelCase
60
+ - Name callback props `handle*` (`handleIncrement`), never `on*`: those names belong to DOM events and lifecycle hooks
61
+
62
+ ## Agent skills
63
+
64
+ Library references for agents, installed as [Agent Skills](https://agentskills.io) in `.agents/skills/` (linked from `.claude/skills/`):
45
65
 
46
- ## Rasti API reference
66
+ - `rasti` — components, template interpolations, lifecycle hooks, models and server-side rendering
67
+ {{#if CSSFUN}}
68
+ - `cssfun` — style sheets, selectors, at-rules, themes and server-side rendering
69
+ {{#endif}}
47
70
 
48
- See [AGENTS-RASTI.md](./AGENTS-RASTI.md) — Rasti's AGENTS.md: component creation, template interpolations, lifecycle hooks, Model.
71
+ They match the library versions this project was created with. After upgrading a library, refresh its skill from `node_modules/<library>/skills/<library>`.
@@ -40,49 +40,66 @@ const { classes } = css({
40
40
  * @typedef {Object} AppState
41
41
  * @property {number} count
42
42
  {{#if ROUTER}}
43
- * @property {import('./router-setup.js').Location | null} location
43
+ * @property {import('./lib/router.js').Location | null} location
44
44
  {{#endif}}
45
45
  */
46
+ {{#if ROUTER}}
46
47
 
47
- /** Root application component with CSS-in-JS global styles.
48
- * @type {typeof import('rasti').Component<{}, AppState>}
48
+ /**
49
+ * Options `App` is created with. Rasti keeps the ones it doesn't reserve as props.
50
+ * @typedef {Object} AppProps
51
+ * @property {string} [url] - URL to route on creation (the request URL on the server).
49
52
  */
50
- const App = Component.create`
51
- <div class="${classes.root}">
52
- <${Header} />
53
+ {{#endif}}
54
+
55
+ /**
56
+ * Root application component with the global styles. Owns the state and passes values and callbacks down as props.
53
57
  {{#if ROUTER}}
54
- ${({ state, partial }) => state.location?.test('/') ?
55
- partial`<${Home} count="${({ state }) => state.count}" handleIncrement="${({ state }) => () => { state.count++; }}" />` :
56
- partial`<${About} />`}
58
+ * @extends {Component<AppProps, AppState>}
57
59
  {{#else}}
58
- <${Home} count="${({ state }) => state.count}" handleIncrement="${({ state }) => () => { state.count++; }}" />
60
+ * @extends {Component<{}, AppState>}
59
61
  {{#endif}}
60
- </div>
62
+ */
63
+ class App extends Component {
61
64
  {{#if ROUTER}}
62
- `.extend({
63
- /**
64
- * @param {Object} [options]
65
- * @param {string} [options.url] - Initial URL for server-side routing.
66
- */
65
+ /** @param {AppProps} [options] */
67
66
  onCreate(options = {}) {
68
67
  this.state = new Model({ location : null, count : 0 });
69
68
  this.router = createAppRouter(this.state);
70
- const url = options.url ?? (typeof window !== 'undefined' ? window.location.pathname + window.location.search : '/');
71
- this.router.navigate(url, { addToHistory : false });
72
- },
69
+ this.router.navigate(options.url ?? '/', { addToHistory : false });
70
+ }
71
+
73
72
  onHydrate() {
74
73
  this.destroyQueue.push(
75
74
  this.router.delegateNavigation(this.el),
76
75
  this.router.bindHistory()
77
76
  );
78
77
  }
79
- });
80
78
  {{#else}}
81
- `.extend({
82
- onCreate(options = {}) {
79
+ onCreate() {
83
80
  this.state = new Model({ count : 0 });
84
81
  }
85
- });
86
82
  {{#endif}}
87
83
 
84
+ /** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
85
+ handleIncrement = () => {
86
+ this.state.count++;
87
+ };
88
+
89
+ template() {
90
+ return this.html`
91
+ <div class="${classes.root}">
92
+ <${Header} />
93
+ {{#if ROUTER}}
94
+ ${this.state.location?.test('/') ?
95
+ this.html`<${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />` :
96
+ this.html`<${About} />`}
97
+ {{#else}}
98
+ <${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />
99
+ {{#endif}}
100
+ </div>
101
+ `;
102
+ }
103
+ }
104
+
88
105
  export default App;