Repository navigation
Expand file tree
/
Copy pathrender.mjs
More file actions
97 lines (90 loc) · 2.8 KB
/
Copy pathrender.mjs
File metadata and controls
97 lines (90 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
/**
* Project-agnostic render entry point.
*
* node scripts/render.mjs <project-id> [revision-id]
* node scripts/render.mjs --project cv-reference --revision revision-009
*
* All doc-kind-specific knobs live in the project's
* template-project.json under the `render` block (see
* scripts/lib/render-runtime.mjs for the contract).
*
* The project is looked up in the resolved workspace: --root, else
* GRAPHCOMPOSE_FLOW_ROOT, else a graphcompose-flow/ directory found above the
* cwd, else this repository's own examples/ (see scripts/lib/workspace.mjs).
*
* Backward compat: scripts/render-cv-reference.mjs and
* scripts/render-invoice-reference.mjs are thin shims that delegate
* here. New reference projects do NOT need a per-project script —
* just a `render` block in their template-project.json.
*
* RENDER_NO_SKIP=1 forces the full pipeline regardless of revision scope.
*/
import { runRender } from "./lib/render-runtime.mjs";
import {
describeWorkspaceLine,
installRoot,
requireProjectDir,
resolveWorkspace,
} from "./lib/workspace.mjs";
const repoRoot = installRoot();
const { projectId, revisionId, root, dataFile, suffix } = parseArgs(process.argv.slice(2));
if (!projectId) {
console.error(
"usage: node scripts/render.mjs <project-id> [revision-id] [--root <workspace>]\n" +
" node scripts/render.mjs --project <id> --revision <id>",
);
process.exit(2);
}
const workspace = resolveWorkspace({ explicitRoot: root });
const banner = describeWorkspaceLine(workspace);
if (banner) console.log(banner);
let projectDir;
try {
projectDir = requireProjectDir(workspace, projectId);
} catch (err) {
console.error(err.message);
process.exit(2);
}
runRender({ repoRoot, projectId, revisionId, projectDir, dataFileOverride: dataFile, outputSuffix: suffix });
function parseArgs(args) {
let projectId = null;
let revisionId = null;
let root = null;
let dataFile = null;
let suffix = "";
const positional = [];
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (arg === "--project" || arg === "-p") {
projectId = args[i + 1];
i += 1;
continue;
}
if (arg === "--revision" || arg === "-r") {
revisionId = args[i + 1];
i += 1;
continue;
}
if (arg === "--root") {
root = args[i + 1];
i += 1;
continue;
}
if (arg === "--data-file") {
dataFile = args[i + 1];
i += 1;
continue;
}
if (arg === "--suffix") {
suffix = args[i + 1];
i += 1;
continue;
}
if (!arg.startsWith("--")) positional.push(arg);
}
projectId = projectId ?? positional[0] ?? null;
revisionId = revisionId ?? positional[1] ?? null;
if (!revisionId) revisionId = "revision-001";
return { projectId, revisionId, root, dataFile, suffix };
}