@workover/cli 0.26.0 → 0.27.0
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/bin/workover.mjs +68 -1
- package/lib.mjs +56 -0
- package/package.json +1 -1
package/bin/workover.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// The Workover CLI. `login` / `logout` / `whoami` authenticate through the device-authorization
|
|
3
3
|
// flow (RFC 8628); everything else works on documents with the stored token: `projects`, `doc`
|
|
4
|
-
// (list/read/create/propose/write/search/tabs/images/image/status), `rules`, `comments`, `draft`,
|
|
4
|
+
// (list/read/create/propose/write/search/tabs/images/image/status), `media` (list/replace), `rules`, `comments`, `draft`,
|
|
5
|
+
// `draft-set`, `eval`,
|
|
5
6
|
// and on hosted Help Centers: `project create` and `site` (create/import/domain/check/publish/status),
|
|
6
7
|
// which need `login --site`.
|
|
7
8
|
//
|
|
@@ -39,6 +40,8 @@ import {
|
|
|
39
40
|
docRef,
|
|
40
41
|
environmentMismatch,
|
|
41
42
|
imagesInHtml,
|
|
43
|
+
mediaListQuery,
|
|
44
|
+
formatMediaList,
|
|
42
45
|
signInHelp,
|
|
43
46
|
jsonObjectFlag,
|
|
44
47
|
vetImageUpload,
|
|
@@ -2143,6 +2146,67 @@ const PROJECT_USAGE = [
|
|
|
2143
2146
|
'',
|
|
2144
2147
|
].join('\n');
|
|
2145
2148
|
|
|
2149
|
+
const MEDIA_USAGE = [
|
|
2150
|
+
'',
|
|
2151
|
+
' Usage: workover media <command>',
|
|
2152
|
+
'',
|
|
2153
|
+
' list <project> [--filter <f>] [--source workover|wordpress]',
|
|
2154
|
+
' [--search "<q>"] [--cursor <n>] [--json]',
|
|
2155
|
+
' the project\u2019s Media library: every image its documents use',
|
|
2156
|
+
' and every WordPress attachment, with usage, alt text and',
|
|
2157
|
+
' problems. <f> is all, in_use, unused, attention, missing_alt,',
|
|
2158
|
+
' oversized, broken, stale or deleted',
|
|
2159
|
+
' replace <project> <assetId> <replacementAssetId> [--json]',
|
|
2160
|
+
' raise ONE reviewed fix that swaps the image for the other in',
|
|
2161
|
+
' every document using it; accepting it in Health is what',
|
|
2162
|
+
' changes them. Needs `login --write`',
|
|
2163
|
+
'',
|
|
2164
|
+
' Asset ids are the #numbers `media list` prints; project ids come from',
|
|
2165
|
+
' `workover projects`.',
|
|
2166
|
+
'',
|
|
2167
|
+
].join('\n');
|
|
2168
|
+
|
|
2169
|
+
/** `workover media`: the project Media library (WO-1811), as workover_list_media and _replace_media. */
|
|
2170
|
+
async function mediaCommand() {
|
|
2171
|
+
const sub = process.argv[3];
|
|
2172
|
+
if (sub !== 'list' && sub !== 'replace') {
|
|
2173
|
+
console.log(MEDIA_USAGE);
|
|
2174
|
+
process.exit(sub ? 1 : 0);
|
|
2175
|
+
}
|
|
2176
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
2177
|
+
const projectId = rowId(positionals[0] ?? '');
|
|
2178
|
+
if (projectId === null) {
|
|
2179
|
+
console.log(MEDIA_USAGE);
|
|
2180
|
+
process.exit(1);
|
|
2181
|
+
}
|
|
2182
|
+
const cfg = requireSignIn();
|
|
2183
|
+
if (sub === 'list') {
|
|
2184
|
+
const res = await authedCall(cfg, `/project/${projectId}/media?${mediaListQuery(flags)}`);
|
|
2185
|
+
if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
|
|
2186
|
+
const out = formatMediaList(projectId, res);
|
|
2187
|
+
return console.log(`\n${out.replace(/^(?=.)/gm, ' ')}\n`);
|
|
2188
|
+
}
|
|
2189
|
+
const assetId = rowId(positionals[1] ?? '');
|
|
2190
|
+
const replacementAssetId = rowId(positionals[2] ?? '');
|
|
2191
|
+
if (assetId === null || replacementAssetId === null || assetId === replacementAssetId) {
|
|
2192
|
+
console.error(
|
|
2193
|
+
'\n Name the image to replace and a different one to put in its place: ' +
|
|
2194
|
+
'workover media replace <project> <assetId> <replacementAssetId>\n',
|
|
2195
|
+
);
|
|
2196
|
+
process.exit(1);
|
|
2197
|
+
}
|
|
2198
|
+
const res = await authedCall(cfg, `/project/${projectId}/media/${assetId}/replace`, {
|
|
2199
|
+
replacementAssetId,
|
|
2200
|
+
});
|
|
2201
|
+
if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
|
|
2202
|
+
console.log(
|
|
2203
|
+
`\n Raised a fix to replace #${assetId} with #${replacementAssetId} in every document that uses it` +
|
|
2204
|
+
`${res?.suggestionId ? ` (fix #${res.suggestionId})` : ''}.\n` +
|
|
2205
|
+
' Nothing has changed yet: accepting it in the project’s Health page rewrites the documents. The old image\n' +
|
|
2206
|
+
' stays in the library.\n',
|
|
2207
|
+
);
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2146
2210
|
async function projectCommand() {
|
|
2147
2211
|
const sub = process.argv[3];
|
|
2148
2212
|
if (sub !== 'create') {
|
|
@@ -2543,6 +2607,7 @@ else if (cmd === 'comments') await commentsCommand();
|
|
|
2543
2607
|
else if (cmd === 'projects') await projects();
|
|
2544
2608
|
else if (cmd === 'status') await status();
|
|
2545
2609
|
else if (cmd === 'project') await projectCommand();
|
|
2610
|
+
else if (cmd === 'media') await mediaCommand();
|
|
2546
2611
|
else if (cmd === 'site') await siteCommand();
|
|
2547
2612
|
else if (cmd === 'feedback') await feedbackCommand();
|
|
2548
2613
|
else if (cmd === 'install-claude') installClaude();
|
|
@@ -2573,6 +2638,8 @@ else {
|
|
|
2573
2638
|
console.log(' rules The style guide agents should write by: list, export, add');
|
|
2574
2639
|
console.log(' workover rules export --project 11 >> AGENTS.md');
|
|
2575
2640
|
console.log(' projects List the projects you can reach, with their ids and workspaces');
|
|
2641
|
+
console.log(' media A project\u2019s Media library: list (usage, alt, problems), replace');
|
|
2642
|
+
console.log(' workover media list 11 --filter missing_alt');
|
|
2576
2643
|
console.log(' status Where a project’s setup has got to, and what is left to do');
|
|
2577
2644
|
console.log(' workover status 11 [--json]');
|
|
2578
2645
|
console.log(' project create: a new project that publishes to a Workover Help Center');
|
package/lib.mjs
CHANGED
|
@@ -851,3 +851,59 @@ export const renderSetupStatus = (s, { web } = {}) => {
|
|
|
851
851
|
lines.push('');
|
|
852
852
|
return lines;
|
|
853
853
|
};
|
|
854
|
+
|
|
855
|
+
// The same two helpers as apps/mcp/lib.mjs (workover_list_media); keep them in step.
|
|
856
|
+
/** `workover media`'s filters, as the flags GET /project/:id/media takes. */
|
|
857
|
+
const MEDIA_FLAGS = {
|
|
858
|
+
attention: 'attention',
|
|
859
|
+
missing_alt: 'missingAlt',
|
|
860
|
+
oversized: 'oversized',
|
|
861
|
+
broken: 'broken',
|
|
862
|
+
stale: 'stale',
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
/** The query string for GET /project/:id/media, from `workover media`'s flags. */
|
|
866
|
+
export function mediaListQuery(args = {}) {
|
|
867
|
+
const q = new URLSearchParams();
|
|
868
|
+
const filter = String(args.filter || 'all');
|
|
869
|
+
if (filter === 'in_use' || filter === 'unused' || filter === 'deleted') q.set('tab', filter);
|
|
870
|
+
if (MEDIA_FLAGS[filter]) q.set(MEDIA_FLAGS[filter], 'true');
|
|
871
|
+
if (args.source === 'workover' || args.source === 'wordpress') q.set('source', args.source);
|
|
872
|
+
const search = typeof args.search === 'string' ? args.search.trim() : '';
|
|
873
|
+
if (search) q.set('search', search);
|
|
874
|
+
const cursor = Number(args.cursor);
|
|
875
|
+
if (Number.isInteger(cursor) && cursor > 0) q.set('cursor', String(cursor));
|
|
876
|
+
q.set('limit', '50');
|
|
877
|
+
return q.toString();
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/** `workover media`'s answer: the counts, one block per asset, then the next page. */
|
|
881
|
+
export function formatMediaList(projectId, res) {
|
|
882
|
+
const items = Array.isArray(res?.items) ? res.items : [];
|
|
883
|
+
const c = res?.counts || {};
|
|
884
|
+
const head =
|
|
885
|
+
`Media library of project #${projectId}: ${c.all ?? items.length} images, ` +
|
|
886
|
+
`${c.inUse ?? 0} in use, ${c.unused ?? 0} not found in imported content, ` +
|
|
887
|
+
`${c.attention ?? 0} need attention.`;
|
|
888
|
+
if (!items.length) return `${head}\n\nNothing matches.`;
|
|
889
|
+
const lines = items.map((a) => {
|
|
890
|
+
const problems = [];
|
|
891
|
+
// Alt text is an image's; a PDF in the WordPress library has none to miss.
|
|
892
|
+
if (!a.alt && (a.mime == null || String(a.mime).startsWith('image/')))
|
|
893
|
+
problems.push('no alt text');
|
|
894
|
+
if (a.oversized) problems.push(`oversized (${Math.round((a.bytes || 0) / 1024)} KB)`);
|
|
895
|
+
if (a.brokenAt) problems.push('broken');
|
|
896
|
+
if (a.staleAt) problems.push(`outdated: ${a.staleReason || 'the UI changed'}`);
|
|
897
|
+
if (a.deletedAt) problems.push('deleted');
|
|
898
|
+
const from = a.wpAttachmentId ? `WordPress #${a.wpAttachmentId}` : 'Workover';
|
|
899
|
+
const used = a.useCount
|
|
900
|
+
? `used in ${a.useCount} doc${a.useCount === 1 ? '' : 's'}`
|
|
901
|
+
: 'not found in imported content';
|
|
902
|
+
return (
|
|
903
|
+
`#${a.id} ${a.filename} (${from}, ${used})\n alt: ${a.alt || '(none)'}` +
|
|
904
|
+
(problems.length ? `\n problems: ${problems.join('; ')}` : '')
|
|
905
|
+
);
|
|
906
|
+
});
|
|
907
|
+
const more = res?.nextCursor ? `\n\nMore: pass cursor ${res.nextCursor} for the next page.` : '';
|
|
908
|
+
return `${head}\n\n${lines.join('\n')}${more}`;
|
|
909
|
+
}
|