create-clarity 1.0.0 → 1.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
@@ -40,10 +40,15 @@ npx create-clarity my-app -y # all defaults, no prompts
40
40
  | `--ts`, `--typescript` | add TypeScript |
41
41
  | `--router` | add the router |
42
42
  | `--i18n` | add internationalization |
43
- | `--testing` | add a test setup |
43
+ | `--testing` | add tests: Vitest with jsdom, through the project's own Vite config, so a test imports a `.clarity` file |
44
44
  | `-y`, `--yes` | accept defaults, no prompts |
45
45
  | `--local <path>` | use a local clarity-js checkout (`file:` dependency) — handy for development |
46
46
 
47
+ Every template also gets `AGENTS.md` (and a `CLAUDE.md` that points at it): it tells a coding
48
+ agent that the project is written in Clarity.js and that the skill for it came with the
49
+ installed package (`node_modules/@ozsarman/clarityjs/skills/clarity/SKILL.md`). You do not have
50
+ to have learnt the language to ask for a change.
51
+
47
52
  ## After scaffolding
48
53
 
49
54
  ```bash
@@ -26,7 +26,7 @@ const { scaffold, isNonEmptyDir } = require('../lib/scaffold');
26
26
  const c = prompts.colors;
27
27
  const PKG_VERSION = require('../package.json').version;
28
28
  // the versions a new project asks for (bumped with each release of the framework)
29
- const VERSIONS = { clarity: '^1.0.0', gl: '^1.0.0', audio: '^1.0.0' };
29
+ const VERSIONS = { clarity: '^1.1.0', gl: '^1.0.0', audio: '^1.0.0' }; // 1.1.0: the first whose `clarity lint` and `clarity check` read a file as the compiler does
30
30
 
31
31
  function parseArgs(argv) {
32
32
  const args = { _: [], flags: {} };
package/lib/game.js CHANGED
@@ -23,6 +23,7 @@ function gameFiles(opts) {
23
23
  build: 'vite build',
24
24
  preview: 'vite preview',
25
25
  test: 'node --test',
26
+ lint: 'clarity lint .',
26
27
  balance: 'clarity balance src/rules.js --seeds 24 --seconds 150',
27
28
  },
28
29
  dependencies: {
@@ -88,6 +89,7 @@ connectAgent({ view: () => describeView(document.querySelector('.game-scene')) }
88
89
  files['test/rules.test.js'] = TEST;
89
90
  files['README.md'] = readme(opts);
90
91
  files['.gitignore'] = 'node_modules\ndist\n.DS_Store\n*.local\n';
92
+ Object.assign(files, require('./templates').agentFiles(opts));
91
93
  return files;
92
94
  }
93
95
 
package/lib/templates.js CHANGED
@@ -43,8 +43,16 @@ function buildFiles(opts) {
43
43
  scripts.serve = 'node server.js --prod';
44
44
  delete scripts.preview;
45
45
  }
46
- if (opts.testing) scripts.test = 'node --test';
46
+ if (opts.testing) {
47
+ // Vitest runs the tests through this project's own Vite config, so a test imports a
48
+ // .clarity file like any other module, in a jsdom page.
49
+ scripts.test = 'vitest run';
50
+ devDeps.vitest = '^3.2.0';
51
+ devDeps.jsdom = '^26.0.0';
52
+ }
47
53
  if (opts.typescript) scripts.typecheck = 'tsc --noEmit';
54
+ // the compiler's errors and the linter's findings for every .clarity file (node_modules and dist are left alone)
55
+ scripts.lint = 'clarity lint .';
48
56
 
49
57
  files['package.json'] = JSON.stringify({
50
58
  name: opts.projectName,
@@ -59,11 +67,12 @@ function buildFiles(opts) {
59
67
  // ── vite.config ──────────────────────────────────────────────────────────--
60
68
  const clarityPluginCall = opts.router ? 'clarity({ scanPages: true })' : 'clarity()';
61
69
  files[`vite.config.${ext === 'ts' ? 'ts' : 'js'}`] =
62
- `import { defineConfig } from 'vite';
70
+ `import { defineConfig } from '${opts.testing ? 'vitest/config' : 'vite'}';
63
71
  import clarity from '@ozsarman/clarityjs/vite';
64
72
 
65
73
  export default defineConfig({
66
- plugins: [${clarityPluginCall}],
74
+ plugins: [${clarityPluginCall}],${opts.testing ? `
75
+ test: { environment: 'jsdom', include: ['test/**/*.test.${ext}'] },` : ''}
67
76
  });
68
77
  `;
