ShtukbaseStandard
package file→ .shtukbase/packages/blueprint-software-factory/lib/factory.ts

lib/factory.ts

28 lines, 1.4 KB.

  1. // Shared bits of the software factory actions: the factory page head (test command, branch), git, and running a
  2. // package action of the installed copy with the same Bun.
  3. import { spawnSync } from 'node:child_process';
  4. import { existsSync } from 'node:fs';
  5. import { join } from 'node:path';
  6. import { pystr, readPage } from '../../collections/checks/lib/pages.ts';
  7. export const PAGE = 'base/software-factory.md';
  8. export const str = (v: unknown): string => (v === null || v === undefined ? '' : pystr(v).trim());
  9. /** The head of /base/software-factory.md, or {} when the page is gone. */
  10. export function factory(root = process.cwd()): Record<string, any> {
  11. const f = join(root, PAGE);
  12. return existsSync(f) ? readPage(f).fm : {};
  13. }
  14. /** `git <args>` in the project root: stdout trimmed, or null when git fails (not a repository, bad revision). */
  15. export function git(args: string[], root = process.cwd()): string | null {
  16. const r = spawnSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
  17. return r.status === 0 ? (r.stdout ?? '').trim() : null;
  18. }
  19. /** Runs `.shtukbase/packages/<pkg>/<file>` with this Bun from the project root; output captured. */
  20. export function pkgAction(pkg: string, file: string, args: string[], root = process.cwd()) {
  21. return spawnSync(process.execPath, [join(root, '.shtukbase/packages', pkg, file), ...args], {
  22. cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, env: { ...process.env },
  23. });
  24. }