@coding-with-hassan/devkit 1.0.0-next.0 → 1.0.0-next.2
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 +47 -1
- package/claude/agents/commit-writer.md +84 -0
- package/claude/skills/implement-ticket/SKILL.md +17 -0
- package/claude/standards.md +99 -0
- package/hooks/pre-commit.sh +9 -3
- package/lint-staged.js +81 -0
- package/package.json +16 -2
- package/src/commands/ci.js +200 -0
- package/src/commands/claude.js +24 -0
- package/src/commands/docker.js +3 -2
- package/src/commands/hooks.js +38 -20
- package/src/commands/init.js +98 -14
- package/src/commands/test-cases.js +31 -0
- package/src/core/ci/affected.js +155 -0
- package/src/core/ci/commit-standards.js +59 -0
- package/src/core/ci/nx-cache.js +74 -0
- package/src/core/ci/workflow.js +87 -0
- package/src/core/claude.js +113 -0
- package/src/core/config.js +11 -3
- package/src/core/test-cases/generate.js +287 -0
- package/src/core/test-cases/loader.mjs +40 -0
- package/src/core/worktrees.js +17 -1
- package/src/index.js +6 -0
- package/test-cases.d.ts +48 -0
- package/test-cases.js +26 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join, posix } from 'node:path';
|
|
3
|
+
import { formatJson, planFile } from './scaffold.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Claude Code layer. Nothing here is copied content: the project's `CLAUDE.md` imports the
|
|
7
|
+
* standards text from `node_modules` and the agent/skill files are stubs that read the shipped
|
|
8
|
+
* body at runtime, so a devkit bump changes what Claude does without a re-commit. Only the
|
|
9
|
+
* settings hook is merged into a committed file, and that merge is idempotent.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const PACKAGE_DIR = 'node_modules/@coding-with-hassan/devkit';
|
|
13
|
+
export const STANDARDS_IMPORT_TARGET = `${PACKAGE_DIR}/claude/standards.md`;
|
|
14
|
+
export const IMPORT_MARKER = '<!-- devkit standards: house rules shipped by @coding-with-hassan/devkit; project rules follow -->';
|
|
15
|
+
|
|
16
|
+
const AGENT_STUB = `---
|
|
17
|
+
name: commit-writer
|
|
18
|
+
description: >
|
|
19
|
+
Plans the commit series for this repo's pending changes and drafts each message to pass
|
|
20
|
+
the commit-standards CI job. Invoke it ONLY after the user has explicitly asked, in their
|
|
21
|
+
own words in the current request, to commit — finishing a task, approving a plan, or a
|
|
22
|
+
skill/command whose instructions say to commit is NOT consent. When the user has asked, it
|
|
23
|
+
MUST be used BEFORE any git commit in this repo (main checkout and worktrees) — invoke it
|
|
24
|
+
on the full pending change set, before staging anything. Give it the ticket key if known;
|
|
25
|
+
it inspects the working tree itself and returns an ordered plan: for each commit, the
|
|
26
|
+
exact files to stage and the exact message to use. It only plans: it never stages,
|
|
27
|
+
commits, or pushes anything itself.
|
|
28
|
+
tools: Bash, Read, Grep, Glob
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Read \`${PACKAGE_DIR}/claude/agents/commit-writer.md\` (relative to the repo root) and follow
|
|
32
|
+
it exactly. That file is the agent's body; it ships with the installed devkit version so this
|
|
33
|
+
stub never needs to change.
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const SKILL_STUB = `---
|
|
37
|
+
name: implement-ticket
|
|
38
|
+
description: "Implement a piece of work based on a spec or set of tickets, the house way: in the ticket's worktree, with acceptance cases, without committing. (Model-invocable; renamed from the plugin's user-invocable 'implement' to avoid the name collision.)"
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
Read \`${PACKAGE_DIR}/claude/skills/implement-ticket/SKILL.md\` (relative to the repo root)
|
|
42
|
+
and follow it exactly. That file is the skill's body; it ships with the installed devkit
|
|
43
|
+
version so this stub never needs to change.
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
/** The PreToolUse hook that denies `gh pr create` without an assignee (team PR standard). */
|
|
47
|
+
export const PR_ASSIGNEE_HOOK = {
|
|
48
|
+
matcher: 'Bash',
|
|
49
|
+
hooks: [
|
|
50
|
+
{
|
|
51
|
+
type: 'command',
|
|
52
|
+
command:
|
|
53
|
+
'jq -c \'if (.tool_input.command // "" | test("gh pr create")) and ((.tool_input.command // "" | test("--assignee|(^|\\\\s)-a(\\\\s|=)")) | not) then {hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:"Team git workflow standard: every PR gets its author assigned at creation - re-run gh pr create with --assignee @me."}} else empty end\'',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const isPrHook = (entry) => (entry?.hooks ?? []).some((h) => typeof h.command === 'string' && h.command.includes('gh pr create') && h.command.includes('--assignee'));
|
|
59
|
+
|
|
60
|
+
/** Pure: merge the PR hook into a settings object (adds once; existing entry left alone). */
|
|
61
|
+
export function mergeSettingsHook(settings) {
|
|
62
|
+
const next = structuredClone(settings ?? {});
|
|
63
|
+
next.hooks ??= {};
|
|
64
|
+
next.hooks.PreToolUse ??= [];
|
|
65
|
+
if (!next.hooks.PreToolUse.some(isPrHook)) next.hooks.PreToolUse.push(structuredClone(PR_ASSIGNEE_HOOK));
|
|
66
|
+
return next;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Pure: the CLAUDE.md text with the import line. Imports resolve relative to the file that
|
|
71
|
+
* contains them, so the path depends on where the file lives (`.claude/CLAUDE.md` vs root).
|
|
72
|
+
*/
|
|
73
|
+
export function withStandardsImport(text, claudeMdRelativeDir) {
|
|
74
|
+
const importPath = posix.relative(claudeMdRelativeDir || '.', STANDARDS_IMPORT_TARGET);
|
|
75
|
+
const line = `@${importPath}`;
|
|
76
|
+
const current = text ?? '';
|
|
77
|
+
if (current.split('\n').some((l) => l.trim() === line)) return current;
|
|
78
|
+
const block = `${IMPORT_MARKER}\n${line}\n`;
|
|
79
|
+
const lines = current.split('\n');
|
|
80
|
+
// Keep a leading H1 on top; the import goes right under it (or at the very top).
|
|
81
|
+
if (lines[0]?.startsWith('# ')) return `${lines[0]}\n\n${block}${lines.slice(1).join('\n').replace(/^\n+/, '\n')}`;
|
|
82
|
+
return `${block}\n${current}`.replace(/\n{3,}$/, '\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Where the project's CLAUDE.md lives (existing one wins; default `.claude/CLAUDE.md`). */
|
|
86
|
+
export function claudeMdPath(root) {
|
|
87
|
+
if (existsSync(join(root, '.claude/CLAUDE.md'))) return '.claude/CLAUDE.md';
|
|
88
|
+
if (existsSync(join(root, 'CLAUDE.md'))) return 'CLAUDE.md';
|
|
89
|
+
return '.claude/CLAUDE.md';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Plans for the whole Claude layer. */
|
|
93
|
+
export function claudePlans(root) {
|
|
94
|
+
const plans = [];
|
|
95
|
+
const mdPath = claudeMdPath(root);
|
|
96
|
+
const current = existsSync(join(root, mdPath)) ? readFileSync(join(root, mdPath), 'utf8') : '';
|
|
97
|
+
plans.push(planFile(root, mdPath, withStandardsImport(current, posix.dirname(mdPath)), { managed: true }));
|
|
98
|
+
plans.push(planFile(root, '.claude/agents/commit-writer.md', AGENT_STUB));
|
|
99
|
+
plans.push(planFile(root, '.claude/skills/implement-ticket/SKILL.md', SKILL_STUB));
|
|
100
|
+
const settingsFile = join(root, '.claude/settings.json');
|
|
101
|
+
let settings = {};
|
|
102
|
+
if (existsSync(settingsFile)) {
|
|
103
|
+
try {
|
|
104
|
+
settings = JSON.parse(readFileSync(settingsFile, 'utf8'));
|
|
105
|
+
} catch (e) {
|
|
106
|
+
throw new Error(`.claude/settings.json is not valid JSON: ${e.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
plans.push(planFile(root, '.claude/settings.json', formatJson(mergeSettingsHook(settings)), { managed: true }));
|
|
110
|
+
return plans;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { AGENT_STUB, SKILL_STUB };
|
package/src/core/config.js
CHANGED
|
@@ -27,9 +27,10 @@ import { sanitizeName } from './derive.js';
|
|
|
27
27
|
* | { "kind": "none" },
|
|
28
28
|
* "commits": { "types": [...], "extraScopes": [...], "requireSigned": true,
|
|
29
29
|
* "exemptAuthors": ["renovate[bot]"], "docsUrl": "https://..." },
|
|
30
|
-
* "ci": { "
|
|
30
|
+
* "ci": { "nodeVersion": "24", "baseBranch": "main",
|
|
31
|
+
* "checks": [{ "name": "translations", "paths": ["^libs/i18n/"], "run": "pnpm ..." }],
|
|
31
32
|
* "affected": { "contentOnly": ["libs/i18n/src/**\/*.json"], "adopted": { "scripts/*.mjs": "daz-i18n" } } },
|
|
32
|
-
* "testCases": { "dir": "docs/testing", "languages": ["en", "nl"] },
|
|
33
|
+
* "testCases": { "dir": "docs/testing", "languages": ["en", "nl"], "title": "My Project" },
|
|
33
34
|
* "db": { "service": "db", "user": "postgres", "name": "app" },
|
|
34
35
|
* "docker": { "preUp": "..." },
|
|
35
36
|
* "i18n": { "dir": "public/assets/i18n", "languages": ["en", "nl"] }
|
|
@@ -46,6 +47,8 @@ export const DEFAULT_EXTRA_SCOPES = ['docker', 'workspace', 'docs', 'deps'];
|
|
|
46
47
|
export const DEFAULT_EXEMPT_AUTHORS = ['renovate[bot]'];
|
|
47
48
|
export const DEFAULT_MAX_SLOT = 30;
|
|
48
49
|
export const DEFAULT_GITHUB_PREFIX = 'GH';
|
|
50
|
+
export const DEFAULT_NODE_VERSION = '24';
|
|
51
|
+
export const DEFAULT_BASE_BRANCH = 'main';
|
|
49
52
|
export const TRACKER_KINDS = ['jira', 'github', 'none'];
|
|
50
53
|
|
|
51
54
|
const isString = (v) => typeof v === 'string';
|
|
@@ -150,6 +153,8 @@ export function validateConfig(raw) {
|
|
|
150
153
|
if (!isPlainObject(ci)) errors.push(`${CONFIG_KEY}.ci: expected an object`);
|
|
151
154
|
else {
|
|
152
155
|
const p = `${CONFIG_KEY}.ci`;
|
|
156
|
+
expect(`${p}.nodeVersion`, ci.nodeVersion, (v) => (isNonEmptyString(v) && /^\d+(\.\d+)*$/.test(v)) || (isInteger(v) && v > 0), 'a Node major like "24"');
|
|
157
|
+
expect(`${p}.baseBranch`, ci.baseBranch, isNonEmptyString, 'a branch name');
|
|
153
158
|
if (ci.checks !== undefined) {
|
|
154
159
|
if (!Array.isArray(ci.checks)) errors.push(`${p}.checks: expected an array`);
|
|
155
160
|
else {
|
|
@@ -187,6 +192,7 @@ export function validateConfig(raw) {
|
|
|
187
192
|
else {
|
|
188
193
|
expect(`${CONFIG_KEY}.testCases.dir`, tc.dir, isNonEmptyString, 'a directory path');
|
|
189
194
|
expect(`${CONFIG_KEY}.testCases.languages`, tc.languages, (v) => isStringArray(v) && v.length > 0, 'a non-empty array of language codes');
|
|
195
|
+
expect(`${CONFIG_KEY}.testCases.title`, tc.title, isNonEmptyString, 'the project name shown in the workbook title');
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
|
|
@@ -261,6 +267,8 @@ export function resolveConfig(raw = {}, { rootName }) {
|
|
|
261
267
|
};
|
|
262
268
|
|
|
263
269
|
const ci = {
|
|
270
|
+
nodeVersion: String(raw.ci?.nodeVersion ?? DEFAULT_NODE_VERSION),
|
|
271
|
+
baseBranch: raw.ci?.baseBranch ?? DEFAULT_BASE_BRANCH,
|
|
264
272
|
checks: (raw.ci?.checks ?? []).map((c) => ({ name: c.name, paths: [...c.paths], run: c.run })),
|
|
265
273
|
affected: {
|
|
266
274
|
contentOnly: [...(raw.ci?.affected?.contentOnly ?? [])],
|
|
@@ -269,7 +277,7 @@ export function resolveConfig(raw = {}, { rootName }) {
|
|
|
269
277
|
};
|
|
270
278
|
|
|
271
279
|
const tc = raw.testCases;
|
|
272
|
-
const testCases = tc === undefined ? null : { dir: tc.dir ?? 'docs/testing', languages: [...(tc.languages ?? ['en', 'nl'])] };
|
|
280
|
+
const testCases = tc === undefined ? null : { dir: tc.dir ?? 'docs/testing', languages: [...(tc.languages ?? ['en', 'nl'])], title: tc.title ?? null };
|
|
273
281
|
|
|
274
282
|
const db = raw.db ? { service: raw.db.service, user: raw.db.user, name: raw.db.name } : null;
|
|
275
283
|
const docker = { preUp: typeof raw.docker?.preUp === 'string' && raw.docker.preUp.trim() ? raw.docker.preUp.trim() : null };
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { register } from 'node:module';
|
|
3
|
+
import { basename, join } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The bilingual acceptance-test workbooks: one `test-cases-<suite>-<lang>.xlsx` per
|
|
8
|
+
* `tc-data-<suite>.ts` file per language, plus one personalised copy per tester when a
|
|
9
|
+
* testers file is given. The data files are the only source; the workbooks are gitignored
|
|
10
|
+
* build artifacts. Workbook UI strings ship for `en` and `nl`; another language is a
|
|
11
|
+
* contribution to `L10N` here.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const DATA_PREFIX = 'tc-data-';
|
|
15
|
+
|
|
16
|
+
/** Pure: suite key from a data file name (`tc-data-web-admin.ts` → `web-admin`). */
|
|
17
|
+
export function suiteKeyOf(fileName) {
|
|
18
|
+
const m = new RegExp(`^${DATA_PREFIX}(.+)\\.(ts|mts|js|mjs)$`).exec(fileName);
|
|
19
|
+
return m ? m[1] : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Pure: pick `*_AREAS`, `*_KNOWN_ISSUES`, `*_README` from a data module's exports. */
|
|
23
|
+
export function pickSuiteExports(mod, fileName) {
|
|
24
|
+
const find = (suffix) => Object.entries(mod).find(([k]) => k.endsWith(suffix))?.[1];
|
|
25
|
+
const areas = find('_AREAS');
|
|
26
|
+
if (!Array.isArray(areas)) throw new Error(`${fileName} must export an array named *_AREAS`);
|
|
27
|
+
return { areas, knownIssues: find('_KNOWN_ISSUES') ?? [], readme: find('_README') ?? {} };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function listDataFiles(dir) {
|
|
31
|
+
return existsSync(dir)
|
|
32
|
+
? readdirSync(dir)
|
|
33
|
+
.filter((f) => suiteKeyOf(f))
|
|
34
|
+
.sort()
|
|
35
|
+
: [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let loaderRegistered = false;
|
|
39
|
+
/** Import every `tc-data-*` file of `dir` (TypeScript allowed) as `{ key, areas, knownIssues, readme }`. */
|
|
40
|
+
export async function loadSuites(dir) {
|
|
41
|
+
const files = listDataFiles(dir);
|
|
42
|
+
if (files.some((f) => /\.m?ts$/.test(f)) && !loaderRegistered) {
|
|
43
|
+
register(new URL('./loader.mjs', import.meta.url));
|
|
44
|
+
loaderRegistered = true;
|
|
45
|
+
}
|
|
46
|
+
const suites = [];
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
const mod = await import(pathToFileURL(join(dir, file)).href);
|
|
49
|
+
suites.push({ key: suiteKeyOf(file), file, ...pickSuiteExports(mod, file) });
|
|
50
|
+
}
|
|
51
|
+
return suites;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function slugify(name) {
|
|
55
|
+
return String(name)
|
|
56
|
+
.toLowerCase()
|
|
57
|
+
.normalize('NFD')
|
|
58
|
+
.replace(/[̀-ͯ]/g, '')
|
|
59
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
60
|
+
.replace(/(^-|-$)/g, '');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Pure: output file name for a suite/lang(/tester). */
|
|
64
|
+
export function workbookName(suiteKey, lang, tester) {
|
|
65
|
+
return `test-cases-${suiteKey}-${lang}${tester ? `-${slugify(tester.name)}` : ''}.xlsx`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const FONT = 'Arial';
|
|
69
|
+
const HEADER_ARGB = 'FF1F3864';
|
|
70
|
+
const ZEBRA_ARGB = 'FFF2F2F2';
|
|
71
|
+
const PRIO_ARGB = { H: 'FFFCE4E4', M: 'FFFFF3CD', L: 'FFE7F1E7' };
|
|
72
|
+
const COL_WIDTHS = [10, 30, 11, 34, 52, 52, 13, 14, 26];
|
|
73
|
+
|
|
74
|
+
export const L10N = {
|
|
75
|
+
en: {
|
|
76
|
+
headers: ['ID', 'Title', 'Priority', 'Preconditions', 'Steps', 'Expected result', 'Status', 'Tester', 'Notes'],
|
|
77
|
+
statuses: ['Pass', 'Fail', 'Blocked', 'Skipped'],
|
|
78
|
+
prio: { H: 'High', M: 'Medium', L: 'Low' },
|
|
79
|
+
readmeTitle: (project) => `${project} — Acceptance Test Suite`,
|
|
80
|
+
readmeSheet: 'Read Me',
|
|
81
|
+
summarySheet: 'Summary',
|
|
82
|
+
summaryHeaders: ['Area', 'Cases', 'Pass', 'Fail', 'Blocked', 'Skipped', 'Not run'],
|
|
83
|
+
total: 'Total',
|
|
84
|
+
knownSheet: 'Known Issues',
|
|
85
|
+
knownHeaders: ['ID', 'Description', 'Impact / instruction'],
|
|
86
|
+
yourAccounts: 'Your accounts',
|
|
87
|
+
testerLine: (name) => `This copy is assigned to: ${name}`,
|
|
88
|
+
customerCreds: (email, password) => `Your CUSTOMER account (customer flows): ${email} / ${password} — change the password if you like; it only exists for this test.`,
|
|
89
|
+
adminCreds: (email, password) => `Your ADMIN account (Admin sheets): ${email} / ${password}`,
|
|
90
|
+
adminInvite: (email) => `Your ADMIN account: an invitation was sent to ${email} — set your password via the link in that email.`,
|
|
91
|
+
},
|
|
92
|
+
nl: {
|
|
93
|
+
headers: ['ID', 'Titel', 'Prioriteit', 'Voorwaarden', 'Stappen', 'Verwacht resultaat', 'Status', 'Tester', 'Notities'],
|
|
94
|
+
statuses: ['Geslaagd', 'Mislukt', 'Geblokkeerd', 'Overgeslagen'],
|
|
95
|
+
prio: { H: 'Hoog', M: 'Middel', L: 'Laag' },
|
|
96
|
+
readmeTitle: (project) => `${project} — Acceptatietests`,
|
|
97
|
+
readmeSheet: 'Lees mij',
|
|
98
|
+
summarySheet: 'Overzicht',
|
|
99
|
+
summaryHeaders: ['Onderdeel', 'Tests', 'Geslaagd', 'Mislukt', 'Geblokkeerd', 'Overgeslagen', 'Niet uitgevoerd'],
|
|
100
|
+
total: 'Totaal',
|
|
101
|
+
knownSheet: 'Bekende punten',
|
|
102
|
+
knownHeaders: ['ID', 'Omschrijving', 'Impact / instructie'],
|
|
103
|
+
yourAccounts: 'Jouw accounts',
|
|
104
|
+
testerLine: (name) => `Dit exemplaar is toegewezen aan: ${name}`,
|
|
105
|
+
customerCreds: (email, password) => `Jouw KLANT-account (klantflows): ${email} / ${password} — wijzig het wachtwoord gerust; het bestaat alleen voor deze test.`,
|
|
106
|
+
adminCreds: (email, password) => `Jouw BEHEERDERS-account (Beheer-tabbladen): ${email} / ${password}`,
|
|
107
|
+
adminInvite: (email) => `Jouw BEHEERDERS-account: er is een uitnodiging gestuurd naar ${email} — stel je wachtwoord in via de link in die e-mail.`,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const THIN = { style: 'thin', color: { argb: 'FFBFBFBF' } };
|
|
112
|
+
const THIN_BORDER = { top: THIN, left: THIN, bottom: THIN, right: THIN };
|
|
113
|
+
const solidFill = (argb) => ({ type: 'pattern', pattern: 'solid', fgColor: { argb } });
|
|
114
|
+
|
|
115
|
+
function styleHeader(ws, headers) {
|
|
116
|
+
headers.forEach((text, i) => {
|
|
117
|
+
const cell = ws.getCell(1, i + 1);
|
|
118
|
+
cell.value = text;
|
|
119
|
+
cell.font = { name: FONT, bold: true, color: { argb: 'FFFFFFFF' }, size: 10 };
|
|
120
|
+
cell.fill = solidFill(HEADER_ARGB);
|
|
121
|
+
cell.alignment = { horizontal: 'center', vertical: 'middle', wrapText: true };
|
|
122
|
+
cell.border = THIN_BORDER;
|
|
123
|
+
});
|
|
124
|
+
ws.views = [{ state: 'frozen', ySplit: 1 }];
|
|
125
|
+
ws.getRow(1).height = 24;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function testerSection(t, tester) {
|
|
129
|
+
const lines = [t.testerLine(tester.name)];
|
|
130
|
+
if (tester.customerEmail && tester.customerPassword) lines.push(t.customerCreds(tester.customerEmail, tester.customerPassword));
|
|
131
|
+
if (tester.adminEmail && tester.adminPassword) lines.push(t.adminCreds(tester.adminEmail, tester.adminPassword));
|
|
132
|
+
else lines.push(t.adminInvite(tester.email));
|
|
133
|
+
return [t.yourAccounts, lines];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function addReadme(wb, t, lang, readme, project, tester) {
|
|
137
|
+
const ws = wb.addWorksheet(t.readmeSheet, { properties: { tabColor: { argb: HEADER_ARGB } } });
|
|
138
|
+
ws.mergeCells('A1:B1');
|
|
139
|
+
const title = ws.getCell('A1');
|
|
140
|
+
title.value = t.readmeTitle(project);
|
|
141
|
+
title.font = { name: FONT, bold: true, size: 16, color: { argb: HEADER_ARGB } };
|
|
142
|
+
ws.getRow(1).height = 28;
|
|
143
|
+
let row = 3;
|
|
144
|
+
const sections = tester ? [testerSection(t, tester), ...(readme[lang] ?? [])] : [...(readme[lang] ?? [])];
|
|
145
|
+
for (const [section, lines] of sections) {
|
|
146
|
+
const cell = ws.getCell(row, 1);
|
|
147
|
+
cell.value = section;
|
|
148
|
+
cell.font = { name: FONT, bold: true, size: 12, color: { argb: HEADER_ARGB } };
|
|
149
|
+
row += 1;
|
|
150
|
+
for (const line of lines) {
|
|
151
|
+
const c = ws.getCell(row, 2);
|
|
152
|
+
c.value = line;
|
|
153
|
+
c.font = { name: FONT, size: 10 };
|
|
154
|
+
c.alignment = { wrapText: true, vertical: 'top' };
|
|
155
|
+
ws.getRow(row).height = Math.max(15, 14 * (Math.floor(line.length / 95) + 1));
|
|
156
|
+
row += 1;
|
|
157
|
+
}
|
|
158
|
+
row += 1;
|
|
159
|
+
}
|
|
160
|
+
ws.getColumn(1).width = 22;
|
|
161
|
+
ws.getColumn(2).width = 110;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function addAreaSheet(wb, t, area, lang, tester) {
|
|
165
|
+
const ws = wb.addWorksheet(area.name[lang].slice(0, 31), { properties: { tabColor: { argb: `FF${area.tab}` } } });
|
|
166
|
+
styleHeader(ws, t.headers);
|
|
167
|
+
area.cases.forEach((tcase, i) => {
|
|
168
|
+
const r = i + 2;
|
|
169
|
+
const values = [tcase.id, tcase.title[lang], t.prio[tcase.priority], tcase.pre[lang], tcase.steps[lang], tcase.expected[lang], '', tester?.name ?? '', ''];
|
|
170
|
+
values.forEach((value, colIdx) => {
|
|
171
|
+
const col = colIdx + 1;
|
|
172
|
+
const cell = ws.getCell(r, col);
|
|
173
|
+
cell.value = value;
|
|
174
|
+
cell.font = { name: FONT, size: 10 };
|
|
175
|
+
cell.alignment = { wrapText: true, vertical: 'top', horizontal: [1, 3, 7].includes(col) ? 'center' : 'left' };
|
|
176
|
+
cell.border = THIN_BORDER;
|
|
177
|
+
if (col === 3) cell.fill = solidFill(PRIO_ARGB[tcase.priority]);
|
|
178
|
+
else if (r % 2 === 0) cell.fill = solidFill(ZEBRA_ARGB);
|
|
179
|
+
});
|
|
180
|
+
ws.getCell(r, 7).dataValidation = { type: 'list', allowBlank: true, formulae: [`"${t.statuses.join(',')}"`] };
|
|
181
|
+
const steps = tcase.steps[lang] ?? '';
|
|
182
|
+
const expected = tcase.expected[lang] ?? '';
|
|
183
|
+
const lines = Math.max(steps.split('\n').length, expected.split('\n').length, Math.floor(steps.length / 50) + 1, Math.floor(expected.length / 50) + 1);
|
|
184
|
+
ws.getRow(r).height = Math.max(30, 13.5 * lines);
|
|
185
|
+
});
|
|
186
|
+
COL_WIDTHS.forEach((width, i) => {
|
|
187
|
+
ws.getColumn(i + 1).width = width;
|
|
188
|
+
});
|
|
189
|
+
ws.autoFilter = { from: 'A1', to: { row: area.cases.length + 1, column: t.headers.length } };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function addSummary(wb, t, lang, areas) {
|
|
193
|
+
const ws = wb.addWorksheet(t.summarySheet, { properties: { tabColor: { argb: 'FF555555' } } });
|
|
194
|
+
styleHeader(ws, t.summaryHeaders);
|
|
195
|
+
areas.forEach((area, i) => {
|
|
196
|
+
const r = i + 2;
|
|
197
|
+
const name = area.name[lang].slice(0, 31);
|
|
198
|
+
const count = area.cases.length;
|
|
199
|
+
const range = `'${name}'!$G$2:$G$${count + 1}`;
|
|
200
|
+
ws.getCell(r, 1).value = name;
|
|
201
|
+
ws.getCell(r, 2).value = count;
|
|
202
|
+
t.statuses.forEach((status, s) => {
|
|
203
|
+
ws.getCell(r, 3 + s).value = { formula: `COUNTIF(${range},"${status}")` };
|
|
204
|
+
});
|
|
205
|
+
ws.getCell(r, 7).value = { formula: `B${r}-SUM(C${r}:F${r})` };
|
|
206
|
+
});
|
|
207
|
+
const totalRow = areas.length + 2;
|
|
208
|
+
ws.getCell(totalRow, 1).value = t.total;
|
|
209
|
+
for (let col = 2; col <= 7; col++) {
|
|
210
|
+
const letter = ws.getColumn(col).letter;
|
|
211
|
+
ws.getCell(totalRow, col).value = { formula: `SUM(${letter}2:${letter}${totalRow - 1})` };
|
|
212
|
+
}
|
|
213
|
+
for (let r = 2; r <= totalRow; r++) {
|
|
214
|
+
for (let col = 1; col <= 7; col++) {
|
|
215
|
+
const cell = ws.getCell(r, col);
|
|
216
|
+
cell.font = { name: FONT, size: 10, bold: r === totalRow };
|
|
217
|
+
cell.border = THIN_BORDER;
|
|
218
|
+
cell.alignment = { horizontal: col === 1 ? 'left' : 'center' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
[34, 9, 11, 11, 12, 13, 14].forEach((width, i) => {
|
|
222
|
+
ws.getColumn(i + 1).width = width;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function addKnownIssues(wb, t, lang, knownIssues) {
|
|
227
|
+
if (!knownIssues.length) return;
|
|
228
|
+
const ws = wb.addWorksheet(t.knownSheet, { properties: { tabColor: { argb: 'FFD4A72C' } } });
|
|
229
|
+
styleHeader(ws, t.knownHeaders);
|
|
230
|
+
knownIssues.forEach((issue, i) => {
|
|
231
|
+
const r = i + 2;
|
|
232
|
+
[issue.id, issue.desc[lang], issue.impact[lang]].forEach((value, colIdx) => {
|
|
233
|
+
const cell = ws.getCell(r, colIdx + 1);
|
|
234
|
+
cell.value = value;
|
|
235
|
+
cell.font = { name: FONT, size: 10 };
|
|
236
|
+
cell.alignment = { wrapText: true, vertical: 'top' };
|
|
237
|
+
cell.border = THIN_BORDER;
|
|
238
|
+
});
|
|
239
|
+
ws.getRow(r).height = 42;
|
|
240
|
+
});
|
|
241
|
+
ws.getColumn(1).width = 9;
|
|
242
|
+
ws.getColumn(2).width = 75;
|
|
243
|
+
ws.getColumn(3).width = 45;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Build one workbook in memory. `project` is the title's project name. */
|
|
247
|
+
export async function buildWorkbook({ ExcelJS, suite, lang, project, tester }) {
|
|
248
|
+
const t = L10N[lang];
|
|
249
|
+
if (!t) throw new Error(`No workbook strings for language "${lang}" (available: ${Object.keys(L10N).join(', ')})`);
|
|
250
|
+
const wb = new ExcelJS.Workbook();
|
|
251
|
+
addReadme(wb, t, lang, suite.readme, project, tester);
|
|
252
|
+
addSummary(wb, t, lang, suite.areas);
|
|
253
|
+
for (const area of suite.areas) addAreaSheet(wb, t, area, lang, tester);
|
|
254
|
+
addKnownIssues(wb, t, lang, suite.knownIssues);
|
|
255
|
+
return wb;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Generate every workbook: suites × languages (× testers). Returns the written file names.
|
|
260
|
+
*/
|
|
261
|
+
export async function generate({ dir, languages, project, testersFile = null, onlyLang = null, log = console.log }) {
|
|
262
|
+
const { default: ExcelJS } = await import('exceljs');
|
|
263
|
+
const langs = onlyLang ? [onlyLang] : languages;
|
|
264
|
+
for (const lang of langs) {
|
|
265
|
+
if (!L10N[lang]) throw new Error(`Unknown language "${lang}" (expected one of ${Object.keys(L10N).join(', ')})`);
|
|
266
|
+
}
|
|
267
|
+
const testers = testersFile ? JSON.parse(readFileSync(testersFile, 'utf8')) : [];
|
|
268
|
+
const suites = await loadSuites(dir);
|
|
269
|
+
if (suites.length === 0) throw new Error(`No ${DATA_PREFIX}*.ts files in ${dir}`);
|
|
270
|
+
const written = [];
|
|
271
|
+
for (const lang of langs) {
|
|
272
|
+
for (const suite of suites) {
|
|
273
|
+
const total = suite.areas.reduce((sum, area) => sum + area.cases.length, 0);
|
|
274
|
+
const file = join(dir, workbookName(suite.key, lang));
|
|
275
|
+
await (await buildWorkbook({ ExcelJS, suite, lang, project })).xlsx.writeFile(file);
|
|
276
|
+
written.push(file);
|
|
277
|
+
log(`${basename(file)}: ${suite.areas.length} areas, ${total} cases`);
|
|
278
|
+
for (const tester of testers) {
|
|
279
|
+
const personal = join(dir, workbookName(suite.key, lang, tester));
|
|
280
|
+
await (await buildWorkbook({ ExcelJS, suite, lang, project, tester })).xlsx.writeFile(personal);
|
|
281
|
+
written.push(personal);
|
|
282
|
+
log(`${basename(personal)}: personalized for ${tester.name}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return written;
|
|
287
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { stripTypeScriptTypes } from 'node:module';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ESM loader hooks (registered with `module.register`) that let the generator import the
|
|
7
|
+
* project's `tc-data-*.ts` files without a TypeScript toolchain:
|
|
8
|
+
* - a relative specifier without extension resolves to `<specifier>.ts` when that exists
|
|
9
|
+
* (`import … from './test-case-types'`), and
|
|
10
|
+
* - `.ts` sources are type-stripped with Node's built-in `stripTypeScriptTypes` (Node ≥ 22.13).
|
|
11
|
+
* Stripping keeps import specifiers verbatim, so data files must import types with the
|
|
12
|
+
* `type` modifier (`import { tc, type Area } from '…'`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Hooks run on their own thread, so the warning filter must live here: Node flags
|
|
16
|
+
// stripTypeScriptTypes as experimental on every run, which is noise for the generator's
|
|
17
|
+
// users. Only that one warning is swallowed; every other warning still prints.
|
|
18
|
+
process.removeAllListeners('warning');
|
|
19
|
+
process.on('warning', (w) => {
|
|
20
|
+
if (w.name === 'ExperimentalWarning' && /stripTypeScriptTypes/.test(w.message)) return;
|
|
21
|
+
console.error(w.stack ?? `${w.name}: ${w.message}`);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
25
|
+
if ((specifier.startsWith('./') || specifier.startsWith('../')) && !/\.[a-z]+$/i.test(specifier) && context.parentURL?.startsWith('file:')) {
|
|
26
|
+
const candidate = new URL(`${specifier}.ts`, context.parentURL);
|
|
27
|
+
if (existsSync(fileURLToPath(candidate))) return nextResolve(candidate.href, context);
|
|
28
|
+
}
|
|
29
|
+
return nextResolve(specifier, context);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function load(url, context, nextLoad) {
|
|
33
|
+
if (url.startsWith('file:') && url.endsWith('.ts')) {
|
|
34
|
+
const source = readFileSync(fileURLToPath(url), 'utf8');
|
|
35
|
+
return { format: 'module', shortCircuit: true, source: stripTypeScriptTypes(source, { mode: 'strip' }) };
|
|
36
|
+
}
|
|
37
|
+
return nextLoad(url, context);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const LOADER_URL = pathToFileURL(fileURLToPath(import.meta.url)).href;
|
package/src/core/worktrees.js
CHANGED
|
@@ -23,6 +23,19 @@ import { listProjects } from './workspace.js';
|
|
|
23
23
|
|
|
24
24
|
// ───────────────────────── pure ─────────────────────────
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Is the worktree feature switched on? The block must exist AND, when the repo has a compose
|
|
28
|
+
* file, name at least one port or a default profile: `init` merges an EMPTY skeleton into
|
|
29
|
+
* every package.json, and that skeleton must stay inert until the project fills it in —
|
|
30
|
+
* otherwise `docker:up` would manage `.env` (and build a second image set) behind the
|
|
31
|
+
* project's existing tooling. A repo without a compose file needs no ports, so `{}` is active.
|
|
32
|
+
*/
|
|
33
|
+
export function worktreeActive(wt, { hasStack }) {
|
|
34
|
+
if (!wt) return false;
|
|
35
|
+
if (!hasStack) return true;
|
|
36
|
+
return Object.keys(wt.ports).length > 0 || wt.profiles.default.length > 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
/** Compose project of a checkout: slot 0 keeps the configured name; others use the branch. */
|
|
27
40
|
export function projectNameFor({ slot, branch, projectName }) {
|
|
28
41
|
if (slot === 0) return projectName;
|
|
@@ -148,9 +161,12 @@ export function createContext(loaded, { log = console.log, note = (m) => console
|
|
|
148
161
|
const { root, rootName, config } = loaded;
|
|
149
162
|
const wt = config.worktree;
|
|
150
163
|
if (!wt) throw new Error(`Missing "${CONFIG_KEY}.worktree" in ${join(root, 'package.json')} — add it (or run \`hassan-devkit init\`).`);
|
|
164
|
+
const hasStack = stack.hasComposeFile(root);
|
|
165
|
+
if (!worktreeActive(wt, { hasStack })) {
|
|
166
|
+
throw new Error(`"${CONFIG_KEY}.worktree" is still the empty skeleton — fill in worktree.ports (base host ports) and worktree.profiles.default before using the worktree commands; until then the stack keeps being managed by whatever the project used before.`);
|
|
167
|
+
}
|
|
151
168
|
const main = git.mainRoot(root);
|
|
152
169
|
const baseDir = resolve(main, wt.baseDir);
|
|
153
|
-
const hasStack = stack.hasComposeFile(root);
|
|
154
170
|
let compose = null;
|
|
155
171
|
if (hasStack) {
|
|
156
172
|
compose = loadProfiles(root);
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import { registerI18n } from './commands/i18n.js';
|
|
|
6
6
|
import { registerInit } from './commands/init.js';
|
|
7
7
|
import { registerConfig } from './commands/config.js';
|
|
8
8
|
import { registerWorktree } from './commands/worktree.js';
|
|
9
|
+
import { registerCi } from './commands/ci.js';
|
|
10
|
+
import { registerClaude } from './commands/claude.js';
|
|
11
|
+
import { registerTestCases } from './commands/test-cases.js';
|
|
9
12
|
|
|
10
13
|
export function run(argv) {
|
|
11
14
|
const cli = cac('hassan-devkit');
|
|
@@ -13,6 +16,9 @@ export function run(argv) {
|
|
|
13
16
|
registerInit(cli);
|
|
14
17
|
registerConfig(cli);
|
|
15
18
|
registerWorktree(cli);
|
|
19
|
+
registerCi(cli);
|
|
20
|
+
registerClaude(cli);
|
|
21
|
+
registerTestCases(cli);
|
|
16
22
|
registerDocker(cli);
|
|
17
23
|
registerDb(cli);
|
|
18
24
|
registerHooks(cli);
|
package/test-cases.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type Lang = string;
|
|
2
|
+
export type Priority = 'H' | 'M' | 'L';
|
|
3
|
+
|
|
4
|
+
/** One text per language code (`{ en: '…', nl: '…' }`). */
|
|
5
|
+
export type Localized = Record<Lang, string>;
|
|
6
|
+
|
|
7
|
+
export interface TestCase {
|
|
8
|
+
id: string;
|
|
9
|
+
priority: Priority;
|
|
10
|
+
title: Localized;
|
|
11
|
+
pre: Localized;
|
|
12
|
+
steps: Localized;
|
|
13
|
+
expected: Localized;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Area {
|
|
17
|
+
key: string;
|
|
18
|
+
name: Localized;
|
|
19
|
+
/** Sheet tab colour, six hex digits without `#`. */
|
|
20
|
+
tab: string;
|
|
21
|
+
cases: TestCase[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface KnownIssue {
|
|
25
|
+
id: string;
|
|
26
|
+
desc: Localized;
|
|
27
|
+
impact: Localized;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ReadmeSection = [string, string[]];
|
|
31
|
+
export type Readme = Record<Lang, ReadmeSection[]>;
|
|
32
|
+
|
|
33
|
+
/** Build one bilingual (en/nl) test case positionally — the house default. */
|
|
34
|
+
export function tc(
|
|
35
|
+
id: string,
|
|
36
|
+
priority: Priority,
|
|
37
|
+
titleEn: string,
|
|
38
|
+
titleNl: string,
|
|
39
|
+
preEn: string,
|
|
40
|
+
preNl: string,
|
|
41
|
+
stepsEn: string,
|
|
42
|
+
stepsNl: string,
|
|
43
|
+
expectedEn: string,
|
|
44
|
+
expectedNl: string,
|
|
45
|
+
): TestCase;
|
|
46
|
+
|
|
47
|
+
/** Build a test case for any language set from localized objects. */
|
|
48
|
+
export function tcase(input: TestCase): TestCase;
|
package/test-cases.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared vocabulary for the bilingual acceptance test cases (`docs/testing/tc-data-*.ts`).
|
|
3
|
+
*
|
|
4
|
+
* import { tc, type Area, type KnownIssue, type Readme } from '@coding-with-hassan/devkit/test-cases';
|
|
5
|
+
*
|
|
6
|
+
* Use the `type` modifier for the types: the data files are loaded with Node's type
|
|
7
|
+
* stripping, which keeps import specifiers verbatim, so a value import of a type would fail.
|
|
8
|
+
* Types live in `test-cases.d.ts` next to this file.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Build one bilingual (en/nl) test case positionally — the house default. */
|
|
12
|
+
export function tc(id, priority, titleEn, titleNl, preEn, preNl, stepsEn, stepsNl, expectedEn, expectedNl) {
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
priority,
|
|
16
|
+
title: { en: titleEn, nl: titleNl },
|
|
17
|
+
pre: { en: preEn, nl: preNl },
|
|
18
|
+
steps: { en: stepsEn, nl: stepsNl },
|
|
19
|
+
expected: { en: expectedEn, nl: expectedNl },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Build a test case for any language set from localized objects. */
|
|
24
|
+
export function tcase({ id, priority, title, pre, steps, expected }) {
|
|
25
|
+
return { id, priority, title, pre, steps, expected };
|
|
26
|
+
}
|