@prenta/component-blocks 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/dist/cli.js ADDED
@@ -0,0 +1,306 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `prenta-component-blocks` — CLI for the extractor + diff + migrate.
4
+ *
5
+ * Usage:
6
+ * prenta-component-blocks extract \
7
+ * --root ./src/blocks \
8
+ * --out ./prenta-blocks.json \
9
+ * [--pattern '**\/*.tsx']
10
+ *
11
+ * prenta-component-blocks diff <old-manifest> <new-manifest> [--json]
12
+ *
13
+ * prenta-component-blocks migrate <old-manifest> <new-manifest> <content> \
14
+ * [--write] [--out <path>] [--json]
15
+ *
16
+ * Exit codes:
17
+ * 0 success (extract / clean diff / migration applied or dry-run with no issues)
18
+ * 1 user error (missing flag, file not found, etc.)
19
+ * 2 diff: breaking changes detected; migrate: unresolved issues found
20
+ *
21
+ * Kept deliberately small — no extra dependency on a CLI framework.
22
+ */
23
+ import { readFileSync, writeFileSync } from 'node:fs';
24
+ import { diffManifests, formatManifestDiff } from './diff.js';
25
+ import { extractToFile } from './extract.js';
26
+ import { formatMigrationSummary, migrateContentJson } from './migrate.js';
27
+ /**
28
+ * Pull a value off the back of a value-taking flag, refusing to
29
+ * silently swallow the next flag or run off the end of argv.
30
+ */
31
+ function consumeValue(argv, i, flag, errors) {
32
+ const next = argv[i + 1];
33
+ if (next === undefined) {
34
+ errors.push(`flag '${flag}' requires a value`);
35
+ return { value: undefined, next: i };
36
+ }
37
+ if (next.startsWith('-')) {
38
+ errors.push(`flag '${flag}' requires a value (got '${next}', which looks like another flag)`);
39
+ return { value: undefined, next: i };
40
+ }
41
+ return { value: next, next: i + 1 };
42
+ }
43
+ function parseArgs(argv) {
44
+ const args = { command: argv[0] ?? 'help', positional: [] };
45
+ const errors = [];
46
+ for (let i = 1; i < argv.length; i++) {
47
+ const a = argv[i];
48
+ if (a === '--help' || a === '-h')
49
+ args.help = true;
50
+ else if (a === '--json')
51
+ args.json = true;
52
+ else if (a === '--write')
53
+ args.write = true;
54
+ else if (a === '--root') {
55
+ const { value, next } = consumeValue(argv, i, '--root', errors);
56
+ args.root = value;
57
+ i = next;
58
+ }
59
+ else if (a === '--out') {
60
+ const { value, next } = consumeValue(argv, i, '--out', errors);
61
+ args.out = value;
62
+ i = next;
63
+ }
64
+ else if (a === '--pattern') {
65
+ const { value, next } = consumeValue(argv, i, '--pattern', errors);
66
+ args.pattern = value;
67
+ i = next;
68
+ }
69
+ else if (a.startsWith('--')) {
70
+ // Unknown flag — surface a clear error rather than silently
71
+ // accepting unknown options that might be typos. The previous
72
+ // implementation pushed these into `positional` "to be
73
+ // surfaced later", but the subcommand helpers then filtered
74
+ // `--*` tokens back out before counting, so unknown flags
75
+ // were effectively dropped on the floor.
76
+ errors.push(`unknown flag '${a}'`);
77
+ }
78
+ else {
79
+ args.positional.push(a);
80
+ }
81
+ }
82
+ return { args, errors };
83
+ }
84
+ const USAGE = `prenta-component-blocks <command> [options]
85
+
86
+ Commands:
87
+ extract Read React components and emit a Manifest JSON file.
88
+ diff Compare two manifests and report shape changes.
89
+ migrate Rewrite stored content to match a new manifest.
90
+
91
+ Options (extract):
92
+ --root <dir> Directory of source files to scan (required).
93
+ --out <file> Manifest JSON output path (required).
94
+ --pattern <glob> File pattern, default '**/*.tsx'.
95
+
96
+ Options (diff):
97
+ --json Emit the diff as JSON instead of a text summary.
98
+
99
+ Options (migrate):
100
+ --write Write the migrated content back to the input file
101
+ (or to --out if provided). Without --write the
102
+ command is a dry-run that prints a summary.
103
+ --out <file> Destination path when --write is set (defaults to
104
+ overwriting the input).
105
+ --json Emit the migration result as JSON (always includes
106
+ the rewritten value, the auto-applied changes, and
107
+ any unresolved issues).
108
+
109
+ Common:
110
+ --help Show this message.
111
+
112
+ Examples:
113
+ prenta-component-blocks extract --root ./src/blocks --out ./prenta-blocks.json
114
+ prenta-component-blocks diff ./previous.json ./prenta-blocks.json
115
+ prenta-component-blocks diff ./previous.json ./current.json --json
116
+ prenta-component-blocks migrate ./old.json ./new.json ./content.json
117
+ prenta-component-blocks migrate ./old.json ./new.json ./content.json --write
118
+
119
+ Exit codes:
120
+ 0 success / no breaking changes / migration clean
121
+ 1 invalid invocation (missing args, file not found, ...)
122
+ 2 diff: at least one breaking change. migrate: unresolved issues.
123
+ `;
124
+ export function runCli(argv = process.argv.slice(2)) {
125
+ const { args, errors } = parseArgs(argv);
126
+ if (args.help || args.command === 'help' || !args.command) {
127
+ process.stdout.write(USAGE);
128
+ return 0;
129
+ }
130
+ // Bail before doing any work if the user mistyped a flag. Listing
131
+ // every parse error up front beats the previous behavior of
132
+ // silently dropping unknown flags and then failing later with a
133
+ // misleading "could not read manifest" or "requires N positional
134
+ // arguments" error.
135
+ if (errors.length > 0) {
136
+ for (const e of errors)
137
+ process.stderr.write(`error: ${e}\n`);
138
+ process.stderr.write('\n' + USAGE);
139
+ return 1;
140
+ }
141
+ if (args.command === 'extract') {
142
+ if (!args.root) {
143
+ process.stderr.write('error: --root is required\n\n' + USAGE);
144
+ return 1;
145
+ }
146
+ if (!args.out) {
147
+ process.stderr.write('error: --out is required\n\n' + USAGE);
148
+ return 1;
149
+ }
150
+ const manifest = extractToFile({
151
+ rootDir: args.root,
152
+ outFile: args.out,
153
+ ...(args.pattern ? { filePattern: args.pattern } : {}),
154
+ });
155
+ const count = manifest.components.length;
156
+ process.stdout.write(`Wrote ${args.out} (${count} component${count === 1 ? '' : 's'})\n`);
157
+ return 0;
158
+ }
159
+ if (args.command === 'diff') {
160
+ return runDiff(args);
161
+ }
162
+ if (args.command === 'migrate') {
163
+ return runMigrate(args);
164
+ }
165
+ process.stderr.write(`error: unknown command '${args.command}'\n\n` + USAGE);
166
+ return 1;
167
+ }
168
+ /**
169
+ * Implementation of the `diff` subcommand. Takes two positional
170
+ * arguments — paths to old and new manifest JSON files — plus a
171
+ * `--json` flag to switch from human text to machine-readable output.
172
+ */
173
+ function runDiff(args) {
174
+ // `parseArgs` already rejected unknown flags at the top level, so
175
+ // `args.positional` only contains non-flag tokens here.
176
+ const positional = args.positional;
177
+ if (positional.length !== 2) {
178
+ process.stderr.write(`error: diff requires two positional arguments (old and new manifest paths)\n\n` + USAGE);
179
+ return 1;
180
+ }
181
+ const [oldPath, newPath] = positional;
182
+ const oldManifest = loadManifest(oldPath);
183
+ if (!oldManifest) {
184
+ process.stderr.write(`error: could not read manifest at '${oldPath}'\n`);
185
+ return 1;
186
+ }
187
+ const newManifest = loadManifest(newPath);
188
+ if (!newManifest) {
189
+ process.stderr.write(`error: could not read manifest at '${newPath}'\n`);
190
+ return 1;
191
+ }
192
+ const diff = diffManifests(oldManifest, newManifest);
193
+ if (args.json) {
194
+ process.stdout.write(JSON.stringify(diff, null, 2) + '\n');
195
+ }
196
+ else {
197
+ process.stdout.write(formatManifestDiff(diff));
198
+ }
199
+ // Exit code 2 specifically for breaking changes — CI integrations
200
+ // pin to this to gate merges. Non-breaking diffs (safe/unknown)
201
+ // exit 0 so they can run on every PR without blocking.
202
+ return diff.worstSeverity === 'breaking' ? 2 : 0;
203
+ }
204
+ function loadManifest(path) {
205
+ let raw;
206
+ try {
207
+ raw = readFileSync(path, 'utf-8');
208
+ }
209
+ catch {
210
+ return null;
211
+ }
212
+ try {
213
+ const parsed = JSON.parse(raw);
214
+ if (!isManifest(parsed))
215
+ return null;
216
+ return parsed;
217
+ }
218
+ catch {
219
+ return null;
220
+ }
221
+ }
222
+ /**
223
+ * Implementation of the `migrate` subcommand. Takes three positional
224
+ * arguments — old manifest, new manifest, content file — plus optional
225
+ * `--write` / `--out` / `--json` flags. Default is a dry-run that
226
+ * prints a summary; `--write` applies the migration to disk.
227
+ */
228
+ function runMigrate(args) {
229
+ // `parseArgs` already rejected unknown flags at the top level, so
230
+ // `args.positional` only contains non-flag tokens here.
231
+ const positional = args.positional;
232
+ if (positional.length !== 3) {
233
+ process.stderr.write(`error: migrate requires three positional arguments (old manifest, new manifest, content file)\n\n` +
234
+ USAGE);
235
+ return 1;
236
+ }
237
+ const [oldPath, newPath, contentPath] = positional;
238
+ const oldManifest = loadManifest(oldPath);
239
+ if (!oldManifest) {
240
+ process.stderr.write(`error: could not read manifest at '${oldPath}'\n`);
241
+ return 1;
242
+ }
243
+ const newManifest = loadManifest(newPath);
244
+ if (!newManifest) {
245
+ process.stderr.write(`error: could not read manifest at '${newPath}'\n`);
246
+ return 1;
247
+ }
248
+ let contentRaw;
249
+ try {
250
+ contentRaw = readFileSync(contentPath, 'utf-8');
251
+ }
252
+ catch {
253
+ process.stderr.write(`error: could not read content file at '${contentPath}'\n`);
254
+ return 1;
255
+ }
256
+ let content;
257
+ try {
258
+ content = JSON.parse(contentRaw);
259
+ }
260
+ catch (err) {
261
+ process.stderr.write(`error: content file at '${contentPath}' is not valid JSON: ${err.message}\n`);
262
+ return 1;
263
+ }
264
+ const result = migrateContentJson(content, oldManifest, newManifest);
265
+ if (args.json) {
266
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
267
+ }
268
+ else {
269
+ process.stdout.write(formatMigrationSummary(result) + '\n');
270
+ }
271
+ if (args.write) {
272
+ const target = args.out ?? contentPath;
273
+ try {
274
+ writeFileSync(target, JSON.stringify(result.migrated, null, 2) + '\n', 'utf-8');
275
+ if (!args.json) {
276
+ process.stdout.write(`\nWrote migrated content to ${target}\n`);
277
+ }
278
+ }
279
+ catch (err) {
280
+ process.stderr.write(`error: could not write migrated content to '${target}': ${err.message}\n`);
281
+ return 1;
282
+ }
283
+ }
284
+ // Exit code 2 when there are unresolved issues — CI integrations gate
285
+ // on this so a stale-content deploy never sneaks through. The
286
+ // command still writes the partial result with --write, so editors
287
+ // can review and finish what the migrator started.
288
+ return result.issues.length > 0 ? 2 : 0;
289
+ }
290
+ function isManifest(value) {
291
+ return (value !== null &&
292
+ typeof value === 'object' &&
293
+ 'version' in value &&
294
+ value.version === 1 &&
295
+ 'components' in value &&
296
+ Array.isArray(value.components));
297
+ }
298
+ const isCliEntry = typeof process !== 'undefined' &&
299
+ Array.isArray(process.argv) &&
300
+ // The bin script resolves to this file when invoked via `npx`.
301
+ process.argv[1]?.endsWith('cli.js');
302
+ if (isCliEntry) {
303
+ const code = runCli();
304
+ process.exit(code);
305
+ }
306
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAoBzE;;;GAGG;AACH,SAAS,YAAY,CACnB,IAAc,EACd,CAAS,EACT,IAAY,EACZ,MAAgB;IAEhB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,oBAAoB,CAAC,CAAA;QAC9C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;IACtC,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,4BAA4B,IAAI,mCAAmC,CAAC,CAAA;QAC7F,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;IACtC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAA;AACrC,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,MAAM,IAAI,GAAY,EAAE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C;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,+CAA+C,MAAM,MAAO,GAAa,CAAC,OAAO,IAAI,CACtF,CAAA;YACD,OAAO,CAAC,CAAA;QACV,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,8DAA8D;IAC9D,mEAAmE;IACnE,mDAAmD;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACzC,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,SAAS,IAAI,KAAK;QACjB,KAA8B,CAAC,OAAO,KAAK,CAAC;QAC7C,YAAY,IAAI,KAAK;QACrB,KAAK,CAAC,OAAO,CAAE,KAAiC,CAAC,UAAU,CAAC,CAC7D,CAAA;AACH,CAAC;AAED,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,WAAW;IAC9B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,+DAA+D;IAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAErC,IAAI,UAAU,EAAE,CAAC;IACf,MAAM,IAAI,GAAG,MAAM,EAAE,CAAA;IACrB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACpB,CAAC"}
package/dist/diff.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Pure functional diff between two component manifests.
3
+ *
4
+ * Why this lives in the package (not in a CMS-server endpoint):
5
+ *
6
+ * - Authors run `prenta-component-blocks diff` locally to decide
7
+ * whether a refactor will require a content migration before they
8
+ * commit.
9
+ * - CI runs the same diff against the production manifest to surface a
10
+ * blocking comment on PRs that change a component's prop shape.
11
+ * - The {@link ManifestDiff} returned here is the input to the
12
+ * forthcoming `migrate` CLI (PR #3b).
13
+ *
14
+ * The classification rules are deliberately conservative: we'd rather
15
+ * tag a change "breaking" and have the author explicitly mark it safe
16
+ * than let bad content silently slip through.
17
+ */
18
+ import type { Manifest, ManifestDiff, PropType } from './types.js';
19
+ /**
20
+ * Compare two manifests and return a structured description of the
21
+ * differences. Both arguments are treated as read-only; this function
22
+ * has no side effects and is safe to run on user-provided JSON.
23
+ */
24
+ export declare function diffManifests(oldManifest: Manifest, newManifest: Manifest): ManifestDiff;
25
+ /**
26
+ * Deep structural equality on PropType trees. Covers all kinds; falls
27
+ * back to JSON serialization for safety on shapes we don't explicitly
28
+ * walk (in practice every kind is covered).
29
+ */
30
+ export declare function propTypesEqual(a: PropType, b: PropType): boolean;
31
+ /**
32
+ * Render a {@link ManifestDiff} as a human-readable text block for the
33
+ * CLI. The format is intentionally plain — no ANSI codes — so it
34
+ * pipes cleanly into PR comments, CI logs, and editor terminals on
35
+ * Windows. Color is the CLI's job, not this function's.
36
+ */
37
+ export declare function formatManifestDiff(diff: ManifestDiff): string;
38
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAIV,QAAQ,EACR,YAAY,EAGZ,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,GAAG,YAAY,CA8BxF;AA0TD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CA8ChE;AAqCD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CA6C7D"}