包文件→ .shtukbase/packages/blueprint-software-factory/lib/factory.ts
lib/factory.ts
28 行, 1.4 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // Shared bits of the software factory actions: the factory page head (test command, branch), git, and running a
- // package action of the installed copy with the same Bun.
- import { spawnSync } from 'node:child_process';
- import { existsSync } from 'node:fs';
- import { join } from 'node:path';
- import { pystr, readPage } from '../../collections/checks/lib/pages.ts';
- export const PAGE = 'base/software-factory.md';
- export const str = (v: unknown): string => (v === null || v === undefined ? '' : pystr(v).trim());
- /** The head of /base/software-factory.md, or {} when the page is gone. */
- export function factory(root = process.cwd()): Record<string, any> {
- const f = join(root, PAGE);
- return existsSync(f) ? readPage(f).fm : {};
- }
- /** `git <args>` in the project root: stdout trimmed, or null when git fails (not a repository, bad revision). */
- export function git(args: string[], root = process.cwd()): string | null {
- const r = spawnSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
- return r.status === 0 ? (r.stdout ?? '').trim() : null;
- }
- /** Runs `.shtukbase/packages/<pkg>/<file>` with this Bun from the project root; output captured. */
- export function pkgAction(pkg: string, file: string, args: string[], root = process.cwd()) {
- return spawnSync(process.execPath, [join(root, '.shtukbase/packages', pkg, file), ...args], {
- cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, env: { ...process.env },
- });
- }