@coding-with-hassan/devkit 0.4.0 → 1.0.0-next.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 +115 -0
- 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 +21 -3
- package/src/commands/ci.js +186 -0
- package/src/commands/claude.js +24 -0
- package/src/commands/config.js +117 -0
- package/src/commands/docker.js +10 -0
- package/src/commands/hooks.js +27 -20
- package/src/commands/init.js +211 -0
- package/src/commands/test-cases.js +31 -0
- package/src/commands/worktree.js +37 -0
- package/src/core/agents-docs.js +225 -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/compose.js +69 -0
- package/src/core/config.js +324 -0
- package/src/core/derive.js +130 -0
- package/src/core/env-block.js +76 -0
- package/src/core/exec.js +45 -0
- package/src/core/git.js +77 -0
- package/src/core/locks.js +60 -0
- package/src/core/root.js +30 -0
- package/src/core/scaffold.js +131 -0
- package/src/core/stack.js +63 -0
- package/src/core/test-cases/generate.js +287 -0
- package/src/core/test-cases/loader.mjs +40 -0
- package/src/core/tracker/github.js +29 -0
- package/src/core/tracker/index.js +37 -0
- package/src/core/tracker/jira.js +101 -0
- package/src/core/workspace.js +105 -0
- package/src/core/worktrees.js +580 -0
- package/src/index.js +12 -0
- package/test-cases.d.ts +48 -0
- package/test-cases.js +26 -0
|
@@ -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;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { issueNumberFromKey } from '../derive.js';
|
|
2
|
+
import { capture, commandExists } from '../exec.js';
|
|
3
|
+
import { remoteUrl } from '../git.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GitHub Issues adapter. On `worktree:create` the issue is assigned to `@me` — nothing
|
|
7
|
+
* else: GitHub has no status field without Projects, and the open PR is the progress
|
|
8
|
+
* signal. Issues live on the base repo (fork model), so `upstream` wins over `origin`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Pure: the `gh` argument list for assigning issue `number` (repo optional). */
|
|
12
|
+
export function githubAssignArgs(number, repo) {
|
|
13
|
+
return ['issue', 'edit', String(number), '--add-assignee', '@me', ...(repo ? ['--repo', repo] : [])];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const githubAdapter = {
|
|
17
|
+
async startTicket({ key, tracker, cwd, log, note }) {
|
|
18
|
+
const number = issueNumberFromKey(key, tracker);
|
|
19
|
+
if (number === null) return;
|
|
20
|
+
if (!commandExists('gh')) {
|
|
21
|
+
note(`gh not installed — assign issue #${number} to yourself on GitHub`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const repo = remoteUrl(cwd, 'upstream') ?? remoteUrl(cwd, 'origin');
|
|
25
|
+
const result = capture('gh', githubAssignArgs(number, repo), { cwd, allowFailure: true });
|
|
26
|
+
if (result === null) note(`assigning #${number} failed (does the issue exist and is gh authenticated?) — assign it to yourself on GitHub`);
|
|
27
|
+
else log(`GitHub: #${number} assigned to you`);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ticketKeyFromBranch } from '../derive.js';
|
|
2
|
+
import { githubAdapter } from './github.js';
|
|
3
|
+
import { jiraAdapter } from './jira.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tracker adapters: what `worktree:create` does with the branch's ticket. Every adapter
|
|
7
|
+
* is best effort — a missing token or an unreachable tracker prints a `note:` and never
|
|
8
|
+
* breaks worktree creation (creating the worktree IS the "work started" signal).
|
|
9
|
+
*
|
|
10
|
+
* Adapter contract: `{ startTicket({ key, branch, tracker, cwd, log, note }) }`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const adapters = {
|
|
14
|
+
none: { startTicket: async () => {} },
|
|
15
|
+
jira: jiraAdapter,
|
|
16
|
+
github: githubAdapter,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function registerTracker(kind, adapter) {
|
|
20
|
+
adapters[kind] = adapter;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function startTicket({ branch, tracker, cwd, log = console.log, note = (m) => console.error(`note: ${m}`) }) {
|
|
24
|
+
const key = ticketKeyFromBranch(branch, tracker);
|
|
25
|
+
if (!key) return null;
|
|
26
|
+
const adapter = adapters[tracker.kind];
|
|
27
|
+
if (!adapter) {
|
|
28
|
+
note(`no tracker adapter for "${tracker.kind}" — start ${key} by hand`);
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await adapter.startTicket({ key, branch, tracker, cwd, log, note });
|
|
33
|
+
} catch (e) {
|
|
34
|
+
note(`${tracker.kind}: ${e.message} — start ${key} by hand`);
|
|
35
|
+
}
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { parseEnv } from '../env-block.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Jira adapter. On `worktree:create`: whoever starts the work owns the ticket, so the
|
|
8
|
+
* issue is assigned to the current user regardless of status, and a `To Do` issue moves
|
|
9
|
+
* to `In Progress`. Best effort throughout — every failure is a `note:`.
|
|
10
|
+
*
|
|
11
|
+
* Credentials: `JIRA_EMAIL`, `JIRA_API_TOKEN` and optionally `JIRA_URL` (or `JIRA_BASE_URL`)
|
|
12
|
+
* from the environment, else from `~/.config/jira/env` (KEY=value lines).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const JIRA_ENV_FILE = join(homedir(), '.config', 'jira', 'env');
|
|
16
|
+
|
|
17
|
+
/** Pure: pick credentials from the process env, falling back to the env file's text. */
|
|
18
|
+
export function resolveJiraCredentials(env, fileText, baseUrlFromConfig) {
|
|
19
|
+
const file = fileText ? unquote(parseEnv(fileText)) : {};
|
|
20
|
+
const pick = (k) => env[k] ?? file[k] ?? null;
|
|
21
|
+
return {
|
|
22
|
+
email: pick('JIRA_EMAIL'),
|
|
23
|
+
token: pick('JIRA_API_TOKEN'),
|
|
24
|
+
baseUrl: (baseUrlFromConfig ?? pick('JIRA_URL') ?? pick('JIRA_BASE_URL') ?? null)?.replace(/\/+$/, '') ?? null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function unquote(obj) {
|
|
29
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, v.replace(/^(['"])(.*)\1$/, '$2')]));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function loadJiraCredentials(tracker) {
|
|
33
|
+
const text = existsSync(JIRA_ENV_FILE) ? readFileSync(JIRA_ENV_FILE, 'utf8') : null;
|
|
34
|
+
return resolveJiraCredentials(process.env, text, tracker.baseUrl);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function api(creds, method, path, body) {
|
|
38
|
+
const res = await fetch(`${creds.baseUrl}/rest/api/3${path}`, {
|
|
39
|
+
method,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Basic ${Buffer.from(`${creds.email}:${creds.token}`).toString('base64')}`,
|
|
42
|
+
Accept: 'application/json',
|
|
43
|
+
...(body ? { 'Content-Type': 'application/json' } : {}),
|
|
44
|
+
},
|
|
45
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
46
|
+
signal: AbortSignal.timeout(15000),
|
|
47
|
+
});
|
|
48
|
+
if (!res.ok) throw new Error(`${method} ${path} → HTTP ${res.status}`);
|
|
49
|
+
const text = await res.text();
|
|
50
|
+
return text ? JSON.parse(text) : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const jiraAdapter = {
|
|
54
|
+
async startTicket({ key, tracker, log, note }) {
|
|
55
|
+
const creds = loadJiraCredentials(tracker);
|
|
56
|
+
if (!creds.email || !creds.token || !creds.baseUrl) {
|
|
57
|
+
note(`Jira credentials unavailable (set JIRA_EMAIL/JIRA_API_TOKEN/JIRA_URL or ${JIRA_ENV_FILE}) — assign ${key} to yourself and move it to In Progress`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let me = null;
|
|
61
|
+
try {
|
|
62
|
+
me = (await api(creds, 'GET', '/myself'))?.accountId ?? null;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
note(`Jira unreachable (${e.message}) — assign ${key} to yourself and move it to In Progress`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await api(creds, 'PUT', `/issue/${key}/assignee`, { accountId: me });
|
|
69
|
+
log(`Jira: ${key} assigned to you`);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
note(`assigning ${key} failed (${e.message}) — assign it to yourself in Jira`);
|
|
72
|
+
}
|
|
73
|
+
let status = null;
|
|
74
|
+
try {
|
|
75
|
+
status = (await api(creds, 'GET', `/issue/${key}?fields=status`))?.fields?.status?.name ?? null;
|
|
76
|
+
} catch {
|
|
77
|
+
status = null;
|
|
78
|
+
}
|
|
79
|
+
if (status !== 'To Do') {
|
|
80
|
+
log(`Jira: ${key} is '${status ?? 'unreachable'}' — leaving its status alone`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let transitionId = null;
|
|
84
|
+
try {
|
|
85
|
+
const { transitions = [] } = (await api(creds, 'GET', `/issue/${key}/transitions`)) ?? {};
|
|
86
|
+
transitionId = transitions.find((t) => t.to?.name === 'In Progress')?.id ?? null;
|
|
87
|
+
} catch {
|
|
88
|
+
transitionId = null;
|
|
89
|
+
}
|
|
90
|
+
if (!transitionId) {
|
|
91
|
+
note(`${key} has no To Do → In Progress transition — move it yourself`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await api(creds, 'POST', `/issue/${key}/transitions`, { transition: { id: transitionId } });
|
|
96
|
+
log(`Jira: ${key} → In Progress`);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
note(`transitioning ${key} failed (${e.message}) — move it to In Progress yourself`);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, join, relative } from 'node:path';
|
|
3
|
+
import { parse as parseYaml } from 'yaml';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Workspace projects are derived from `pnpm-workspace.yaml`, never declared: every
|
|
7
|
+
* directory matched by a `packages:` glob that holds a package.json is a project.
|
|
8
|
+
*
|
|
9
|
+
* name — the directory basename (`apps/web-admin` → `web-admin`); this is what commit
|
|
10
|
+
* scopes, lint-staged targets and Nx project names are keyed on
|
|
11
|
+
* kind — `api` (has nest-cli.json), `spa` (has angular.json), else `lib`
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', '.nx', '.angular', 'www']);
|
|
15
|
+
|
|
16
|
+
export function parseWorkspaceGlobs(yamlText) {
|
|
17
|
+
const doc = parseYaml(yamlText) ?? {};
|
|
18
|
+
const globs = Array.isArray(doc.packages) ? doc.packages : [];
|
|
19
|
+
return globs.filter((g) => typeof g === 'string' && g.trim()).map((g) => g.trim().replace(/\/+$/, ''));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function subdirs(dir) {
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
26
|
+
} catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return entries
|
|
30
|
+
.filter((e) => e.isDirectory() && !SKIP_DIRS.has(e.name) && !e.name.startsWith('.'))
|
|
31
|
+
.map((e) => join(dir, e.name));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function segmentMatcher(segment) {
|
|
35
|
+
const re = new RegExp(`^${segment.split('*').map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('[^/]*')}$`);
|
|
36
|
+
return (name) => re.test(name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Expand one pnpm-style glob (`apps/*`, `packages/**`, `tools/cli`) to existing dirs. */
|
|
40
|
+
export function expandGlob(root, pattern) {
|
|
41
|
+
const segments = pattern.split('/').filter((s) => s && s !== '.');
|
|
42
|
+
const results = new Set();
|
|
43
|
+
const walk = (dir, segs) => {
|
|
44
|
+
if (segs.length === 0) {
|
|
45
|
+
if (existsSync(dir) && statSync(dir).isDirectory() && dir !== root) results.add(dir);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const [seg, ...rest] = segs;
|
|
49
|
+
if (seg === '**') {
|
|
50
|
+
walk(dir, rest);
|
|
51
|
+
for (const sub of subdirs(dir)) walk(sub, segs);
|
|
52
|
+
} else if (seg.includes('*')) {
|
|
53
|
+
const matches = segmentMatcher(seg);
|
|
54
|
+
for (const sub of subdirs(dir)) if (matches(basename(sub))) walk(sub, rest);
|
|
55
|
+
} else {
|
|
56
|
+
walk(join(dir, seg), rest);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
walk(root, segments);
|
|
60
|
+
return [...results];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function detectKind(dir) {
|
|
64
|
+
if (existsSync(join(dir, 'nest-cli.json'))) return 'api';
|
|
65
|
+
if (existsSync(join(dir, 'angular.json'))) return 'spa';
|
|
66
|
+
return 'lib';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* List the workspace projects of `root`, sorted by relative directory.
|
|
71
|
+
* Negated globs (`!apps/legacy`) remove matches. Directories without a package.json are
|
|
72
|
+
* ignored, like pnpm does.
|
|
73
|
+
*/
|
|
74
|
+
export function listProjects(root) {
|
|
75
|
+
const wsFile = join(root, 'pnpm-workspace.yaml');
|
|
76
|
+
if (!existsSync(wsFile)) return [];
|
|
77
|
+
const globs = parseWorkspaceGlobs(readFileSync(wsFile, 'utf8'));
|
|
78
|
+
const included = new Set();
|
|
79
|
+
const excluded = new Set();
|
|
80
|
+
for (const glob of globs) {
|
|
81
|
+
const negated = glob.startsWith('!');
|
|
82
|
+
const dirs = expandGlob(root, negated ? glob.slice(1) : glob);
|
|
83
|
+
for (const d of dirs) (negated ? excluded : included).add(d);
|
|
84
|
+
}
|
|
85
|
+
const projects = [];
|
|
86
|
+
for (const dir of included) {
|
|
87
|
+
if (excluded.has(dir)) continue;
|
|
88
|
+
const pkgFile = join(dir, 'package.json');
|
|
89
|
+
if (!existsSync(pkgFile)) continue;
|
|
90
|
+
let packageName = null;
|
|
91
|
+
try {
|
|
92
|
+
packageName = JSON.parse(readFileSync(pkgFile, 'utf8')).name ?? null;
|
|
93
|
+
} catch {
|
|
94
|
+
packageName = null;
|
|
95
|
+
}
|
|
96
|
+
projects.push({
|
|
97
|
+
name: basename(dir),
|
|
98
|
+
dir: relative(root, dir).split('\\').join('/'),
|
|
99
|
+
kind: detectKind(dir),
|
|
100
|
+
packageName,
|
|
101
|
+
hasEslint: readdirSync(dir).some((f) => /^eslint\.config\.(c|m)?js$/.test(f)),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return projects.sort((a, b) => a.dir.localeCompare(b.dir));
|
|
105
|
+
}
|