@standards/cli 1.0.0-alpha.382 → 1.0.0-alpha.384

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/bin.mjs CHANGED
@@ -236,6 +236,15 @@ function registerCodemodCommand(program) {
236
236
  for (const failure of report.failures) process.stderr.write(`${failure.message}\n`);
237
237
  if (report.failures.length > 0) process.exitCode = 1;
238
238
  });
239
+ codemod.command("image").description("Rewrite .imageShape(x) to .image({ shape: x }) and appearance.imageFileId to appearance.image?.fileId").argument("[paths...]", "files or directories to rewrite", ["."]).option("--dry-run", "report without writing").action(async (paths, opts) => {
240
+ const { runImage } = await import("./image-Ca-XlG3r.mjs");
241
+ const report = await runImage(paths, { write: !opts.dryRun });
242
+ const verb = opts.dryRun ? "Would rewrite" : "Rewrote";
243
+ process.stdout.write(`${verb} ${report.changed} references in ${report.files} files.\n`);
244
+ for (const { file, line, column } of report.skipped) process.stdout.write(`${file}:${line}:${column} appearance.imageFileId a write, rewrite by hand\n`);
245
+ for (const failure of report.failures) process.stderr.write(`${failure.message}\n`);
246
+ if (report.skipped.length > 0 || report.failures.length > 0) process.exitCode = 1;
247
+ });
239
248
  codemod.command("engine-imports").description("Move imports of names that left @standards/schema to @standards/engine").argument("[paths...]", "files or directories to rewrite", ["."]).option("--dry-run", "report without writing").option("--root <dir>", "where @standards/schema and @standards/engine are installed", ".").action(async (paths, opts) => {
240
249
  const { runEngineImports } = await import("./engine-imports-K-yySYo3.mjs");
241
250
  const report = await runEngineImports(paths, {
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ /*! © 2025-2026 AND YOU CREATE SAS (RCS Paris 940 190 614). Proprietary — see LICENSE (Standards SDK License 1.0). */
3
+ import { i as rewriteSourceFiles, n as parseSourceFile, t as applyEdits } from "./source-files-D2Bdfvhx.mjs";
4
+ import ts from "typescript";
5
+ //#region src/codemod/image.ts
6
+ function isAssignmentTarget(node) {
7
+ const { parent } = node;
8
+ if (ts.isBinaryExpression(parent)) {
9
+ const operator = parent.operatorToken.kind;
10
+ return parent.left === node && operator >= ts.SyntaxKind.FirstAssignment && operator <= ts.SyntaxKind.LastAssignment;
11
+ }
12
+ return (ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) && (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken);
13
+ }
14
+ /**
15
+ * Rewrites `.imageShape(x)` to `.image({ shape: x })` and `.appearance.imageFileId`
16
+ * to `.appearance.image?.fileId` in one source file.
17
+ */
18
+ function rewriteImage(text, fileName) {
19
+ const { file, error } = parseSourceFile(text, fileName);
20
+ if (error !== void 0) return {
21
+ output: text,
22
+ changed: 0,
23
+ skipped: [],
24
+ error
25
+ };
26
+ const edits = [];
27
+ const skipped = [];
28
+ let changed = 0;
29
+ function visit(node) {
30
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "imageShape" && node.arguments.length === 1) {
31
+ const argument = node.arguments[0];
32
+ const open = node.arguments.pos;
33
+ const close = node.getEnd() - 1;
34
+ const before = text.slice(open, argument.getStart(file));
35
+ const after = text.slice(argument.getEnd(), close);
36
+ edits.push({
37
+ start: node.expression.name.getStart(file),
38
+ end: /^\s*$/.test(before) ? argument.getStart(file) : open,
39
+ text: "image({ shape: "
40
+ });
41
+ edits.push({
42
+ start: /^[\s,]*$/.test(after) ? argument.getEnd() : close,
43
+ end: node.getEnd(),
44
+ text: " })"
45
+ });
46
+ changed += 1;
47
+ } else if (ts.isPropertyAccessExpression(node) && node.name.text === "imageFileId" && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "appearance") {
48
+ if (isAssignmentTarget(node)) {
49
+ const { line, character } = file.getLineAndCharacterOfPosition(node.getStart(file));
50
+ skipped.push({
51
+ line: line + 1,
52
+ column: character + 1
53
+ });
54
+ } else {
55
+ edits.push({
56
+ start: node.name.getStart(file),
57
+ end: node.name.getEnd(),
58
+ text: "image?.fileId"
59
+ });
60
+ changed += 1;
61
+ }
62
+ }
63
+ ts.forEachChild(node, visit);
64
+ }
65
+ visit(file);
66
+ return {
67
+ output: applyEdits(text, edits),
68
+ changed,
69
+ skipped
70
+ };
71
+ }
72
+ /** Walks `paths`, rewrites every TS or JS file, writes back when `write` is set. */
73
+ async function runImage(paths, options) {
74
+ const report = {
75
+ files: 0,
76
+ changed: 0,
77
+ skipped: [],
78
+ failures: []
79
+ };
80
+ for (const { path, result } of await rewriteSourceFiles(paths, options.write, rewriteImage)) {
81
+ if (result.error !== void 0) {
82
+ report.failures.push({
83
+ file: path,
84
+ message: result.error
85
+ });
86
+ continue;
87
+ }
88
+ for (const at of result.skipped) report.skipped.push({
89
+ file: path,
90
+ ...at
91
+ });
92
+ if (result.changed === 0) continue;
93
+ report.files += 1;
94
+ report.changed += result.changed;
95
+ }
96
+ return report;
97
+ }
98
+ //#endregion
99
+ export { runImage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@standards/cli",
3
- "version": "1.0.0-alpha.382",
3
+ "version": "1.0.0-alpha.384",
4
4
  "description": "CLI tool to interact with Standards API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,9 +19,9 @@
19
19
  "commander": "^13.1.0",
20
20
  "typescript": "^5.6.3",
21
21
  "ws": "8.21.1",
22
- "@standards/client": "1.0.0-alpha.382",
23
- "@standards/constants": "1.0.0-alpha.382",
24
- "@standards/schema": "1.0.0-alpha.382"
22
+ "@standards/client": "1.0.0-alpha.384",
23
+ "@standards/constants": "1.0.0-alpha.384",
24
+ "@standards/schema": "1.0.0-alpha.384"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^25.6.0",