@diagc/cli 1.1.5 → 1.1.6
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/dist/api/handlers.js +18 -0
- package/dist/cli.js +25 -16
- package/package.json +2 -2
package/dist/api/handlers.js
CHANGED
|
@@ -192,9 +192,24 @@ export async function readComposedDiagram(diagramsDir, name) {
|
|
|
192
192
|
return { status: 409, body: { issues: [{ message: errMessage(e) }] } };
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
/** A 409 when `<name>.diagram.ts` exists: that diagram is TypeScript's, and a JSON
|
|
196
|
+
* twin beside it would compile to the same artifact, the last compile winning. */
|
|
197
|
+
async function ownedByTs(diagramsDir, name) {
|
|
198
|
+
const tsPath = path.join(diagramsDir, `${name}.diagram.ts`);
|
|
199
|
+
try {
|
|
200
|
+
await access(tsPath);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
return { status: 409, body: { issues: [{ message: `'${name}' is already TypeScript-owned (${tsPath})` }] } };
|
|
206
|
+
}
|
|
195
207
|
export async function saveDiagram(diagramsDir, name, payload) {
|
|
196
208
|
if (!isSafeName(name))
|
|
197
209
|
return { status: 400, body: { issues: [{ message: `Unsafe name '${name}'` }] } };
|
|
210
|
+
const owned = await ownedByTs(diagramsDir, name);
|
|
211
|
+
if (owned !== undefined)
|
|
212
|
+
return owned;
|
|
198
213
|
const p = payload;
|
|
199
214
|
const arraysOk = p !== null &&
|
|
200
215
|
p.version === 1 &&
|
|
@@ -238,6 +253,9 @@ export async function renameDiagram(diagramsDir, from, to) {
|
|
|
238
253
|
catch {
|
|
239
254
|
/* target free — proceed */
|
|
240
255
|
}
|
|
256
|
+
const owned = await ownedByTs(diagramsDir, to);
|
|
257
|
+
if (owned !== undefined)
|
|
258
|
+
return owned;
|
|
241
259
|
let model;
|
|
242
260
|
try {
|
|
243
261
|
model = JSON.parse(raw);
|
package/dist/cli.js
CHANGED
|
@@ -225,6 +225,15 @@ export function publishDirs(args) {
|
|
|
225
225
|
assetsDir: path.join(srcDir, 'assets'),
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
+
/** End the process once stdout and stderr have taken everything written to them:
|
|
229
|
+
* `process.exit` straight after a write drops what a pipe has not accepted yet. A
|
|
230
|
+
* zero-length write's callback runs after everything queued before it. It ends with
|
|
231
|
+
* `process.exit`, not `exitCode`, so an open handle (a keep-alive socket from a remote
|
|
232
|
+
* include, a Chrome process) cannot keep the CLI running. */
|
|
233
|
+
async function exit(code) {
|
|
234
|
+
await Promise.all([process.stdout, process.stderr].map((s) => new Promise((done) => s.write('', done))));
|
|
235
|
+
process.exit(code);
|
|
236
|
+
}
|
|
228
237
|
async function main() {
|
|
229
238
|
let args;
|
|
230
239
|
try {
|
|
@@ -234,12 +243,12 @@ async function main() {
|
|
|
234
243
|
catch (e) {
|
|
235
244
|
if (e instanceof HelpRequested) {
|
|
236
245
|
console.log(USAGE);
|
|
237
|
-
|
|
246
|
+
return exit(0);
|
|
238
247
|
}
|
|
239
248
|
if (e instanceof UnknownFlagError || e instanceof BadFlagValueError || e instanceof ArgNotTakenError) {
|
|
240
249
|
console.error(`diagc: ${e.message}\n`);
|
|
241
250
|
console.error(USAGE);
|
|
242
|
-
|
|
251
|
+
return exit(1);
|
|
243
252
|
}
|
|
244
253
|
throw e;
|
|
245
254
|
}
|
|
@@ -274,7 +283,7 @@ async function main() {
|
|
|
274
283
|
// the genuinely stale ones — skip the prune until every file compiles clean.
|
|
275
284
|
if (args.updateIncludes && args.files.length === 0 && !failed)
|
|
276
285
|
await snap.prune();
|
|
277
|
-
|
|
286
|
+
return exit(failed ? 1 : 0);
|
|
278
287
|
}
|
|
279
288
|
else if (args.command === 'lint') {
|
|
280
289
|
const files = args.files.length > 0 ? args.files : await fg(SOURCES);
|
|
@@ -289,7 +298,7 @@ async function main() {
|
|
|
289
298
|
else
|
|
290
299
|
for (const r of reports)
|
|
291
300
|
console.log(formatLintReport(r));
|
|
292
|
-
|
|
301
|
+
return exit(reports.length > 0 ? 1 : 0);
|
|
293
302
|
}
|
|
294
303
|
else if (args.command === 'watch') {
|
|
295
304
|
// Always locked, and --update-includes is refused here: watch is a long-running
|
|
@@ -297,9 +306,9 @@ async function main() {
|
|
|
297
306
|
// sense, so it has its own session rather than the shared one (mirrors
|
|
298
307
|
// studio.ts's own hardcoded 'locked' session).
|
|
299
308
|
const dir = args.files[0] ?? '.diagrams/src';
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
(await fg('**/*.diagram.{ts,json}', { cwd: dir })).length === 0)
|
|
309
|
+
// A directory that does not exist holds no diagrams either; a file is left alone.
|
|
310
|
+
if (!existsSync(dir) ||
|
|
311
|
+
(statSync(dir).isDirectory() && (await fg('**/*.diagram.{ts,json}', { cwd: dir })).length === 0))
|
|
303
312
|
warnNoSources(dir);
|
|
304
313
|
const watchSnap = snapshotSession(resolveInclude, '.diagrams', 'locked');
|
|
305
314
|
startWatch(dir, args.out, {
|
|
@@ -324,7 +333,7 @@ async function main() {
|
|
|
324
333
|
console.error(home.layout === 'monorepo'
|
|
325
334
|
? 'viewer shell not built — run `pnpm --filter @diagc/viewer build` in the monorepo.'
|
|
326
335
|
: `viewer shell missing from this install (${home.viewerShell}) — reinstall diagc.`);
|
|
327
|
-
|
|
336
|
+
return exit(1);
|
|
328
337
|
}
|
|
329
338
|
const dirs = publishDirs(args);
|
|
330
339
|
// Compile first so artifacts reflect current sources (TS + include expansion).
|
|
@@ -375,7 +384,7 @@ async function main() {
|
|
|
375
384
|
if (res.images.length > 0)
|
|
376
385
|
console.log(`✓ ${res.images.length} image(s) -> ${dirs.staticDir}`);
|
|
377
386
|
console.log(`✓ gallery -> ${res.gallery}`);
|
|
378
|
-
|
|
387
|
+
return exit(0);
|
|
379
388
|
}
|
|
380
389
|
else if (args.command === 'studio') {
|
|
381
390
|
// Studio's own compile-watch loop always resolves includes locked (see
|
|
@@ -390,20 +399,20 @@ async function main() {
|
|
|
390
399
|
if (name === undefined || name === '') {
|
|
391
400
|
console.error('diagc: eject needs a diagram name.');
|
|
392
401
|
console.error(USAGE);
|
|
393
|
-
|
|
402
|
+
return exit(1);
|
|
394
403
|
}
|
|
395
404
|
try {
|
|
396
405
|
const res = await ejectDiagram('.diagrams/src', args.out, name, { coreEntry: home.coreEntry });
|
|
397
406
|
console.log(`✓ ${res.tsPath}`);
|
|
398
|
-
|
|
407
|
+
return exit(0);
|
|
399
408
|
}
|
|
400
409
|
catch (e) {
|
|
401
410
|
console.error(errMessage(e));
|
|
402
|
-
|
|
411
|
+
return exit(1);
|
|
403
412
|
}
|
|
404
413
|
}
|
|
405
414
|
else if (args.command === 'diff') {
|
|
406
|
-
|
|
415
|
+
return exit(await runDiff(args, home));
|
|
407
416
|
}
|
|
408
417
|
else if (args.command === 'guide') {
|
|
409
418
|
// exitCode and a return, not process.exit: the guide is tens of kilobytes and
|
|
@@ -419,7 +428,7 @@ async function main() {
|
|
|
419
428
|
else if (args.command === 'init') {
|
|
420
429
|
if (args.files.length > 1) {
|
|
421
430
|
console.error(`diagc: init takes one name, got ${args.files.length} — e.g. diagc init shop --type c4`);
|
|
422
|
-
|
|
431
|
+
return exit(1);
|
|
423
432
|
}
|
|
424
433
|
process.exitCode = await runInit({
|
|
425
434
|
cwd: process.cwd(),
|
|
@@ -437,7 +446,7 @@ async function main() {
|
|
|
437
446
|
else {
|
|
438
447
|
console.error(`diagc: Unknown command '${args.command}'.`);
|
|
439
448
|
console.error(USAGE);
|
|
440
|
-
|
|
449
|
+
return exit(1);
|
|
441
450
|
}
|
|
442
451
|
}
|
|
443
452
|
/** `A..B` or `A` (against the working tree). */
|
|
@@ -526,5 +535,5 @@ async function runDiff(args, home) {
|
|
|
526
535
|
}
|
|
527
536
|
main().catch((e) => {
|
|
528
537
|
console.error(errMessage(e));
|
|
529
|
-
|
|
538
|
+
return exit(1);
|
|
530
539
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diagc/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Bogdan Frankovskyi",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"fast-glob": "^3.3.0",
|
|
45
45
|
"jiti": "^2.0.0",
|
|
46
46
|
"playwright-core": "^1.62.0",
|
|
47
|
-
"@diagc/core": "1.1.
|
|
47
|
+
"@diagc/core": "1.1.6"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|