@conloca/cli 0.2.0 → 0.2.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 +8 -3
- package/dist/conloca.js +91 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -111,7 +111,8 @@ conloca doctor [path] [--json] [--live]
|
|
|
111
111
|
|
|
112
112
|
Content checks, always:
|
|
113
113
|
|
|
114
|
-
- `sites.json` exists, parses, and declares `defaultLocale` plus a non-empty `locales` list for every site
|
|
114
|
+
- `sites.json` exists, parses, and declares `defaultLocale` plus a non-empty `locales` list for every site, each locale
|
|
115
|
+
one a content file name can carry: a two-letter language code, optionally with a region, like `en` or `en-US`
|
|
115
116
|
- every configured site has its `pages/` directory on disk (site-shaped directories missing from `sites.json` are
|
|
116
117
|
flagged too)
|
|
117
118
|
- every content file indexes cleanly — each file reported is one the CMS would otherwise silently drop
|
|
@@ -189,8 +190,12 @@ conloca page create --site <site> --collection <collection> --pathname <pathname
|
|
|
189
190
|
Writes a new `.vxjson` file under `<content root>/<site>/<collection>` with the same empty Puck payload the CMS writes
|
|
190
191
|
for a new page, then prints the page id and the created file path. It exits 1 when the site is unknown, the pathname is
|
|
191
192
|
invalid or already taken, or the write fails; validation failures name the offending option. `--json` prints
|
|
192
|
-
`{ok, id, path}` on success and `{ok: false, error, field?}` on failure — stdout carries exactly that one
|
|
193
|
-
progress lines go to stderr.
|
|
193
|
+
`{ok, id, path, warnings?}` on success and `{ok: false, error, field?}` on failure — stdout carries exactly that one
|
|
194
|
+
object, progress lines and warnings go to stderr.
|
|
195
|
+
|
|
196
|
+
A collection other than `pages` must be declared with `conlocaPages({ collection })` in the content config, or the build
|
|
197
|
+
fails on its pages, and given a route in `conlocaCMS({ routing })` to be served; `page create` warns when the config
|
|
198
|
+
plainly does not declare it.
|
|
194
199
|
|
|
195
200
|
Example:
|
|
196
201
|
|
package/dist/conloca.js
CHANGED
|
@@ -2357,6 +2357,7 @@ Working with a coding agent? \`.claude/skills/conloca/SKILL.md\` teaches it Conl
|
|
|
2357
2357
|
// src/commands/doctor.ts
|
|
2358
2358
|
import { readdir as readdir2, readFile as readFile5, stat } from "node:fs/promises";
|
|
2359
2359
|
import { join as join6, resolve as resolve3 } from "node:path";
|
|
2360
|
+
import { invalidLocaleMessage, isContentLocale } from "@conloca/content-api/content-path";
|
|
2360
2361
|
import { ContentIndex, FileSystemReaderBackend } from "@conloca/content-api/node";
|
|
2361
2362
|
|
|
2362
2363
|
// src/lib/content-root.ts
|
|
@@ -2565,6 +2566,64 @@ function extractCmsOptions(configText) {
|
|
|
2565
2566
|
const parsed = objectText === null ? null : parseObjectEntries(objectText);
|
|
2566
2567
|
return parsed === null ? { state: "dynamic" } : { state: "literal", ...parsed };
|
|
2567
2568
|
}
|
|
2569
|
+
var IN_VIEW_COLLECTION_CALLS = new Set(["conlocaPages", "conlocaData", "conlocaFragments", "defineCollection"]);
|
|
2570
|
+
function isInViewCollectionCall(value) {
|
|
2571
|
+
const call = /^([$A-Za-z_][$\w]*)\s*\(/.exec(value);
|
|
2572
|
+
if (call === null || !IN_VIEW_COLLECTION_CALLS.has(call[1]))
|
|
2573
|
+
return false;
|
|
2574
|
+
const argsStart = call[0].length - 1;
|
|
2575
|
+
return balancedSlice(value, argsStart) === value.slice(argsStart);
|
|
2576
|
+
}
|
|
2577
|
+
function collectionsAllInView(text) {
|
|
2578
|
+
const declaration = /\b(?:const|let|var)\s+collections\s*=\s*/.exec(text);
|
|
2579
|
+
const start = declaration === null ? -1 : declaration.index + declaration[0].length;
|
|
2580
|
+
const objectText = text[start] === "{" ? balancedSlice(text, start) : null;
|
|
2581
|
+
if (objectText === null)
|
|
2582
|
+
return false;
|
|
2583
|
+
const body = objectText.slice(1, -1);
|
|
2584
|
+
for (let i = 0;i < body.length; ) {
|
|
2585
|
+
const end = skipValue(body, i);
|
|
2586
|
+
const member = body.slice(i, end).trim();
|
|
2587
|
+
i = end + 1;
|
|
2588
|
+
if (member === "")
|
|
2589
|
+
continue;
|
|
2590
|
+
const key = /^(?:\.\.\.|(?:[$A-Za-z_][$\w]*|'[^']*'|"[^"]*")\s*:)/.exec(member);
|
|
2591
|
+
if (key === null || !isInViewCollectionCall(member.slice(key[0].length).trim()))
|
|
2592
|
+
return false;
|
|
2593
|
+
}
|
|
2594
|
+
return true;
|
|
2595
|
+
}
|
|
2596
|
+
function declaredPageCollections(configText) {
|
|
2597
|
+
const text = stripComments(configText);
|
|
2598
|
+
if (["createConlocaCollections", "conlocaLoader"].some((marker) => containsOutsideStrings(text, marker))) {
|
|
2599
|
+
return null;
|
|
2600
|
+
}
|
|
2601
|
+
if (/\bconlocaPages\s+as\b/.test(text) || !collectionsAllInView(text))
|
|
2602
|
+
return null;
|
|
2603
|
+
const declared = new Set;
|
|
2604
|
+
for (const call of text.matchAll(/\bconlocaPages\s*\(/g)) {
|
|
2605
|
+
const args = balancedSlice(text, call.index + call[0].length - 1);
|
|
2606
|
+
if (args === null)
|
|
2607
|
+
return null;
|
|
2608
|
+
const inner = args.slice(1, -1).trim().replace(/,$/, "").trim();
|
|
2609
|
+
if (inner === "") {
|
|
2610
|
+
declared.add("pages");
|
|
2611
|
+
continue;
|
|
2612
|
+
}
|
|
2613
|
+
const objectText = inner.startsWith("{") ? balancedSlice(inner, 0) : null;
|
|
2614
|
+
const options = objectText === inner ? parseObjectEntries(objectText) : null;
|
|
2615
|
+
if (options === null || options.hasSpread)
|
|
2616
|
+
return null;
|
|
2617
|
+
const raw = options.entries.get("collection");
|
|
2618
|
+
if (raw === undefined && /\bcollection\b/.test(inner))
|
|
2619
|
+
return null;
|
|
2620
|
+
const name = raw === undefined ? "pages" : stringLiteral(raw);
|
|
2621
|
+
if (name === null)
|
|
2622
|
+
return null;
|
|
2623
|
+
declared.add(name);
|
|
2624
|
+
}
|
|
2625
|
+
return declared.size > 0 ? declared : null;
|
|
2626
|
+
}
|
|
2568
2627
|
var ASTRO_CHECK_LABELS = {
|
|
2569
2628
|
C1: "content config registers Conloca collections",
|
|
2570
2629
|
C2: "siteName matches a sites.json entry",
|
|
@@ -3118,6 +3177,11 @@ var CONTENT_GLOB = "{**/*.{vxjson,mdx},data/**/*.json}";
|
|
|
3118
3177
|
function isLocaleList(value) {
|
|
3119
3178
|
return Array.isArray(value) && value.length > 0 && value.every((locale) => typeof locale === "string" && locale.trim() !== "");
|
|
3120
3179
|
}
|
|
3180
|
+
function declaredLocales(parsed) {
|
|
3181
|
+
const sites = isRecord(parsed.sites) ? Object.values(parsed.sites).filter(isRecord) : [];
|
|
3182
|
+
const lists = [parsed.globalLocales, ...sites.flatMap((site) => [site.locales, [site.defaultLocale]])];
|
|
3183
|
+
return lists.flatMap((list) => Array.isArray(list) ? list : []).filter((locale) => typeof locale === "string" && locale.trim() !== "");
|
|
3184
|
+
}
|
|
3121
3185
|
function counted(count, noun) {
|
|
3122
3186
|
return count === 1 ? `1 ${noun}` : `${count} ${noun}s`;
|
|
3123
3187
|
}
|
|
@@ -3183,7 +3247,13 @@ async function checkSitesFile(contentRoot) {
|
|
|
3183
3247
|
if (Array.isArray(parsed.globalLocales) && parsed.globalLocales.length > 0 && !isLocaleList(parsed.globalLocales)) {
|
|
3184
3248
|
problems.push({ check: "C3", level: "error", message: "globalLocales must contain only non-empty strings", path });
|
|
3185
3249
|
}
|
|
3186
|
-
|
|
3250
|
+
const unusable = problems.some((problem) => problem.level === "error");
|
|
3251
|
+
for (const locale of new Set(declaredLocales(parsed))) {
|
|
3252
|
+
if (!isContentLocale(locale)) {
|
|
3253
|
+
problems.push({ check: "C3", level: "error", message: invalidLocaleMessage(locale), path });
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
if (unusable) {
|
|
3187
3257
|
return { outcome, config: null };
|
|
3188
3258
|
}
|
|
3189
3259
|
const globalLocales = Array.isArray(parsed.globalLocales) && parsed.globalLocales.length > 0 ? parsed.globalLocales : ["en"];
|
|
@@ -3299,7 +3369,7 @@ import { join as join8, resolve as resolve4 } from "node:path";
|
|
|
3299
3369
|
// src/lib/sites-config.ts
|
|
3300
3370
|
import { readFile as readFile6, writeFile } from "node:fs/promises";
|
|
3301
3371
|
import { join as join7 } from "node:path";
|
|
3302
|
-
var DEFAULT_LOCALES = ["en"
|
|
3372
|
+
var DEFAULT_LOCALES = ["en"];
|
|
3303
3373
|
async function ensureSiteInSitesConfig(contentPath, siteName) {
|
|
3304
3374
|
const path = join7(contentPath, "sites.json");
|
|
3305
3375
|
let sitesConfig = { sites: {}, globalLocales: [...DEFAULT_LOCALES] };
|
|
@@ -4269,7 +4339,8 @@ Next steps:`);
|
|
|
4269
4339
|
}
|
|
4270
4340
|
|
|
4271
4341
|
// src/commands/page-create.ts
|
|
4272
|
-
import {
|
|
4342
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
4343
|
+
import { relative as relative2, resolve as resolve6 } from "node:path";
|
|
4273
4344
|
function toCliMessage(error, directory, options) {
|
|
4274
4345
|
switch (error.reason) {
|
|
4275
4346
|
case "missing_leading_slash":
|
|
@@ -4280,6 +4351,15 @@ function toCliMessage(error, directory, options) {
|
|
|
4280
4351
|
return error.message;
|
|
4281
4352
|
}
|
|
4282
4353
|
}
|
|
4354
|
+
async function undeclaredCollectionWarning(directory, collection) {
|
|
4355
|
+
const { findContentConfig } = await import("@conloca/astro-cms/checks");
|
|
4356
|
+
const configPath = findContentConfig(resolve6(directory));
|
|
4357
|
+
const text = configPath === null ? null : await readFile8(configPath, "utf-8").catch(() => null);
|
|
4358
|
+
const declared = text === null ? null : declaredPageCollections(text);
|
|
4359
|
+
if (configPath === null || declared === null || declared.has(collection))
|
|
4360
|
+
return null;
|
|
4361
|
+
return `${relative2(process.cwd(), configPath)} declares no page collection "${collection}", so the build fails on this page. Declare it with conlocaPages({ collection: '${collection}' }) and give it a route in conlocaCMS({ routing }).`;
|
|
4362
|
+
}
|
|
4283
4363
|
async function pageCreate(directory, options) {
|
|
4284
4364
|
try {
|
|
4285
4365
|
await createPage(directory, options);
|
|
@@ -4306,13 +4386,16 @@ async function createPage(directory, options) {
|
|
|
4306
4386
|
throw error;
|
|
4307
4387
|
}
|
|
4308
4388
|
const relPath = relative2(process.cwd(), written.filePath);
|
|
4389
|
+
const warning = await undeclaredCollectionWarning(directory, options.collection).catch(() => null);
|
|
4309
4390
|
if (json) {
|
|
4310
|
-
console.log(JSON.stringify({ ok: true, id: written.id, path: relPath }));
|
|
4311
|
-
|
|
4391
|
+
console.log(JSON.stringify({ ok: true, id: written.id, path: relPath, ...warning ? { warnings: [warning] } : {} }));
|
|
4392
|
+
} else {
|
|
4393
|
+
console.log(`✓ Created page ${written.pathname} (${written.id})`);
|
|
4394
|
+
console.log(` File: ${relPath}`);
|
|
4395
|
+
console.log("The page is now editable in the CMS.");
|
|
4312
4396
|
}
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
console.log("The page is now editable in the CMS.");
|
|
4397
|
+
if (warning)
|
|
4398
|
+
console.error(`Warning: ${warning}`);
|
|
4316
4399
|
}
|
|
4317
4400
|
|
|
4318
4401
|
// src/cli.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conloca/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"directory": "packages/cli"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@conloca/astro-cms": "0.2.
|
|
14
|
-
"@conloca/content-api": "0.2.
|
|
13
|
+
"@conloca/astro-cms": "0.2.1",
|
|
14
|
+
"@conloca/content-api": "0.2.1"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
17
|
"conloca": "./dist/conloca.js"
|