create-chanom-app 0.2.0 → 0.3.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 +6 -1
- package/dist/index.js +122 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,8 @@ Run with no flags, the CLI walks you through:
|
|
|
31
31
|
1. **Project name** - the target directory (kebab-cased). Defaults to `my-chanom-app`.
|
|
32
32
|
2. **Initialize a git repository?** - `git init` plus an initial commit.
|
|
33
33
|
3. **Add commit hooks?** - husky + lint-staged + commitlint (only asked when git is enabled).
|
|
34
|
-
4. **
|
|
34
|
+
4. **Add agent coding standards?** - the `coding-standards` skill in `.agents/skills`, linked into `.claude/skills`.
|
|
35
|
+
5. **Install dependencies now?** - runs `<pm> install` after scaffolding.
|
|
35
36
|
|
|
36
37
|
Every prompt has a matching flag so you can pre-answer any of them (or all, with `--yes`).
|
|
37
38
|
|
|
@@ -43,6 +44,8 @@ Every prompt has a matching flag so you can pre-answer any of them (or all, with
|
|
|
43
44
|
| `--git` / `--no-git` | Initialize a git repository (default: yes) |
|
|
44
45
|
| `--commit-hooks` | Add husky + lint-staged + commitlint (requires git) |
|
|
45
46
|
| `--no-commit-hooks` | Skip the commit-hooks topping |
|
|
47
|
+
| `--agent-skills` | Add the coding-standards skill (default: yes) |
|
|
48
|
+
| `--no-agent-skills` | Skip the agent-skills topping |
|
|
46
49
|
| `--install` / `--no-install` | Install dependencies after scaffolding (default: install) |
|
|
47
50
|
| `--pm <pnpm\|npm\|yarn\|bun>` | Package manager to record (default: detected) |
|
|
48
51
|
| `-y`, `--yes` | Accept all defaults, no prompts (CI-friendly) |
|
|
@@ -76,6 +79,8 @@ A minimal Vite + React + TS app wired to the chanom shared configs:
|
|
|
76
79
|
|
|
77
80
|
With the **commit-hooks** topping, it also adds husky, lint-staged, and commitlint as dev dependencies plus their config files (`.husky/pre-commit`, `.husky/commit-msg`, `.lintstagedrc.json`, `.commitlintrc.json`). The hooks materialize on the first install via the generated `prepare: "husky"` script.
|
|
78
81
|
|
|
82
|
+
With the **agent-skills** topping, it adds the `coding-standards` agent skill - a router `SKILL.md` plus TypeScript, React, and Vitest references written for exactly the stack scaffolded here. The real files land in `.agents/skills/coding-standards/` so any agent tool can read them, and `.claude/skills/coding-standards` is a relative symlink pointing at that directory rather than a second copy. It contributes no packages and no scripts, so skipping it leaves both directories out entirely.
|
|
83
|
+
|
|
79
84
|
## Development
|
|
80
85
|
|
|
81
86
|
```sh
|
package/dist/index.js
CHANGED
|
@@ -206,6 +206,58 @@ var Prompter = class extends Effect.Service()("internal/Prompter", { succeed: {
|
|
|
206
206
|
})
|
|
207
207
|
} }) {};
|
|
208
208
|
//#endregion
|
|
209
|
+
//#region ../internal/src/skills/index.ts
|
|
210
|
+
/**
|
|
211
|
+
* The coding-standards skill, targeting the stack `create-chanom-app` scaffolds
|
|
212
|
+
* (Vite + React + TypeScript, oxlint, oxfmt, vitest). Its markdown is authored
|
|
213
|
+
* as real `.md` files under `skills/coding-standards/` and inlined here at
|
|
214
|
+
* build time through the `__CODING_STANDARDS_FILES__` define, so `chanom brew`
|
|
215
|
+
* and `create-chanom-app` install byte-identical content from one source.
|
|
216
|
+
*/
|
|
217
|
+
const codingStandardsSkill = {
|
|
218
|
+
name: "coding-standards",
|
|
219
|
+
files: [
|
|
220
|
+
{
|
|
221
|
+
"path": "references/react.md",
|
|
222
|
+
"contents": "# React\n\nReact 19 with the Vite plugin. Entry is `src/main.tsx`, which mounts `App` from\n`src/app.tsx` in `StrictMode`.\n\n## Structure\n\n`src/` grows by role as the app does: `components/`, `hooks/`, `utils/`,\n`pages/`, `providers/`. Feature-scoped code lives under `features/<name>/` and\nmirrors that same layout. Put code in the feature folder unless two features\nshare it.\n\n## Components\n\n- **Container / presentational**: containers fetch data and hold logic;\n presentational components take props and return JSX with no side effects.\n- Props are wrapped in `Readonly<>`:\n `export function UserCard({ name }: Readonly<UserCardProps>)`.\n- Conditional rendering uses a ternary (`isOpen ? <Panel /> : null`), never\n `&&` — a falsy number renders as `0`.\n- Every component exports inline. `default` export is reserved for route-level\n page components.\n- Shared state lives in a context provider under `providers/`. Reach for\n context only once prop-passing spans three levels.\n\n## Hooks\n\nCustom hooks are named `use-<thing>.ts` and return an object, not a positional\ntuple, once they return more than two values. Every effect declares its full\ndependency array; an effect with no cleanup and no async work is usually a\nrender-time computation instead.\n"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"path": "references/typescript.md",
|
|
226
|
+
"contents": "# TypeScript\n\n## Types\n\n- Never use `any`. Reach for generics and utility types; when you must escape\n the type system use `unknown` and narrow explicitly.\n- Type-only imports use `import type { ... }`. A mixed import splits its type\n part into a separate `import type` line.\n- Derive types from their source rather than restating them — `z.infer` for a\n schema, `ReturnType`/`Parameters` for a function, `typeof` for a const object.\n A hand-written duplicate drifts.\n- Props and params objects are declared as `interface`, named after their owner:\n `interface UserCardProps`, `interface UseCurrentUserParams`.\n\n## Modules\n\n- Functions, not classes. Hooks, utils, factories, and components are plain\n exported functions.\n- Export inline (`export function formatDate(...)`) rather than a trailing\n `export { ... }` block.\n- Import order is enforced by oxlint — run `pnpm lint --fix` rather than\n hand-sorting.\n\n## Errors\n\nThrow `Error` (or a subclass) with a message naming what failed and the value\nthat caused it. An unused catch binding is omitted: `catch {`, not\n`catch (_e) {`.\n"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"path": "references/vitest.md",
|
|
230
|
+
"contents": "# Vitest\n\nTests run on jsdom with globals enabled — `describe`, `it`, `expect`, and `vi`\nneed no import. `src/test-setup.ts` loads `@testing-library/jest-dom/vitest`, so\nits matchers are available everywhere. Run with `pnpm test`, or `pnpm test:watch`\nwhile iterating.\n\n## Layout\n\nTests are colocated and named `*.test.ts` / `*.test.tsx`, sitting beside the\nfile they cover: `src/app.tsx` → `src/app.test.tsx`.\n\n## Component tests\n\nTesting Library with `user-event`, querying by role and accessible name:\n\n```tsx\ndescribe('UserCard', () => {\n it('should render the user name correctly', () => {\n render(<UserCard name=\"Ada\" />);\n expect(screen.getByRole('heading', { name: 'Ada' })).toBeInTheDocument();\n });\n\n it('should call onSelect when clicked', async () => {\n const user = userEvent.setup();\n const onSelect = vi.fn();\n render(<UserCard name=\"Ada\" onSelect={onSelect} />);\n await user.click(screen.getByRole('button', { name: 'Select' }));\n expect(onSelect).toHaveBeenCalledTimes(1);\n });\n});\n```\n\n- Interactions go through `userEvent.setup()` and `await user.click(...)`, not\n `fireEvent`.\n- Handlers are `vi.fn()` asserted by call count, including the negative case —\n a disabled control asserts `toHaveBeenCalledTimes(0)`.\n- Query by `getByRole` / `getByText`. Reach for `getByTestId` only when no\n accessible query exists, such as a decorative spinner.\n- Assert on what the user observes, not on state or implementation details.\n\n## Naming\n\nTest names read `should <behaviour> correctly` or `should <effect> when\n<action>`. Group a unit's tests in one `describe` named for the unit.\n"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"path": "SKILL.md",
|
|
234
|
+
"contents": "---\nname: coding-standards\ndescription: Coding standards for this Vite + React + TypeScript app. Use when writing or changing components, hooks, utils, or tests, and before committing.\n---\n\n# Coding standards\n\nVite + React 19 + TypeScript, scaffolded with `create-chanom-app`. oxlint lints,\noxfmt formats, vitest tests. Read the reference for what you touch **before**\nwriting, so new code matches the code already here.\n\n## Which reference to load\n\n| You are writing… | Load |\n| -------------------------------------------- | -------------------------- |\n| Any `.ts` / `.tsx` file | `references/typescript.md` |\n| A component, hook, or anything rendering JSX | `references/react.md` |\n| A `*.test.ts` / `*.test.tsx` file | `references/vitest.md` |\n\nThese layer: a new component with a test reads all three. Load every row that\napplies.\n\n## Universal rules\n\n- Filenames are kebab-case: `user-card.tsx`, `use-current-user.ts`, `format-date.ts`.\n- Before adding a file, open two neighbouring files of the same kind and match\n their shape — import order, export style, test naming.\n- Source lives under `src/`. Colocate a test beside the code it covers:\n `src/utils/format-date.ts` → `src/utils/format-date.test.ts`.\n\n## Verify\n\nAfter implementing, from the project root:\n\n```sh\npnpm lint\npnpm test\npnpm build\n```\n\nDone only when all three exit clean. On failure, fix and rerun until they do.\nRun `pnpm format` before committing. Comment- or doc-only changes may skip all\nfour.\n\n## Committing\n\nAsk before committing. Use conventional commits under 100 characters:\n`<type>(<scope>): <subject>`, e.g. `feat(auth): add sign-out button`. Scope is\nthe area you touched, not the repo name.\n"
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
};
|
|
238
|
+
/** Directory holding the real skill files, agent-agnostic. */
|
|
239
|
+
const SKILLS_ROOT = ".agents/skills";
|
|
240
|
+
/** Directory Claude Code reads skills from; its entries are links into {@link SKILLS_ROOT}. */
|
|
241
|
+
const CLAUDE_SKILLS_ROOT = ".claude/skills";
|
|
242
|
+
/** Files a skill writes, rooted at `.agents/skills/<name>/`. */
|
|
243
|
+
function skillFiles(skill) {
|
|
244
|
+
return skill.files.map((file) => ({
|
|
245
|
+
path: `${SKILLS_ROOT}/${skill.name}/${file.path}`,
|
|
246
|
+
contents: file.contents
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The `.claude/skills/<name>` link for a skill. Real files live under
|
|
251
|
+
* `.agents/skills/` so any agent tool can read them; Claude Code only looks in
|
|
252
|
+
* `.claude/skills/`, so it gets a link rather than a second copy.
|
|
253
|
+
*/
|
|
254
|
+
function skillLink(skill) {
|
|
255
|
+
return {
|
|
256
|
+
path: `${CLAUDE_SKILLS_ROOT}/${skill.name}`,
|
|
257
|
+
target: `../../${SKILLS_ROOT}/${skill.name}`
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
209
261
|
//#region src/bundled-versions.ts
|
|
210
262
|
const depVersions = {
|
|
211
263
|
"react": "19.2.8",
|
|
@@ -232,7 +284,7 @@ const depVersions = {
|
|
|
232
284
|
"@chanom/vite-config": "0.1.0"
|
|
233
285
|
};
|
|
234
286
|
/** This package's own version, for `--version`. */
|
|
235
|
-
const pkgVersion = "0.
|
|
287
|
+
const pkgVersion = "0.3.0";
|
|
236
288
|
//#endregion
|
|
237
289
|
//#region src/domain/args.ts
|
|
238
290
|
const PACKAGE_MANAGERS = [
|
|
@@ -280,6 +332,12 @@ function parseArgs(argv) {
|
|
|
280
332
|
case "--no-commit-hooks":
|
|
281
333
|
args.commitHooks = false;
|
|
282
334
|
break;
|
|
335
|
+
case "--agent-skills":
|
|
336
|
+
args.agentSkills = true;
|
|
337
|
+
break;
|
|
338
|
+
case "--no-agent-skills":
|
|
339
|
+
args.agentSkills = false;
|
|
340
|
+
break;
|
|
283
341
|
case "--install":
|
|
284
342
|
args.install = true;
|
|
285
343
|
break;
|
|
@@ -342,16 +400,27 @@ function toKebabCase(name) {
|
|
|
342
400
|
}
|
|
343
401
|
//#endregion
|
|
344
402
|
//#region src/domain/contribution.ts
|
|
403
|
+
const emptyContribution = {
|
|
404
|
+
dependencies: [],
|
|
405
|
+
devDependencies: [],
|
|
406
|
+
scripts: {},
|
|
407
|
+
viteImports: [],
|
|
408
|
+
vitePlugins: [],
|
|
409
|
+
files: [],
|
|
410
|
+
links: []
|
|
411
|
+
};
|
|
345
412
|
const dedupe = (values) => [...new Set(values)];
|
|
346
413
|
/**
|
|
347
414
|
* Folds contributions in order into a single value. Package names, vite imports,
|
|
348
415
|
* and plugins are concatenated then de-duplicated (first occurrence wins its
|
|
349
416
|
* position); scripts merge with later contributions overriding earlier keys;
|
|
350
|
-
* files de-duplicate by path (first writer wins).
|
|
417
|
+
* files and links de-duplicate by path (first writer wins).
|
|
351
418
|
*/
|
|
352
419
|
function mergeContributions(contributions) {
|
|
353
420
|
const filesByPath = /* @__PURE__ */ new Map();
|
|
354
421
|
for (const contribution of contributions) for (const file of contribution.files) if (!filesByPath.has(file.path)) filesByPath.set(file.path, file);
|
|
422
|
+
const linksByPath = /* @__PURE__ */ new Map();
|
|
423
|
+
for (const contribution of contributions) for (const link of contribution.links) if (!linksByPath.has(link.path)) linksByPath.set(link.path, link);
|
|
355
424
|
return {
|
|
356
425
|
dependencies: dedupe(contributions.flatMap((c) => c.dependencies)),
|
|
357
426
|
devDependencies: dedupe(contributions.flatMap((c) => c.devDependencies)),
|
|
@@ -361,7 +430,8 @@ function mergeContributions(contributions) {
|
|
|
361
430
|
}), {}),
|
|
362
431
|
viteImports: dedupe(contributions.flatMap((c) => c.viteImports)),
|
|
363
432
|
vitePlugins: dedupe(contributions.flatMap((c) => c.vitePlugins)),
|
|
364
|
-
files: [...filesByPath.values()]
|
|
433
|
+
files: [...filesByPath.values()],
|
|
434
|
+
links: [...linksByPath.values()]
|
|
365
435
|
};
|
|
366
436
|
}
|
|
367
437
|
//#endregion
|
|
@@ -597,7 +667,8 @@ const baseline = {
|
|
|
597
667
|
}, {
|
|
598
668
|
path: ".vscode/extensions.json",
|
|
599
669
|
contents: asJson({ recommendations: RECOMMENDED_EXTENSIONS })
|
|
600
|
-
}]
|
|
670
|
+
}],
|
|
671
|
+
links: []
|
|
601
672
|
};
|
|
602
673
|
const LINT_STAGED_CONFIG = {
|
|
603
674
|
"**/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}": ["oxlint --fix --no-error-on-unmatched-pattern"],
|
|
@@ -644,12 +715,27 @@ function commitHooks(pm) {
|
|
|
644
715
|
path: ".commitlintrc.json",
|
|
645
716
|
contents: JSON.stringify(COMMITLINT_CONFIG, null, 2) + "\n"
|
|
646
717
|
}
|
|
647
|
-
]
|
|
718
|
+
],
|
|
719
|
+
links: []
|
|
648
720
|
};
|
|
649
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* The `agent-skills` topping: the chanom coding-standards skill. Real files go
|
|
724
|
+
* to `.agents/skills/` so any agent tool can read them, and `.claude/skills/`
|
|
725
|
+
* gets a symlink rather than a second copy. Contributes files and links only -
|
|
726
|
+
* no packages, no scripts - so projects that skip it get neither directory.
|
|
727
|
+
*/
|
|
728
|
+
const agentSkills = {
|
|
729
|
+
...emptyContribution,
|
|
730
|
+
files: skillFiles(codingStandardsSkill),
|
|
731
|
+
links: [skillLink(codingStandardsSkill)]
|
|
732
|
+
};
|
|
650
733
|
/** The baseline plus whichever toppings the resolved options select, in fold order. */
|
|
651
734
|
function selectContributions(selection) {
|
|
652
|
-
|
|
735
|
+
const contributions = [baseline];
|
|
736
|
+
if (selection.commitHooks) contributions.push(commitHooks(selection.pm));
|
|
737
|
+
if (selection.agentSkills) contributions.push(agentSkills);
|
|
738
|
+
return contributions;
|
|
653
739
|
}
|
|
654
740
|
//#endregion
|
|
655
741
|
//#region src/scaffold.ts
|
|
@@ -671,6 +757,25 @@ const copyTemplates = Effect.fn("scaffold.copyTemplates")(function* (plan) {
|
|
|
671
757
|
yield* writeFile(plan.targetDir, file.dest, contents);
|
|
672
758
|
}
|
|
673
759
|
});
|
|
760
|
+
/**
|
|
761
|
+
* Creates one topping-contributed symlink, making its parent directory first.
|
|
762
|
+
* Scaffolding into an existing directory (`create chanom-app .`) can meet a link
|
|
763
|
+
* an earlier run - or `chanom add-skills` - already made, and `symlink` fails
|
|
764
|
+
* with EEXIST on anything already there, so an occupied path is left alone and
|
|
765
|
+
* reported instead of aborting the scaffold after the files are written.
|
|
766
|
+
*/
|
|
767
|
+
const writeLink = Effect.fn("scaffold.writeLink")(function* (targetDir, link) {
|
|
768
|
+
const fs = yield* FileSystem.FileSystem;
|
|
769
|
+
const path = yield* Path.Path;
|
|
770
|
+
const prompter = yield* Prompter;
|
|
771
|
+
const linkPath = path.join(targetDir, link.path);
|
|
772
|
+
if (yield* fs.exists(linkPath)) {
|
|
773
|
+
yield* prompter.warn(`\`${link.path}\` already exists - skipping link`);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
yield* fs.makeDirectory(path.dirname(linkPath), { recursive: true });
|
|
777
|
+
yield* fs.symlink(link.target, linkPath);
|
|
778
|
+
});
|
|
674
779
|
const writeGeneratedFiles = Effect.fn("scaffold.writeGeneratedFiles")(function* (plan, folded) {
|
|
675
780
|
const appName = toKebabCase(plan.appName);
|
|
676
781
|
yield* writeFile(plan.targetDir, "package.json", buildPackageJson({
|
|
@@ -684,6 +789,7 @@ const writeGeneratedFiles = Effect.fn("scaffold.writeGeneratedFiles")(function*
|
|
|
684
789
|
yield* writeFile(plan.targetDir, "tsconfig.json", buildTsconfig());
|
|
685
790
|
yield* writeFile(plan.targetDir, "index.html", renderIndexHtml(appName));
|
|
686
791
|
for (const file of folded.files) yield* writeFile(plan.targetDir, file.path, file.contents);
|
|
792
|
+
for (const link of folded.links) yield* writeLink(plan.targetDir, link);
|
|
687
793
|
});
|
|
688
794
|
const initGit = Effect.fn("scaffold.initGit")(function* (plan) {
|
|
689
795
|
const git = yield* Git;
|
|
@@ -709,7 +815,8 @@ const scaffold = Effect.fn("scaffold")(function* (plan) {
|
|
|
709
815
|
const fs = yield* FileSystem.FileSystem;
|
|
710
816
|
const folded = mergeContributions(selectContributions({
|
|
711
817
|
pm: plan.pm,
|
|
712
|
-
commitHooks: plan.commitHooks
|
|
818
|
+
commitHooks: plan.commitHooks,
|
|
819
|
+
agentSkills: plan.agentSkills
|
|
713
820
|
}));
|
|
714
821
|
yield* fs.makeDirectory(plan.targetDir, { recursive: true });
|
|
715
822
|
yield* copyTemplates(plan);
|
|
@@ -731,6 +838,8 @@ ${pc.bold("Options")}
|
|
|
731
838
|
${pc.cyan("--git / --no-git")} Initialize a git repository (default: yes)
|
|
732
839
|
${pc.cyan("--commit-hooks")} Add husky + lint-staged + commitlint (requires git)
|
|
733
840
|
${pc.cyan("--no-commit-hooks")} Skip the commit-hooks topping
|
|
841
|
+
${pc.cyan("--agent-skills")} Add the coding-standards skill to .claude/skills
|
|
842
|
+
${pc.cyan("--no-agent-skills")} Skip the agent-skills topping
|
|
734
843
|
${pc.cyan("--install / --no-install")} Install dependencies after scaffolding (default: install)
|
|
735
844
|
${pc.cyan("--pm <pnpm|npm|yarn|bun>")} Package manager to record (default: detected)
|
|
736
845
|
${pc.cyan("-y, --yes")} Accept all defaults, no prompts (CI-friendly)
|
|
@@ -802,6 +911,10 @@ const program$1 = (argv, cwd, options) => Effect.gen(function* () {
|
|
|
802
911
|
message: "Add commit hooks (husky + lint-staged + commitlint)?",
|
|
803
912
|
initialValue: true
|
|
804
913
|
})) : false;
|
|
914
|
+
const agentSkills = yield* resolveConfirm(args.agentSkills, args.yes, prompter.confirm({
|
|
915
|
+
message: "Add agent coding standards (.agents/skills)?",
|
|
916
|
+
initialValue: true
|
|
917
|
+
}));
|
|
805
918
|
const install = yield* resolveConfirm(args.install, args.yes, prompter.confirm({
|
|
806
919
|
message: "Install dependencies now?",
|
|
807
920
|
initialValue: true
|
|
@@ -815,6 +928,7 @@ const program$1 = (argv, cwd, options) => Effect.gen(function* () {
|
|
|
815
928
|
`${pc.dim("package mgr")} ${pm}`,
|
|
816
929
|
`${pc.dim("git")} ${git ? "yes" : "no"}`,
|
|
817
930
|
`${pc.dim("commit hooks")} ${git ? commitHooks ? "yes" : "no" : pc.dim("n/a")}`,
|
|
931
|
+
`${pc.dim("agent skills")} ${agentSkills ? "yes" : "no"}`,
|
|
818
932
|
`${pc.dim("install")} ${install ? "yes" : "no"}`
|
|
819
933
|
].join("\n"));
|
|
820
934
|
yield* scaffold({
|
|
@@ -824,6 +938,7 @@ const program$1 = (argv, cwd, options) => Effect.gen(function* () {
|
|
|
824
938
|
packageManagerField: packageManagerField(pm, options.userAgent),
|
|
825
939
|
git,
|
|
826
940
|
commitHooks,
|
|
941
|
+
agentSkills,
|
|
827
942
|
install,
|
|
828
943
|
templatesRoot: options.templatesRoot
|
|
829
944
|
});
|