-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace loader to load all scripts at once
- Loading branch information
Showing
7 changed files
with
145 additions
and
481 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { walk } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { basename, join } from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
const flags = parse(Deno.args, { | ||
string: ["root"], | ||
}); | ||
|
||
if (!flags.root) { | ||
console.error("Missing root parameter"); | ||
Deno.exit(1); | ||
} | ||
|
||
for await (const path of walk(flags.root)) { | ||
if (!path.isFile) { | ||
continue; | ||
} | ||
|
||
if (path.path.includes(".deno")) { | ||
continue; | ||
} | ||
|
||
const fileName = basename(path.path); | ||
|
||
if (!/script\..+\.ts/gm.test(fileName)) { | ||
continue; | ||
} | ||
|
||
console.info("Load script", path.path); | ||
|
||
new Worker(new URL(join(Deno.cwd(), path.path), import.meta.url).href, { | ||
type: "module", | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { walk } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { basename } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { basename, dirname } from "https://deno.land/[email protected]/path/mod.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
const flags = parse(Deno.args, { | ||
string: ["root"], | ||
|
@@ -13,55 +12,41 @@ async function executeScripts(abort: AbortSignal) { | |
return; | ||
} | ||
|
||
for await (const path of walk(flags.root)) { | ||
if (!path.isFile) { | ||
continue; | ||
} | ||
if (abort.aborted) { | ||
continue; | ||
} | ||
const args = [ | ||
"deno", | ||
"run", | ||
`--lock=${join(flags.root, "deno.lock")}`, | ||
"--allow-read", | ||
`--allow-env=NODE_ENV,HASS_LONG_LIVED_TOKEN,HASS_URL`, | ||
"--allow-net", | ||
"--unstable", // npm import | ||
]; | ||
|
||
if (path.path.includes(".deno")) { | ||
continue; | ||
} | ||
const importMapPath = join(flags.root, "import_map.json"); | ||
|
||
const fileName = basename(path.path); | ||
try { | ||
const fileInfo = Deno.statSync(importMapPath); | ||
|
||
if (!/script\..+\.ts/gm.test(fileName)) { | ||
continue; | ||
if (fileInfo && fileInfo.isFile) { | ||
args.push(`--import-map=${importMapPath}`); | ||
} | ||
|
||
console.info("Load script", path.path); | ||
|
||
const args = [ | ||
"deno", | ||
"run", | ||
`--lock=${join(flags.root, "deno.lock")}`, | ||
"--allow-read", | ||
`--allow-env=NODE_ENV,HASS_LONG_LIVED_TOKEN,HASS_URL`, | ||
"--allow-net", | ||
"--unstable", // npm import | ||
]; | ||
|
||
const importMapPath = join(flags.root, "import_map.json"); | ||
|
||
try { | ||
const fileInfo = Deno.statSync(importMapPath); | ||
|
||
if (fileInfo && fileInfo.isFile) { | ||
args.push(`--import-map=${importMapPath}`); | ||
} | ||
// deno-lint-ignore no-empty | ||
} catch {} | ||
|
||
const process = Deno.run({ | ||
cmd: [...args, path.path], | ||
}); | ||
|
||
abort.addEventListener("abort", () => { | ||
process.kill(); | ||
}); | ||
} | ||
// deno-lint-ignore no-empty | ||
} catch {} | ||
|
||
const currentFileLocation = new URL(import.meta.url); | ||
|
||
const process = Deno.run({ | ||
cmd: [ | ||
...args, | ||
join(dirname(currentFileLocation.pathname), "./loader.ts"), | ||
"--root", | ||
flags.root, | ||
], | ||
}); | ||
|
||
abort.addEventListener("abort", () => { | ||
process.kill(); | ||
}); | ||
} | ||
|
||
if (!flags.root) { | ||
|
Oops, something went wrong.