shipmd 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -2
- package/dist/cli.js +843 -0
- package/dist/cli.js.map +1 -0
- package/dist/web/assets/index-BObuDEOy.css +1 -0
- package/dist/web/assets/index-EMd_Ib9S.js +26 -0
- package/dist/web/index.html +14 -0
- package/package.json +56 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command, Option } from "commander";
|
|
5
|
+
import path3 from "path";
|
|
6
|
+
|
|
7
|
+
// src/core/config.ts
|
|
8
|
+
import { readFile, writeFile } from "fs/promises";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
var CONFIG_FILE = "shipmd.json";
|
|
11
|
+
var DEFAULT_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
12
|
+
var configSchema = z.object({
|
|
13
|
+
project: z.object({
|
|
14
|
+
name: z.string().min(1),
|
|
15
|
+
key: z.string().regex(/^[A-Z][A-Z0-9]*$/, 'project.key must be uppercase letters/digits, e.g. "MB"')
|
|
16
|
+
}),
|
|
17
|
+
statuses: z.array(z.object({ id: z.string().min(1), name: z.string().min(1) })).min(1),
|
|
18
|
+
priorities: z.array(z.string().min(1)).default(["low", "medium", "high", "critical"]),
|
|
19
|
+
efforts: z.array(z.string().min(1)).default([...DEFAULT_EFFORTS]),
|
|
20
|
+
defaultStatus: z.string().optional()
|
|
21
|
+
});
|
|
22
|
+
function defaultConfig(name, key) {
|
|
23
|
+
return {
|
|
24
|
+
project: { name, key },
|
|
25
|
+
statuses: [
|
|
26
|
+
{ id: "todo", name: "\xC0 faire" },
|
|
27
|
+
{ id: "in-progress", name: "En cours" },
|
|
28
|
+
{ id: "review", name: "Revue" },
|
|
29
|
+
{ id: "done", name: "Termin\xE9" }
|
|
30
|
+
],
|
|
31
|
+
priorities: ["low", "medium", "high", "critical"],
|
|
32
|
+
efforts: [...DEFAULT_EFFORTS],
|
|
33
|
+
defaultStatus: "todo"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function keyFromName(name) {
|
|
37
|
+
const words = name.normalize("NFD").replace(/[̀-ͯ]/g, "").split(/[^A-Za-z0-9]+|(?<=[a-z])(?=[A-Z])/).filter(Boolean);
|
|
38
|
+
let key = words.length > 1 ? words.map((w) => w[0]).join("") : (words[0] ?? "MB").slice(0, 3);
|
|
39
|
+
key = key.toUpperCase().replace(/^[0-9]+/, "");
|
|
40
|
+
return key || "MB";
|
|
41
|
+
}
|
|
42
|
+
function parseConfig(raw) {
|
|
43
|
+
const result = configSchema.safeParse(raw);
|
|
44
|
+
if (!result.success) {
|
|
45
|
+
const msg = result.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
|
|
46
|
+
throw new Error(`Invalid ${CONFIG_FILE}: ${msg}`);
|
|
47
|
+
}
|
|
48
|
+
const c = result.data;
|
|
49
|
+
const defaultStatus = c.defaultStatus ?? c.statuses[0].id;
|
|
50
|
+
if (!c.statuses.some((s) => s.id === defaultStatus)) {
|
|
51
|
+
throw new Error(`Invalid ${CONFIG_FILE}: defaultStatus "${defaultStatus}" is not a status id`);
|
|
52
|
+
}
|
|
53
|
+
return { ...c, defaultStatus };
|
|
54
|
+
}
|
|
55
|
+
async function readConfig(file) {
|
|
56
|
+
let text;
|
|
57
|
+
try {
|
|
58
|
+
text = await readFile(file, "utf8");
|
|
59
|
+
} catch {
|
|
60
|
+
throw new Error(`Cannot read ${file}`);
|
|
61
|
+
}
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = JSON.parse(text);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
throw new Error(`Invalid JSON in ${file}: ${e.message}`);
|
|
67
|
+
}
|
|
68
|
+
return parseConfig(raw);
|
|
69
|
+
}
|
|
70
|
+
async function writeConfig(file, config) {
|
|
71
|
+
await writeFile(file, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/core/ticket.ts
|
|
75
|
+
import matter from "gray-matter";
|
|
76
|
+
var EPIC_FILE = "_epic.md";
|
|
77
|
+
var KNOWN_KEYS = [
|
|
78
|
+
"id",
|
|
79
|
+
"title",
|
|
80
|
+
"status",
|
|
81
|
+
"priority",
|
|
82
|
+
"effort",
|
|
83
|
+
"assignee",
|
|
84
|
+
"labels",
|
|
85
|
+
"order",
|
|
86
|
+
"created",
|
|
87
|
+
"updated"
|
|
88
|
+
];
|
|
89
|
+
function slugify(text, maxLength = 40) {
|
|
90
|
+
const slug = text.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
91
|
+
return slug.slice(0, maxLength).replace(/-+$/, "");
|
|
92
|
+
}
|
|
93
|
+
function ticketFileName(id, title) {
|
|
94
|
+
const slug = slugify(title);
|
|
95
|
+
return slug ? `${id}-${slug}.md` : `${id}.md`;
|
|
96
|
+
}
|
|
97
|
+
function today() {
|
|
98
|
+
return toDateString(/* @__PURE__ */ new Date());
|
|
99
|
+
}
|
|
100
|
+
function toDateString(d) {
|
|
101
|
+
return d.toISOString().slice(0, 10);
|
|
102
|
+
}
|
|
103
|
+
function normalizeValue(v) {
|
|
104
|
+
if (v instanceof Date) return toDateString(v);
|
|
105
|
+
return v;
|
|
106
|
+
}
|
|
107
|
+
function optString(v) {
|
|
108
|
+
if (v === void 0 || v === null || v === "") return void 0;
|
|
109
|
+
return String(normalizeValue(v));
|
|
110
|
+
}
|
|
111
|
+
function splitFrontmatter(text) {
|
|
112
|
+
const parsed = matter(text, {});
|
|
113
|
+
const data = {};
|
|
114
|
+
for (const [k, v] of Object.entries(parsed.data ?? {})) data[k] = normalizeValue(v);
|
|
115
|
+
return { data, body: parsed.content.replace(/^\r?\n/, "") };
|
|
116
|
+
}
|
|
117
|
+
function joinFrontmatter(data, body) {
|
|
118
|
+
const ordered = {};
|
|
119
|
+
for (const k of KNOWN_KEYS) {
|
|
120
|
+
if (data[k] !== void 0 && data[k] !== null && data[k] !== "") ordered[k] = data[k];
|
|
121
|
+
}
|
|
122
|
+
for (const [k, v] of Object.entries(data)) {
|
|
123
|
+
if (!KNOWN_KEYS.includes(k) && v !== void 0) ordered[k] = v;
|
|
124
|
+
}
|
|
125
|
+
const trimmed = body.replace(/^\s*\n/, "").replace(/\s*$/, "");
|
|
126
|
+
return matter.stringify(trimmed ? `
|
|
127
|
+
${trimmed}
|
|
128
|
+
` : "", ordered).replace(/^(created|updated): '(\d{4}-\d{2}-\d{2})'$/gm, "$1: $2");
|
|
129
|
+
}
|
|
130
|
+
function ticketFromData(data, body, ctx) {
|
|
131
|
+
const fromName = /^([A-Za-z][A-Za-z0-9]*-\d+)/.exec(ctx.fileName)?.[1];
|
|
132
|
+
const id = optString(data.id) ?? fromName;
|
|
133
|
+
if (!id) return 'missing "id" in frontmatter';
|
|
134
|
+
const title = optString(data.title);
|
|
135
|
+
if (!title) return 'missing "title" in frontmatter';
|
|
136
|
+
const status = optString(data.status);
|
|
137
|
+
if (!status) return 'missing "status" in frontmatter';
|
|
138
|
+
let labels2 = [];
|
|
139
|
+
if (Array.isArray(data.labels)) labels2 = data.labels.map((l) => String(l));
|
|
140
|
+
else if (typeof data.labels === "string" && data.labels.trim())
|
|
141
|
+
labels2 = data.labels.split(",").map((l) => l.trim()).filter(Boolean);
|
|
142
|
+
const order = Number(data.order);
|
|
143
|
+
return {
|
|
144
|
+
id: id.toUpperCase(),
|
|
145
|
+
title,
|
|
146
|
+
status,
|
|
147
|
+
priority: optString(data.priority),
|
|
148
|
+
effort: optString(data.effort),
|
|
149
|
+
assignee: optString(data.assignee),
|
|
150
|
+
labels: labels2,
|
|
151
|
+
order: Number.isFinite(order) ? order : 0,
|
|
152
|
+
created: optString(data.created),
|
|
153
|
+
updated: optString(data.updated),
|
|
154
|
+
epic: ctx.epic,
|
|
155
|
+
body,
|
|
156
|
+
path: ctx.path
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function epicFromData(slug, data, body) {
|
|
160
|
+
return {
|
|
161
|
+
slug,
|
|
162
|
+
title: optString(data.title) ?? slug,
|
|
163
|
+
color: optString(data.color),
|
|
164
|
+
description: body.trim()
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/core/repository.ts
|
|
169
|
+
import { access, mkdir, readdir, readFile as readFile2, rename, rm, writeFile as writeFile2 } from "fs/promises";
|
|
170
|
+
import path from "path";
|
|
171
|
+
var BOARD_DIR = ".shipmd";
|
|
172
|
+
var ORDER_STEP = 1e3;
|
|
173
|
+
var EPIC_SLUG = /^[a-z0-9][a-z0-9_-]*$/;
|
|
174
|
+
async function exists(p) {
|
|
175
|
+
try {
|
|
176
|
+
await access(p);
|
|
177
|
+
return true;
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function findBoardDir(start) {
|
|
183
|
+
let dir = path.resolve(start);
|
|
184
|
+
for (; ; ) {
|
|
185
|
+
const candidate = path.join(dir, BOARD_DIR);
|
|
186
|
+
if (await exists(path.join(candidate, CONFIG_FILE))) return candidate;
|
|
187
|
+
const parent = path.dirname(dir);
|
|
188
|
+
if (parent === dir) return null;
|
|
189
|
+
dir = parent;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
var ShipmdError = class extends Error {
|
|
193
|
+
constructor(message, code = "invalid") {
|
|
194
|
+
super(message);
|
|
195
|
+
this.code = code;
|
|
196
|
+
}
|
|
197
|
+
code;
|
|
198
|
+
};
|
|
199
|
+
var Repository = class _Repository {
|
|
200
|
+
constructor(dir) {
|
|
201
|
+
this.dir = dir;
|
|
202
|
+
}
|
|
203
|
+
dir;
|
|
204
|
+
/** Open the board that contains `start` (searching parent folders). */
|
|
205
|
+
static async open(start = process.cwd()) {
|
|
206
|
+
const dir = await findBoardDir(start);
|
|
207
|
+
if (!dir) {
|
|
208
|
+
throw new ShipmdError(
|
|
209
|
+
`No ${BOARD_DIR}/ folder found here or in any parent folder. Run "shipmd init" first.`,
|
|
210
|
+
"not_found"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return new _Repository(dir);
|
|
214
|
+
}
|
|
215
|
+
/** Create `.shipmd/shipmd.json` inside `projectDir`. */
|
|
216
|
+
static async init(projectDir, opts = {}) {
|
|
217
|
+
const dir = path.join(path.resolve(projectDir), BOARD_DIR);
|
|
218
|
+
const file = path.join(dir, CONFIG_FILE);
|
|
219
|
+
if (await exists(file)) {
|
|
220
|
+
throw new ShipmdError(`${path.relative(process.cwd(), file) || file} already exists`, "conflict");
|
|
221
|
+
}
|
|
222
|
+
const folderName = path.basename(path.resolve(projectDir));
|
|
223
|
+
const name = opts.name ?? folderName;
|
|
224
|
+
const key = (opts.key ?? keyFromName(folderName)).toUpperCase();
|
|
225
|
+
const config = defaultConfig(name, key);
|
|
226
|
+
if (!/^[A-Z][A-Z0-9]*$/.test(key)) {
|
|
227
|
+
throw new ShipmdError(`Invalid key "${key}": use uppercase letters and digits, e.g. MB`);
|
|
228
|
+
}
|
|
229
|
+
await mkdir(dir, { recursive: true });
|
|
230
|
+
await writeConfig(file, config);
|
|
231
|
+
return new _Repository(dir);
|
|
232
|
+
}
|
|
233
|
+
get configPath() {
|
|
234
|
+
return path.join(this.dir, CONFIG_FILE);
|
|
235
|
+
}
|
|
236
|
+
config() {
|
|
237
|
+
return readConfig(this.configPath);
|
|
238
|
+
}
|
|
239
|
+
// ---------------------------------------------------------------- reading
|
|
240
|
+
async loadBoard() {
|
|
241
|
+
const config = await this.config();
|
|
242
|
+
const issues = [];
|
|
243
|
+
const tickets = [];
|
|
244
|
+
const epics = [];
|
|
245
|
+
const entries = await readdir(this.dir, { withFileTypes: true });
|
|
246
|
+
for (const entry of entries) {
|
|
247
|
+
if (entry.name.startsWith(".")) continue;
|
|
248
|
+
if (entry.isFile() && entry.name.endsWith(".md") && !entry.name.startsWith("_")) {
|
|
249
|
+
await this.readTicketInto(tickets, issues, entry.name, null);
|
|
250
|
+
} else if (entry.isDirectory()) {
|
|
251
|
+
const slug = entry.name;
|
|
252
|
+
let epic2 = { slug, title: slug, description: "" };
|
|
253
|
+
const epicFile = path.join(this.dir, slug, EPIC_FILE);
|
|
254
|
+
if (await exists(epicFile)) {
|
|
255
|
+
try {
|
|
256
|
+
const { data, body } = splitFrontmatter(await readFile2(epicFile, "utf8"));
|
|
257
|
+
epic2 = epicFromData(slug, data, body);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
issues.push({ path: `${slug}/${EPIC_FILE}`, message: e.message });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
epics.push(epic2);
|
|
263
|
+
const files = await readdir(path.join(this.dir, slug), { withFileTypes: true });
|
|
264
|
+
for (const f of files) {
|
|
265
|
+
if (f.isFile() && f.name.endsWith(".md") && !f.name.startsWith("_")) {
|
|
266
|
+
await this.readTicketInto(tickets, issues, `${slug}/${f.name}`, slug);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const seen = /* @__PURE__ */ new Map();
|
|
272
|
+
const unique = [];
|
|
273
|
+
for (const t of tickets.sort((a, b) => a.path.localeCompare(b.path))) {
|
|
274
|
+
const prev = seen.get(t.id);
|
|
275
|
+
if (prev) {
|
|
276
|
+
issues.push({ path: t.path, message: `duplicate id ${t.id} (also in ${prev.path})` });
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
seen.set(t.id, t);
|
|
280
|
+
unique.push(t);
|
|
281
|
+
}
|
|
282
|
+
const statusIds = new Set(config.statuses.map((s) => s.id));
|
|
283
|
+
for (const t of unique) {
|
|
284
|
+
if (!statusIds.has(t.status)) {
|
|
285
|
+
issues.push({ path: t.path, message: `unknown status "${t.status}"` });
|
|
286
|
+
}
|
|
287
|
+
if (t.effort && !config.efforts.includes(t.effort)) {
|
|
288
|
+
issues.push({ path: t.path, message: `unknown effort "${t.effort}"` });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
unique.sort((a, b) => a.order - b.order || compareIds(a.id, b.id));
|
|
292
|
+
epics.sort((a, b) => a.title.localeCompare(b.title));
|
|
293
|
+
return { config, epics, tickets: unique, issues };
|
|
294
|
+
}
|
|
295
|
+
async readTicketInto(tickets, issues, rel2, epic2) {
|
|
296
|
+
try {
|
|
297
|
+
const text = await readFile2(path.join(this.dir, rel2), "utf8");
|
|
298
|
+
const { data, body } = splitFrontmatter(text);
|
|
299
|
+
const t = ticketFromData(data, body, { path: rel2, epic: epic2, fileName: path.basename(rel2) });
|
|
300
|
+
if (typeof t === "string") issues.push({ path: rel2, message: t });
|
|
301
|
+
else tickets.push(t);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
issues.push({ path: rel2, message: `cannot parse: ${e.message}` });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async getTicket(id) {
|
|
307
|
+
const board = await this.loadBoard();
|
|
308
|
+
const t = board.tickets.find((x) => x.id === id.toUpperCase());
|
|
309
|
+
if (!t) throw new ShipmdError(`Ticket ${id} not found`, "not_found");
|
|
310
|
+
return t;
|
|
311
|
+
}
|
|
312
|
+
// ---------------------------------------------------------------- writing
|
|
313
|
+
async createEpic(slug, title, color2) {
|
|
314
|
+
if (!EPIC_SLUG.test(slug)) {
|
|
315
|
+
throw new ShipmdError(
|
|
316
|
+
`Invalid epic name "${slug}": use lowercase letters, digits, "-" or "_" (e.g. "auth")`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
const dir = path.join(this.dir, slug);
|
|
320
|
+
if (await exists(dir)) throw new ShipmdError(`Epic "${slug}" already exists`, "conflict");
|
|
321
|
+
await mkdir(dir);
|
|
322
|
+
const data = { title: title || slug };
|
|
323
|
+
if (color2) data.color = color2;
|
|
324
|
+
await writeFile2(path.join(dir, EPIC_FILE), joinFrontmatter(data, ""), "utf8");
|
|
325
|
+
return { slug, title: title || slug, color: color2, description: "" };
|
|
326
|
+
}
|
|
327
|
+
async createTicket(input) {
|
|
328
|
+
const board = await this.loadBoard();
|
|
329
|
+
const { config } = board;
|
|
330
|
+
const title = input.title?.trim();
|
|
331
|
+
if (!title) throw new ShipmdError("A ticket needs a title");
|
|
332
|
+
const status = input.status ?? config.defaultStatus;
|
|
333
|
+
this.checkStatus(config, status);
|
|
334
|
+
if (input.priority) this.checkPriority(config, input.priority);
|
|
335
|
+
if (input.effort) this.checkEffort(config, input.effort);
|
|
336
|
+
const epic2 = input.epic || null;
|
|
337
|
+
if (epic2) this.checkEpic(board, epic2);
|
|
338
|
+
const id = nextId(config.project.key, board);
|
|
339
|
+
const inColumn = board.tickets.filter((t) => t.status === status);
|
|
340
|
+
const order = Math.max(0, ...inColumn.map((t) => t.order)) + ORDER_STEP;
|
|
341
|
+
const date = today();
|
|
342
|
+
const data = {
|
|
343
|
+
id,
|
|
344
|
+
title,
|
|
345
|
+
status,
|
|
346
|
+
priority: input.priority,
|
|
347
|
+
effort: input.effort,
|
|
348
|
+
assignee: input.assignee?.trim() || void 0,
|
|
349
|
+
labels: input.labels?.length ? input.labels : void 0,
|
|
350
|
+
order,
|
|
351
|
+
created: date,
|
|
352
|
+
updated: date
|
|
353
|
+
};
|
|
354
|
+
const rel2 = toRel(epic2, ticketFileName(id, title));
|
|
355
|
+
await writeFile2(path.join(this.dir, rel2), joinFrontmatter(data, input.body ?? ""), {
|
|
356
|
+
encoding: "utf8",
|
|
357
|
+
flag: "wx"
|
|
358
|
+
});
|
|
359
|
+
return this.getTicket(id);
|
|
360
|
+
}
|
|
361
|
+
async updateTicket(id, patch) {
|
|
362
|
+
const board = await this.loadBoard();
|
|
363
|
+
const current = board.tickets.find((t) => t.id === id.toUpperCase());
|
|
364
|
+
if (!current) throw new ShipmdError(`Ticket ${id} not found`, "not_found");
|
|
365
|
+
const { config } = board;
|
|
366
|
+
const oldAbs = path.join(this.dir, current.path);
|
|
367
|
+
const { data, body } = splitFrontmatter(await readFile2(oldAbs, "utf8"));
|
|
368
|
+
if (patch.title !== void 0) {
|
|
369
|
+
const title = patch.title.trim();
|
|
370
|
+
if (!title) throw new ShipmdError("A ticket needs a title");
|
|
371
|
+
data.title = title;
|
|
372
|
+
}
|
|
373
|
+
if (patch.status !== void 0) {
|
|
374
|
+
this.checkStatus(config, patch.status);
|
|
375
|
+
data.status = patch.status;
|
|
376
|
+
if (patch.order === void 0 && patch.status !== current.status) {
|
|
377
|
+
const inColumn = board.tickets.filter((t) => t.status === patch.status);
|
|
378
|
+
data.order = Math.max(0, ...inColumn.map((t) => t.order)) + ORDER_STEP;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (patch.priority !== void 0) {
|
|
382
|
+
if (patch.priority) this.checkPriority(config, patch.priority);
|
|
383
|
+
data.priority = patch.priority || void 0;
|
|
384
|
+
}
|
|
385
|
+
if (patch.effort !== void 0) {
|
|
386
|
+
if (patch.effort) this.checkEffort(config, patch.effort);
|
|
387
|
+
data.effort = patch.effort || void 0;
|
|
388
|
+
}
|
|
389
|
+
if (patch.assignee !== void 0) data.assignee = patch.assignee?.trim() || void 0;
|
|
390
|
+
if (patch.labels !== void 0) data.labels = patch.labels.length ? patch.labels : void 0;
|
|
391
|
+
if (patch.order !== void 0) {
|
|
392
|
+
if (!Number.isFinite(patch.order)) throw new ShipmdError("order must be a number");
|
|
393
|
+
data.order = patch.order;
|
|
394
|
+
}
|
|
395
|
+
data.id = current.id;
|
|
396
|
+
data.updated = today();
|
|
397
|
+
let epic2 = current.epic;
|
|
398
|
+
if (patch.epic !== void 0) {
|
|
399
|
+
epic2 = patch.epic || null;
|
|
400
|
+
if (epic2) this.checkEpic(board, epic2);
|
|
401
|
+
}
|
|
402
|
+
const newRel = toRel(epic2, ticketFileName(current.id, String(data.title)));
|
|
403
|
+
const newAbs = path.join(this.dir, newRel);
|
|
404
|
+
const content = joinFrontmatter(data, patch.body !== void 0 ? patch.body : body);
|
|
405
|
+
if (newRel === current.path) {
|
|
406
|
+
await writeFile2(oldAbs, content, "utf8");
|
|
407
|
+
} else {
|
|
408
|
+
if (await exists(newAbs)) {
|
|
409
|
+
throw new ShipmdError(`Cannot move ${current.id}: ${newRel} already exists`, "conflict");
|
|
410
|
+
}
|
|
411
|
+
await writeFile2(oldAbs, content, "utf8");
|
|
412
|
+
await rename(oldAbs, newAbs);
|
|
413
|
+
}
|
|
414
|
+
return this.getTicket(current.id);
|
|
415
|
+
}
|
|
416
|
+
async deleteTicket(id) {
|
|
417
|
+
const t = await this.getTicket(id);
|
|
418
|
+
await rm(path.join(this.dir, t.path));
|
|
419
|
+
}
|
|
420
|
+
checkStatus(config, status) {
|
|
421
|
+
if (!config.statuses.some((s) => s.id === status)) {
|
|
422
|
+
const ids = config.statuses.map((s) => s.id).join(", ");
|
|
423
|
+
throw new ShipmdError(`Unknown status "${status}". Valid statuses: ${ids}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
checkPriority(config, priority) {
|
|
427
|
+
if (!config.priorities.includes(priority)) {
|
|
428
|
+
throw new ShipmdError(
|
|
429
|
+
`Unknown priority "${priority}". Valid priorities: ${config.priorities.join(", ")}`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
checkEffort(config, effort) {
|
|
434
|
+
if (!config.efforts.includes(effort)) {
|
|
435
|
+
throw new ShipmdError(
|
|
436
|
+
`Unknown effort "${effort}". Valid efforts: ${config.efforts.join(", ")}`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
checkEpic(board, epic2) {
|
|
441
|
+
if (!board.epics.some((e) => e.slug === epic2)) {
|
|
442
|
+
throw new ShipmdError(
|
|
443
|
+
`Epic "${epic2}" does not exist. Create it with: shipmd epic new ${epic2}`,
|
|
444
|
+
"not_found"
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
function toRel(epic2, fileName) {
|
|
450
|
+
return epic2 ? `${epic2}/${fileName}` : fileName;
|
|
451
|
+
}
|
|
452
|
+
function idNumber(id) {
|
|
453
|
+
const m = /-(\d+)$/.exec(id);
|
|
454
|
+
return m ? Number(m[1]) : NaN;
|
|
455
|
+
}
|
|
456
|
+
function compareIds(a, b) {
|
|
457
|
+
return (idNumber(a) || 0) - (idNumber(b) || 0) || a.localeCompare(b);
|
|
458
|
+
}
|
|
459
|
+
function nextId(key, board) {
|
|
460
|
+
let max = 0;
|
|
461
|
+
for (const t of board.tickets) {
|
|
462
|
+
if (t.id.startsWith(`${key}-`)) {
|
|
463
|
+
const n = idNumber(t.id);
|
|
464
|
+
if (Number.isFinite(n) && n > max) max = n;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return `${key}-${max + 1}`;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/server/server.ts
|
|
471
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
472
|
+
import { existsSync } from "fs";
|
|
473
|
+
import { fileURLToPath } from "url";
|
|
474
|
+
|
|
475
|
+
// src/server/routes.ts
|
|
476
|
+
import { Hono } from "hono";
|
|
477
|
+
import { streamSSE } from "hono/streaming";
|
|
478
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
479
|
+
import path2 from "path";
|
|
480
|
+
var MIME = {
|
|
481
|
+
".html": "text/html; charset=utf-8",
|
|
482
|
+
".js": "text/javascript; charset=utf-8",
|
|
483
|
+
".css": "text/css; charset=utf-8",
|
|
484
|
+
".svg": "image/svg+xml",
|
|
485
|
+
".png": "image/png",
|
|
486
|
+
".ico": "image/x-icon",
|
|
487
|
+
".json": "application/json",
|
|
488
|
+
".woff2": "font/woff2"
|
|
489
|
+
};
|
|
490
|
+
function str(v) {
|
|
491
|
+
return typeof v === "string" ? v : void 0;
|
|
492
|
+
}
|
|
493
|
+
function labels(v) {
|
|
494
|
+
if (v === void 0) return void 0;
|
|
495
|
+
if (!Array.isArray(v)) throw new ShipmdError("labels must be an array of strings");
|
|
496
|
+
return v.map((x) => String(x).trim()).filter(Boolean);
|
|
497
|
+
}
|
|
498
|
+
function createApp(repo, opts = {}) {
|
|
499
|
+
const app = new Hono();
|
|
500
|
+
app.onError((err, c) => {
|
|
501
|
+
if (err instanceof ShipmdError) {
|
|
502
|
+
const status = err.code === "not_found" ? 404 : err.code === "conflict" ? 409 : 400;
|
|
503
|
+
return c.json({ error: err.message }, status);
|
|
504
|
+
}
|
|
505
|
+
if (err instanceof SyntaxError) return c.json({ error: "Invalid JSON body" }, 400);
|
|
506
|
+
console.error(err);
|
|
507
|
+
return c.json({ error: err.message || "Internal error" }, 500);
|
|
508
|
+
});
|
|
509
|
+
app.use("/api/*", async (c, next) => {
|
|
510
|
+
if (c.req.method !== "GET") {
|
|
511
|
+
const origin = c.req.header("origin");
|
|
512
|
+
const host = c.req.header("host");
|
|
513
|
+
if (origin && host && new URL(origin).host !== host) {
|
|
514
|
+
return c.json({ error: "Cross-origin request refused" }, 403);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
await next();
|
|
518
|
+
});
|
|
519
|
+
app.get("/api/board", async (c) => c.json(await repo.loadBoard()));
|
|
520
|
+
app.get("/api/tickets/:id", async (c) => c.json(await repo.getTicket(c.req.param("id"))));
|
|
521
|
+
app.post("/api/tickets", async (c) => {
|
|
522
|
+
const b = await c.req.json();
|
|
523
|
+
const input = {
|
|
524
|
+
title: str(b.title) ?? "",
|
|
525
|
+
status: str(b.status),
|
|
526
|
+
priority: str(b.priority) || void 0,
|
|
527
|
+
effort: str(b.effort) || void 0,
|
|
528
|
+
assignee: str(b.assignee),
|
|
529
|
+
labels: labels(b.labels),
|
|
530
|
+
epic: str(b.epic) || null,
|
|
531
|
+
body: str(b.body)
|
|
532
|
+
};
|
|
533
|
+
return c.json(await repo.createTicket(input), 201);
|
|
534
|
+
});
|
|
535
|
+
app.patch("/api/tickets/:id", async (c) => {
|
|
536
|
+
const b = await c.req.json();
|
|
537
|
+
const patch = {};
|
|
538
|
+
if ("title" in b) patch.title = str(b.title) ?? "";
|
|
539
|
+
if ("status" in b) patch.status = str(b.status);
|
|
540
|
+
if ("priority" in b) patch.priority = str(b.priority) || null;
|
|
541
|
+
if ("effort" in b) patch.effort = str(b.effort) || null;
|
|
542
|
+
if ("assignee" in b) patch.assignee = str(b.assignee) || null;
|
|
543
|
+
if ("labels" in b) patch.labels = labels(b.labels);
|
|
544
|
+
if ("epic" in b) patch.epic = str(b.epic) || null;
|
|
545
|
+
if ("body" in b) patch.body = str(b.body) ?? "";
|
|
546
|
+
if ("order" in b) patch.order = Number(b.order);
|
|
547
|
+
return c.json(await repo.updateTicket(c.req.param("id"), patch));
|
|
548
|
+
});
|
|
549
|
+
app.post("/api/epics", async (c) => {
|
|
550
|
+
const b = await c.req.json();
|
|
551
|
+
return c.json(await repo.createEpic(str(b.slug) ?? "", str(b.title), str(b.color)), 201);
|
|
552
|
+
});
|
|
553
|
+
app.get(
|
|
554
|
+
"/api/events",
|
|
555
|
+
(c) => streamSSE(c, async (stream) => {
|
|
556
|
+
let wake;
|
|
557
|
+
let pending = false;
|
|
558
|
+
const unsubscribe = opts.subscribe?.(() => {
|
|
559
|
+
pending = true;
|
|
560
|
+
wake?.();
|
|
561
|
+
});
|
|
562
|
+
stream.onAbort(() => wake?.());
|
|
563
|
+
await stream.writeSSE({ event: "hello", data: "ok" });
|
|
564
|
+
while (!stream.aborted) {
|
|
565
|
+
await new Promise((resolve) => {
|
|
566
|
+
wake = resolve;
|
|
567
|
+
setTimeout(resolve, 25e3);
|
|
568
|
+
});
|
|
569
|
+
if (stream.aborted) break;
|
|
570
|
+
if (pending) {
|
|
571
|
+
pending = false;
|
|
572
|
+
await stream.writeSSE({ event: "changed", data: String(Date.now()) });
|
|
573
|
+
} else {
|
|
574
|
+
await stream.writeSSE({ event: "ping", data: "" });
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
unsubscribe?.();
|
|
578
|
+
})
|
|
579
|
+
);
|
|
580
|
+
app.all("/api/*", (c) => c.json({ error: "Not found" }, 404));
|
|
581
|
+
app.get("*", async (c) => {
|
|
582
|
+
if (!opts.webDir) return c.text('Dashboard not built. Run "npm run build".', 404);
|
|
583
|
+
const root = path2.resolve(opts.webDir);
|
|
584
|
+
const wanted = path2.resolve(root, "." + decodeURIComponent(new URL(c.req.url).pathname));
|
|
585
|
+
const candidates = wanted.startsWith(root + path2.sep) ? [wanted] : [];
|
|
586
|
+
candidates.push(path2.join(root, "index.html"));
|
|
587
|
+
for (const file of candidates) {
|
|
588
|
+
try {
|
|
589
|
+
const data = await readFile3(file);
|
|
590
|
+
const type = MIME[path2.extname(file)] ?? "application/octet-stream";
|
|
591
|
+
return c.body(data, 200, { "content-type": type });
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return c.text('Dashboard not built. Run "npm run build".', 404);
|
|
596
|
+
});
|
|
597
|
+
return app;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/server/watcher.ts
|
|
601
|
+
import { watch } from "chokidar";
|
|
602
|
+
function watchBoard(dir, onChange, delay = 120) {
|
|
603
|
+
let timer;
|
|
604
|
+
const watcher = watch(dir, { ignoreInitial: true, depth: 2 });
|
|
605
|
+
watcher.on("all", () => {
|
|
606
|
+
clearTimeout(timer);
|
|
607
|
+
timer = setTimeout(onChange, delay);
|
|
608
|
+
});
|
|
609
|
+
watcher.on("error", () => {
|
|
610
|
+
});
|
|
611
|
+
return async () => {
|
|
612
|
+
clearTimeout(timer);
|
|
613
|
+
await watcher.close();
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/server/server.ts
|
|
618
|
+
function defaultWebDir() {
|
|
619
|
+
const dir = fileURLToPath(new URL("./web/", import.meta.url));
|
|
620
|
+
return existsSync(dir) ? dir : void 0;
|
|
621
|
+
}
|
|
622
|
+
async function startServer(repo, opts = {}) {
|
|
623
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
624
|
+
const stopWatching = watchBoard(repo.dir, () => listeners.forEach((l) => l()));
|
|
625
|
+
const app = createApp(repo, {
|
|
626
|
+
webDir: opts.webDir ?? defaultWebDir(),
|
|
627
|
+
subscribe: (l) => {
|
|
628
|
+
listeners.add(l);
|
|
629
|
+
return () => listeners.delete(l);
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
const host = opts.host ?? "127.0.0.1";
|
|
633
|
+
const firstPort = opts.port ?? 4321;
|
|
634
|
+
for (let port = firstPort; port < firstPort + 20; port++) {
|
|
635
|
+
const server = createAdaptorServer({ fetch: app.fetch });
|
|
636
|
+
const ok = await new Promise((resolve, reject) => {
|
|
637
|
+
server.once(
|
|
638
|
+
"error",
|
|
639
|
+
(err) => err.code === "EADDRINUSE" && port !== 0 ? resolve(false) : reject(err)
|
|
640
|
+
);
|
|
641
|
+
server.listen(port, host, () => resolve(true));
|
|
642
|
+
});
|
|
643
|
+
if (!ok) continue;
|
|
644
|
+
const actual = server.address().port;
|
|
645
|
+
return {
|
|
646
|
+
url: `http://${host === "127.0.0.1" ? "localhost" : host}:${actual}`,
|
|
647
|
+
close: async () => {
|
|
648
|
+
await stopWatching();
|
|
649
|
+
await new Promise((resolve) => {
|
|
650
|
+
if ("closeAllConnections" in server) server.closeAllConnections();
|
|
651
|
+
server.close(() => resolve());
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
await stopWatching();
|
|
657
|
+
throw new Error(`No free port between ${firstPort} and ${firstPort + 19}`);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// package.json
|
|
661
|
+
var package_default = {
|
|
662
|
+
name: "shipmd",
|
|
663
|
+
version: "0.1.0",
|
|
664
|
+
description: "A local, file-based Jira: tickets are Markdown files, epics are folders, with a kanban dashboard.",
|
|
665
|
+
type: "module",
|
|
666
|
+
bin: {
|
|
667
|
+
shipmd: "dist/cli.js"
|
|
668
|
+
},
|
|
669
|
+
files: [
|
|
670
|
+
"dist"
|
|
671
|
+
],
|
|
672
|
+
engines: {
|
|
673
|
+
node: ">=22"
|
|
674
|
+
},
|
|
675
|
+
scripts: {
|
|
676
|
+
build: "tsup && vite build --config web/vite.config.ts",
|
|
677
|
+
"build:cli": "tsup",
|
|
678
|
+
"build:web": "vite build --config web/vite.config.ts",
|
|
679
|
+
"dev:web": "vite --config web/vite.config.ts",
|
|
680
|
+
test: "vitest run",
|
|
681
|
+
typecheck: "tsc --noEmit && tsc --noEmit -p web/tsconfig.json",
|
|
682
|
+
prepublishOnly: "npm run typecheck && npm test && npm run build"
|
|
683
|
+
},
|
|
684
|
+
keywords: [
|
|
685
|
+
"kanban",
|
|
686
|
+
"jira",
|
|
687
|
+
"markdown",
|
|
688
|
+
"tickets",
|
|
689
|
+
"local",
|
|
690
|
+
"cli"
|
|
691
|
+
],
|
|
692
|
+
license: "MIT",
|
|
693
|
+
dependencies: {
|
|
694
|
+
"@hono/node-server": "^2.1.11",
|
|
695
|
+
chokidar: "^6.0.0",
|
|
696
|
+
commander: "^15.1.0",
|
|
697
|
+
"gray-matter": "^4.0.3",
|
|
698
|
+
hono: "^4.13.23",
|
|
699
|
+
open: "^11.0.4",
|
|
700
|
+
zod: "^4.6.7"
|
|
701
|
+
},
|
|
702
|
+
devDependencies: {
|
|
703
|
+
"@dnd-kit/core": "^6.3.1",
|
|
704
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
705
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
706
|
+
"@types/node": "^26.6.11",
|
|
707
|
+
"@types/react": "^19.3.3",
|
|
708
|
+
"@types/react-dom": "^19.3.0",
|
|
709
|
+
"@vitejs/plugin-react": "^6.3.1",
|
|
710
|
+
react: "^19.3.1",
|
|
711
|
+
"react-dom": "^19.3.1",
|
|
712
|
+
"react-markdown": "^10.1.0",
|
|
713
|
+
tsup: "^9.0.0",
|
|
714
|
+
typescript: "^7.0.2",
|
|
715
|
+
vite: "^8.4.1",
|
|
716
|
+
vitest: "^5.1.2"
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// src/cli.ts
|
|
721
|
+
var color = (code) => (s) => process.stdout.isTTY && !process.env.NO_COLOR ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
722
|
+
var bold = color(1);
|
|
723
|
+
var dim = color(2);
|
|
724
|
+
var green = color(32);
|
|
725
|
+
var yellow = color(33);
|
|
726
|
+
function collect(value, previous = []) {
|
|
727
|
+
return previous.concat(value.split(",").map((v) => v.trim()).filter(Boolean));
|
|
728
|
+
}
|
|
729
|
+
async function warnIssues(repo) {
|
|
730
|
+
const { issues } = await repo.loadBoard();
|
|
731
|
+
for (const i of issues) console.error(yellow(`warning: ${i.path}: ${i.message}`));
|
|
732
|
+
}
|
|
733
|
+
function rel(repo, t) {
|
|
734
|
+
return path3.relative(process.cwd(), path3.join(repo.dir, t.path)) || t.path;
|
|
735
|
+
}
|
|
736
|
+
var program = new Command().name("shipmd").description("A local, file-based Jira: tickets are Markdown files, epics are folders.").version(package_default.version);
|
|
737
|
+
program.command("init").description("create .shipmd/ in the current folder").option("-k, --key <KEY>", "ticket id prefix, e.g. MB (default: from folder name)").option("-n, --name <name>", "project name (default: folder name)").action(async (opts) => {
|
|
738
|
+
const repo = await Repository.init(process.cwd(), opts);
|
|
739
|
+
const config = await repo.config();
|
|
740
|
+
console.log(green(`Created ${path3.relative(process.cwd(), repo.configPath)}`));
|
|
741
|
+
console.log(`Project "${config.project.name}", tickets will be numbered ${config.project.key}-1, ${config.project.key}-2, ...`);
|
|
742
|
+
console.log(dim('Next: shipmd new "My first ticket" then shipmd serve'));
|
|
743
|
+
});
|
|
744
|
+
program.command("new").description("create a ticket").argument("<title...>", "ticket title").option("-e, --epic <epic>", "epic (folder) to put it in").option("-s, --status <status>", "status id (default: config defaultStatus)").option("-p, --priority <priority>", "priority").option("-f, --effort <level>", "AI effort level (config efforts, e.g. low, medium, high, xhigh, max)").option("-a, --assignee <name>", "assignee").option("-l, --label <label>", "label (repeatable or comma-separated)", collect).option("-d, --description <text>", "Markdown description").action(async (titleWords, opts) => {
|
|
745
|
+
const repo = await Repository.open();
|
|
746
|
+
const t = await repo.createTicket({
|
|
747
|
+
title: titleWords.join(" "),
|
|
748
|
+
epic: opts.epic,
|
|
749
|
+
status: opts.status,
|
|
750
|
+
priority: opts.priority,
|
|
751
|
+
effort: opts.effort,
|
|
752
|
+
assignee: opts.assignee,
|
|
753
|
+
labels: opts.label,
|
|
754
|
+
body: opts.description
|
|
755
|
+
});
|
|
756
|
+
console.log(`${green("Created")} ${bold(t.id)} ${dim(rel(repo, t))}`);
|
|
757
|
+
});
|
|
758
|
+
program.command("list").alias("ls").description("list tickets grouped by status").option("-s, --status <status>", "only this status").option("-e, --epic <epic>", 'only this epic ("none" for tickets without epic)').option("-a, --assignee <name>", "only this assignee").option("-f, --effort <level>", 'only this AI effort level ("none" for tickets without one)').option("--json", "print JSON").action(async (opts) => {
|
|
759
|
+
const repo = await Repository.open();
|
|
760
|
+
const board = await repo.loadBoard();
|
|
761
|
+
const tickets = board.tickets.filter(
|
|
762
|
+
(t) => (!opts.status || t.status === opts.status) && (!opts.epic || (opts.epic === "none" ? t.epic === null : t.epic === opts.epic)) && (!opts.assignee || t.assignee === opts.assignee) && (!opts.effort || (opts.effort === "none" ? !t.effort : t.effort === opts.effort))
|
|
763
|
+
);
|
|
764
|
+
if (opts.json) {
|
|
765
|
+
console.log(JSON.stringify(tickets, null, 2));
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
const columns = [...board.config.statuses];
|
|
769
|
+
for (const t of tickets) {
|
|
770
|
+
if (!columns.some((c) => c.id === t.status)) columns.push({ id: t.status, name: `${t.status} (?)` });
|
|
771
|
+
}
|
|
772
|
+
const idWidth = Math.max(4, ...tickets.map((t) => t.id.length));
|
|
773
|
+
for (const col of columns) {
|
|
774
|
+
const inCol = tickets.filter((t) => t.status === col.id);
|
|
775
|
+
if (opts.status && !inCol.length) continue;
|
|
776
|
+
console.log(`
|
|
777
|
+
${bold(col.name)} ${dim(`(${inCol.length})`)}`);
|
|
778
|
+
for (const t of inCol) {
|
|
779
|
+
const meta = [t.epic && `#${t.epic}`, t.priority, t.effort && `effort:${t.effort}`, t.assignee && `@${t.assignee}`].filter(Boolean).join(" ");
|
|
780
|
+
console.log(` ${t.id.padEnd(idWidth)} ${t.title} ${dim(meta)}`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
for (const i of board.issues) console.error(yellow(`warning: ${i.path}: ${i.message}`));
|
|
784
|
+
});
|
|
785
|
+
program.command("show").description("print a ticket").argument("<id>", "ticket id, e.g. MB-1").action(async (id) => {
|
|
786
|
+
const repo = await Repository.open();
|
|
787
|
+
const t = await repo.getTicket(id);
|
|
788
|
+
console.log(`${bold(t.id)} ${t.title}`);
|
|
789
|
+
console.log(dim(`status: ${t.status} epic: ${t.epic ?? "-"} priority: ${t.priority ?? "-"} effort: ${t.effort ?? "-"} assignee: ${t.assignee ?? "-"} labels: ${t.labels.join(", ") || "-"}`));
|
|
790
|
+
console.log(dim(rel(repo, t)));
|
|
791
|
+
if (t.body.trim()) console.log(`
|
|
792
|
+
${t.body.trim()}`);
|
|
793
|
+
});
|
|
794
|
+
program.command("move").alias("mv").description("change the status and/or epic of a ticket").argument("<id>", "ticket id, e.g. MB-1").argument("[status]", "new status id").option("-e, --epic <epic>", 'move to this epic ("none" to take it out of its epic)').action(async (id, status, opts) => {
|
|
795
|
+
if (!status && opts.epic === void 0) {
|
|
796
|
+
throw new ShipmdError("Give a status and/or --epic, e.g. shipmd move MB-1 done");
|
|
797
|
+
}
|
|
798
|
+
const repo = await Repository.open();
|
|
799
|
+
const t = await repo.updateTicket(id, {
|
|
800
|
+
status,
|
|
801
|
+
epic: opts.epic === void 0 ? void 0 : opts.epic === "none" ? null : opts.epic
|
|
802
|
+
});
|
|
803
|
+
console.log(`${green("Moved")} ${bold(t.id)} \u2192 ${t.status}${t.epic ? ` #${t.epic}` : ""} ${dim(rel(repo, t))}`);
|
|
804
|
+
});
|
|
805
|
+
program.command("effort").description("set the AI effort level of a ticket").argument("<id>", "ticket id, e.g. MB-1").argument("<level>", 'effort level from config efforts, or "none" to clear it').action(async (id, level) => {
|
|
806
|
+
const repo = await Repository.open();
|
|
807
|
+
const t = await repo.updateTicket(id, { effort: level === "none" ? null : level });
|
|
808
|
+
console.log(`${green("Updated")} ${bold(t.id)} effort \u2192 ${t.effort ?? "-"} ${dim(rel(repo, t))}`);
|
|
809
|
+
});
|
|
810
|
+
var epic = program.command("epic").description("manage epics (folders)");
|
|
811
|
+
epic.command("new").description("create an epic").argument("<slug>", "folder name, e.g. auth").argument("[title...]", "display title").option("-c, --color <color>", "CSS color, e.g. #3b82f6").action(async (slug, title, opts) => {
|
|
812
|
+
const repo = await Repository.open();
|
|
813
|
+
const e = await repo.createEpic(slug, title.join(" ") || void 0, opts.color);
|
|
814
|
+
console.log(`${green("Created epic")} ${bold(e.slug)} ${dim(path3.relative(process.cwd(), path3.join(repo.dir, e.slug)))}`);
|
|
815
|
+
});
|
|
816
|
+
epic.command("list").alias("ls").description("list epics").action(async () => {
|
|
817
|
+
const repo = await Repository.open();
|
|
818
|
+
const board = await repo.loadBoard();
|
|
819
|
+
for (const e of board.epics) {
|
|
820
|
+
const count = board.tickets.filter((t) => t.epic === e.slug).length;
|
|
821
|
+
console.log(`${e.slug.padEnd(20)} ${e.title} ${dim(`(${count})`)}`);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
program.command("serve").description("open the kanban dashboard").addOption(new Option("-p, --port <port>", "port").default(4321).argParser((v) => Number(v))).option("--no-open", "do not open the browser").action(async (opts) => {
|
|
825
|
+
const repo = await Repository.open();
|
|
826
|
+
await warnIssues(repo);
|
|
827
|
+
const { url } = await startServer(repo, { port: opts.port });
|
|
828
|
+
console.log(`${green("shipmd")} running at ${bold(url)} ${dim("(Ctrl+C to stop)")}`);
|
|
829
|
+
if (opts.open) {
|
|
830
|
+
const { default: open } = await import("open");
|
|
831
|
+
await open(url).catch(() => {
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
program.parseAsync().catch((e) => {
|
|
836
|
+
if (e instanceof ShipmdError || e instanceof Error) {
|
|
837
|
+
console.error(`error: ${e.message}`);
|
|
838
|
+
} else {
|
|
839
|
+
console.error(e);
|
|
840
|
+
}
|
|
841
|
+
process.exit(1);
|
|
842
|
+
});
|
|
843
|
+
//# sourceMappingURL=cli.js.map
|