@mehshekari/gsap-motion 3.5.0 → 3.6.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/README.md +2 -1
- package/bin/gsap-motion.mjs +8 -0
- package/package.json +1 -1
- package/skill/SKILL.md +5 -5
- package/skill/reference/project-rules.md +66 -0
- package/skill/scripts/patterns.mjs +352 -0
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ No dependencies, no install scripts, Node.js 18 or later.
|
|
|
23
23
|
| `inspect <url>` | Watches a page animate over the DevTools Protocol and reports what it saw: a filmstrip, the timeline GSAP is running, and the layouts, style recalculations and frames the browser did. `--scroll`, `--hover` and `--click` reach the state first; `--reduced`, `--dark`, `--mobile` and `--cpu` change the conditions. Needs a Chrome on the machine; installs nothing. |
|
|
24
24
|
| `explain <file...|url>` | Maps an animation and changes nothing: where it lives, its preference branches, its beats in order with the reasons their comments give, its scroll configuration, and what the audit says. Given a URL it reads the running page instead, where the timeline is the one GSAP actually built. |
|
|
25
25
|
| `review <url>` | Measures what the motion actually did, by sampling the DOM every frame rather than by reading GSAP's timeline — which a bundled app never exposes, and which would make it work on demo pages and fail on real ones. Reports time to first motion, the share of the screen moving at its busiest, loop seams, and motion over text being read. Sampling forces layout, so it does not report layout counts; `inspect` measures those. Takes the same `--scroll`, `--reduced`, `--dark`, `--mobile` and `--cpu`. |
|
|
26
|
+
| `patterns check [file]` | Validates the Patterns section of your `ANIMATION.md`: the fields each status needs, the recorded uses behind `validated`, the named reviewer behind `canonical`, and entries verified against an older GSAP than the one installed. Exits 1 on a claim the evidence does not support, so it belongs in `lint` beside `audit`. A project with no Patterns section passes. |
|
|
26
27
|
| `doctor` | Checks Node.js, the installed skill's version for this project and your user, your project's `gsap` and `@gsap/react`, and whether an `ANIMATION.md` exists. |
|
|
27
28
|
|
|
28
29
|
## In CI
|
|
@@ -31,7 +32,7 @@ The audit needs no install. Pin the version, so a new rule cannot fail your
|
|
|
31
32
|
build without warning:
|
|
32
33
|
|
|
33
34
|
```json
|
|
34
|
-
"lint": "eslint && npx @mehshekari/gsap-motion@3.
|
|
35
|
+
"lint": "eslint && npx @mehshekari/gsap-motion@3.6.0 audit src --quiet"
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
Or install it with `npm install --save-dev --save-exact @mehshekari/gsap-motion`.
|
package/bin/gsap-motion.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* npx @mehshekari/gsap-motion inspect <url> [--at ...] [--hover ...] [--reduced]
|
|
11
11
|
* npx @mehshekari/gsap-motion explain <file...|url>
|
|
12
12
|
* npx @mehshekari/gsap-motion review <url> [--scroll ...] [--mobile]
|
|
13
|
+
* npx @mehshekari/gsap-motion patterns check [ANIMATION.md]
|
|
13
14
|
* npx @mehshekari/gsap-motion doctor
|
|
14
15
|
*
|
|
15
16
|
* Installed as a dependency, the same commands run as `gsap-motion <command>`.
|
|
@@ -94,6 +95,10 @@ Commands
|
|
|
94
95
|
--cpu 4 Throttle the CPU by this factor
|
|
95
96
|
--out <dir> Save a frame alongside the measurements
|
|
96
97
|
--json Machine-readable output
|
|
98
|
+
patterns check [file] Check the Patterns section of your ANIMATION.md:
|
|
99
|
+
the fields each status needs, the uses behind
|
|
100
|
+
validated, the reviewer behind canonical
|
|
101
|
+
--json Machine-readable output
|
|
97
102
|
doctor Check Node, the installed skill and your project's GSAP
|
|
98
103
|
--version Print the version
|
|
99
104
|
|
|
@@ -335,6 +340,9 @@ switch (command) {
|
|
|
335
340
|
case "review":
|
|
336
341
|
runScript("review-motion.mjs", args);
|
|
337
342
|
break;
|
|
343
|
+
case "patterns":
|
|
344
|
+
runScript("patterns.mjs", args);
|
|
345
|
+
break;
|
|
338
346
|
case "doctor":
|
|
339
347
|
doctor();
|
|
340
348
|
break;
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -4,7 +4,7 @@ description: Senior motion engineer for GSAP. Turns a visual or interaction idea
|
|
|
4
4
|
license: MIT. See LICENSE; GSAP itself is licensed separately, see NOTICE.md
|
|
5
5
|
compatibility: Any Agent Skills client; written for Claude Code. GSAP 3.13+, where every plugin is free. React guidance targets @gsap/react 2.x, React 18/19 and the Next.js App Router. The audit scripts need Node.js 18+ and nothing else.
|
|
6
6
|
metadata:
|
|
7
|
-
version: "3.
|
|
7
|
+
version: "3.6.0"
|
|
8
8
|
verified-gsap: "3.15"
|
|
9
9
|
verified-gsap-react: "2.1"
|
|
10
10
|
---
|
|
@@ -101,8 +101,8 @@ intent → precedent → targets → trigger → motion language → technique
|
|
|
101
101
|
2. **Precedent** — grep for the animation this codebase already has. Its
|
|
102
102
|
trigger point, easing, durations, stagger shape and attribute naming are the
|
|
103
103
|
house language: match them, and differ only for a reason you can state.
|
|
104
|
-
Nothing downstream catches a skipped precedent
|
|
105
|
-
|
|
104
|
+
Nothing downstream catches a skipped precedent: the code compiles, the audit
|
|
105
|
+
passes, and the page reads as two different sites.
|
|
106
106
|
3. **Targets** — which elements move, and can they be reached without a
|
|
107
107
|
positional selector that breaks when the markup moves?
|
|
108
108
|
4. **Trigger** — mount, in-view, scroll position, pointer, click, route, loop.
|
|
@@ -112,8 +112,8 @@ intent → precedent → targets → trigger → motion language → technique
|
|
|
112
112
|
8. **Implementation** — typed, cleaned up, responsive.
|
|
113
113
|
9. **Performance** — transform and opacity; measure before defending anything else.
|
|
114
114
|
10. **Accessibility** — the reduced-motion design, focus, keyboard.
|
|
115
|
-
11. **Validate** — [refine.md](reference/refine.md): audit, fix in order,
|
|
116
|
-
|
|
115
|
+
11. **Validate** — [refine.md](reference/refine.md): audit, fix in order, re-run,
|
|
116
|
+
then the checklist in [motion-design.md](reference/motion-design.md).
|
|
117
117
|
|
|
118
118
|
## Output format
|
|
119
119
|
|
|
@@ -83,10 +83,76 @@ one is short, and each section is an instruction rather than an essay:
|
|
|
83
83
|
|
|
84
84
|
## Precedents
|
|
85
85
|
<!-- Files that already do this well, by path, and what each one taught. -->
|
|
86
|
+
|
|
87
|
+
## Patterns
|
|
88
|
+
<!-- Shapes this project has proven. Format and statuses below; `patterns
|
|
89
|
+
check` validates this section. Omit the section until there is one. -->
|
|
86
90
|
````
|
|
87
91
|
|
|
88
92
|
---
|
|
89
93
|
|
|
94
|
+
## Patterns: what the project has proven
|
|
95
|
+
|
|
96
|
+
A pattern is a shape of animation this project has used and can use again. The
|
|
97
|
+
section is optional, and empty is the honest state for a new project.
|
|
98
|
+
|
|
99
|
+
**Nothing becomes guidance by having been written.** A pattern loaded as
|
|
100
|
+
guidance repeats in every session after it, so a wrong one is not one mistake,
|
|
101
|
+
it is every future mistake. That is why a status is evidence, not a claim.
|
|
102
|
+
|
|
103
|
+
| Status | Reached when | Loaded as |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `experimental` | Built for one request, its claims verified, the audit clean. **Offered in the answer, never written to the file.** | Nothing |
|
|
106
|
+
| `candidate` | The user accepts it into ANIMATION.md. That acceptance is its first use. | An option to mention, never a default |
|
|
107
|
+
| `validated` | Used again in a **different component** — two uses by default — each recorded with its file and commit, and each audit clean | The house way, unless the request gives a reason not to |
|
|
108
|
+
| `canonical` | A **named person** has reviewed it | A precedent, followed like the house motion language |
|
|
109
|
+
| `retired` | Disproved. Kept, with the reason, so it is not reinvented | A warning only |
|
|
110
|
+
|
|
111
|
+
**Who moves an entry.** The skill offers entries and proposes promotions with
|
|
112
|
+
their evidence; it never changes a status on its own. `candidate` needs your
|
|
113
|
+
yes. `validated` is counted by `patterns check` from the recorded uses, never
|
|
114
|
+
asserted by the entry. `canonical` needs a reviewer's name.
|
|
115
|
+
|
|
116
|
+
**Moving down is evidence too.** A bug traced to a pattern returns it to
|
|
117
|
+
`candidate` with the failure recorded. A GSAP release past its verified version
|
|
118
|
+
marks it for re-verification — it stays loaded, marked. A use later reverted
|
|
119
|
+
does not count.
|
|
120
|
+
|
|
121
|
+
### The format
|
|
122
|
+
|
|
123
|
+
```markdown
|
|
124
|
+
### Ink behind a moving pen
|
|
125
|
+
|
|
126
|
+
- **Status:** candidate
|
|
127
|
+
- **Concept:** a mask shares the pen's duration and ease, so ink appears only
|
|
128
|
+
where the nib has already been.
|
|
129
|
+
- **Fixed:** the mask and the path share one duration and one ease.
|
|
130
|
+
- **Parameters:** duration, ease, nib radius.
|
|
131
|
+
- **Not when:** the stroke crosses itself — the mask reveals the crossing early.
|
|
132
|
+
- **Reduced motion:** the finished stroke is set, and no tween runs.
|
|
133
|
+
- **Verified against:** gsap 3.15, DrawSVGPlugin
|
|
134
|
+
- **Uses:**
|
|
135
|
+
- `src/components/Signature.tsx` — `a1b2c3d` — audit clean
|
|
136
|
+
- `src/components/Hero.tsx` — `e4f5a6b` — audit clean, review: no seams
|
|
137
|
+
- **Reviewed by:** <!-- a name, for canonical only -->
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`Concept`, `Not when`, `Reduced motion` and `Verified against` are required of
|
|
141
|
+
every entry that is in the file. A `retired` entry needs only **Why**. Two uses
|
|
142
|
+
in the same file count once: one component is one use.
|
|
143
|
+
|
|
144
|
+
Run it with the rest of the checks:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
gsap-motion patterns check # or: patterns check path/to/ANIMATION.md
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
It exits 1 on a claim the evidence does not support, so it belongs in `lint`
|
|
151
|
+
beside `audit`. Where a candidate has earned `validated`, it says so and leaves
|
|
152
|
+
the promotion to you.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
90
156
|
## Rules worth knowing without a file
|
|
91
157
|
|
|
92
158
|
Each of these fails silently in any project that has the condition.
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* patterns — what a project has proven, and what it has only tried.
|
|
4
|
+
*
|
|
5
|
+
* A skill that writes down whatever it just invented teaches itself its own
|
|
6
|
+
* mistakes: a bad pattern, once loaded as guidance, repeats in every session
|
|
7
|
+
* after it. So a pattern's standing is not something it can claim. It is
|
|
8
|
+
* counted from evidence recorded in the project's own ANIMATION.md:
|
|
9
|
+
*
|
|
10
|
+
* experimental built once, verified, offered in an answer. Never written.
|
|
11
|
+
* candidate the user put it in the file. Mentionable, never a default.
|
|
12
|
+
* validated used again, in another component, each use with its commit.
|
|
13
|
+
* canonical a named person reviewed it.
|
|
14
|
+
* retired disproved, kept with the reason so it is not reinvented.
|
|
15
|
+
*
|
|
16
|
+
* `validated` is computed here rather than asserted there, and `canonical`
|
|
17
|
+
* needs a name, because those are the two a keen assistant would otherwise
|
|
18
|
+
* grant itself. This command only reads and reports; it never edits the file.
|
|
19
|
+
*
|
|
20
|
+
* Node.js 18+, no dependencies.
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync } from "node:fs";
|
|
23
|
+
import { resolve } from "node:path";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
|
|
26
|
+
export const STATUSES = ["experimental", "candidate", "validated", "canonical", "retired"];
|
|
27
|
+
|
|
28
|
+
/** How many separate components a pattern must appear in to be validated. */
|
|
29
|
+
export const USES_FOR_VALIDATED = 2;
|
|
30
|
+
|
|
31
|
+
const FIELDS = {
|
|
32
|
+
concept: "concept",
|
|
33
|
+
fixed: "fixed",
|
|
34
|
+
parameters: "parameters",
|
|
35
|
+
"not when": "notWhen",
|
|
36
|
+
"reduced motion": "reducedMotion",
|
|
37
|
+
"verified against": "verifiedAgainst",
|
|
38
|
+
"reviewed by": "reviewedBy",
|
|
39
|
+
why: "why",
|
|
40
|
+
status: "status",
|
|
41
|
+
uses: "uses",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Read the Patterns section of an ANIMATION.md.
|
|
46
|
+
*
|
|
47
|
+
* The format is what a person would write by hand — a heading per pattern and a
|
|
48
|
+
* bold-labelled list under it — because a format nobody will write is a format
|
|
49
|
+
* nothing will be recorded in. A field may wrap over several lines.
|
|
50
|
+
*/
|
|
51
|
+
export function parse(markdown) {
|
|
52
|
+
const lines = markdown.split(/\r?\n/);
|
|
53
|
+
const entries = [];
|
|
54
|
+
|
|
55
|
+
let inSection = false;
|
|
56
|
+
let entry = null;
|
|
57
|
+
let field = null;
|
|
58
|
+
|
|
59
|
+
const closeField = () => {
|
|
60
|
+
if (entry && field && entry.fields[field] !== undefined) {
|
|
61
|
+
entry.fields[field] = entry.fields[field].trim();
|
|
62
|
+
}
|
|
63
|
+
field = null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
for (const line of lines) {
|
|
67
|
+
const heading = /^(#{2,3})\s+(.*)$/.exec(line);
|
|
68
|
+
if (heading) {
|
|
69
|
+
const [, hashes, title] = heading;
|
|
70
|
+
if (hashes === "##") {
|
|
71
|
+
closeField();
|
|
72
|
+
entry = null;
|
|
73
|
+
inSection = /^patterns\b/i.test(title.trim());
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (inSection) {
|
|
77
|
+
closeField();
|
|
78
|
+
entry = { name: title.trim(), status: null, fields: {}, uses: [] };
|
|
79
|
+
entries.push(entry);
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (!inSection || !entry) continue;
|
|
84
|
+
|
|
85
|
+
const labelled = /^\s*-\s+\*\*(.+?):\*\*\s*(.*)$/.exec(line);
|
|
86
|
+
if (labelled) {
|
|
87
|
+
closeField();
|
|
88
|
+
const key = FIELDS[labelled[1].trim().toLowerCase()];
|
|
89
|
+
if (!key) continue;
|
|
90
|
+
if (key === "status") {
|
|
91
|
+
entry.status = labelled[2].trim().toLowerCase() || null;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (key === "uses") {
|
|
95
|
+
field = "uses";
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
field = key;
|
|
99
|
+
entry.fields[key] = labelled[2];
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A use: a file, the commit it landed in, and what was checked. */
|
|
104
|
+
const use = /^\s+-\s+`([^`]+)`\s*[—-]\s*`([^`]+)`\s*(?:[—-]\s*(.*))?$/.exec(line);
|
|
105
|
+
if (use && field === "uses") {
|
|
106
|
+
entry.uses.push({ file: use[1].trim(), commit: use[2].trim(), note: (use[3] ?? "").trim() });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A continuation of the field above, wrapped by a person or a formatter. */
|
|
111
|
+
if (field && field !== "uses" && /^\s+\S/.test(line)) {
|
|
112
|
+
entry.fields[field] = `${entry.fields[field] ?? ""} ${line.trim()}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
closeField();
|
|
116
|
+
|
|
117
|
+
return entries;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Components, not lines: two commits to one file is one pattern used once. */
|
|
121
|
+
const distinctUses = (entry) => new Set(entry.uses.map((use) => use.file)).size;
|
|
122
|
+
|
|
123
|
+
const REQUIRED = ["concept", "notWhen", "reducedMotion", "verifiedAgainst"];
|
|
124
|
+
const LABEL = {
|
|
125
|
+
concept: "concept",
|
|
126
|
+
notWhen: "not when",
|
|
127
|
+
reducedMotion: "reduced motion",
|
|
128
|
+
verifiedAgainst: "verified against",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* What the section gets wrong.
|
|
133
|
+
*
|
|
134
|
+
* Errors are claims the evidence does not support; warnings are entries that
|
|
135
|
+
* are fine but should not be in the file yet. Nothing here is a judgement about
|
|
136
|
+
* whether the pattern is any good.
|
|
137
|
+
*/
|
|
138
|
+
export function check(entries, { uses = USES_FOR_VALIDATED } = {}) {
|
|
139
|
+
const found = [];
|
|
140
|
+
const at = (entry, level, message) => found.push({ name: entry.name, level, message });
|
|
141
|
+
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
if (!entry.status) {
|
|
144
|
+
at(entry, "error", `"${entry.name}" has no status. One of: ${STATUSES.join(", ")}.`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!STATUSES.includes(entry.status)) {
|
|
148
|
+
at(
|
|
149
|
+
entry,
|
|
150
|
+
"error",
|
|
151
|
+
`"${entry.name}": ${entry.status} is not a status. One of: ${STATUSES.join(", ")}.`,
|
|
152
|
+
);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (entry.status === "retired") {
|
|
157
|
+
/** A retired pattern is kept only so it is not reinvented, so it owes one thing. */
|
|
158
|
+
if (!entry.fields.why) {
|
|
159
|
+
at(entry, "error", `"${entry.name}" is retired but does not say why it was retired.`);
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (entry.status === "experimental") {
|
|
165
|
+
at(
|
|
166
|
+
entry,
|
|
167
|
+
"warn",
|
|
168
|
+
`"${entry.name}" is experimental, which is offered, not written. ` +
|
|
169
|
+
"Make it a candidate when it is accepted, or take it out.",
|
|
170
|
+
);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const missing = REQUIRED.filter((key) => !entry.fields[key]);
|
|
175
|
+
if (missing.length) {
|
|
176
|
+
at(
|
|
177
|
+
entry,
|
|
178
|
+
"error",
|
|
179
|
+
`"${entry.name}" is missing: ${missing.map((key) => LABEL[key]).join(", ")}.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (entry.status === "validated" || entry.status === "canonical") {
|
|
184
|
+
const count = distinctUses(entry);
|
|
185
|
+
if (count < uses) {
|
|
186
|
+
at(
|
|
187
|
+
entry,
|
|
188
|
+
"error",
|
|
189
|
+
`"${entry.name}" claims ${entry.status} with ${count} recorded use${count === 1 ? "" : "s"}. ` +
|
|
190
|
+
`${uses} in separate components are needed, each with its file and commit.`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (entry.status === "canonical" && !entry.fields.reviewedBy) {
|
|
196
|
+
at(
|
|
197
|
+
entry,
|
|
198
|
+
"error",
|
|
199
|
+
`"${entry.name}" claims canonical with nobody named. Add "Reviewed by".`,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return found;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const asVersion = (text) => {
|
|
208
|
+
const found = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(text ?? "");
|
|
209
|
+
return found ? [Number(found[1]), Number(found[2]), Number(found[3] ?? 0)] : null;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Patterns verified against a GSAP older than the installed one.
|
|
214
|
+
*
|
|
215
|
+
* They stay loaded — a pattern does not stop working because a minor version
|
|
216
|
+
* shipped — but they are marked, because the claim behind them was checked
|
|
217
|
+
* against something else. A patch difference is not worth a word.
|
|
218
|
+
*/
|
|
219
|
+
export function stale(entries, { gsap } = {}) {
|
|
220
|
+
const installed = asVersion(gsap);
|
|
221
|
+
if (!installed) return [];
|
|
222
|
+
|
|
223
|
+
const found = [];
|
|
224
|
+
for (const entry of entries) {
|
|
225
|
+
if (entry.status === "retired") continue;
|
|
226
|
+
const verified = asVersion(entry.fields.verifiedAgainst);
|
|
227
|
+
if (!verified) continue;
|
|
228
|
+
const older = verified[0] < installed[0] || (verified[0] === installed[0] && verified[1] < installed[1]);
|
|
229
|
+
if (older) {
|
|
230
|
+
found.push({
|
|
231
|
+
name: entry.name,
|
|
232
|
+
level: "warn",
|
|
233
|
+
message:
|
|
234
|
+
`"${entry.name}" was verified against gsap ${verified[0]}.${verified[1]}, ` +
|
|
235
|
+
`and ${gsap} is installed. Re-verify it, or record the version you checked.`,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return found;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Candidates that have earned validated.
|
|
244
|
+
*
|
|
245
|
+
* Proposed, never applied: the skill offers a promotion with its evidence and a
|
|
246
|
+
* person accepts it. Canonical is absent on purpose — no amount of use earns a
|
|
247
|
+
* review.
|
|
248
|
+
*/
|
|
249
|
+
export function promotable(entries, { uses = USES_FOR_VALIDATED } = {}) {
|
|
250
|
+
return entries
|
|
251
|
+
.filter((entry) => entry.status === "candidate" && distinctUses(entry) >= uses)
|
|
252
|
+
.filter((entry) => REQUIRED.every((key) => entry.fields[key]))
|
|
253
|
+
.map((entry) => ({
|
|
254
|
+
name: entry.name,
|
|
255
|
+
to: "validated",
|
|
256
|
+
uses: distinctUses(entry),
|
|
257
|
+
files: [...new Set(entry.uses.map((use) => use.file))],
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// --- The command ---------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
const installedGsap = (root) => {
|
|
264
|
+
for (const path of ["node_modules/gsap/package.json", "package.json"]) {
|
|
265
|
+
try {
|
|
266
|
+
const json = JSON.parse(readFileSync(resolve(root, path), "utf8"));
|
|
267
|
+
const version = path.endsWith("gsap/package.json")
|
|
268
|
+
? json.version
|
|
269
|
+
: json.dependencies?.gsap ?? json.devDependencies?.gsap;
|
|
270
|
+
if (version) return String(version).replace(/^[\^~]/, "");
|
|
271
|
+
} catch {
|
|
272
|
+
/** No package.json, or no gsap in it: there is simply nothing to compare. */
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export function report(entries, findings, { file, json, quiet }) {
|
|
279
|
+
if (json) {
|
|
280
|
+
return JSON.stringify({ file, patterns: entries.length, findings }, null, 2);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* In a lint script, a check with nothing to say should say nothing. Errors
|
|
285
|
+
* still print, because they are why the run fails.
|
|
286
|
+
*/
|
|
287
|
+
if (quiet) {
|
|
288
|
+
const errors = findings.filter((finding) => finding.level === "error");
|
|
289
|
+
return errors.map((finding) => ` error ${finding.message}`).join("\n");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const lines = [];
|
|
293
|
+
if (!entries.length) {
|
|
294
|
+
lines.push(`No Patterns section in ${file}.`);
|
|
295
|
+
lines.push("Nothing to check. A pattern is written there once it has been accepted.");
|
|
296
|
+
return lines.join("\n");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const by = (status) => entries.filter((entry) => entry.status === status).length;
|
|
300
|
+
lines.push(`${entries.length} pattern${entries.length === 1 ? "" : "s"} in ${file}`);
|
|
301
|
+
lines.push(
|
|
302
|
+
" " +
|
|
303
|
+
STATUSES.map((status) => `${by(status)} ${status}`)
|
|
304
|
+
.filter((part) => !part.startsWith("0 "))
|
|
305
|
+
.join(" · "),
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
if (findings.length) {
|
|
309
|
+
lines.push("");
|
|
310
|
+
for (const finding of findings) {
|
|
311
|
+
lines.push(` ${finding.level === "error" ? "error" : " warn"} ${finding.message}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const ready = promotable(entries);
|
|
316
|
+
if (ready.length) {
|
|
317
|
+
lines.push("", "Earned a promotion — yours to grant, with the evidence:");
|
|
318
|
+
for (const entry of ready) {
|
|
319
|
+
lines.push(` ${entry.name} → validated (${entry.uses} uses: ${entry.files.join(", ")})`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!findings.length) lines.push("", "patterns: clean");
|
|
324
|
+
return lines.join("\n");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function main(argv) {
|
|
328
|
+
const json = argv.includes("--json");
|
|
329
|
+
const quiet = argv.includes("--quiet");
|
|
330
|
+
const rest = argv.filter(
|
|
331
|
+
(argument) => !["--json", "--quiet", "check"].includes(argument),
|
|
332
|
+
);
|
|
333
|
+
const file = rest[0] ?? "ANIMATION.md";
|
|
334
|
+
const root = process.cwd();
|
|
335
|
+
|
|
336
|
+
let markdown;
|
|
337
|
+
try {
|
|
338
|
+
markdown = readFileSync(resolve(root, file), "utf8");
|
|
339
|
+
} catch {
|
|
340
|
+
console.error(`Cannot read ${file}. Pass the path to your ANIMATION.md.`);
|
|
341
|
+
process.exit(2);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const entries = parse(markdown);
|
|
345
|
+
const findings = [...check(entries), ...stale(entries, { gsap: installedGsap(root) })];
|
|
346
|
+
const text = report(entries, findings, { file, json, quiet });
|
|
347
|
+
if (text) console.log(text);
|
|
348
|
+
process.exit(findings.some((finding) => finding.level === "error") ? 1 : 0);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const invoked = process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
352
|
+
if (invoked) await main(process.argv.slice(2));
|