@domandigital/sanity-copy 0.2.1 → 0.3.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/CHANGELOG.md +13 -0
- package/README.md +13 -0
- package/dist/cli.js +47 -3
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +13 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @domandigital/sanity-copy
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cd13c94: `sanity-copy --claims` lists every price, figure, date and named source in a dataset, on its field, marked sourced or UNSOURCED, for a person to check against the primary source. `documentClaims(doc)` does the same in code.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- cd13c94: `withCopyCheck` accepts a real Studio's schema types. Sanity declares its definitions as interfaces, which have no index signature, so the old `SchemaTypeLike` made `tsc` fail in the first Studio it was installed in.
|
|
12
|
+
- Updated dependencies [cd13c94]
|
|
13
|
+
- Updated dependencies [cd13c94]
|
|
14
|
+
- @domandigital/craft@0.10.0
|
|
15
|
+
|
|
3
16
|
## 0.2.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -60,6 +60,19 @@ Findings are listed per document and field. Exit **0** no house-rule finding,
|
|
|
60
60
|
**1** at least one, **2** nothing was checked. A token is read from the
|
|
61
61
|
environment, never a flag. It reports and changes nothing.
|
|
62
62
|
|
|
63
|
+
## The claims list
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx @domandigital/sanity-copy --project <id> --claims
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
No style rule can say whether a figure is true. `--claims` lists every
|
|
70
|
+
sentence holding a price, a figure, a date or a named source, on its field,
|
|
71
|
+
marked `sourced` (a source is named, in the sentence or a footnote) or
|
|
72
|
+
`UNSOURCED`. Check each against its primary source, then source it, correct it
|
|
73
|
+
or cut it. It always exits 0: a checklist, not a verdict. `documentClaims(doc)`
|
|
74
|
+
does the same in code.
|
|
75
|
+
|
|
63
76
|
## In code
|
|
64
77
|
|
|
65
78
|
```ts
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { readFileSync } from "fs";
|
|
5
5
|
|
|
6
6
|
// src/core.ts
|
|
7
|
-
import { applyHouseGate, checkCopy } from "@domandigital/craft";
|
|
7
|
+
import { applyHouseGate, checkCopy, findClaims } from "@domandigital/craft";
|
|
8
8
|
var DEFAULT_EXCLUDED_TYPES = ["testimonial", "review", "proofQuote", "quote"];
|
|
9
9
|
var DEFAULT_SKIP_FIELDS = [
|
|
10
10
|
"slug",
|
|
@@ -113,6 +113,17 @@ function checkDocumentCopy(doc, options = {}) {
|
|
|
113
113
|
}
|
|
114
114
|
return findings;
|
|
115
115
|
}
|
|
116
|
+
function documentClaims(doc, options = {}) {
|
|
117
|
+
if (!isRecord(doc)) return [];
|
|
118
|
+
const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
|
|
119
|
+
if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
|
|
120
|
+
const pieces = collectCopy(doc, options);
|
|
121
|
+
const { claims } = findClaims(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
|
|
122
|
+
return claims.flatMap(({ path, line: _line, ...claim }) => {
|
|
123
|
+
const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
|
|
124
|
+
return piece ? [{ ...claim, path: piece.path }] : [];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
116
127
|
function describeFinding(f) {
|
|
117
128
|
const lead = f.tier === "block" ? "House rule" : "Worth a look";
|
|
118
129
|
return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
|
|
@@ -123,7 +134,7 @@ function pathToString(path) {
|
|
|
123
134
|
|
|
124
135
|
// src/cli.ts
|
|
125
136
|
function parse(argv) {
|
|
126
|
-
const args = { dataset: "production", json: false };
|
|
137
|
+
const args = { dataset: "production", json: false, claims: false };
|
|
127
138
|
for (let i = 0; i < argv.length; i += 1) {
|
|
128
139
|
const a = argv[i];
|
|
129
140
|
const value = () => {
|
|
@@ -136,6 +147,7 @@ function parse(argv) {
|
|
|
136
147
|
else if (a === "--types") args.types = value().split(",").map((t) => t.trim()).filter(Boolean);
|
|
137
148
|
else if (a === "--file") args.file = value();
|
|
138
149
|
else if (a === "--json") args.json = true;
|
|
150
|
+
else if (a === "--claims") args.claims = true;
|
|
139
151
|
else if (a === "--help" || a === "-h") return "help";
|
|
140
152
|
else return `unknown option ${a}`;
|
|
141
153
|
}
|
|
@@ -171,7 +183,9 @@ var label = (doc) => {
|
|
|
171
183
|
async function main(argv, out = console.log, err = console.error) {
|
|
172
184
|
const args = parse(argv);
|
|
173
185
|
if (args === "help") {
|
|
174
|
-
out(
|
|
186
|
+
out(
|
|
187
|
+
"usage: sanity-copy --project <id> [--dataset production] [--types a,b] [--claims] [--json]\n sanity-copy --file export.json [--claims] [--json]\n--claims lists every price, figure, date and named source, sourced or UNSOURCED, to check by hand."
|
|
188
|
+
);
|
|
175
189
|
return 0;
|
|
176
190
|
}
|
|
177
191
|
if (typeof args === "string") {
|
|
@@ -189,6 +203,7 @@ async function main(argv, out = console.log, err = console.error) {
|
|
|
189
203
|
err("sanity-copy: the dataset returned 0 documents. Nothing was checked.");
|
|
190
204
|
return 2;
|
|
191
205
|
}
|
|
206
|
+
if (args.claims) return reportClaims(docs, args.json, out);
|
|
192
207
|
const results = [];
|
|
193
208
|
for (const doc of docs) {
|
|
194
209
|
const findings = checkDocumentCopy(doc);
|
|
@@ -209,6 +224,35 @@ sanity-copy: ${docs.length} documents, ${block} house-rule finding${block === 1
|
|
|
209
224
|
}
|
|
210
225
|
return block > 0 ? 1 : 0;
|
|
211
226
|
}
|
|
227
|
+
function reportClaims(docs, json, out) {
|
|
228
|
+
const results = [];
|
|
229
|
+
for (const doc of docs) {
|
|
230
|
+
const claims = documentClaims(doc);
|
|
231
|
+
if (claims.length) results.push({ doc: label(doc), claims });
|
|
232
|
+
}
|
|
233
|
+
const all = results.flatMap((r) => r.claims);
|
|
234
|
+
const unsourced = all.filter((c) => c.sources.length === 0).length;
|
|
235
|
+
if (json) {
|
|
236
|
+
out(JSON.stringify({ documents: docs.length, claims: all.length, unsourced, results }, null, 2));
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
for (const r of results) {
|
|
240
|
+
out(r.doc);
|
|
241
|
+
for (const c of r.claims) {
|
|
242
|
+
const what = [
|
|
243
|
+
...c.facts.map((f) => f.value),
|
|
244
|
+
...c.sources.map((s) => `source: ${s}`),
|
|
245
|
+
...c.nearby ? [`${c.nearby.join(", ")} named earlier in the paragraph: does it cover this?`] : []
|
|
246
|
+
].join(" \xB7 ");
|
|
247
|
+
out(` ${pathToString(c.path)} ${c.sources.length ? "sourced " : "UNSOURCED"} ${what}`);
|
|
248
|
+
out(` ${c.sentence}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
out(`
|
|
252
|
+
sanity-copy --claims: ${docs.length} documents, ${all.length} claim${all.length === 1 ? "" : "s"} to check, ${unsourced} with no source named.`);
|
|
253
|
+
out("Check each against its primary source. Sourced means a source is named, not that it agrees.");
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
212
256
|
var invoked = process.argv[1] ?? "";
|
|
213
257
|
if (/sanity-copy|cli\.(?:c?js|ts)$/.test(invoked)) {
|
|
214
258
|
main(process.argv.slice(2)).then((code) => process.exit(code));
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
collectCopy: () => collectCopy,
|
|
27
27
|
copyCheckRule: () => copyCheckRule,
|
|
28
28
|
describeFinding: () => describeFinding,
|
|
29
|
+
documentClaims: () => documentClaims,
|
|
29
30
|
pathToString: () => pathToString,
|
|
30
31
|
withCopyCheck: () => withCopyCheck
|
|
31
32
|
});
|
|
@@ -141,6 +142,17 @@ function checkDocumentCopy(doc, options = {}) {
|
|
|
141
142
|
}
|
|
142
143
|
return findings;
|
|
143
144
|
}
|
|
145
|
+
function documentClaims(doc, options = {}) {
|
|
146
|
+
if (!isRecord(doc)) return [];
|
|
147
|
+
const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
|
|
148
|
+
if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
|
|
149
|
+
const pieces = collectCopy(doc, options);
|
|
150
|
+
const { claims } = (0, import_craft.findClaims)(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
|
|
151
|
+
return claims.flatMap(({ path, line: _line, ...claim }) => {
|
|
152
|
+
const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
|
|
153
|
+
return piece ? [{ ...claim, path: piece.path }] : [];
|
|
154
|
+
});
|
|
155
|
+
}
|
|
144
156
|
function describeFinding(f) {
|
|
145
157
|
const lead = f.tier === "block" ? "House rule" : "Worth a look";
|
|
146
158
|
return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
|
|
@@ -183,6 +195,7 @@ function withCopyCheck(types, options = {}) {
|
|
|
183
195
|
collectCopy,
|
|
184
196
|
copyCheckRule,
|
|
185
197
|
describeFinding,
|
|
198
|
+
documentClaims,
|
|
186
199
|
pathToString,
|
|
187
200
|
withCopyCheck
|
|
188
201
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Claim } from '@domandigital/craft';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The house copy check over a Sanity document.
|
|
3
5
|
*
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
* the same answer in all three. The rules are craft's: this file only decides
|
|
7
9
|
* which strings in a document are copy, and where each finding belongs.
|
|
8
10
|
*/
|
|
11
|
+
|
|
9
12
|
/** A Studio path: field names, array indices, or `{ _key }` for keyed array items. */
|
|
10
13
|
type PathSegment = string | number | {
|
|
11
14
|
_key: string;
|
|
@@ -48,6 +51,17 @@ interface Piece {
|
|
|
48
51
|
declare function collectCopy(doc: unknown, options?: CopyCheckOptions): Piece[];
|
|
49
52
|
/** Check one document. Returns nothing for an excluded type. */
|
|
50
53
|
declare function checkDocumentCopy(doc: unknown, options?: CopyCheckOptions): CopyFinding[];
|
|
54
|
+
interface DocumentClaim extends Omit<Claim, "path" | "line"> {
|
|
55
|
+
/** The field the sentence is in. */
|
|
56
|
+
path: Path;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Every sentence in a document holding a price, figure, date or named source,
|
|
60
|
+
* for a person to check against the primary source. craft's claims list, with
|
|
61
|
+
* each claim on the field an editor would open. Excluded types are skipped, as
|
|
62
|
+
* for the copy check: a client's own words are verified with them, not here.
|
|
63
|
+
*/
|
|
64
|
+
declare function documentClaims(doc: unknown, options?: CopyCheckOptions): DocumentClaim[];
|
|
51
65
|
/** One line an editor can act on. */
|
|
52
66
|
declare function describeFinding(f: CopyFinding): string;
|
|
53
67
|
/** A path as text, for a report: `hero.title`, `body[_key=="a1"]`. */
|
|
@@ -98,4 +112,4 @@ declare function copyCheckRule(rule: RuleLike, options?: CopyCheckOptions): Rule
|
|
|
98
112
|
/** Every document type gains the copy check as a warning, beside the validation it already has. */
|
|
99
113
|
declare function withCopyCheck<T extends SchemaTypeLike>(types: T[], options?: CopyCheckOptions): T[];
|
|
100
114
|
|
|
101
|
-
export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, pathToString, withCopyCheck };
|
|
115
|
+
export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type DocumentClaim, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, documentClaims, pathToString, withCopyCheck };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Claim } from '@domandigital/craft';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The house copy check over a Sanity document.
|
|
3
5
|
*
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
* the same answer in all three. The rules are craft's: this file only decides
|
|
7
9
|
* which strings in a document are copy, and where each finding belongs.
|
|
8
10
|
*/
|
|
11
|
+
|
|
9
12
|
/** A Studio path: field names, array indices, or `{ _key }` for keyed array items. */
|
|
10
13
|
type PathSegment = string | number | {
|
|
11
14
|
_key: string;
|
|
@@ -48,6 +51,17 @@ interface Piece {
|
|
|
48
51
|
declare function collectCopy(doc: unknown, options?: CopyCheckOptions): Piece[];
|
|
49
52
|
/** Check one document. Returns nothing for an excluded type. */
|
|
50
53
|
declare function checkDocumentCopy(doc: unknown, options?: CopyCheckOptions): CopyFinding[];
|
|
54
|
+
interface DocumentClaim extends Omit<Claim, "path" | "line"> {
|
|
55
|
+
/** The field the sentence is in. */
|
|
56
|
+
path: Path;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Every sentence in a document holding a price, figure, date or named source,
|
|
60
|
+
* for a person to check against the primary source. craft's claims list, with
|
|
61
|
+
* each claim on the field an editor would open. Excluded types are skipped, as
|
|
62
|
+
* for the copy check: a client's own words are verified with them, not here.
|
|
63
|
+
*/
|
|
64
|
+
declare function documentClaims(doc: unknown, options?: CopyCheckOptions): DocumentClaim[];
|
|
51
65
|
/** One line an editor can act on. */
|
|
52
66
|
declare function describeFinding(f: CopyFinding): string;
|
|
53
67
|
/** A path as text, for a report: `hero.title`, `body[_key=="a1"]`. */
|
|
@@ -98,4 +112,4 @@ declare function copyCheckRule(rule: RuleLike, options?: CopyCheckOptions): Rule
|
|
|
98
112
|
/** Every document type gains the copy check as a warning, beside the validation it already has. */
|
|
99
113
|
declare function withCopyCheck<T extends SchemaTypeLike>(types: T[], options?: CopyCheckOptions): T[];
|
|
100
114
|
|
|
101
|
-
export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, pathToString, withCopyCheck };
|
|
115
|
+
export { type CopyCheckOptions, type CopyFinding, DEFAULT_EXCLUDED_TYPES, DEFAULT_SKIP_FIELDS, type DocumentClaim, type Path, type PathSegment, type RuleLike, type SchemaTypeLike, type Tier, checkDocumentCopy, collectCopy, copyCheckRule, describeFinding, documentClaims, pathToString, withCopyCheck };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core.ts
|
|
2
|
-
import { applyHouseGate, checkCopy } from "@domandigital/craft";
|
|
2
|
+
import { applyHouseGate, checkCopy, findClaims } from "@domandigital/craft";
|
|
3
3
|
var DEFAULT_EXCLUDED_TYPES = ["testimonial", "review", "proofQuote", "quote"];
|
|
4
4
|
var DEFAULT_SKIP_FIELDS = [
|
|
5
5
|
"slug",
|
|
@@ -108,6 +108,17 @@ function checkDocumentCopy(doc, options = {}) {
|
|
|
108
108
|
}
|
|
109
109
|
return findings;
|
|
110
110
|
}
|
|
111
|
+
function documentClaims(doc, options = {}) {
|
|
112
|
+
if (!isRecord(doc)) return [];
|
|
113
|
+
const excluded = new Set(options.excludeTypes ?? DEFAULT_EXCLUDED_TYPES);
|
|
114
|
+
if (typeof doc._type === "string" && excluded.has(doc._type)) return [];
|
|
115
|
+
const pieces = collectCopy(doc, options);
|
|
116
|
+
const { claims } = findClaims(pieces.map((p, i) => ({ path: fileFor(i), text: p.text })));
|
|
117
|
+
return claims.flatMap(({ path, line: _line, ...claim }) => {
|
|
118
|
+
const piece = pieces[Number(/^field-(\d+)\.md$/.exec(path)?.[1])];
|
|
119
|
+
return piece ? [{ ...claim, path: piece.path }] : [];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
111
122
|
function describeFinding(f) {
|
|
112
123
|
const lead = f.tier === "block" ? "House rule" : "Worth a look";
|
|
113
124
|
return `${lead} (${f.name}): ${f.message}. ${f.fix}`;
|
|
@@ -149,6 +160,7 @@ export {
|
|
|
149
160
|
collectCopy,
|
|
150
161
|
copyCheckRule,
|
|
151
162
|
describeFinding,
|
|
163
|
+
documentClaims,
|
|
152
164
|
pathToString,
|
|
153
165
|
withCopyCheck
|
|
154
166
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domandigital/sanity-copy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Doman Digital house copy check in Sanity Studio: every document type gains craft's copy rules as validation warnings on the field that caused them. Also a pure checker for a document or an export. No Sanity dependency.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"provenance": true
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@domandigital/craft": "^0.
|
|
50
|
+
"@domandigital/craft": "^0.10.0"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"sanity",
|