@velocity-astro/cms-astro 0.1.0-beta.11 → 0.1.0-beta.12
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/agents/cms.md +145 -0
- package/agents/skills/cms-add-content-type/SKILL.md +81 -0
- package/agents/skills/cms-add-form/SKILL.md +85 -0
- package/agents/skills/cms-add-section/SKILL.md +97 -0
- package/agents/skills/cms-add-to-site/SKILL.md +57 -0
- package/agents/skills/cms-connect-page/SKILL.md +64 -0
- package/agents/skills/cms-deploy/SKILL.md +64 -0
- package/agents/skills/cms-import-content/SKILL.md +63 -0
- package/agents/skills/cms-set-up-crm/SKILL.md +53 -0
- package/agents/skills/cms-write-plugin/SKILL.md +81 -0
- package/dist/agent-files.d.ts +23 -0
- package/dist/agent-files.d.ts.map +1 -0
- package/dist/agent-files.js +84 -0
- package/dist/agent-files.js.map +1 -0
- package/dist/check.d.ts +38 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +194 -0
- package/dist/check.js.map +1 -0
- package/dist/cli-content.d.ts +22 -0
- package/dist/cli-content.d.ts.map +1 -0
- package/dist/cli-content.js +309 -0
- package/dist/cli-content.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +128 -5
- package/dist/cli.js.map +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +1 -0
- package/dist/editor.js.map +1 -1
- package/dist/import-files.d.ts +30 -0
- package/dist/import-files.d.ts.map +1 -0
- package/dist/import-files.js +100 -0
- package/dist/import-files.js.map +1 -0
- package/dist/site-client.d.ts +37 -0
- package/dist/site-client.d.ts.map +1 -0
- package/dist/site-client.js +73 -0
- package/dist/site-client.js.map +1 -0
- package/package.json +8 -7
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cms-import-content
|
|
3
|
+
description: Bring existing content into Velocity CMS from another site or from files (WordPress, Markdown posts, a spreadsheet, JSON): map it onto content types, import entries and pictures as drafts, keep old addresses, and report what could not be taken. Use when asked to import, migrate, move content over, or load posts, products or listings from a file.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Import content
|
|
7
|
+
|
|
8
|
+
Read `.agents/cms.md` first ("Working with content"). Imports go through the site's API, as
|
|
9
|
+
drafts, so nothing reaches visitors until someone publishes.
|
|
10
|
+
|
|
11
|
+
## 1. Get access
|
|
12
|
+
|
|
13
|
+
The commands need the site running (or its live address) and an access token:
|
|
14
|
+
|
|
15
|
+
- `npx velocity-cms token "Import" --save` makes one from this computer and writes
|
|
16
|
+
`VELOCITY_CMS_TOKEN` to `.env` (it needs the site's database, so it works locally). For a
|
|
17
|
+
live site, ask an owner to make one in the editor under Settings, Access tokens.
|
|
18
|
+
- Start the dev server (`npm run dev`), or set `VELOCITY_CMS_ORIGIN` to the live address.
|
|
19
|
+
- Check with `npx velocity-cms types`.
|
|
20
|
+
|
|
21
|
+
## 2. Map the old content onto content types
|
|
22
|
+
|
|
23
|
+
1. Look at a few items of the old content and at `npx velocity-cms type <type>`. Make a table:
|
|
24
|
+
old field, new field key, and what to do with it.
|
|
25
|
+
2. If the site has no type for it, add one first (`cms-add-content-type`).
|
|
26
|
+
3. Keep old addresses: the slug is the last part of the old URL. Where the URL pattern differs
|
|
27
|
+
(`/2024/05/hello` became `/blog/hello`), tell the person which redirects the host needs.
|
|
28
|
+
|
|
29
|
+
Get the content into one of these:
|
|
30
|
+
|
|
31
|
+
- **Markdown files** with front matter (a folder of `.md`): front matter keys become fields,
|
|
32
|
+
the text under it goes into the type's formatted text field (`--body <key>` to choose).
|
|
33
|
+
WordPress: export with a tool such as `wordpress-export-to-markdown`, or read its REST API
|
|
34
|
+
(`/wp-json/wp/v2/posts`) and write the files yourself.
|
|
35
|
+
- **JSON**: a list of `{ "slug": "...", "locale": "en", "data": { "<key>": value } }`. Formatted
|
|
36
|
+
text may be `{ "markdown": "..." }`. Build this from a CSV or an export with a short script.
|
|
37
|
+
|
|
38
|
+
## 3. Try it, then import
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npx velocity-cms import posts ./old-posts --dry-run # says what would come in and what is left out
|
|
42
|
+
npx velocity-cms import posts ./old-posts --map date=publishedAt --map summary=excerpt
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Keys the type has no field for are left out and named; `--map old=new` keeps one.
|
|
46
|
+
- A picture an `image` field names by a path on this computer is uploaded, and the field holds
|
|
47
|
+
its name. A picture by address must be downloaded first (by you, with the person's OK). Pictures
|
|
48
|
+
inside the text are left out: formatted text holds no pictures.
|
|
49
|
+
- An entry whose slug is already there is left alone unless `--update`.
|
|
50
|
+
- Everything comes in as a draft. Add `--publish` only when the person asks, and only with a
|
|
51
|
+
token that may publish.
|
|
52
|
+
|
|
53
|
+
## 4. Report
|
|
54
|
+
|
|
55
|
+
Tell the person, from the command's own report:
|
|
56
|
+
|
|
57
|
+
- how many came in, and which were refused and why;
|
|
58
|
+
- what was left out (fields, pictures inside text) and what you suggest for each;
|
|
59
|
+
- which redirects the old addresses need;
|
|
60
|
+
- that the entries are drafts, and where to review them (`/admin`, the type's list).
|
|
61
|
+
|
|
62
|
+
Never import personal data (people's names, emails, orders) into a content type: contacts go to
|
|
63
|
+
the CRM (`cms-set-up-crm`), with the person's say-so.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cms-set-up-crm
|
|
3
|
+
description: Set up the built-in CRM of a Velocity CMS site: name the pipeline's stages, add custom fields to contacts and deals, say who gets new contacts, set a monthly target, mark which content types deals can be about, and connect forms to it. Use when asked to set up a sales pipeline, the CRM, deals, lead stages or lead routing.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Set up the CRM
|
|
7
|
+
|
|
8
|
+
Read `.agents/cms.md` first. The CRM is part of the CMS: whoever sends a form becomes a contact,
|
|
9
|
+
contacts move through the pipeline's stages, and deals are what a contact may buy. It is
|
|
10
|
+
personal data, so this skill needs a token allowed to read contacts and forms.
|
|
11
|
+
|
|
12
|
+
## 1. Get access
|
|
13
|
+
|
|
14
|
+
An owner makes a token in the editor (Settings, Access tokens) with "May read contacts, deals and
|
|
15
|
+
what forms received" ticked, or `npx velocity-cms token "CRM setup" --personal-data --save` on a
|
|
16
|
+
computer with the site's database. Put it in `VELOCITY_CMS_TOKEN`. The MCP tools below are the
|
|
17
|
+
same over `npx velocity-cms mcp` or the site's `/api/cms/mcp`.
|
|
18
|
+
|
|
19
|
+
## 2. Ask the person
|
|
20
|
+
|
|
21
|
+
Don't guess a sales process. Ask, and confirm before saving:
|
|
22
|
+
|
|
23
|
+
- the stages a lead goes through, in order, and which mean won or lost (for example: New,
|
|
24
|
+
Contacted, Tour booked, Offer, Won, Lost), with how likely an open stage is to close;
|
|
25
|
+
- the currency, and a monthly target if they track one;
|
|
26
|
+
- who on the team looks after new contacts (`list_team`); new contacts go to whoever of them
|
|
27
|
+
has the fewest;
|
|
28
|
+
- what else they note about a contact or a deal (budget, source, move-in date).
|
|
29
|
+
|
|
30
|
+
## 3. Save it
|
|
31
|
+
|
|
32
|
+
1. `get_pipeline`, then `save_pipeline` with every stage in order. Keep the `id` of a stage that
|
|
33
|
+
stays, so contacts stay in it; a stage left out is removed and its contacts move to the first.
|
|
34
|
+
Labels may be left out for the stages the CMS came with.
|
|
35
|
+
2. `get_custom_fields`, then `save_custom_fields` with the whole list for contacts and for deals.
|
|
36
|
+
Keep each field's `id`. Kinds: `text`, `email`, `phone`, `number`, `date`, `select`,
|
|
37
|
+
`boolean`, `url`. None can be required.
|
|
38
|
+
3. Deals about the site's content (a listing, a service): set `forDeals: true` on that content
|
|
39
|
+
type in the model and run the seed. A form on its pages with `startsDeal: true` then starts a
|
|
40
|
+
deal about the entry.
|
|
41
|
+
4. Forms: make sure each form names `contact` (`name`, `email`, `phone` keys) and, where an answer
|
|
42
|
+
belongs on the contact, `fills` (form field key to the custom field's id). See `cms-add-form`.
|
|
43
|
+
|
|
44
|
+
## 4. Never
|
|
45
|
+
|
|
46
|
+
- Never copy contacts, deals or submissions into a file in the repository, a log, or a page.
|
|
47
|
+
- Never import contacts without the person's say-so; when they give a file, the editor's
|
|
48
|
+
Contacts screen imports CSV, and `create_contact` adds one at a time.
|
|
49
|
+
|
|
50
|
+
## 5. Check
|
|
51
|
+
|
|
52
|
+
`get_pipeline` and `get_custom_fields` read back what you saved. Send a form on the dev server and
|
|
53
|
+
look at Contacts in `/admin`: the sender is there, in the first stage, given to someone.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cms-write-plugin
|
|
3
|
+
description: Connect Velocity CMS to another service or add to its editor with a plugin (send leads to a dispatch system, sync to a CRM, add a reading-time panel), after checking the plugins that ship. Fewest permissions, secrets kept as secrets, outside calls through cms.tasks. Use when asked to integrate, sync, send data somewhere, add a webhook or extend the editor.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Write a plugin or an integration
|
|
7
|
+
|
|
8
|
+
Read `.agents/cms.md` first ("Plugins").
|
|
9
|
+
|
|
10
|
+
## 1. Use what ships first
|
|
11
|
+
|
|
12
|
+
The CMS ships plugins an owner switches on under Plugins, with no code:
|
|
13
|
+
|
|
14
|
+
- **Webhooks**: posts what happens (a form sent, a contact or deal changed, a page published) to
|
|
15
|
+
addresses the owner lists, signed. Most "send X to our system" requests are this.
|
|
16
|
+
- **Mailchimp**: adds whoever sends a form to an audience, with consent.
|
|
17
|
+
- **Slack**: posts to a channel when a form is sent or a contact is made.
|
|
18
|
+
- **HubSpot**: copies contacts to HubSpot.
|
|
19
|
+
- **SEO**: judges each page's title and description.
|
|
20
|
+
|
|
21
|
+
If one fits, tell the person how to switch it on and fill its settings. Stop there.
|
|
22
|
+
|
|
23
|
+
## 2. Otherwise, write one
|
|
24
|
+
|
|
25
|
+
A file in the site (such as `cms/plugins/dispatch.mjs`) named in
|
|
26
|
+
`velocityCms({ plugins: ['./cms/plugins/dispatch.mjs'] })`:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { definePlugin } from '@velocity-astro/cms-astro';
|
|
30
|
+
|
|
31
|
+
export default definePlugin({
|
|
32
|
+
name: 'dispatch', // lowercase, unique
|
|
33
|
+
apiVersion: 1,
|
|
34
|
+
label: { en: 'Dispatch' },
|
|
35
|
+
version: '1.0.0',
|
|
36
|
+
permissions: ['submission:read'], // the fewest it needs; personal data only if it must
|
|
37
|
+
enabledByDefault: false,
|
|
38
|
+
settings: [{ key: 'form', type: 'text', label: { en: 'Form key to send' } }],
|
|
39
|
+
secrets: [{ key: 'apiKey', label: { en: 'API key' } }], // never a setting
|
|
40
|
+
setup(cms) {
|
|
41
|
+
cms.tasks.define('send', async (lead, task) => {
|
|
42
|
+
const key = await cms.secrets.get('apiKey');
|
|
43
|
+
if (!key) return;
|
|
44
|
+
const response = await fetch('https://api.dispatch.example/leads', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
// A piece of work may run twice: the id lets the other side tell.
|
|
47
|
+
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json', 'idempotency-key': task.id },
|
|
48
|
+
body: JSON.stringify(lead),
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) throw new Error(`Dispatch answered ${response.status}`); // the host retries
|
|
51
|
+
});
|
|
52
|
+
cms.events.on('submission.received', async ({ form, submission }) => {
|
|
53
|
+
const { form: wanted } = await cms.settings.get(); // settings by key; submission.data is by field id
|
|
54
|
+
if (form.key === wanted) await cms.tasks.add('send', { form: form.key, data: submission.data }, { label: 'New lead' });
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Check the exact names against `PluginContext` in `@velocity-astro/cms-core` (`plugin.ts`) before
|
|
61
|
+
relying on them; they are a promise to plugin authors, so they change only with `apiVersion`.
|
|
62
|
+
|
|
63
|
+
Rules:
|
|
64
|
+
|
|
65
|
+
- **Fewest permissions.** A plugin hears of a submission only if it declared `submission:read`.
|
|
66
|
+
- **A key is a secret** (`secrets`), saved by an owner one at a time, never shown again, read
|
|
67
|
+
only by `cms.secrets.get`.
|
|
68
|
+
- **Outside calls go through `cms.tasks`**, which retries for about a day and shows failures
|
|
69
|
+
under Plugins. A task's data may be personal: never log it, and keep errors to the host and
|
|
70
|
+
status, never the body.
|
|
71
|
+
- **Only public `https` addresses.** A host a person typed is checked with `cms.net.isPublic`.
|
|
72
|
+
- A plugin's failure never stops a save or a publish; don't catch and hide errors to "help".
|
|
73
|
+
- To change a page's head, use `pages.head` rules and call `pages.changed()`; nothing else of a
|
|
74
|
+
page is a plugin's.
|
|
75
|
+
- An editor part (`editor`) is one prebuilt module that builds only from the parts it is handed.
|
|
76
|
+
|
|
77
|
+
## 3. Check
|
|
78
|
+
|
|
79
|
+
Build, start the dev server, switch the plugin on under Plugins, fill its settings and secret,
|
|
80
|
+
and make it happen (send the form). Look under Plugins for its tasks. Run `npx velocity-cms check`.
|
|
81
|
+
Tell the person which secret they must paste in themselves.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files that teach an AI coding agent how to build on the CMS: the rules (`.agents/cms.md`)
|
|
3
|
+
* and the `cms-*` skills, kept in both places agents look for skills (`.agents/skills/` and
|
|
4
|
+
* `.claude/skills/`). They ship in this package (`agents/`) and travel with the CMS, so a site
|
|
5
|
+
* on plain Astro gets them too and they match the version the site runs. `velocity-cms init`
|
|
6
|
+
* installs them and `velocity-cms agents` brings them up to date; both replace what the CMS
|
|
7
|
+
* wrote and leave the site's own files alone.
|
|
8
|
+
*/
|
|
9
|
+
/** Where the rules go in a site. */
|
|
10
|
+
export declare const CMS_RULES_FILE = ".agents/cms.md";
|
|
11
|
+
/** The line the site's AGENTS.md gains, so an agent finds the rules. */
|
|
12
|
+
export declare const AGENTS_LINE = "- This site uses Velocity CMS. Before changing content types, pages, sections, forms, menus or how the site is deployed, read `.agents/cms.md` and use the `cms-*` skills.";
|
|
13
|
+
/** The version of the CMS the files come from. The rules carry it, and `velocity-cms check` compares it. */
|
|
14
|
+
export declare const AGENT_FILES_VERSION: string;
|
|
15
|
+
/** The skills this version ships, by name. */
|
|
16
|
+
export declare function shippedSkills(): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Installs the rules and skills in a site's folder and points its AGENTS.md at them (making one
|
|
19
|
+
* if it has none, and a CLAUDE.md that reads it). A skill the CMS no longer ships is removed; a
|
|
20
|
+
* skill of the site's own, whose name does not start with `cms-`, is never touched.
|
|
21
|
+
*/
|
|
22
|
+
export declare function installAgentFiles(dir: string, print: (line: string) => void): void;
|
|
23
|
+
//# sourceMappingURL=agent-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-files.d.ts","sourceRoot":"","sources":["../src/agent-files.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,oCAAoC;AACpC,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAG/C,wEAAwE;AACxE,eAAO,MAAM,WAAW,+KAA+K,CAAC;AAIxM,4GAA4G;AAC5G,eAAO,MAAM,mBAAmB,EAAE,MAA0H,CAAC;AAE7J,8CAA8C;AAC9C,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAMxC;AAeD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAqClF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* The files that teach an AI coding agent how to build on the CMS: the rules (`.agents/cms.md`)
|
|
5
|
+
* and the `cms-*` skills, kept in both places agents look for skills (`.agents/skills/` and
|
|
6
|
+
* `.claude/skills/`). They ship in this package (`agents/`) and travel with the CMS, so a site
|
|
7
|
+
* on plain Astro gets them too and they match the version the site runs. `velocity-cms init`
|
|
8
|
+
* installs them and `velocity-cms agents` brings them up to date; both replace what the CMS
|
|
9
|
+
* wrote and leave the site's own files alone.
|
|
10
|
+
*/
|
|
11
|
+
/** Where the rules go in a site. */
|
|
12
|
+
export const CMS_RULES_FILE = '.agents/cms.md';
|
|
13
|
+
/** The folders a skill is written to, one copy in each. */
|
|
14
|
+
const SKILL_FOLDERS = ['.agents/skills', '.claude/skills'];
|
|
15
|
+
/** The line the site's AGENTS.md gains, so an agent finds the rules. */
|
|
16
|
+
export const AGENTS_LINE = '- This site uses Velocity CMS. Before changing content types, pages, sections, forms, menus or how the site is deployed, read `.agents/cms.md` and use the `cms-*` skills.';
|
|
17
|
+
const source = new URL('../agents/', import.meta.url);
|
|
18
|
+
/** The version of the CMS the files come from. The rules carry it, and `velocity-cms check` compares it. */
|
|
19
|
+
export const AGENT_FILES_VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
20
|
+
/** The skills this version ships, by name. */
|
|
21
|
+
export function shippedSkills() {
|
|
22
|
+
return fs
|
|
23
|
+
.readdirSync(new URL('skills/', source), { withFileTypes: true })
|
|
24
|
+
.filter((entry) => entry.isDirectory() && entry.name.startsWith('cms-'))
|
|
25
|
+
.map((entry) => entry.name)
|
|
26
|
+
.sort();
|
|
27
|
+
}
|
|
28
|
+
function stamped(text) {
|
|
29
|
+
const mark = `<!-- velocity-cms ${AGENT_FILES_VERSION}. Written by \`velocity-cms agents\`, which replaces this file: keep your own notes in AGENTS.md. -->`;
|
|
30
|
+
return `${mark}\n\n${text}`;
|
|
31
|
+
}
|
|
32
|
+
/** Writes a file unless it already holds exactly that. Answers whether it changed. */
|
|
33
|
+
function write(file, text) {
|
|
34
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === text)
|
|
35
|
+
return false;
|
|
36
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
37
|
+
fs.writeFileSync(file, text);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Installs the rules and skills in a site's folder and points its AGENTS.md at them (making one
|
|
42
|
+
* if it has none, and a CLAUDE.md that reads it). A skill the CMS no longer ships is removed; a
|
|
43
|
+
* skill of the site's own, whose name does not start with `cms-`, is never touched.
|
|
44
|
+
*/
|
|
45
|
+
export function installAgentFiles(dir, print) {
|
|
46
|
+
const at = (file) => path.join(dir, file);
|
|
47
|
+
const changed = [];
|
|
48
|
+
if (write(at(CMS_RULES_FILE), stamped(fs.readFileSync(new URL('cms.md', source), 'utf8'))))
|
|
49
|
+
changed.push(CMS_RULES_FILE);
|
|
50
|
+
const skills = shippedSkills();
|
|
51
|
+
for (const folder of SKILL_FOLDERS) {
|
|
52
|
+
for (const skill of skills) {
|
|
53
|
+
if (write(at(`${folder}/${skill}/SKILL.md`), fs.readFileSync(new URL(`skills/${skill}/SKILL.md`, source), 'utf8')))
|
|
54
|
+
changed.push(`${folder}/${skill}`);
|
|
55
|
+
}
|
|
56
|
+
// A cms- skill an earlier version wrote and this one does not ship.
|
|
57
|
+
if (!fs.existsSync(at(folder)))
|
|
58
|
+
continue;
|
|
59
|
+
for (const entry of fs.readdirSync(at(folder), { withFileTypes: true })) {
|
|
60
|
+
if (entry.isDirectory() && entry.name.startsWith('cms-') && !skills.includes(entry.name)) {
|
|
61
|
+
fs.rmSync(at(`${folder}/${entry.name}`), { recursive: true });
|
|
62
|
+
changed.push(`${folder}/${entry.name} (removed)`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const agents = at('AGENTS.md');
|
|
67
|
+
if (!fs.existsSync(agents)) {
|
|
68
|
+
fs.writeFileSync(agents, `# Agent guide\n\nInstructions for AI coding agents working on this site.\n\n${AGENTS_LINE}\n`);
|
|
69
|
+
changed.push('AGENTS.md');
|
|
70
|
+
if (!fs.existsSync(at('CLAUDE.md'))) {
|
|
71
|
+
fs.writeFileSync(at('CLAUDE.md'), '@AGENTS.md\n');
|
|
72
|
+
changed.push('CLAUDE.md');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const text = fs.readFileSync(agents, 'utf8');
|
|
77
|
+
if (!text.includes(CMS_RULES_FILE)) {
|
|
78
|
+
fs.writeFileSync(agents, `${text}${text.endsWith('\n') ? '' : '\n'}\n${AGENTS_LINE}\n`);
|
|
79
|
+
changed.push('AGENTS.md');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
print(changed.length > 0 ? `Agent files: wrote ${changed.join(', ')}.` : 'Agent files: already up to date.');
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=agent-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-files.js","sourceRoot":"","sources":["../src/agent-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;GAOG;AAEH,oCAAoC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAC/C,2DAA2D;AAC3D,MAAM,aAAa,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;AAC3D,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,4KAA4K,CAAC;AAExM,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEtD,4GAA4G;AAC5G,MAAM,CAAC,MAAM,mBAAmB,GAAY,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAyB,CAAC,OAAO,CAAC;AAE7J,8CAA8C;AAC9C,MAAM,UAAU,aAAa;IAC3B,OAAO,EAAE;SACN,WAAW,CAAC,IAAI,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAChE,MAAM,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QACzH,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YACpC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC;YAClD,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YACnC,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC;YACxF,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,sBAAsB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC;AAC/G,CAAC"}
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ContentTypeDef } from '@velocity-astro/cms-core';
|
|
2
|
+
/**
|
|
3
|
+
* `velocity-cms check`: inspects a site on the CMS and names each problem with its file, the
|
|
4
|
+
* rule in `.agents/cms.md` it breaks and the fix, so an agent (or a person) can prove its work
|
|
5
|
+
* before saying it is done. It reads the site's files and, where it can, the content types in
|
|
6
|
+
* its database; it changes nothing.
|
|
7
|
+
*/
|
|
8
|
+
export type FindingLevel = 'error' | 'warning';
|
|
9
|
+
export interface Finding {
|
|
10
|
+
/** A short name for the rule, such as `prerendered-cms-page`. */
|
|
11
|
+
readonly rule: string;
|
|
12
|
+
readonly level: FindingLevel;
|
|
13
|
+
/** The file it is about, from the site's folder. */
|
|
14
|
+
readonly file: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
/** The heading in `.agents/cms.md` the rule is written under. */
|
|
17
|
+
readonly see: string;
|
|
18
|
+
readonly fix: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CheckResult {
|
|
21
|
+
readonly findings: readonly Finding[];
|
|
22
|
+
/** What the check could not look at, and why: a database it could not read, say. */
|
|
23
|
+
readonly skipped: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export interface CheckOptions {
|
|
26
|
+
readonly dir: string;
|
|
27
|
+
/** The content types, as the site's database holds them. Left out, the rules that need them are skipped. */
|
|
28
|
+
readonly types?: readonly ContentTypeDef[];
|
|
29
|
+
/** Why there are no types, when there are none. */
|
|
30
|
+
readonly typesSkipped?: string;
|
|
31
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
32
|
+
}
|
|
33
|
+
/** The keys of an object literal that maps blocks to components: `export const blocks = { hero: Hero, 'call-to-action': Cta }`. */
|
|
34
|
+
export declare function blockMapKeys(text: string): Map<string, string> | null;
|
|
35
|
+
export declare function checkSite({ dir, types, typesSkipped, env }: CheckOptions): CheckResult;
|
|
36
|
+
/** The result as a person reads it: one finding a few lines, the errors first. */
|
|
37
|
+
export declare function formatCheck({ findings, skipped }: CheckResult): string;
|
|
38
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1F;;;;;GAKG;AAEH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;AAE/C,MAAM,WAAW,OAAO;IACtB,iEAAiE;IACjE,QAAQ,CAAC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ms-core';
|
|
4
|
+
import { AGENT_FILES_VERSION, CMS_RULES_FILE } from './agent-files.js';
|
|
5
|
+
import { readEnvFile } from './init.js';
|
|
6
|
+
const CONFIG_FILES = ['astro.config.mjs', 'astro.config.ts', 'astro.config.js', 'astro.config.mts'];
|
|
7
|
+
const SOURCE = /\.(astro|ts|tsx|js|jsx|mjs|mts)$/;
|
|
8
|
+
/** What a template calls to read the CMS for a page. A file that calls one draws CMS content. */
|
|
9
|
+
const READERS = /\b(entryPage|single|menuLinks|linkTo|siteForm|pageHead|getLiveCollection|getLiveEntry)\s*\(/;
|
|
10
|
+
const PACKAGE = '@velocity-astro/cms-astro';
|
|
11
|
+
/** Every source file under a folder, from the site's folder, skipping what is built or installed. */
|
|
12
|
+
function filesUnder(dir, folder) {
|
|
13
|
+
const root = path.join(dir, folder);
|
|
14
|
+
if (!fs.existsSync(root))
|
|
15
|
+
return [];
|
|
16
|
+
return fs
|
|
17
|
+
.readdirSync(root, { recursive: true, encoding: 'utf8' })
|
|
18
|
+
.filter((name) => SOURCE.test(name) && !/(^|[\\/])(node_modules|dist|\.astro)[\\/]/.test(name))
|
|
19
|
+
.map((name) => path.join(folder, name).split(path.sep).join('/'));
|
|
20
|
+
}
|
|
21
|
+
/** The files a file imports by path, resolved from the site's folder (`@/` is `src/`). Packages are left out. */
|
|
22
|
+
function importsOf(dir, file, text) {
|
|
23
|
+
const found = [];
|
|
24
|
+
for (const match of text.matchAll(/(?:import|from)\s*['"]([^'"]+)['"]/g)) {
|
|
25
|
+
const spec = match[1] ?? '';
|
|
26
|
+
const base = spec.startsWith('@/') ? path.join('src', spec.slice(2)) : spec.startsWith('.') ? path.join(path.dirname(file), spec) : null;
|
|
27
|
+
if (base === null)
|
|
28
|
+
continue;
|
|
29
|
+
for (const candidate of [base, `${base}.ts`, `${base}.astro`, `${base}.js`, `${base}.tsx`, path.join(base, 'index.ts')]) {
|
|
30
|
+
if (fs.existsSync(path.join(dir, candidate)) && fs.statSync(path.join(dir, candidate)).isFile()) {
|
|
31
|
+
found.push(candidate.split(path.sep).join('/'));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
/** A page's own setting: `true` for `prerender = true`, `false` for `prerender = false`, `null` when it says nothing. */
|
|
39
|
+
function prerenderOf(text) {
|
|
40
|
+
const match = /export\s+const\s+prerender\s*=\s*(true|false)/.exec(text);
|
|
41
|
+
return match ? match[1] === 'true' : null;
|
|
42
|
+
}
|
|
43
|
+
/** The keys of an object literal that maps blocks to components: `export const blocks = { hero: Hero, 'call-to-action': Cta }`. */
|
|
44
|
+
export function blockMapKeys(text) {
|
|
45
|
+
const start = /export\s+const\s+blocks\b[^=]*=\s*\{/.exec(text);
|
|
46
|
+
if (!start)
|
|
47
|
+
return null;
|
|
48
|
+
let depth = 1;
|
|
49
|
+
let at = start.index + start[0].length;
|
|
50
|
+
const begin = at;
|
|
51
|
+
while (at < text.length && depth > 0) {
|
|
52
|
+
if (text[at] === '{')
|
|
53
|
+
depth += 1;
|
|
54
|
+
if (text[at] === '}')
|
|
55
|
+
depth -= 1;
|
|
56
|
+
at += 1;
|
|
57
|
+
}
|
|
58
|
+
const body = text.slice(begin, at - 1);
|
|
59
|
+
const map = new Map();
|
|
60
|
+
for (const match of body.matchAll(/(?:^|[,{\s])(?:'([^']+)'|"([^"]+)"|([A-Za-z_$][\w$]*))\s*:\s*([A-Za-z_$][\w$]*)/g)) {
|
|
61
|
+
map.set(match[1] ?? match[2] ?? match[3] ?? '', match[4] ?? '');
|
|
62
|
+
}
|
|
63
|
+
return map;
|
|
64
|
+
}
|
|
65
|
+
/** The blocks a site's pages can be built from today: those of every top-level field of sections. */
|
|
66
|
+
function siteBlocks(types) {
|
|
67
|
+
const blocks = new Map();
|
|
68
|
+
for (const type of types) {
|
|
69
|
+
for (const field of liveFields(type.fields)) {
|
|
70
|
+
const allowed = field.options.blocks;
|
|
71
|
+
if (!Array.isArray(allowed))
|
|
72
|
+
continue;
|
|
73
|
+
for (const block of allowed)
|
|
74
|
+
if (block.retiredAt === undefined)
|
|
75
|
+
blocks.set(block.key, block);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return blocks;
|
|
79
|
+
}
|
|
80
|
+
export function checkSite({ dir, types, typesSkipped, env = {} }) {
|
|
81
|
+
const findings = [];
|
|
82
|
+
const skipped = [];
|
|
83
|
+
const add = (finding) => findings.push(finding);
|
|
84
|
+
const read = (file) => fs.readFileSync(path.join(dir, file), 'utf8');
|
|
85
|
+
// 1. Setup: the integration, an adapter, an address, a secret kept out of git.
|
|
86
|
+
const configFile = CONFIG_FILES.find((file) => fs.existsSync(path.join(dir, file)));
|
|
87
|
+
const config = configFile ? read(configFile) : '';
|
|
88
|
+
if (!configFile) {
|
|
89
|
+
add({ rule: 'no-astro-site', level: 'error', file: '.', message: 'There is no Astro config here.', see: 'Setup', fix: 'Run the check in the site\'s own folder.' });
|
|
90
|
+
return { findings, skipped };
|
|
91
|
+
}
|
|
92
|
+
if (!config.includes(PACKAGE))
|
|
93
|
+
add({ rule: 'no-integration', level: 'error', file: configFile, message: 'The CMS is not in the Astro config.', see: 'Setup', fix: 'Run `npx velocity-cms init`, or add `velocityCms()` to `integrations`.' });
|
|
94
|
+
if (!/\badapter\s*:/.test(config))
|
|
95
|
+
add({ rule: 'no-adapter', level: 'error', file: configFile, message: 'The site has no server adapter, and the editor and live pages run on a server.', see: 'Setup', fix: 'Add one for where the site will live, such as `npx astro add node`.' });
|
|
96
|
+
if (!/\bsite\s*:/.test(config))
|
|
97
|
+
add({ rule: 'no-site-address', level: 'warning', file: configFile, message: 'The config has no `site`, so sign-in links have no address to lead to once deployed.', see: 'Setup', fix: 'Set `site` to the site\'s address (or `VELOCITY_CMS_ORIGIN` on the host).' });
|
|
98
|
+
if (/\boutput\s*:\s*['"]server['"]/.test(config))
|
|
99
|
+
add({ rule: 'output-server', level: 'warning', file: configFile, message: 'The whole site renders on demand (`output: \'server\'`).', see: 'Live pages', fix: 'Remove it, and mark only the pages that read the CMS with `export const prerender = false`.' });
|
|
100
|
+
if (!/tags\s*:\s*\[[^\]]*['"]cms['"]/.test(config)) {
|
|
101
|
+
add({ rule: 'no-cms-cache-tag', level: 'warning', file: configFile, message: 'No route rule tags pages with `cms`, so a page that reads the CMS through a layout may be kept after a publish.', see: 'Live pages', fix: 'Add `routeRules: { \'/[...path]\': { maxAge: 86400, tags: [\'cms\'] } }` and a `cache` provider, as the starter does.' });
|
|
102
|
+
}
|
|
103
|
+
const dotEnv = fs.existsSync(path.join(dir, '.env')) ? readEnvFile(read('.env')) : {};
|
|
104
|
+
if (!env['VELOCITY_CMS_SECRET'] && !dotEnv['VELOCITY_CMS_SECRET'])
|
|
105
|
+
add({ rule: 'no-secret', level: 'error', file: '.env', message: 'VELOCITY_CMS_SECRET is not set.', see: 'Setup', fix: 'Run `npx velocity-cms init`, which writes one. Set the same name on your host.' });
|
|
106
|
+
const ignored = fs.existsSync(path.join(dir, '.gitignore')) ? read('.gitignore').split(/\r?\n/).map((line) => line.trim().replace(/^\//, '')) : [];
|
|
107
|
+
if (fs.existsSync(path.join(dir, '.env')) && !ignored.some((line) => line === '.env' || line === '.env*')) {
|
|
108
|
+
add({ rule: 'env-in-git', level: 'error', file: '.gitignore', message: '.env is not left out of git, and it holds the site\'s secret and tokens.', see: 'Setup', fix: 'Add `.env` to .gitignore (`npx velocity-cms init` does).' });
|
|
109
|
+
}
|
|
110
|
+
// 2. Pages that read the CMS must be drawn on demand, or a publish never reaches them.
|
|
111
|
+
const sources = filesUnder(dir, 'src');
|
|
112
|
+
const texts = new Map(sources.map((file) => [file, read(file)]));
|
|
113
|
+
const readsCms = new Set(sources.filter((file) => READERS.test(texts.get(file) ?? '') && ((texts.get(file) ?? '').includes(PACKAGE) || (texts.get(file) ?? '').includes('astro:content'))));
|
|
114
|
+
const pages = sources.filter((file) => file.startsWith('src/pages/') && /\.(astro|ts|js|mjs)$/.test(file));
|
|
115
|
+
const prerenderedByDefault = !/\boutput\s*:\s*['"]server['"]/.test(config);
|
|
116
|
+
for (const page of pages) {
|
|
117
|
+
const text = texts.get(page) ?? '';
|
|
118
|
+
const through = readsCms.has(page) ? page : importsOf(dir, page, text).find((file) => readsCms.has(file));
|
|
119
|
+
if (!through)
|
|
120
|
+
continue;
|
|
121
|
+
const prerender = prerenderOf(text);
|
|
122
|
+
if (prerender === true || (prerender === null && prerenderedByDefault)) {
|
|
123
|
+
add({
|
|
124
|
+
rule: 'prerendered-cms-page',
|
|
125
|
+
level: 'error',
|
|
126
|
+
file: page,
|
|
127
|
+
message: through === page ? 'This page reads the CMS but is built ahead of time, so a publish never reaches it.' : `This page reads the CMS through ${through} but is built ahead of time, so a publish never reaches it.`,
|
|
128
|
+
see: 'Live pages',
|
|
129
|
+
fix: 'Add `export const prerender = false;` to the page.',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const drawsEntries = sources.some((file) => /\b(entryPage|getLiveEntry|getLiveCollection)\s*\(/.test(texts.get(file) ?? ''));
|
|
134
|
+
if (drawsEntries && !sources.some((file) => /\bpageHead\s*\(/.test(texts.get(file) ?? ''))) {
|
|
135
|
+
add({ rule: 'no-page-head', level: 'warning', file: 'src/layouts', message: 'Pages draw CMS entries, but nothing calls `pageHead`, so the SEO plugin and the editor\'s titles never reach the page\'s head.', see: 'Template helpers', fix: 'In the layout, call `const head = await pageHead(Astro, { title, description })` and write `head.title`, `head.description` and `head.robots`.' });
|
|
136
|
+
}
|
|
137
|
+
for (const file of sources) {
|
|
138
|
+
const text = texts.get(file) ?? '';
|
|
139
|
+
if (/\b(sharedConnection|createCms)\s*\(/.test(text) || /\.content\.(find|get|findBySlug)\s*\(/.test(text)) {
|
|
140
|
+
add({ rule: 'reads-around-helpers', level: 'warning', file, message: 'This file reads the CMS around the helpers, which is how drafts leak onto pages and previews break.', see: 'Drafts never leak', fix: 'Read through `entryPage`, `single`, `menuLinks`, `linkTo` or the live loader (`getLiveCollection`, `getLiveEntry`).' });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// 3. Every block has a component, and every component a block.
|
|
144
|
+
const mapFile = sources.find((file) => /export\s+const\s+blocks\b/.test(texts.get(file) ?? '') && blockMapKeys(texts.get(file) ?? '') !== null);
|
|
145
|
+
if (!types) {
|
|
146
|
+
skipped.push(`Blocks and forms were not compared with the model: ${typesSkipped ?? 'the content types could not be read'}.`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const blocks = siteBlocks(types);
|
|
150
|
+
if (blocks.size > 0 && !mapFile) {
|
|
151
|
+
add({ rule: 'no-block-map', level: 'error', file: 'src', message: `Pages are built from ${blocks.size} blocks, but no file maps them to components.`, see: 'Sections', fix: 'Write `export const blocks = { <block key>: Component }` (as `src/components/blocks.ts` in the starter) and draw a page\'s sections from it.' });
|
|
152
|
+
}
|
|
153
|
+
if (mapFile) {
|
|
154
|
+
const mapText = texts.get(mapFile) ?? '';
|
|
155
|
+
const mapped = blockMapKeys(mapText) ?? new Map();
|
|
156
|
+
for (const [key, block] of blocks) {
|
|
157
|
+
if (!mapped.has(key))
|
|
158
|
+
add({ rule: 'block-without-component', level: 'error', file: mapFile, message: `The block "${key}" has no component, so its sections are left off every page.`, see: 'Sections', fix: `Write its component, import it here and add \`'${key}': Component\` to \`blocks\`.` });
|
|
159
|
+
const takesForm = liveFields(block.fields).some((field) => field.type === 'form');
|
|
160
|
+
const component = mapped.get(key);
|
|
161
|
+
if (!takesForm || !component)
|
|
162
|
+
continue;
|
|
163
|
+
const from = new RegExp(`import\\s+${component}\\s+from\\s+['"]([^'"]+)['"]`).exec(mapText)?.[1];
|
|
164
|
+
const resolved = from ? importsOf(dir, mapFile, `import x from '${from}'`)[0] : undefined;
|
|
165
|
+
if (resolved && !/\bsiteForm\s*\(/.test(texts.get(resolved) ?? '')) {
|
|
166
|
+
add({ rule: 'form-section-without-form', level: 'error', file: resolved, message: `The block "${key}" lets editors choose a form, but its component never calls \`siteForm\`, so the form is not drawn and nothing is received.`, see: 'Forms', fix: 'Call `const form = await siteForm(Astro, { id })` with the field\'s value and draw its fields, `form.hidden` and `form.trap`, posting to `form.action`.' });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const key of mapped.keys()) {
|
|
170
|
+
if (!blocks.has(key))
|
|
171
|
+
add({ rule: 'component-without-block', level: 'warning', file: mapFile, message: `"${key}" has a component but no block in the model, so editors cannot add it.`, see: 'Sections', fix: `Describe a block with the key "${key}" in the model and apply it (\`schema.define\`), or remove it here.` });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// 4. The agent files are there, and are this version's.
|
|
176
|
+
const rules = path.join(dir, CMS_RULES_FILE);
|
|
177
|
+
if (!fs.existsSync(rules)) {
|
|
178
|
+
add({ rule: 'no-agent-rules', level: 'warning', file: CMS_RULES_FILE, message: 'The CMS\'s rules for agents are not installed.', see: 'Setup', fix: 'Run `npx velocity-cms agents`.' });
|
|
179
|
+
}
|
|
180
|
+
else if (!fs.readFileSync(rules, 'utf8').includes(`velocity-cms ${AGENT_FILES_VERSION}`)) {
|
|
181
|
+
add({ rule: 'old-agent-rules', level: 'warning', file: CMS_RULES_FILE, message: 'The CMS\'s rules for agents are from another version of the CMS.', see: 'Setup', fix: 'Run `npx velocity-cms agents` to bring them up to date.' });
|
|
182
|
+
}
|
|
183
|
+
return { findings, skipped };
|
|
184
|
+
}
|
|
185
|
+
/** The result as a person reads it: one finding a few lines, the errors first. */
|
|
186
|
+
export function formatCheck({ findings, skipped }) {
|
|
187
|
+
const ordered = [...findings].sort((a, b) => (a.level === b.level ? 0 : a.level === 'error' ? -1 : 1));
|
|
188
|
+
const lines = ordered.map((finding) => `${finding.level === 'error' ? 'Error' : 'Warning'}: ${finding.file}\n ${finding.message}\n Rule: "${finding.see}" in ${CMS_RULES_FILE} (${finding.rule})\n Fix: ${finding.fix}`);
|
|
189
|
+
const errors = findings.filter((finding) => finding.level === 'error').length;
|
|
190
|
+
const warnings = findings.length - errors;
|
|
191
|
+
const summary = findings.length === 0 ? 'velocity-cms check: no problems found.' : `velocity-cms check: ${errors} error${errors === 1 ? '' : 's'}, ${warnings} warning${warnings === 1 ? '' : 's'}.`;
|
|
192
|
+
return [...lines, ...skipped.map((line) => `Not checked: ${line}`), summary].join('\n\n');
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAsC,MAAM,0BAA0B,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAsCxC,MAAM,YAAY,GAAG,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AACpG,MAAM,MAAM,GAAG,kCAAkC,CAAC;AAClD,iGAAiG;AACjG,MAAM,OAAO,GAAG,6FAA6F,CAAC;AAC9G,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAE5C,qGAAqG;AACrG,SAAS,UAAU,CAAC,GAAW,EAAE,MAAc;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,EAAE;SACN,WAAW,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;SACxD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,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AM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,MAAM,CAAC;IAC9E,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC,uBAAuB,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,QAAQ,WAAW,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACrM,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** A command's words, split into what it names in order and what it sets with `--name value` or `--flag`. */
|
|
2
|
+
export interface Parsed {
|
|
3
|
+
readonly positional: readonly string[];
|
|
4
|
+
readonly flags: Readonly<Record<string, string | true>>;
|
|
5
|
+
/** Every value a flag was given, for one that may be given more than once (`--map a=b --map c=d`). */
|
|
6
|
+
readonly all: Readonly<Record<string, readonly string[]>>;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseArgs(args: readonly string[]): Parsed;
|
|
9
|
+
export interface ContentEnvironment {
|
|
10
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
11
|
+
readonly print: (line: string) => void;
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
/** Lines read from the agent, for `mcp`. Defaults to the process's standard input. */
|
|
14
|
+
readonly input?: AsyncIterable<string>;
|
|
15
|
+
readonly fetch?: typeof fetch;
|
|
16
|
+
}
|
|
17
|
+
/** The commands that work with a site's content, over its API. Each answers with the exit code, or `null` for a command it does not know. */
|
|
18
|
+
export declare const CONTENT_COMMANDS: Set<string>;
|
|
19
|
+
export declare const CONTENT_USAGE = "Content, over the site's API (needs VELOCITY_CMS_TOKEN, and VELOCITY_CMS_ORIGIN for a site that is not on this computer):\n velocity-cms types The content types and their fields.\n velocity-cms type <type> One content type in full, with the blocks its pages take.\n velocity-cms entries <type> [--status s] [--locale l] [--limit n]\n velocity-cms entry <id> One entry, its values by field key.\n velocity-cms create <type> <slug> --data '<json>' [--locale l] [--publish]\n velocity-cms update <id> --data '<json>' [--publish]\n velocity-cms publish <id> | unpublish <id>\n velocity-cms sections <id> A page's sections, in order.\n velocity-cms import <type> <file.json | file.md | folder> [--publish] [--body <field>] [--map old=new] [--update] [--dry-run]\n velocity-cms export <type> [--out <file.json>]\n velocity-cms upload <image> Prints the name an image field stores.\n velocity-cms forms | submissions <form> | pipeline\n velocity-cms mcp An MCP server on standard input and output, for an agent on this computer.\n Add --json to print what the site answered as it is.";
|
|
20
|
+
/** Runs one content command. */
|
|
21
|
+
export declare function runContentCommand(command: string, parsed: Parsed, environment: ContentEnvironment): Promise<number>;
|
|
22
|
+
//# sourceMappingURL=cli-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-content.d.ts","sourceRoot":"","sources":["../src/cli-content.ts"],"names":[],"mappings":"AAKA,6GAA6G;AAC7G,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IACxD,sGAAsG;IACtG,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CAC3D;AAKD,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAkBzD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;AAED,6IAA6I;AAC7I,eAAO,MAAM,gBAAgB,aAAkL,CAAC;AAEhN,eAAO,MAAM,aAAa,+sCAc6B,CAAC;AAExD,gCAAgC;AAChC,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyGzH"}
|