-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { build_sw } from "../server/build_sw.ts"; | ||
|
||
await build_sw(); | ||
Deno.exit(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { build } from "esbuild/mod.js"; | ||
import { join, resolve } from "std/path/mod.ts"; | ||
import { asyncForEach, calFileMd5, checkMapFile } from "../utils.ts"; | ||
|
||
export async function build_sw() { | ||
let base = import.meta.resolve("../static").slice(7); | ||
if (Deno.build.os === "windows") { | ||
base = base.slice(1); | ||
} | ||
const map_file = join(base, "sw.meta.json"); | ||
if (!(await checkMapFile(map_file))) { | ||
const data = await build({ | ||
entryPoints: [join(base, "sw.ts")], | ||
outfile: join(base, "sw.js"), | ||
metafile: true, | ||
bundle: true, | ||
minify: true, | ||
sourcemap: true, | ||
}); | ||
const map = data.metafile; | ||
await asyncForEach( | ||
Object.getOwnPropertyNames(map.inputs), | ||
async (k) => { | ||
const p = resolve(k); | ||
if (p !== k) { | ||
map.inputs[p] = map.inputs[k]; | ||
delete map.inputs[k]; | ||
k = p; | ||
} | ||
const data = map.inputs[k]; | ||
// @ts-ignore add custom property | ||
data.md5 = await calFileMd5(k); | ||
}, | ||
); | ||
await asyncForEach( | ||
Object.getOwnPropertyNames(map.outputs), | ||
async (k) => { | ||
const p = resolve(k); | ||
if (p !== k) { | ||
map.outputs[p] = map.outputs[k]; | ||
delete map.outputs[k]; | ||
k = p; | ||
} | ||
const data = map.outputs[k]; | ||
// @ts-ignore add custom property | ||
data.md5 = await calFileMd5(k); | ||
}, | ||
); | ||
await Deno.writeTextFile(map_file, JSON.stringify(map)); | ||
console.log("Rebuild."); | ||
} | ||
} |