@cmssy/codemod 6.2.0 → 7.0.1
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/index.js +30 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,8 +13,8 @@ var SERVER_SYMBOLS = /* @__PURE__ */ new Set([
|
|
|
13
13
|
"createCmssyPage",
|
|
14
14
|
"createCmssyEditPage",
|
|
15
15
|
"createCmssyNotFound",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"CmssyLayoutSlot",
|
|
17
|
+
"CmssyLayoutSlotProps",
|
|
18
18
|
"CreateCmssyNotFoundOptions",
|
|
19
19
|
"buildCmssyMetadata",
|
|
20
20
|
"BuildCmssyMetadataOptions",
|
|
@@ -144,7 +144,27 @@ function transform(source) {
|
|
|
144
144
|
return { code, changed };
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// src/v7.ts
|
|
148
|
+
var RENAMES2 = {
|
|
149
|
+
CmssyChrome: "CmssyLayoutSlot",
|
|
150
|
+
CmssyChromeProps: "CmssyLayoutSlotProps"
|
|
151
|
+
};
|
|
152
|
+
function transform2(source) {
|
|
153
|
+
let code = source;
|
|
154
|
+
let changed = false;
|
|
155
|
+
for (const [from, to] of Object.entries(RENAMES2)) {
|
|
156
|
+
const pattern = new RegExp(`\\b${from}\\b`, "g");
|
|
157
|
+
if (pattern.test(code)) {
|
|
158
|
+
code = code.replace(pattern, to);
|
|
159
|
+
changed = true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { code, changed };
|
|
163
|
+
}
|
|
164
|
+
|
|
147
165
|
// src/index.ts
|
|
166
|
+
var TRANSFORMS = { v5: transform, v7: transform2 };
|
|
167
|
+
var PREVIOUS_MAJOR = { v5: "4.x", v7: "6.x" };
|
|
148
168
|
var SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage"]);
|
|
149
169
|
var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
150
170
|
function skipDirectory(name) {
|
|
@@ -166,28 +186,31 @@ async function sourceFiles(dir) {
|
|
|
166
186
|
async function main() {
|
|
167
187
|
const args = process.argv.slice(2);
|
|
168
188
|
const version = args[0];
|
|
169
|
-
|
|
170
|
-
|
|
189
|
+
const transform3 = TRANSFORMS[version];
|
|
190
|
+
if (!transform3) {
|
|
191
|
+
console.error("usage: cmssy-codemod v5|v7 [path] [--dry]");
|
|
171
192
|
process.exitCode = 1;
|
|
172
193
|
return;
|
|
173
194
|
}
|
|
174
195
|
const dry = args.includes("--dry");
|
|
175
196
|
const target = resolve(
|
|
176
|
-
args.find((a) => !a.startsWith("-") && a
|
|
197
|
+
args.find((a) => !a.startsWith("-") && !(a in TRANSFORMS)) ?? "."
|
|
177
198
|
);
|
|
178
199
|
const files = await sourceFiles(target);
|
|
179
200
|
const touched = [];
|
|
180
201
|
let needsCore = false;
|
|
181
202
|
for (const file of files) {
|
|
182
203
|
const source = await readFile(file, "utf8");
|
|
183
|
-
const { code, changed } =
|
|
204
|
+
const { code, changed } = transform3(source);
|
|
184
205
|
if (!changed) continue;
|
|
185
206
|
touched.push(file);
|
|
186
207
|
if (code.includes('from "@cmssy/core"')) needsCore = true;
|
|
187
208
|
if (!dry) await writeFile(file, code);
|
|
188
209
|
}
|
|
189
210
|
if (touched.length === 0) {
|
|
190
|
-
console.log(
|
|
211
|
+
console.log(
|
|
212
|
+
`cmssy: nothing to migrate - no ${PREVIOUS_MAJOR[version]} imports found.`
|
|
213
|
+
);
|
|
191
214
|
return;
|
|
192
215
|
}
|
|
193
216
|
console.log(
|