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