Skip to content

Commit

Permalink
feat: auto update import map version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Jan 24, 2023
1 parent b96b2c7 commit 3f57398
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reactive_home/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ COPY run.sh /
COPY deno.lock /
COPY run.ts /
COPY loader.ts /
COPY config.yaml /
COPY update-import-map.ts /

RUN chmod a+x /run.sh

Expand Down
1 change: 1 addition & 0 deletions reactive_home/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ if [[ ! -f /config/reactive-home/import_map.json ]]; then
}" >> /config/reactive-home/import_map.json
fi

deno run --lock=/deno.lock --allow-read=/config/reactive-home/import_map.json,/config.yaml --allow-write=/config/reactive-home/import_map.json /update-import-map.ts
deno run --lock=/deno.lock --allow-run --allow-read /run.ts --root /config/reactive-home
36 changes: 36 additions & 0 deletions reactive_home/update-import-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const versionRegex = /version: "(.+?)"/gim;

const configYaml = await Deno.readTextFile("/config.yaml");

const result = versionRegex.exec(configYaml);

const version = result?.at?.(1);

if (version) {
const importMapText = await Deno.readTextFile(
"/config/reactive-home/import_map.json"
);

let importMapJson: Record<string, any> = {};

try {
importMapJson = JSON.parse(importMapText);
} catch (e) {
console.error("Failed to parse import map. Recreate import map.", e);
}

if (!importMapJson.imports) {
importMapJson.imports = {};
}

console.log(`Set reactivehome version to v${version}`);

importMapJson.imports[
"reactive-home"
] = `https://deno.land/x/reactivehome@v${version}/mod.ts`;

await Deno.writeTextFile(
"/config/reactive-home/import_map.json",
JSON.stringify(importMapJson, null, 2)
);
}

0 comments on commit 3f57398

Please sign in to comment.