@palettelab/cli 0.3.27 → 0.3.28
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/lib/bundler.js +38 -18
- package/package.json +1 -1
package/lib/bundler.js
CHANGED
|
@@ -132,28 +132,48 @@ async function bundleBackend(pluginDir) {
|
|
|
132
132
|
pluginDir = path.resolve(pluginDir)
|
|
133
133
|
const { spawnSync } = require("child_process")
|
|
134
134
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "palette-bundle-"))
|
|
135
|
+
const stage = path.join(tmp, "stage")
|
|
135
136
|
const outPath = path.join(tmp, "backend.tar.gz")
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
try {
|
|
139
|
+
fs.mkdirSync(stage, { recursive: true })
|
|
140
|
+
const copy = (from, to) => {
|
|
141
|
+
fs.cpSync(from, to, {
|
|
142
|
+
recursive: true,
|
|
143
|
+
filter(src) {
|
|
144
|
+
const parts = src.split(path.sep)
|
|
145
|
+
return !parts.includes("__pycache__") && !parts.includes(".venv")
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
}
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
)
|
|
150
|
+
const backendDir = path.join(pluginDir, "backend")
|
|
151
|
+
if (fs.existsSync(backendDir)) copy(backendDir, path.join(stage, "backend"))
|
|
152
|
+
for (const metadataFile of ["package.json", "pyproject.toml", "palette-plugin.json"]) {
|
|
153
|
+
const src = path.join(pluginDir, metadataFile)
|
|
154
|
+
if (fs.existsSync(src)) fs.copyFileSync(src, path.join(stage, metadataFile))
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const sdkDir = path.resolve(__dirname, "..", "backend-sdk", "palette_sdk")
|
|
158
|
+
const targetSdkDir = path.join(stage, "backend", "palette_sdk")
|
|
159
|
+
if (fs.existsSync(sdkDir) && fs.existsSync(path.join(stage, "backend"))) {
|
|
160
|
+
copy(sdkDir, targetSdkDir)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const includes = fs.readdirSync(stage)
|
|
164
|
+
const result = spawnSync("tar", ["-czf", outPath, ...includes], {
|
|
165
|
+
cwd: stage,
|
|
166
|
+
stdio: "pipe",
|
|
167
|
+
})
|
|
168
|
+
if (result.status !== 0) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`tar failed (exit ${result.status}): ${result.stderr?.toString() || "unknown error"}`,
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
return fs.readFileSync(outPath)
|
|
174
|
+
} finally {
|
|
175
|
+
fs.rmSync(tmp, { recursive: true, force: true })
|
|
153
176
|
}
|
|
154
|
-
const buf = fs.readFileSync(outPath)
|
|
155
|
-
fs.rmSync(tmp, { recursive: true, force: true })
|
|
156
|
-
return buf
|
|
157
177
|
}
|
|
158
178
|
|
|
159
179
|
module.exports = { bundleFrontend, bundleBackend, watchFrontend }
|