@forumulate/cli 0.10.0 → 0.11.1
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/README.md +1 -1
- package/dist/api/command.d.ts +1 -1
- package/dist/api/command.d.ts.map +1 -1
- package/dist/api/command.js +1 -1
- package/dist/api/http.d.ts +6 -1
- package/dist/api/http.d.ts.map +1 -1
- package/dist/api/http.js +7 -1
- package/dist/api/http.js.map +1 -1
- package/dist/api/operations.json +1 -1
- package/dist/api/rows.d.ts +2 -0
- package/dist/api/rows.d.ts.map +1 -0
- package/dist/api/rows.js +9 -0
- package/dist/api/rows.js.map +1 -0
- package/dist/commands/completion.d.ts.map +1 -1
- package/dist/commands/completion.js +2 -0
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/job-wait.d.ts +2 -2
- package/dist/commands/job-wait.js +2 -2
- package/dist/content/library.d.ts +0 -9
- package/dist/content/library.d.ts.map +1 -1
- package/dist/content/library.js +12 -2
- package/dist/content/library.js.map +1 -1
- package/dist/help-commands.d.ts +1 -0
- package/dist/help-commands.d.ts.map +1 -1
- package/dist/help-commands.js +50 -1
- package/dist/help-commands.js.map +1 -1
- package/dist/help.d.ts +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +11 -1
- package/dist/help.js.map +1 -1
- package/dist/import/media.d.ts.map +1 -1
- package/dist/import/media.js +2 -1
- package/dist/import/media.js.map +1 -1
- package/dist/plan/command.d.ts +51 -0
- package/dist/plan/command.d.ts.map +1 -0
- package/dist/plan/command.js +182 -0
- package/dist/plan/command.js.map +1 -0
- package/dist/plan/document.d.ts +24 -0
- package/dist/plan/document.d.ts.map +1 -0
- package/dist/plan/document.js +208 -0
- package/dist/plan/document.js.map +1 -0
- package/dist/plan/markdown-dir.d.ts +73 -0
- package/dist/plan/markdown-dir.d.ts.map +1 -0
- package/dist/plan/markdown-dir.js +220 -0
- package/dist/plan/markdown-dir.js.map +1 -0
- package/dist/plan/output.d.ts +59 -0
- package/dist/plan/output.d.ts.map +1 -0
- package/dist/plan/output.js +102 -0
- package/dist/plan/output.js.map +1 -0
- package/dist/publish/api.d.ts.map +1 -1
- package/dist/publish/api.js +3 -2
- package/dist/publish/api.js.map +1 -1
- package/dist/publish/frontmatter.d.ts +8 -1
- package/dist/publish/frontmatter.d.ts.map +1 -1
- package/dist/publish/frontmatter.js +21 -0
- package/dist/publish/frontmatter.js.map +1 -1
- package/dist/publish/rows.d.ts +13 -0
- package/dist/publish/rows.d.ts.map +1 -0
- package/dist/publish/rows.js +21 -0
- package/dist/publish/rows.js.map +1 -0
- package/dist/publish/scan.d.ts +2 -0
- package/dist/publish/scan.d.ts.map +1 -1
- package/dist/publish/scan.js +1 -0
- package/dist/publish/scan.js.map +1 -1
- package/dist/publish-command.d.ts.map +1 -1
- package/dist/publish-command.js +2 -1
- package/dist/publish-command.js.map +1 -1
- package/dist/publish-dir.d.ts +54 -0
- package/dist/publish-dir.d.ts.map +1 -0
- package/dist/publish-dir.js +119 -0
- package/dist/publish-dir.js.map +1 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +37 -16
- package/dist/run.js.map +1 -1
- package/dist/translations/target.d.ts +0 -7
- package/dist/translations/target.d.ts.map +1 -1
- package/dist/translations/target.js +10 -2
- package/dist/translations/target.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runPlanCommand = runPlanCommand;
|
|
4
|
+
exports.hasChanges = hasChanges;
|
|
5
|
+
exports.batches = batches;
|
|
6
|
+
const api_1 = require("../publish/api");
|
|
7
|
+
const manifest_1 = require("../publish/manifest");
|
|
8
|
+
const rewrite_1 = require("../publish/rewrite");
|
|
9
|
+
const exit_codes_1 = require("../exit-codes");
|
|
10
|
+
const document_1 = require("./document");
|
|
11
|
+
const output_1 = require("./output");
|
|
12
|
+
async function runPlanCommand(flags, deps) {
|
|
13
|
+
const file = (0, manifest_1.findManifest)(deps.cwd ?? process.cwd(), flags.file);
|
|
14
|
+
if (!file) {
|
|
15
|
+
deps.err(`forumulate ${flags.command}: no forumulate.yaml here; pass the file: forumulate ${flags.command} path/to/forumulate.yaml`);
|
|
16
|
+
return exit_codes_1.EXIT.USAGE;
|
|
17
|
+
}
|
|
18
|
+
let doc;
|
|
19
|
+
try {
|
|
20
|
+
doc = (0, document_1.loadPlanDocument)(file);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
deps.err(e.message);
|
|
24
|
+
return exit_codes_1.EXIT.USAGE;
|
|
25
|
+
}
|
|
26
|
+
const org = flags.org ?? doc.org ?? deps.env?.FORUMULATE_ORG ?? process.env.FORUMULATE_ORG;
|
|
27
|
+
if (!org) {
|
|
28
|
+
deps.err('Which organization? Put `org:` in forumulate.yaml, pass --org, or set FORUMULATE_ORG.');
|
|
29
|
+
return exit_codes_1.EXIT.USAGE;
|
|
30
|
+
}
|
|
31
|
+
if (flags.prune)
|
|
32
|
+
doc.body.prune = true;
|
|
33
|
+
for (const s of doc.skipped)
|
|
34
|
+
deps.err(`skipped ${s}`);
|
|
35
|
+
const api = new api_1.PublishApi({
|
|
36
|
+
client: deps.client,
|
|
37
|
+
authed: true,
|
|
38
|
+
readOnly: flags.command === 'plan',
|
|
39
|
+
paceMs: 0,
|
|
40
|
+
upload: deps.upload,
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
let spaces = await spaceIds(api, org);
|
|
44
|
+
await settleImpliedCollections(api, org, doc, spaces);
|
|
45
|
+
await resolveAssets(api, org, doc, spaces, flags.command === 'apply');
|
|
46
|
+
const planned = await send(deps.client, org, doc.body, false);
|
|
47
|
+
if (flags.command === 'plan') {
|
|
48
|
+
if (flags.json)
|
|
49
|
+
deps.out(JSON.stringify(planned, null, 2));
|
|
50
|
+
else
|
|
51
|
+
(0, output_1.formatPlan)(planned, { diff: flags.diff, verbose: flags.verbose }).forEach((l) => deps.out(l));
|
|
52
|
+
if (!planned.ok)
|
|
53
|
+
return exit_codes_1.EXIT.FAILED;
|
|
54
|
+
return flags.check && hasChanges(planned) ? exit_codes_1.EXIT.FAILED : exit_codes_1.EXIT.OK;
|
|
55
|
+
}
|
|
56
|
+
// Pages pointing at local files in a space this apply creates: the space
|
|
57
|
+
// must exist before its assets can be uploaded, so everything but the
|
|
58
|
+
// pages lands first, then the uploads, then a fresh plan.
|
|
59
|
+
const answers = [];
|
|
60
|
+
let plan = planned;
|
|
61
|
+
if (pendingAssets(doc, spaces)) {
|
|
62
|
+
const { pages: _p, prune: _x, ...rest } = doc.body;
|
|
63
|
+
answers.push(await send(deps.client, org, rest, true));
|
|
64
|
+
if (!answers[0].ok)
|
|
65
|
+
return report(answers, flags, deps);
|
|
66
|
+
spaces = await spaceIds(api, org);
|
|
67
|
+
await resolveAssets(api, org, doc, spaces, true);
|
|
68
|
+
plan = await send(deps.client, org, doc.body, false);
|
|
69
|
+
}
|
|
70
|
+
for (const body of batches(doc.body, plan, flags.batch)) {
|
|
71
|
+
const answer = await send(deps.client, org, body, true);
|
|
72
|
+
answers.push(answer);
|
|
73
|
+
if (!answer.ok)
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
return report(answers, flags, deps);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
const err = e;
|
|
80
|
+
deps.err(`forumulate ${flags.command}: ${err.message ?? String(e)}`);
|
|
81
|
+
if (err.details && typeof err.details === 'object')
|
|
82
|
+
deps.err(JSON.stringify(err.details));
|
|
83
|
+
return (0, exit_codes_1.exitCodeForError)(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function report(answers, flags, deps) {
|
|
87
|
+
if (flags.json)
|
|
88
|
+
deps.out(JSON.stringify({ ok: answers.every((a) => a.ok), batches: answers }, null, 2));
|
|
89
|
+
else
|
|
90
|
+
(0, output_1.formatApply)(answers, { verbose: flags.verbose }).forEach((l) => deps.out(l));
|
|
91
|
+
const bad = answers.some((a) => !a.ok || a.steps.some((s) => s.status === 'failed' || ('readBack' in s && s.readBack === 'mismatch')));
|
|
92
|
+
return bad ? exit_codes_1.EXIT.FAILED : exit_codes_1.EXIT.OK;
|
|
93
|
+
}
|
|
94
|
+
/** The manifest door: a dry run, or `?apply=true`. */
|
|
95
|
+
async function send(client, org, body, apply) {
|
|
96
|
+
// The dry run writes nothing by the API's own contract (dry run is its
|
|
97
|
+
// default), so it is sent straight through rather than through the
|
|
98
|
+
// read-only guard that stops a planning bug from writing.
|
|
99
|
+
return client.request('PUT', `/orgs/${encodeURIComponent(org)}/manifest`, {
|
|
100
|
+
body,
|
|
101
|
+
...(apply ? { query: { apply: true } } : {}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function hasChanges(answer) {
|
|
105
|
+
return answer.steps.some((s) => s.action !== 'unchanged' && s.action !== 'unsupported');
|
|
106
|
+
}
|
|
107
|
+
async function spaceIds(api, org) {
|
|
108
|
+
const rows = await api.all(`/orgs/${encodeURIComponent(org)}/spaces`, 'spaces', { limit: 500 });
|
|
109
|
+
return new Map(rows.map((s) => [s.slug, s.id]));
|
|
110
|
+
}
|
|
111
|
+
async function settleImpliedCollections(api, org, doc, spaces) {
|
|
112
|
+
for (const [space, slugs] of doc.implied) {
|
|
113
|
+
const id = spaces.get(space);
|
|
114
|
+
if (!id)
|
|
115
|
+
continue;
|
|
116
|
+
const have = await api.all(`/orgs/${encodeURIComponent(org)}/spaces/${id}/collections`, 'collections');
|
|
117
|
+
(0, document_1.dropImplied)(doc.body, space, new Set(have.map((c) => c.slug)), slugs);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function pendingAssets(doc, spaces) {
|
|
121
|
+
return [...doc.assets.keys()].some((space) => !spaces.has(space));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Local references → asset URLs, in every page body, slot and metadata value.
|
|
125
|
+
* A plan only LOOKS an asset up (by content hash); a file not uploaded yet
|
|
126
|
+
* gets a placeholder, so the page shows as changing — which it will.
|
|
127
|
+
*/
|
|
128
|
+
async function resolveAssets(api, org, doc, spaces, upload) {
|
|
129
|
+
const pages = (0, document_1.pagesOf)(doc.body);
|
|
130
|
+
for (const [space, byPage] of doc.assets) {
|
|
131
|
+
const spaceId = spaces.get(space);
|
|
132
|
+
const existing = spaceId ? await api.assets(org, spaceId) : new Map();
|
|
133
|
+
for (const [key, refs] of byPage) {
|
|
134
|
+
const urls = new Map();
|
|
135
|
+
for (const [ref, abs] of refs) {
|
|
136
|
+
const known = (0, api_1.lookupAsset)(existing, abs);
|
|
137
|
+
if (known)
|
|
138
|
+
urls.set(ref, known);
|
|
139
|
+
else if (upload && spaceId)
|
|
140
|
+
urls.set(ref, await api.upload(org, spaceId, abs, existing));
|
|
141
|
+
else
|
|
142
|
+
urls.set(ref, `https://assets.invalid/${encodeURIComponent(ref)}`);
|
|
143
|
+
}
|
|
144
|
+
const [slug, locale] = key.split('@');
|
|
145
|
+
const page = pages.find((p) => p.space === space && p.slug === slug);
|
|
146
|
+
if (!page)
|
|
147
|
+
continue;
|
|
148
|
+
const target = (locale ? page.translations?.[locale] : page);
|
|
149
|
+
if (!target)
|
|
150
|
+
continue;
|
|
151
|
+
if (target.body)
|
|
152
|
+
target.body = (0, rewrite_1.rewriteAssets)(target.body, urls);
|
|
153
|
+
if (target.sections)
|
|
154
|
+
target.sections = Object.fromEntries(Object.entries(target.sections).map(([k, v]) => [k, (0, rewrite_1.rewriteAssets)(v, urls)]));
|
|
155
|
+
if (target.metadata)
|
|
156
|
+
target.metadata = (0, rewrite_1.rewriteValue)(target.metadata, urls);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The apply requests: every page the plan leaves alone is in all of them;
|
|
162
|
+
* the changed ones are added `size` at a time; the last request is the whole
|
|
163
|
+
* document, and is the only one that may prune.
|
|
164
|
+
*/
|
|
165
|
+
function batches(body, plan, size) {
|
|
166
|
+
const pages = (0, document_1.pagesOf)(body);
|
|
167
|
+
const changed = new Set(plan.steps
|
|
168
|
+
.filter((s) => s.unit === 'pages' && s.action !== 'unchanged' && s.action !== 'delete')
|
|
169
|
+
.map((s) => s.ref.split('@')[0]));
|
|
170
|
+
const settled = pages.filter((p) => !changed.has(`${p.space}/${p.slug}`));
|
|
171
|
+
const moving = pages.filter((p) => changed.has(`${p.space}/${p.slug}`));
|
|
172
|
+
const n = Math.max(1, size);
|
|
173
|
+
if (moving.length <= n)
|
|
174
|
+
return [body];
|
|
175
|
+
const out = [];
|
|
176
|
+
for (let end = n; end < moving.length; end += n) {
|
|
177
|
+
out.push({ ...body, pages: [...settled, ...moving.slice(0, end)], prune: false });
|
|
178
|
+
}
|
|
179
|
+
out.push(body);
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/plan/command.ts"],"names":[],"mappings":";;AAkDA,wCAkEC;AAsBD,gCAEC;AAgED,0BAiBC;AA7ND,wCAAyD;AAEzD,kDAAmD;AACnD,gDAAiE;AACjE,8CAAuD;AACvD,yCAAuF;AACvF,qCAAwE;AA4CjE,KAAK,UAAU,cAAc,CAAC,KAAgB,EAAE,IAAiB;IACtE,MAAM,IAAI,GAAG,IAAA,uBAAY,EAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACjE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,OAAO,wDAAwD,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;QACrI,OAAO,iBAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACD,IAAI,GAAiB,CAAC;IACtB,IAAI,CAAC;QACH,GAAG,GAAG,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 -0,0 +1,24 @@
|
|
|
1
|
+
import { type ScannedPage } from './markdown-dir';
|
|
2
|
+
export interface PlanDocument {
|
|
3
|
+
file: string;
|
|
4
|
+
org?: string;
|
|
5
|
+
/** The body for `PUT /orgs/{org}/manifest`. */
|
|
6
|
+
body: Record<string, unknown>;
|
|
7
|
+
/** Local files pages point at: space → page key (`slug`, `slug@es`) → reference → absolute path. */
|
|
8
|
+
assets: Map<string, Map<string, Map<string, string>>>;
|
|
9
|
+
/** Files left out on purpose (drafts), for the plan to name. */
|
|
10
|
+
skipped: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Collections this loader added to a space's `collections` (space → slugs),
|
|
13
|
+
* because a folder implies them. The command drops the ones the space
|
|
14
|
+
* already has: declaring an existing collection under a guessed name would
|
|
15
|
+
* plan a RENAME of it.
|
|
16
|
+
*/
|
|
17
|
+
implied: Map<string, string[]>;
|
|
18
|
+
}
|
|
19
|
+
export declare function loadPlanDocument(file: string): PlanDocument;
|
|
20
|
+
/** Take back implied collections the space turned out to have already. */
|
|
21
|
+
export declare function dropImplied(body: Record<string, unknown>, space: string, existing: Set<string>, implied: string[]): void;
|
|
22
|
+
/** The pages of a body, typed loosely: what the CLI rewrites and batches. */
|
|
23
|
+
export declare function pagesOf(body: Record<string, unknown>): ScannedPage[];
|
|
24
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/plan/document.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAuCnE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,oGAAoG;IACpG,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACtD,gEAAgE;IAChE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAChC;AAoDD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAoE3D;AAED,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAOxH;AAsBD,6EAA6E;AAC7E,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,EAAE,CAEpE"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadPlanDocument = loadPlanDocument;
|
|
4
|
+
exports.dropImplied = dropImplied;
|
|
5
|
+
exports.pagesOf = pagesOf;
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
const markdown_dir_1 = require("./markdown-dir");
|
|
10
|
+
/**
|
|
11
|
+
* `forumulate.yaml` as `forumulate plan` / `apply` read it (DX-D): the API's
|
|
12
|
+
* version-2 manifest (`PUT /orgs/{org}/manifest`), plus the few things only a
|
|
13
|
+
* file on disk can say.
|
|
14
|
+
*
|
|
15
|
+
* version: 2
|
|
16
|
+
* org: numestri # or --org / FORUMULATE_ORG
|
|
17
|
+
* spaces:
|
|
18
|
+
* - slug: about
|
|
19
|
+
* name: About
|
|
20
|
+
* type: ABOUT
|
|
21
|
+
* locales: [{ code: es, label: Español }]
|
|
22
|
+
* about: about.yaml # a file beside this one, or the map itself
|
|
23
|
+
* - slug: contact
|
|
24
|
+
* type: CONTACT
|
|
25
|
+
* contactForm: contact-form.yaml
|
|
26
|
+
* - slug: reference
|
|
27
|
+
* type: DOCS
|
|
28
|
+
* homeDoc: intro.md # the intro; intro.es.md beside it is its Spanish twin
|
|
29
|
+
* openapi: { spec: openapi.yaml, collection: API reference } # a spec file, read as text
|
|
30
|
+
* pages:
|
|
31
|
+
* - { dir: content/about, space: about } # a Markdown folder (see markdown-dir.ts)
|
|
32
|
+
* - { space: about, slug: press, title: Press, body: "…" } # or a page, inline
|
|
33
|
+
* sites: [...]
|
|
34
|
+
*
|
|
35
|
+
* Everything else is sent to the API exactly as written, and the API — not
|
|
36
|
+
* this file — decides what is valid: the same schemas its endpoints use, so a
|
|
37
|
+
* key the CLI let through cannot mean something the API would refuse. What is
|
|
38
|
+
* resolved here is only what needs the disk: a `dir` becomes its pages, a
|
|
39
|
+
* file name under `about` / `contactForm` becomes the map it holds, a
|
|
40
|
+
* `homeDoc` file becomes the intro (with its `.<code>.md` twins), and an
|
|
41
|
+
* `openapi[].spec` file name becomes the document's text.
|
|
42
|
+
*/
|
|
43
|
+
/** Keys only the CLI reads; never sent. */
|
|
44
|
+
const CLI_ONLY = ['org', '$schema'];
|
|
45
|
+
function asMap(v, where) {
|
|
46
|
+
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
47
|
+
throw new Error(`${where} must be a map`);
|
|
48
|
+
return v;
|
|
49
|
+
}
|
|
50
|
+
function readData(file) {
|
|
51
|
+
const text = (0, node_fs_1.readFileSync)(file, 'utf8');
|
|
52
|
+
try {
|
|
53
|
+
return /\.json$/i.test(file) ? JSON.parse(text) : (0, yaml_1.parse)(text);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new Error(`${file}: ${e.message}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `homeDoc: intro.md` → `{body, translations}`: the file, and each declared
|
|
61
|
+
* language's twin beside it (`intro.es.md`) — the suffix form a Markdown
|
|
62
|
+
* folder uses (markdown-dir.ts). A map stays a map.
|
|
63
|
+
*/
|
|
64
|
+
function homeDocOf(v, base, locales, where) {
|
|
65
|
+
if (typeof v !== 'string')
|
|
66
|
+
return v;
|
|
67
|
+
const file = (0, node_path_1.resolve)(base, v);
|
|
68
|
+
if (!(0, node_fs_1.existsSync)(file))
|
|
69
|
+
throw new Error(`${where}: ${v} does not exist`);
|
|
70
|
+
const stem = (0, node_path_1.join)((0, node_path_1.dirname)(file), (0, node_path_1.basename)(file, (0, node_path_1.extname)(file)));
|
|
71
|
+
const translations = {};
|
|
72
|
+
for (const code of locales) {
|
|
73
|
+
const twin = `${stem}.${code}${(0, node_path_1.extname)(file)}`;
|
|
74
|
+
if ((0, node_fs_1.existsSync)(twin))
|
|
75
|
+
translations[code] = { body: (0, node_fs_1.readFileSync)(twin, 'utf8') };
|
|
76
|
+
}
|
|
77
|
+
return { body: (0, node_fs_1.readFileSync)(file, 'utf8'), ...(Object.keys(translations).length ? { translations } : {}) };
|
|
78
|
+
}
|
|
79
|
+
/** `openapi: {spec: openapi.yaml}` → the file's text, which the import door parses (YAML or JSON). */
|
|
80
|
+
function openApiOf(v, base) {
|
|
81
|
+
const one = (e) => {
|
|
82
|
+
if (!e || typeof e !== 'object' || Array.isArray(e))
|
|
83
|
+
return e;
|
|
84
|
+
const spec = e.spec;
|
|
85
|
+
if (typeof spec !== 'string' || !/\.(ya?ml|json)$/i.test(spec))
|
|
86
|
+
return e;
|
|
87
|
+
const file = (0, node_path_1.resolve)(base, spec);
|
|
88
|
+
return (0, node_fs_1.existsSync)(file) ? { ...e, spec: (0, node_fs_1.readFileSync)(file, 'utf8') } : e;
|
|
89
|
+
};
|
|
90
|
+
return Array.isArray(v) ? v.map(one) : one(v);
|
|
91
|
+
}
|
|
92
|
+
/** `about: about.yaml` → the map in that file; a map stays a map. */
|
|
93
|
+
function fileOrMap(v, base, where) {
|
|
94
|
+
if (typeof v !== 'string')
|
|
95
|
+
return v;
|
|
96
|
+
return asMap(readData((0, node_path_1.resolve)(base, v)), `${where} (${v})`);
|
|
97
|
+
}
|
|
98
|
+
function loadPlanDocument(file) {
|
|
99
|
+
const raw = asMap(readData(file) ?? {}, file);
|
|
100
|
+
if (raw.version !== 2) {
|
|
101
|
+
throw new Error(`${file}: \`forumulate plan\` and \`apply\` read a \`version: 2\` manifest. ` +
|
|
102
|
+
(raw.version === undefined
|
|
103
|
+
? 'This looks like a `forumulate publish` file (one folder per space); add `version: 2` and the blocks in docs/guides/forumulate-yaml-apply.md, or keep using `forumulate publish`.'
|
|
104
|
+
: `It says version ${String(raw.version)}.`));
|
|
105
|
+
}
|
|
106
|
+
const base = (0, node_path_1.dirname)(file);
|
|
107
|
+
const body = {};
|
|
108
|
+
for (const [k, v] of Object.entries(raw))
|
|
109
|
+
if (!CLI_ONLY.includes(k))
|
|
110
|
+
body[k] = v;
|
|
111
|
+
const spaces = Array.isArray(body.spaces) ? body.spaces : [];
|
|
112
|
+
for (const [i, s] of spaces.entries()) {
|
|
113
|
+
asMap(s, `spaces[${i}]`);
|
|
114
|
+
if (s.about !== undefined)
|
|
115
|
+
s.about = fileOrMap(s.about, base, `spaces[${i}].about`);
|
|
116
|
+
if (s.contactForm !== undefined)
|
|
117
|
+
s.contactForm = fileOrMap(s.contactForm, base, `spaces[${i}].contactForm`);
|
|
118
|
+
const codes = Array.isArray(s.locales) ? s.locales.map((l) => String(l.code ?? '')) : [];
|
|
119
|
+
if (s.homeDoc !== undefined)
|
|
120
|
+
s.homeDoc = homeDocOf(s.homeDoc, base, codes, `spaces[${i}].homeDoc`);
|
|
121
|
+
if (s.openapi !== undefined)
|
|
122
|
+
s.openapi = openApiOf(s.openapi, base);
|
|
123
|
+
}
|
|
124
|
+
const localesOf = (slug) => {
|
|
125
|
+
const s = spaces.find((x) => x.slug === slug);
|
|
126
|
+
return Array.isArray(s?.locales) ? s.locales.map((l) => String(l.code ?? '')) : [];
|
|
127
|
+
};
|
|
128
|
+
const assets = new Map();
|
|
129
|
+
const skipped = [];
|
|
130
|
+
const implied = new Map();
|
|
131
|
+
if (body.pages !== undefined) {
|
|
132
|
+
if (!Array.isArray(body.pages))
|
|
133
|
+
throw new Error(`${file}: pages must be a list`);
|
|
134
|
+
const pages = [];
|
|
135
|
+
for (const [i, entry] of body.pages.entries()) {
|
|
136
|
+
const e = asMap(entry, `pages[${i}]`);
|
|
137
|
+
if (e.dir === undefined) {
|
|
138
|
+
pages.push(e);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const extra = Object.keys(e).filter((k) => !['dir', 'space', 'collection', 'locales'].includes(k));
|
|
142
|
+
if (extra.length)
|
|
143
|
+
throw new Error(`pages[${i}]: a folder entry takes dir, space, collection and locales; not ${extra.join(', ')}`);
|
|
144
|
+
if (typeof e.dir !== 'string' || typeof e.space !== 'string')
|
|
145
|
+
throw new Error(`pages[${i}]: a folder entry needs \`dir\` and \`space\``);
|
|
146
|
+
const extraLocales = Array.isArray(e.locales) ? e.locales.map(String) : [];
|
|
147
|
+
const scan = (0, markdown_dir_1.scanMarkdownDir)((0, node_path_1.resolve)(base, e.dir), {
|
|
148
|
+
space: e.space,
|
|
149
|
+
locales: [...localesOf(e.space), ...extraLocales],
|
|
150
|
+
...(typeof e.collection === 'string' ? { collection: e.collection } : {}),
|
|
151
|
+
});
|
|
152
|
+
pages.push(...scan.pages);
|
|
153
|
+
skipped.push(...scan.skipped.map((s) => `${e.dir}/${s}`));
|
|
154
|
+
const forSpace = assets.get(e.space) ?? new Map();
|
|
155
|
+
for (const [k, v] of scan.assets)
|
|
156
|
+
forSpace.set(k, v);
|
|
157
|
+
if (forSpace.size)
|
|
158
|
+
assets.set(e.space, forSpace);
|
|
159
|
+
const added = declareCollections(spaces, e.space, scan.collections);
|
|
160
|
+
if (added.length)
|
|
161
|
+
implied.set(e.space, [...(implied.get(e.space) ?? []), ...added]);
|
|
162
|
+
}
|
|
163
|
+
body.pages = pages;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
file,
|
|
167
|
+
...(typeof raw.org === 'string' ? { org: raw.org } : {}),
|
|
168
|
+
body,
|
|
169
|
+
assets,
|
|
170
|
+
skipped,
|
|
171
|
+
implied,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Take back implied collections the space turned out to have already. */
|
|
175
|
+
function dropImplied(body, space, existing, implied) {
|
|
176
|
+
const s = (Array.isArray(body.spaces) ? body.spaces : []).find((x) => x.slug === space);
|
|
177
|
+
if (!s || !Array.isArray(s.collections))
|
|
178
|
+
return;
|
|
179
|
+
s.collections = s.collections.filter((c) => !(implied.includes(String(c.slug)) && existing.has(String(c.slug))));
|
|
180
|
+
if (s.collections.length === 0)
|
|
181
|
+
delete s.collections;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A folder of pages is a collection; the space's `collections` block gets
|
|
185
|
+
* each one it does not already declare, so a tree with a `guides/` folder
|
|
186
|
+
* needs no second mention of `guides`. Only for a space the document itself
|
|
187
|
+
* declares — the API creates collections through that block.
|
|
188
|
+
*/
|
|
189
|
+
function declareCollections(spaces, slug, found) {
|
|
190
|
+
const space = spaces.find((s) => s.slug === slug);
|
|
191
|
+
if (!space || found.size === 0)
|
|
192
|
+
return [];
|
|
193
|
+
const list = Array.isArray(space.collections) ? space.collections : [];
|
|
194
|
+
const added = [];
|
|
195
|
+
for (const [cslug, name] of found) {
|
|
196
|
+
if (list.some((c) => c.slug === cslug))
|
|
197
|
+
continue;
|
|
198
|
+
list.push({ name, slug: cslug });
|
|
199
|
+
added.push(cslug);
|
|
200
|
+
}
|
|
201
|
+
space.collections = list;
|
|
202
|
+
return added;
|
|
203
|
+
}
|
|
204
|
+
/** The pages of a body, typed loosely: what the CLI rewrites and batches. */
|
|
205
|
+
function pagesOf(body) {
|
|
206
|
+
return Array.isArray(body.pages) ? body.pages : [];
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AC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6EAA6E;AAC7E,SAAgB,OAAO,CAAC,IAA6B;IACnD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,KAAuB,CAAC,CAAC,CAAC,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A folder of Markdown → the manifest's `pages` entries (DX-D).
|
|
3
|
+
*
|
|
4
|
+
* content/about/
|
|
5
|
+
* index.md → page `index`
|
|
6
|
+
* index.es.md → its Spanish twin (suffix form)
|
|
7
|
+
* 01-team.md → page `team`, order 1
|
|
8
|
+
* guides/setup.md → page `setup` in the `guides` collection
|
|
9
|
+
* es/guides/setup.md → the Spanish twin of guides/setup.md (folder form)
|
|
10
|
+
*
|
|
11
|
+
* Both twin forms are read, because both are what static-site generators
|
|
12
|
+
* write (Hugo and Jekyll put the language in the file name, Docusaurus and
|
|
13
|
+
* MkDocs in a folder) and a customer moving to us should not have to rename a
|
|
14
|
+
* tree to say the same thing. A suffix or a top folder only counts as a
|
|
15
|
+
* language when it is one of the space's declared language codes: `v1.2.md`
|
|
16
|
+
* and a folder called `de` in a German-only space are ordinary names.
|
|
17
|
+
*
|
|
18
|
+
* Front matter, per file: `title`, `slug`, `seoTitle`, `seoDescription`,
|
|
19
|
+
* `canonicalUrl`, `sections` (Markdown per slot), `collection`, `order`, `preset`
|
|
20
|
+
* (the kind of piece), `parentSlug` (the page it nests under), `params` (the kind's
|
|
21
|
+
* parameters), and
|
|
22
|
+
* `api` (the operation a page documents), and
|
|
23
|
+
* every page metadata key `forumulate publish` reads (same aliases: `description`
|
|
24
|
+
* is `seoDescription`, `canonical` is `canonicalUrl`, …). A key nothing reads
|
|
25
|
+
* is an error naming the file, not a value silently not published. `draft:
|
|
26
|
+
* true` leaves the file out. Without a `title`, the leading `# heading` is the
|
|
27
|
+
* title and is taken out of the body, as the importer does.
|
|
28
|
+
*/
|
|
29
|
+
export interface ScannedPage {
|
|
30
|
+
space: string;
|
|
31
|
+
slug: string;
|
|
32
|
+
title: string;
|
|
33
|
+
body?: string;
|
|
34
|
+
sections?: Record<string, string>;
|
|
35
|
+
seoTitle?: string;
|
|
36
|
+
seoDescription?: string;
|
|
37
|
+
canonicalUrl?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
collection?: string;
|
|
40
|
+
order?: number;
|
|
41
|
+
/** The kind of piece (`preset:`), the parent page's slug (`parentSlug:`) and the kind's parameters (`params:`) — source pages only. */
|
|
42
|
+
preset?: string | null;
|
|
43
|
+
parent?: string | null;
|
|
44
|
+
params?: Record<string, string | boolean>;
|
|
45
|
+
translations?: Record<string, Omit<ScannedPage, 'space' | 'collection' | 'order' | 'preset' | 'parent' | 'params' | 'translations' | 'slug'> & {
|
|
46
|
+
slug?: string;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
export interface ScanResult {
|
|
50
|
+
pages: ScannedPage[];
|
|
51
|
+
/** Folders read as collections: slug → name, for the space's `collections` block. */
|
|
52
|
+
collections: Map<string, string>;
|
|
53
|
+
/** Local files the pages point at, by page key (`slug` or `slug@es`): reference → absolute path. */
|
|
54
|
+
assets: Map<string, Map<string, string>>;
|
|
55
|
+
/** Files left out, and why (a draft). */
|
|
56
|
+
skipped: string[];
|
|
57
|
+
}
|
|
58
|
+
/** Front matter keys this reader consumes itself; the rest go through `pageMeta`. */
|
|
59
|
+
export declare const OWN: Set<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Read one directory into page entries for `space`. `locales` are the codes
|
|
62
|
+
* the space publishes in (from the document); `collection` puts every page of
|
|
63
|
+
* the directory into that collection unless a sub-folder or front matter says
|
|
64
|
+
* otherwise.
|
|
65
|
+
*/
|
|
66
|
+
export declare function scanMarkdownDir(dir: string, opts: {
|
|
67
|
+
space: string;
|
|
68
|
+
locales?: string[];
|
|
69
|
+
collection?: string;
|
|
70
|
+
}): ScanResult;
|
|
71
|
+
/** For messages: a path as the user wrote it. */
|
|
72
|
+
export declare function shown(root: string, abs: string): string;
|
|
73
|
+
//# sourceMappingURL=markdown-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-dir.d.ts","sourceRoot":"","sources":["../../src/plan/markdown-dir.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uIAAuI;IACvI,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC1C,YAAY,CAAC,EAAE,MAAM,CACnB,MAAM,EACN,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,Q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