mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
fix: bundle a2ui before tests
This commit is contained in:
@@ -27,23 +27,49 @@ INPUT_PATHS=(
|
||||
"$A2UI_APP_DIR"
|
||||
)
|
||||
|
||||
collect_files() {
|
||||
local path
|
||||
for path in "${INPUT_PATHS[@]}"; do
|
||||
if [[ -d "$path" ]]; then
|
||||
find "$path" -type f -print0
|
||||
else
|
||||
printf '%s\0' "$path"
|
||||
fi
|
||||
done
|
||||
compute_hash() {
|
||||
ROOT_DIR="$ROOT_DIR" node --input-type=module - "${INPUT_PATHS[@]}" <<'NODE'
|
||||
import { createHash } from "node:crypto";
|
||||
import { promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const rootDir = process.env.ROOT_DIR ?? process.cwd();
|
||||
const inputs = process.argv.slice(2);
|
||||
const files = [];
|
||||
|
||||
async function walk(entryPath) {
|
||||
const st = await fs.stat(entryPath);
|
||||
if (st.isDirectory()) {
|
||||
const entries = await fs.readdir(entryPath);
|
||||
for (const entry of entries) {
|
||||
await walk(path.join(entryPath, entry));
|
||||
}
|
||||
return;
|
||||
}
|
||||
files.push(entryPath);
|
||||
}
|
||||
|
||||
compute_hash() {
|
||||
collect_files \
|
||||
| LC_ALL=C sort -z \
|
||||
| xargs -0 shasum -a 256 \
|
||||
| shasum -a 256 \
|
||||
| awk '{print $1}'
|
||||
for (const input of inputs) {
|
||||
await walk(input);
|
||||
}
|
||||
|
||||
function normalize(p) {
|
||||
return p.split(path.sep).join("/");
|
||||
}
|
||||
|
||||
files.sort((a, b) => normalize(a).localeCompare(normalize(b)));
|
||||
|
||||
const hash = createHash("sha256");
|
||||
for (const filePath of files) {
|
||||
const rel = normalize(path.relative(rootDir, filePath));
|
||||
hash.update(rel);
|
||||
hash.update("\0");
|
||||
hash.update(await fs.readFile(filePath));
|
||||
hash.update("\0");
|
||||
}
|
||||
|
||||
process.stdout.write(hash.digest("hex"));
|
||||
NODE
|
||||
}
|
||||
|
||||
current_hash="$(compute_hash)"
|
||||
|
||||
Reference in New Issue
Block a user