@primate/native 0.1.6 → 0.3.0
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/private/Loader.d.ts +17 -0
- package/lib/private/Loader.js +28 -0
- package/lib/private/Module.d.ts +25 -0
- package/lib/private/Module.js +62 -0
- package/lib/private/NativeTarget.d.ts +6 -0
- package/lib/private/NativeTarget.js +2 -0
- package/lib/private/command.d.ts +8 -0
- package/lib/private/command.js +22 -0
- package/lib/private/desktop.d.ts +4 -0
- package/lib/private/desktop.js +82 -0
- package/lib/private/targets.d.ts +4 -0
- package/lib/private/targets.js +37 -0
- package/lib/public/FileRef.d.ts +2 -0
- package/lib/public/FileRef.js +2 -0
- package/lib/public/Loader.d.ts +2 -0
- package/lib/public/Loader.js +2 -0
- package/lib/public/Webview.d.ts +2 -0
- package/lib/public/Webview.js +2 -0
- package/lib/public/index.d.ts +4 -0
- package/lib/public/index.js +3 -0
- package/lib/public/target/darwin-arm64.d.ts +2 -0
- package/lib/public/target/darwin-arm64.js +2 -0
- package/lib/public/target/darwin-x64.d.ts +2 -0
- package/lib/public/target/darwin-x64.js +2 -0
- package/lib/public/target/default.d.ts +2 -0
- package/lib/public/target/default.js +2 -0
- package/lib/public/target/linux-x64.d.ts +2 -0
- package/lib/public/target/linux-x64.js +2 -0
- package/lib/public/target/windows-x64.d.ts +2 -0
- package/lib/public/target/windows-x64.js +2 -0
- package/package.json +37 -16
- package/src/desktop.js +0 -89
- package/src/index.js +0 -44
- package/src/platform/darwin-arm64.js +0 -1
- package/src/platform/darwin-x64.js +0 -1
- package/src/platform/linux-x64.js +0 -1
- package/src/platform/windows-x64.js +0 -1
- package/src/public/loader.js +0 -42
- package/src/targets.js +0 -37
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Loader from "@primate/core/Loader";
|
|
2
|
+
import type Dict from "@rcompat/type/Dict";
|
|
3
|
+
type Init = {
|
|
4
|
+
client_imports: Dict<string>;
|
|
5
|
+
pages: Dict<string>;
|
|
6
|
+
pages_app: string;
|
|
7
|
+
rootfile: string;
|
|
8
|
+
static_imports: Dict<string>;
|
|
9
|
+
static_root: string;
|
|
10
|
+
};
|
|
11
|
+
export default class NativeLoader extends Loader {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(init: Init);
|
|
14
|
+
serve(pathname: string): Promise<Response | undefined>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=Loader.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Loader from "@primate/core/Loader";
|
|
2
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
3
|
+
import entries from "@rcompat/record/entries";
|
|
4
|
+
export default class NativeLoader extends Loader {
|
|
5
|
+
#clients = {};
|
|
6
|
+
#statics = {};
|
|
7
|
+
constructor(init) {
|
|
8
|
+
super(init);
|
|
9
|
+
this.#clients = entries(init.client_imports)
|
|
10
|
+
.valmap(([, url]) => new FileRef(url)).get();
|
|
11
|
+
this.#statics = entries(init.static_imports)
|
|
12
|
+
.valmap(([, url]) => new FileRef(url)).get();
|
|
13
|
+
}
|
|
14
|
+
async serve(pathname) {
|
|
15
|
+
const client_file = this.#clients[pathname];
|
|
16
|
+
if (client_file !== undefined) {
|
|
17
|
+
return this.asset(client_file);
|
|
18
|
+
}
|
|
19
|
+
if (pathname.startsWith(this.static_root)) {
|
|
20
|
+
const assetname = pathname.slice(this.static_root.length);
|
|
21
|
+
const static_file = this.#statics[assetname];
|
|
22
|
+
if (static_file !== undefined) {
|
|
23
|
+
return this.asset(static_file);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=Loader.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type App from "@primate/core/App";
|
|
2
|
+
import type BuildApp from "@primate/core/BuildApp";
|
|
3
|
+
import Module from "@primate/core/Module";
|
|
4
|
+
import type Next from "@primate/core/Next";
|
|
5
|
+
import type NextBuild from "@primate/core/NextBuild";
|
|
6
|
+
import type NextServe from "@primate/core/NextServe";
|
|
7
|
+
import type ServeApp from "@primate/core/ServeApp";
|
|
8
|
+
declare const schema: import("pema").ObjectType<{
|
|
9
|
+
debug: import("pema").DefaultType<import("pema/boolean").BooleanType, false>;
|
|
10
|
+
start: import("pema").DefaultType<import("pema/string").StringType, "/">;
|
|
11
|
+
}>;
|
|
12
|
+
export default class NativeModule extends Module {
|
|
13
|
+
#private;
|
|
14
|
+
name: string;
|
|
15
|
+
static input: {
|
|
16
|
+
debug?: boolean | undefined;
|
|
17
|
+
start?: string | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
constructor(config: typeof schema.input);
|
|
20
|
+
init<T extends App>(app: T, next: Next<T>): import("@rcompat/type/MaybePromise").default<T>;
|
|
21
|
+
build(app: BuildApp, next: NextBuild): import("@rcompat/type/MaybePromise").default<BuildApp>;
|
|
22
|
+
serve(app: ServeApp, next: NextServe): import("@rcompat/type/MaybePromise").default<ServeApp>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=Module.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import command from "#command";
|
|
2
|
+
import targets from "#targets";
|
|
3
|
+
import log from "@primate/core/log";
|
|
4
|
+
import Module from "@primate/core/Module";
|
|
5
|
+
import dim from "@rcompat/cli/color/dim";
|
|
6
|
+
import execute from "@rcompat/stdio/execute";
|
|
7
|
+
import pema from "pema";
|
|
8
|
+
import boolean from "pema/boolean";
|
|
9
|
+
import string from "pema/string";
|
|
10
|
+
const names = targets.map(t => t.name);
|
|
11
|
+
const schema = pema({
|
|
12
|
+
debug: boolean.default(false),
|
|
13
|
+
start: string.default("/"),
|
|
14
|
+
});
|
|
15
|
+
export default class NativeModule extends Module {
|
|
16
|
+
name = "native";
|
|
17
|
+
#config;
|
|
18
|
+
static input = schema.input;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super();
|
|
21
|
+
this.#config = schema.parse(config);
|
|
22
|
+
}
|
|
23
|
+
init(app, next) {
|
|
24
|
+
targets.forEach(t => app.target.add(t));
|
|
25
|
+
return next(app);
|
|
26
|
+
}
|
|
27
|
+
build(app, next) {
|
|
28
|
+
if (names.includes(app.target.name)) {
|
|
29
|
+
app.done(async () => {
|
|
30
|
+
const { exe, flags } = app.target.get();
|
|
31
|
+
const executable_path = dim(`${app.path.build}/${exe}`);
|
|
32
|
+
const { host, port } = app.config("http");
|
|
33
|
+
await app.runpath("worker.js").write(`
|
|
34
|
+
import target from "@primate/native/target/${app.target.target}";
|
|
35
|
+
import Webview from "@primate/native/Webview";
|
|
36
|
+
const webview = new Webview({ platform: target });
|
|
37
|
+
webview.navigate("http://${host}:${port}/${this.#config.start}");
|
|
38
|
+
webview.run();
|
|
39
|
+
`);
|
|
40
|
+
await execute(command({
|
|
41
|
+
exe,
|
|
42
|
+
files: ["serve.js", "worker.js"],
|
|
43
|
+
flags,
|
|
44
|
+
}));
|
|
45
|
+
log.system("executable written to {0}", executable_path);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return next(app);
|
|
49
|
+
}
|
|
50
|
+
serve(app, next) {
|
|
51
|
+
if (names.includes(app.target.name)) {
|
|
52
|
+
const worker = new Worker(app.root.join("worker.js").path);
|
|
53
|
+
worker.addEventListener("message", event => {
|
|
54
|
+
if (event.data === "destroyed") {
|
|
55
|
+
app.stop();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return next(app);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=Module.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fail from "@primate/core/fail";
|
|
2
|
+
import runtime from "@rcompat/runtime";
|
|
3
|
+
const commands = {
|
|
4
|
+
bun: "bun build",
|
|
5
|
+
deno: "deno compile",
|
|
6
|
+
};
|
|
7
|
+
function which(target) {
|
|
8
|
+
if (target in commands)
|
|
9
|
+
return commands[target];
|
|
10
|
+
throw fail("unsupported runtime {0}", target);
|
|
11
|
+
}
|
|
12
|
+
;
|
|
13
|
+
export default function (init) {
|
|
14
|
+
return `
|
|
15
|
+
${which(runtime)} \
|
|
16
|
+
${init.files.map(file => `build/${file}`).join(" ")} \
|
|
17
|
+
--conditions=runtime --compile --minify \
|
|
18
|
+
${init.flags} \
|
|
19
|
+
--outfile build/${init.exe}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import location from "@primate/core/location";
|
|
2
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
3
|
+
import dedent from "@rcompat/string/dedent";
|
|
4
|
+
const html = /^.*.html$/u;
|
|
5
|
+
export default async (app) => {
|
|
6
|
+
const server_static = app.runpath(location.server, location.static);
|
|
7
|
+
// explicitly import static assets as files
|
|
8
|
+
const static_imports = (await server_static.collect()).map((path, i) => dedent `
|
|
9
|
+
import static${i} from
|
|
10
|
+
"${FileRef.webpath(`./server/static${path.debase(server_static)}`)}"
|
|
11
|
+
with { type: "file" };
|
|
12
|
+
static_imports["${FileRef
|
|
13
|
+
.webpath(path.debase(server_static))}"] = static${i};
|
|
14
|
+
`)
|
|
15
|
+
.join("\n");
|
|
16
|
+
const client = app.runpath(location.client);
|
|
17
|
+
// explicitly import client assets as files
|
|
18
|
+
const client_imports = (await Promise.all((await client.collect())
|
|
19
|
+
.map(async (file, i) => {
|
|
20
|
+
const type = file.extension === ".css" ? "style" : "js";
|
|
21
|
+
const src = `/${file.debase(client).name}`;
|
|
22
|
+
const path = `./${file.debase(`${app.path.build}/`)}`;
|
|
23
|
+
return {
|
|
24
|
+
code: `await FileRef.text(asset${i})`,
|
|
25
|
+
empty: (await file.text()).length === 0,
|
|
26
|
+
path,
|
|
27
|
+
src,
|
|
28
|
+
type,
|
|
29
|
+
};
|
|
30
|
+
}))).filter(file => !file.empty);
|
|
31
|
+
const d = app.runpath(location.server, location.pages);
|
|
32
|
+
const pages = await Promise.all((await FileRef.collect(d, file => html.test(file.path)))
|
|
33
|
+
.map(async (file) => `${file}`.replace(`${d}/`, _ => "")));
|
|
34
|
+
const app_js = client_imports.find($import => $import.src.endsWith(".js"));
|
|
35
|
+
const assets_scripts = dedent `
|
|
36
|
+
import Webview from "@primate/native/target/${app.target.target}";
|
|
37
|
+
import Loader from "@primate/native/Loader";
|
|
38
|
+
import FileRef from "@primate/native/FileRef";
|
|
39
|
+
|
|
40
|
+
const static_imports = {};
|
|
41
|
+
${static_imports}
|
|
42
|
+
|
|
43
|
+
const client_imports = {};
|
|
44
|
+
${client_imports.map(({ path, src }, i) => dedent `
|
|
45
|
+
import client${i} from "${path}" with { type: "file" };
|
|
46
|
+
client_imports["${FileRef.webpath(src)}"] = client${i};
|
|
47
|
+
const file${i} = await FileRef.text(client${i});
|
|
48
|
+
`).join("\n ")}
|
|
49
|
+
|
|
50
|
+
const assets = [${client_imports.map(($import, i) => dedent `{
|
|
51
|
+
src: "${$import.src}",
|
|
52
|
+
code: file${i},
|
|
53
|
+
type: "${$import.type}",
|
|
54
|
+
inline: false,
|
|
55
|
+
}`).join(",\n ")}];
|
|
56
|
+
|
|
57
|
+
const page_imports = {};
|
|
58
|
+
${pages.map((page, i) => dedent `
|
|
59
|
+
import page${i} from "${FileRef.webpath(`./${location.server}/${location.pages}/${page}`)}" with { type: "file" };
|
|
60
|
+
page_imports["${page}"] = page${i};`).join("\n ")}
|
|
61
|
+
|
|
62
|
+
const load = async resource_map =>
|
|
63
|
+
Object.fromEntries(await Promise.all(Object.entries(resource_map).map(
|
|
64
|
+
async ([key, url]) => [key, await FileRef.text(url)])));
|
|
65
|
+
const pages = await load(page_imports);
|
|
66
|
+
|
|
67
|
+
export default {
|
|
68
|
+
assets,
|
|
69
|
+
loader: new Loader({
|
|
70
|
+
pages,
|
|
71
|
+
rootfile: import.meta.url,
|
|
72
|
+
static_root: "${app.config("http.static.root")}",
|
|
73
|
+
client_imports,
|
|
74
|
+
static_imports,
|
|
75
|
+
Webview,
|
|
76
|
+
}),
|
|
77
|
+
target: "${app.target.name}",
|
|
78
|
+
};
|
|
79
|
+
`;
|
|
80
|
+
await app.path.build.join("target.js").write(assets_scripts);
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=desktop.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import runner from "#desktop";
|
|
2
|
+
const targets = [
|
|
3
|
+
{
|
|
4
|
+
exe: "app",
|
|
5
|
+
flags: "--target=bun-linux-x64",
|
|
6
|
+
name: "linux-x64",
|
|
7
|
+
runner,
|
|
8
|
+
target: "linux-x64",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
exe: "app.exe",
|
|
12
|
+
flags: "--target=bun-windows-x64",
|
|
13
|
+
name: "windows-x64",
|
|
14
|
+
runner,
|
|
15
|
+
target: "windows-x64",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
exe: "app",
|
|
19
|
+
flags: "--target=bun-darwin-x64",
|
|
20
|
+
name: "darwin-x64",
|
|
21
|
+
runner,
|
|
22
|
+
target: "darwin-x64",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
exe: "app",
|
|
26
|
+
flags: "--target=bun-darwin-arm64",
|
|
27
|
+
name: "darwin-arm64",
|
|
28
|
+
runner,
|
|
29
|
+
target: "darwin-arm64",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
targets.push({
|
|
33
|
+
...targets.find(t => t.target === `${process.platform}-${process.arch}`),
|
|
34
|
+
name: "desktop",
|
|
35
|
+
});
|
|
36
|
+
export default targets;
|
|
37
|
+
//# sourceMappingURL=targets.js.map
|
package/package.json
CHANGED
|
@@ -1,31 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Primate native
|
|
5
|
-
"homepage": "https://
|
|
6
|
-
"bugs": "https://github.com/
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Primate native",
|
|
5
|
+
"homepage": "https://primate.run/docs/native",
|
|
6
|
+
"bugs": "https://github.com/primate-run/primate/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"/lib/**/*.js",
|
|
10
|
+
"/lib/**/*.d.ts",
|
|
11
|
+
"!/**/*.spec.*"
|
|
11
12
|
],
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/primate-run/primate",
|
|
15
16
|
"directory": "packages/native"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@rcompat/cli": "^0.
|
|
19
|
-
"@rcompat/fs": "^0.
|
|
20
|
-
"@rcompat/
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"@rcompat/
|
|
23
|
-
"@
|
|
19
|
+
"@rcompat/cli": "^0.11.3",
|
|
20
|
+
"@rcompat/fs": "^0.21.1",
|
|
21
|
+
"@rcompat/record": "^0.9.1",
|
|
22
|
+
"@rcompat/runtime": "^0.6.0",
|
|
23
|
+
"@rcompat/stdio": "^0.12.2",
|
|
24
|
+
"@rcompat/string": "^0.10.0",
|
|
25
|
+
"@rcompat/webview": "^0.14.0",
|
|
26
|
+
"@primate/core": "^0.3.0",
|
|
27
|
+
"pema": "^0.3.0"
|
|
24
28
|
},
|
|
25
29
|
"type": "module",
|
|
30
|
+
"imports": {
|
|
31
|
+
"#*": {
|
|
32
|
+
"apekit": "./src/private/*.ts",
|
|
33
|
+
"default": "./lib/private/*.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
26
36
|
"exports": {
|
|
27
|
-
".":
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
".": {
|
|
38
|
+
"apekit": "./src/public/index.ts",
|
|
39
|
+
"default": "./lib/public/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./*": {
|
|
42
|
+
"apekit": "./src/public/*.ts",
|
|
43
|
+
"default": "./lib/public/*.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "npm run clean && tsc",
|
|
48
|
+
"clean": "rm -rf ./lib",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"test": "npm run build && npx proby"
|
|
30
51
|
}
|
|
31
52
|
}
|
package/src/desktop.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import collect from "@rcompat/fs/collect";
|
|
2
|
-
import join from "@rcompat/fs/join";
|
|
3
|
-
import webpath from "@rcompat/fs/webpath";
|
|
4
|
-
|
|
5
|
-
const html = /^.*.html$/u;
|
|
6
|
-
|
|
7
|
-
export default async app => {
|
|
8
|
-
const location = app.get("location");
|
|
9
|
-
const client = app.runpath(location.client);
|
|
10
|
-
const server_static = app.runpath(location.server, location.static);
|
|
11
|
-
const re = /app..*(?:js|css)$/u;
|
|
12
|
-
|
|
13
|
-
const static_imports = (await server_static.collect()).map((path, i) => `
|
|
14
|
-
import static${i} from "${webpath(`./server/static${path.debase(server_static)}`)}" with { type: "file" };
|
|
15
|
-
static_imports["${webpath(path.debase(server_static))}"] = static${i};`)
|
|
16
|
-
.join("\n");
|
|
17
|
-
|
|
18
|
-
const client_imports = (await Promise.all((await client.collect())
|
|
19
|
-
.map(async (file, i) => {
|
|
20
|
-
const type = file.extension === ".css" ? "style" : "js";
|
|
21
|
-
const src = `/${file.debase(client).name}`;
|
|
22
|
-
const path = `./${file.debase(`${app.path.build}/`)}`;
|
|
23
|
-
return {
|
|
24
|
-
src,
|
|
25
|
-
path,
|
|
26
|
-
code: `await load_text(asset${i})`,
|
|
27
|
-
type,
|
|
28
|
-
empty: (await file.text()).length === 0,
|
|
29
|
-
};
|
|
30
|
-
}))).filter(file => !file.empty);
|
|
31
|
-
const d = app.runpath(location.server, location.pages);
|
|
32
|
-
const pages = await Promise.all((await collect(d, html, { recursive: true }))
|
|
33
|
-
.map(async file => `${file}`.replace(`${d}/`, _ => "")));
|
|
34
|
-
const app_js = client_imports.find($import => $import.src.endsWith(".js"));
|
|
35
|
-
|
|
36
|
-
const assets_scripts = `
|
|
37
|
-
import Webview from "@primate/native/platform/${app.build_target}";
|
|
38
|
-
import loader from "@primate/native/loader";
|
|
39
|
-
import load_text from "primate/load-text";
|
|
40
|
-
|
|
41
|
-
const static_imports = {};
|
|
42
|
-
${static_imports}
|
|
43
|
-
|
|
44
|
-
const client_imports = {};
|
|
45
|
-
${client_imports.map(({ path, src }, i) =>
|
|
46
|
-
`import client${i} from "${path}" with { type: "file" };
|
|
47
|
-
client_imports["${webpath(src)}"] = client${i};
|
|
48
|
-
const file${i} = await load_text(client${i});`).join("\n ")}
|
|
49
|
-
const assets = [${client_imports.map(($import, i) => `{
|
|
50
|
-
src: "${$import.src}",
|
|
51
|
-
code: file${i},
|
|
52
|
-
type: "${$import.type}",
|
|
53
|
-
inline: false,
|
|
54
|
-
}`).join(",\n ")}];
|
|
55
|
-
|
|
56
|
-
${app_js === undefined ? "" :
|
|
57
|
-
`
|
|
58
|
-
const imports = {
|
|
59
|
-
app: "${join("/", client_imports.find($import =>
|
|
60
|
-
$import.src.includes("app") && $import.src.endsWith(".js")).src).webpath()}"
|
|
61
|
-
};
|
|
62
|
-
// importmap
|
|
63
|
-
assets.push({
|
|
64
|
-
inline: true,
|
|
65
|
-
code: { imports },
|
|
66
|
-
type: "importmap",
|
|
67
|
-
});`}
|
|
68
|
-
|
|
69
|
-
const page_imports = {};
|
|
70
|
-
${pages.map((page, i) =>
|
|
71
|
-
`import page${i} from "${webpath(`./${location.server}/${location.pages}/${page}`)}" with { type: "file" };
|
|
72
|
-
page_imports["${page}"] = page${i};`).join("\n ")}
|
|
73
|
-
|
|
74
|
-
export default {
|
|
75
|
-
assets,
|
|
76
|
-
loader: await loader({
|
|
77
|
-
page_imports,
|
|
78
|
-
client_imports,
|
|
79
|
-
static_imports,
|
|
80
|
-
pages_app: "${app.get("pages.app")}",
|
|
81
|
-
static_root: "${app.get("http.static.root")}",
|
|
82
|
-
Webview,
|
|
83
|
-
}),
|
|
84
|
-
target: "${app.build_target}",
|
|
85
|
-
};
|
|
86
|
-
`;
|
|
87
|
-
await app.path.build.join("target.js").write(assets_scripts);
|
|
88
|
-
|
|
89
|
-
};
|
package/src/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import dim from "@rcompat/cli/color/dim";
|
|
2
|
-
import execute from "@rcompat/stdio/execute";
|
|
3
|
-
import targets from "./targets.js";
|
|
4
|
-
import log from "@primate/core/log";
|
|
5
|
-
|
|
6
|
-
const target_keys = Object.keys(targets);
|
|
7
|
-
const command = "bun build build/serve.js --conditions=runtime --compile --minify";
|
|
8
|
-
|
|
9
|
-
export default ({
|
|
10
|
-
start = "/",
|
|
11
|
-
debug = false,
|
|
12
|
-
} = {}) => {
|
|
13
|
-
return {
|
|
14
|
-
name: "primate:native",
|
|
15
|
-
init(app, next) {
|
|
16
|
-
target_keys.forEach(target => app.target(target, targets[target]));
|
|
17
|
-
return next(app);
|
|
18
|
-
},
|
|
19
|
-
build(app, next) {
|
|
20
|
-
if (target_keys.includes(app.build_target)) {
|
|
21
|
-
app.done(async () => {
|
|
22
|
-
const { flags, exe } = targets[app.build_target];
|
|
23
|
-
const executable_path = dim(`${app.path.build}/${exe}`);
|
|
24
|
-
await execute(`${command} ${flags} --outfile build/${exe}`);
|
|
25
|
-
log.system(`executable written to ${executable_path}`);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return next(app);
|
|
29
|
-
},
|
|
30
|
-
async serve(app, next) {
|
|
31
|
-
if (target_keys.includes(app.build_target)) {
|
|
32
|
-
const Webview = app.loader.webview();
|
|
33
|
-
const webview = new Webview(debug);
|
|
34
|
-
const { host, port } = app.get("http");
|
|
35
|
-
webview.navigate(`http://${host}:${port}${start}`);
|
|
36
|
-
webview.run();
|
|
37
|
-
webview.closed(() => {
|
|
38
|
-
app.stop();
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return next(app);
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "@rcompat/webview/worker/darwin-arm64";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "@rcompat/webview/worker/darwin-x64";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "@rcompat/webview/worker/linux-x64";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "@rcompat/webview/worker/windows-x64";
|
package/src/public/loader.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import serve_asset from "primate/serve-asset";
|
|
2
|
-
import file from "@rcompat/fs/file";
|
|
3
|
-
import map from "@rcompat/object/map";
|
|
4
|
-
|
|
5
|
-
const load = async resource_map =>
|
|
6
|
-
Object.fromEntries(await Promise.all(Object.entries(resource_map).map(
|
|
7
|
-
async ([key, url]) => [key, await file(url).text()])));
|
|
8
|
-
|
|
9
|
-
export default async ({
|
|
10
|
-
pages_app,
|
|
11
|
-
page_imports,
|
|
12
|
-
client_imports,
|
|
13
|
-
static_imports,
|
|
14
|
-
static_root,
|
|
15
|
-
Webview,
|
|
16
|
-
}) => {
|
|
17
|
-
const clients = map(client_imports, ([key, url]) => [key, file(url)]);
|
|
18
|
-
const statics = map(static_imports, ([key, url]) => [key, file(url)]);
|
|
19
|
-
const pages = await load(page_imports);
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
page(name) {
|
|
23
|
-
return pages[name] ?? pages[pages_app];
|
|
24
|
-
},
|
|
25
|
-
asset(pathname) {
|
|
26
|
-
const client_file = clients[pathname];
|
|
27
|
-
if (client_file !== undefined) {
|
|
28
|
-
return serve_asset(client_file);
|
|
29
|
-
}
|
|
30
|
-
if (pathname.startsWith(static_root)) {
|
|
31
|
-
const assetname = pathname.slice(static_root.length);
|
|
32
|
-
const static_file = statics[assetname];
|
|
33
|
-
if (static_file !== undefined) {
|
|
34
|
-
return serve_asset(static_file);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
webview() {
|
|
39
|
-
return Webview;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
};
|
package/src/targets.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import target from "./desktop.js";
|
|
2
|
-
|
|
3
|
-
const desktop = {
|
|
4
|
-
forward: `${process.platform}-${process.arch}`,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const linux_x64 = {
|
|
8
|
-
flags: "--target=bun-linux-x64",
|
|
9
|
-
exe: "app",
|
|
10
|
-
target,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const windows_x64 = {
|
|
14
|
-
flags: "--target=bun-windows-x64",
|
|
15
|
-
exe: "app.exe",
|
|
16
|
-
target,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const darwin_x64 = {
|
|
20
|
-
flags: "--target=bun-darwin-x64",
|
|
21
|
-
exe: "app",
|
|
22
|
-
target,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const darwin_arm64 = {
|
|
26
|
-
flags: "--target=bun-darwin-arm64",
|
|
27
|
-
exe: "app",
|
|
28
|
-
target,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default {
|
|
32
|
-
desktop,
|
|
33
|
-
"linux-x64": linux_x64,
|
|
34
|
-
"windows-x64": windows_x64,
|
|
35
|
-
"darwin-x64": darwin_x64,
|
|
36
|
-
"darwin-arm64": darwin_arm64,
|
|
37
|
-
};
|