69
78
 
@@ -104,13 +113,13 @@ ${opts.i18n ? "import './i18n.js';\n" : ''}
104
113
  // Load this URL's page first so the client renders the same page the server sent,
105
114
  // then take over the server HTML.
106
115
  Routes.preload(location.pathname).then(() => {
107
- hydrateRoot(document.getElementById('app'), Routes);
116
+ hydrateRoot(document.getElementById('app')${opts.typescript ? '!' : ''}, Routes);
108
117
  });
109
118
  `
110
119
  : `import { mount } from '@ozsarman/clarityjs';
111
120
  import { Routes } from 'virtual:clarity-pages';
112
121
  ${opts.i18n ? "import './i18n.js';\n" : ''}
113
- const container = document.getElementById('app');
122
+ const container = document.getElementById('app')${opts.typescript ? '!' : ''};
114
123
  mount(Routes, container);
115
124
  `;
116
125
  files['pages/index.clarity'] = indexPage(opts);
@@ -123,12 +132,12 @@ mount(Routes, container);
123
132
  import { App } from './App.clarity';
124
133
  ${opts.i18n ? "import './i18n.js';\n" : ''}
125
134
  // Take over the HTML the server rendered.
126
- hydrateRoot(document.getElementById('app'), App);
135
+ hydrateRoot(document.getElementById('app')${opts.typescript ? '!' : ''}, App);
127
136
  `
128
137
  : `import { mount } from '@ozsarman/clarityjs';
129
138
  import { App } from './App.clarity';
130
139
  ${opts.i18n ? "import './i18n.js';\n" : ''}
131
- const container = document.getElementById('app');
140
+ const container = document.getElementById('app')${opts.typescript ? '!' : ''};
132
141
  mount(App, container);
133
142
  `;
134
143
  files['src/App.clarity'] = appComponent(opts);
@@ -261,13 +270,13 @@ export const t = i18n.t;
261
270
  skipLibCheck: true,
262
271
  noEmit: true,
263
272
  },
264
- include: ['src', 'pages'],
273
+ include: opts.testing ? ['src', 'pages', 'test'] : ['src', 'pages'],
265
274
  }, null, 2) + '\n';
266
275
 
267
276
  files['src/clarity.d.ts'] =
268
277
  `// Let TypeScript understand .clarity imports.
269
278
  declare module '*.clarity' {
270
- const component: (props?: Record<string, unknown>) => Node;
279
+ const component: (props?: Record<string, unknown>) => HTMLElement;
271
280
  export const App: typeof component;
272
281
  export default component;
273
282
  }
@@ -275,7 +284,7 @@ ${opts.router ? `
275
284
  // The Vite scanPages plugin generates this virtual module from pages/.
276
285
  declare module 'virtual:clarity-pages' {
277
286
  export const routes: Array<{ pattern: string; file: string; load: () => Promise<unknown> }>;
278
- export const Routes: (props?: Record<string, unknown>) => Node;
287
+ export const Routes: ((props?: Record<string, unknown>) => HTMLElement) & { preload(path: string): Promise<unknown> };
279
288
  const _default: typeof Routes;
280
289
  export default _default;
281
290
  }
