ShtukbaseStandard
包文件→ .shtukbase/packages/ontology/actions/graph.ts

actions/graph.ts

31 行, 1.5 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // Action `graph`: writes the static lens base/ontology/graph.html, one graph of all layers' types and links,
  2. // with the kit embedded. The kit comes with the lenses package (kit/ there; an install puts it at
  3. // .shtukbase/packages/lenses/kit/); SHTUK_KIT, when set, points to another copy. Without a kit the action says
  4. // what is missing and exits non-zero. Run from the project root; the one option is --out <file>.
  5. import { existsSync } from 'node:fs';
  6. import { join, resolve } from 'node:path';
  7. import { outOption } from './lib/lenscommon.ts';
  8. import { main } from './lib/render_layer_ontology.ts';
  9. // the lenses package next to this one: .shtukbase/packages/lenses/kit in a project, packages/lenses/kit in the standard
  10. const PLACES = [join(import.meta.dir, '..', '..', 'lenses', 'kit'), join('.shtukbase', 'packages', 'lenses', 'kit')];
  11. /** The kit folder: SHTUK_KIT when set, else the copy the lenses package brought; null when there is none. */
  12. function findKit(): string | null {
  13. const given = process.env.SHTUK_KIT ?? '';
  14. const kit = (given ? [given] : PLACES).find((k) => existsSync(join(k, 'kit', 'kit.js')));
  15. return kit ? resolve(kit) : null;
  16. }
  17. const kit = findKit();
  18. if (!kit) {
  19. console.log('kit not found: the ontology graph embeds the kit; it comes with the lenses package - install it '
  20. + '(or point SHTUK_KIT to another copy of the kit)');
  21. process.exit(2);
  22. }
  23. try {
  24. console.log('wrote', main('.', kit, outOption(process.argv.slice(2))));
  25. } catch (err) {
  26. console.error((err as Error).message);
  27. process.exit(1);
  28. }