@lumerahq/cli 0.34.3 → 0.34.4
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
CHANGED
|
@@ -293,7 +293,7 @@ async function main() {
|
|
|
293
293
|
await import("./status-NPNIY3QP.js").then((m) => m.status(args.slice(1)));
|
|
294
294
|
break;
|
|
295
295
|
case "migrate":
|
|
296
|
-
await import("./migrate-
|
|
296
|
+
await import("./migrate-Q2QY3YSL.js").then((m) => m.migrate(args.slice(1)));
|
|
297
297
|
break;
|
|
298
298
|
// Skills
|
|
299
299
|
case "skills":
|
|
@@ -14,7 +14,7 @@ import "./chunk-PNKVD2UK.js";
|
|
|
14
14
|
// src/commands/migrate.ts
|
|
15
15
|
import pc from "picocolors";
|
|
16
16
|
import { execFileSync } from "child_process";
|
|
17
|
-
import { existsSync, mkdirSync, renameSync, readdirSync, readFileSync, writeFileSync, rmSync, rmdirSync } from "fs";
|
|
17
|
+
import { cpSync, existsSync, mkdirSync, renameSync, readdirSync, readFileSync, writeFileSync, rmSync, rmdirSync } from "fs";
|
|
18
18
|
import { join, resolve } from "path";
|
|
19
19
|
import { stringify } from "smol-toml";
|
|
20
20
|
function showHelp() {
|
|
@@ -65,16 +65,26 @@ function rewriteAppImports(source, modules) {
|
|
|
65
65
|
for (const moduleName of modules) {
|
|
66
66
|
const escaped = moduleName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
67
67
|
rewritten = rewritten.replace(
|
|
68
|
-
new RegExp(`^(\\s*)import\\s+${escaped}(\\s*(?:#.*)?)$`, "gm"),
|
|
69
|
-
`$1from app import ${moduleName}$2`
|
|
68
|
+
new RegExp(`^(\\s*)import\\s+${escaped}(\\s+as\\s+\\w+)?(\\s*(?:#.*)?)$`, "gm"),
|
|
69
|
+
`$1from app import ${moduleName}$2$3`
|
|
70
70
|
);
|
|
71
71
|
rewritten = rewritten.replace(
|
|
72
|
-
new RegExp(`^(\\s*)from\\s
|
|
73
|
-
|
|
72
|
+
new RegExp(`^(\\s*)from\\s+(${escaped}(?:\\.\\w+)*)\\s+import\\s+`, "gm"),
|
|
73
|
+
"$1from app.$2 import "
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
return rewritten;
|
|
77
77
|
}
|
|
78
|
+
function moveAppAPISource(source, destination, renameDirectory = renameSync, copyDirectory = cpSync) {
|
|
79
|
+
try {
|
|
80
|
+
renameDirectory(source, destination);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error.code !== "EXDEV") throw error;
|
|
83
|
+
mkdirSync(destination);
|
|
84
|
+
copyDirectory(source, destination, { recursive: true, force: false, errorOnExist: true });
|
|
85
|
+
rmSync(source, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
78
88
|
function migrateAppAPI(projectRoot, dryRun) {
|
|
79
89
|
const legacyDir = join(projectRoot, "app-api", "lambda");
|
|
80
90
|
const destination = join(projectRoot, "platform", "app");
|
|
@@ -107,19 +117,24 @@ function migrateAppAPI(projectRoot, dryRun) {
|
|
|
107
117
|
stdio: "inherit"
|
|
108
118
|
});
|
|
109
119
|
mkdirSync(join(projectRoot, "platform"), { recursive: true });
|
|
110
|
-
|
|
120
|
+
moveAppAPISource(legacyDir, destination);
|
|
111
121
|
rmSync(join(destination, "requirements.txt"), { force: true });
|
|
112
122
|
if (!existsSync(join(destination, "__init__.py"))) {
|
|
113
123
|
writeFileSync(join(destination, "__init__.py"), "", "utf8");
|
|
114
124
|
}
|
|
115
125
|
const modules = new Set(
|
|
116
|
-
readdirSync(destination, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".py")).map((entry) => entry.name.slice(0, -3)).filter((name) => name !== "__init__")
|
|
126
|
+
readdirSync(destination, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".py") || entry.isDirectory() && existsSync(join(destination, entry.name, "__init__.py"))).map((entry) => entry.isDirectory() ? entry.name : entry.name.slice(0, -3)).filter((name) => name !== "__init__")
|
|
117
127
|
);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
const rewriteDirectory = (directory) => {
|
|
129
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
130
|
+
const path = join(directory, entry.name);
|
|
131
|
+
if (entry.isDirectory()) rewriteDirectory(path);
|
|
132
|
+
else if (entry.isFile() && entry.name.endsWith(".py")) {
|
|
133
|
+
writeFileSync(path, rewriteAppImports(readFileSync(path, "utf8"), modules), "utf8");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
rewriteDirectory(destination);
|
|
123
138
|
writeFileSync(
|
|
124
139
|
pyprojectPath,
|
|
125
140
|
addReleaseAppEntrypoint(readFileSync(pyprojectPath, "utf8"), projectRoot),
|
|
@@ -296,5 +311,6 @@ async function migrate(args) {
|
|
|
296
311
|
console.log(pc.dim("Your project now uses the v1 structure."));
|
|
297
312
|
}
|
|
298
313
|
export {
|
|
299
|
-
migrate
|
|
314
|
+
migrate,
|
|
315
|
+
moveAppAPISource
|
|
300
316
|
};
|