@@ -288,24 +297,28 @@ declare module 'virtual:clarity-pages' {
288
297
  ? "import Home from '../pages/index.clarity';"
289
298
  : "import { App } from '../src/App.clarity';";
290
299
  const testTarget = opts.router ? 'Home' : 'App';
291
- files['test/app.test.js'] =
292
- `import { test } from 'node:test';
293
- import assert from 'node:assert';
294
- import { render, fireEvent } from '@ozsarman/clarityjs/test';
300
+ const bang = opts.typescript ? '!' : '';
301
+ files[`test/app.test.${ext}`] =
302
+ `import { test, expect, afterEach } from 'vitest';
303
+ import { render, query, click, cleanup } from '@ozsarman/clarityjs/test';
295
304
  ${testImport}
296
305
 
297
- test('page renders and is interactive', async () => {
298
- const { container, getByText } = render(${testTarget});
299
- assert.ok(container, 'component mounted');
306
+ afterEach(cleanup);
300
307
 
301
- const button = getByText(/count|click/i) || container.querySelector('button');
302
- if (button) {
303
- fireEvent.click(button);
304
- }
308
+ test('the page renders, and a click counts', () => {
309
+ const { container } = render(${testTarget});
310
+ const button = query(container, 'button')${bang};
311
+ const shown = () => ${opts.router ? 'button' : `query(container, 'p')${bang}`}.textContent;
312
+ expect(shown()).toContain('0');
313
+ click(button);
314
+ expect(shown()).toContain('1');
305
315
  });
306
316
  `;
307
317
  }
308
318
 
319
+ // ── For the AI that works in this project ──────────────────────────────────
320
+ Object.assign(files, agentFiles(opts));
321
+
309
322
  // ── README ───────────────────────────────────────────────────────────────--
310
323
  files['README.md'] = readme(opts);
311
324
 
@@ -473,4 +486,47 @@ ${opts.i18n ? ' i18n.js # translations\n' : ''} styles.css
473
486
  `;
474
487
  }
475
488
 
476
- module.exports = { buildFiles };
489
+ /**
490
+ * AGENTS.md (read by Codex, Cursor, Copilot, Gemini CLI and others) and CLAUDE.md (Claude Code),
491
+ * which points at it. They say the one thing an agent cannot guess: this project is written in
492
+ * a language it was not trained on, and the instructions for it came with the installed package.
493
+ */
494
+ function agentFiles(opts) {
495
+ const skill = 'node_modules/@ozsarman/clarityjs/skills/clarity';
496
+ const where = opts.game
497
+ ? 'the rules are in `src/rules.js` (plain JavaScript, no page), the page is `src/Game.clarity`'
498
+ : (opts.router ? 'pages are files under `pages/` (a file is a route), shared pieces under `src/`' : 'the app starts at `src/App.clarity`');
499
+ const agents = `# For AI agents working in this project
500
+
501
+ This is a [Clarity.js](https://clarity-js.com) project. Clarity.js is a compiled framework with a
502
+ small language of its own (\`.clarity\` files). It is not React, Vue or Svelte, and what you know
503
+ of their syntax does not apply here.
504
+
505
+ **Before you write or change a \`.clarity\` file, read \`${skill}/SKILL.md\`.**
506
+ It came with the installed version of the framework, so it matches it. Its references are
507
+ beside it: \`references/language.md\` (the whole language), \`references/recipes.md\` (routes,
508
+ data, server rendering, forms, tests) and \`references/porting.md\` (from React, Vue or Svelte).
509
+
510
+ Two rules:
511
+
512
+ 1. **Do not invent syntax.** If it is not in \`references/language.md\`, it does not exist.
513
+ 2. **Check before you say it is done:** \`npx clarity check path/File.clarity\` for every file
514
+ you wrote or changed. It compiles the file and lints it: an error means it is not done, and a
515
+ warning names something that is almost surely a mistake (\`npm run lint\` does the whole project).
516
+
517
+ ## This project
518
+
519
+ - ${where[0].toUpperCase() + where.slice(1)}.
520
+ - \`npm run dev\` runs it${opts.testing || opts.game ? ', \`npm test\` tests it' : ''}, \`npm run build\` builds it.
521
+ - A component says what an AI agent may read and do on the page with \`ai:readable\`,
522
+ \`ai:actionable\` and \`ai:forbidden\`. Give one to every component a person would want an
523
+ assistant to operate, and put secrets in \`ai:forbidden\`.
524
+ ${opts.game ? `- This is a game: the \`clarity-game\` and \`clarity-gl\` skills cover it
525
+ (\`npx skills add https://gitlab.com/ozsarman/clarity.js\`).
526
+ ` : `- For anything 3D, and for games: \`npx skills add https://gitlab.com/ozsarman/clarity.js\`
527
+ (the \`clarity-gl\` and \`clarity-game\` skills).
528
+ `}`;
529
+ return { 'AGENTS.md': agents, 'CLAUDE.md': '@AGENTS.md\n' };
530
+ }
531
+
532
+ module.exports = { buildFiles, agentFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-clarity",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Scaffold a new Clarity.js app — npm create clarity@latest",
5
5
  "type": "commonjs",
6
6
  "bin": {