@primate/native 0.1.5 → 0.1.6
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/package.json +5 -4
- package/src/desktop.js +16 -12
- package/src/public/loader.js +14 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Primate native applications",
|
|
5
5
|
"homepage": "https://primatejs.com/modules/native",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@rcompat/cli": "^0.5.1",
|
|
19
|
-
"@rcompat/fs": "^0.
|
|
19
|
+
"@rcompat/fs": "^0.7.0",
|
|
20
|
+
"@rcompat/object": "^0.5.0",
|
|
20
21
|
"@rcompat/stdio": "^0.5.0",
|
|
21
|
-
"@rcompat/webview": "^0.
|
|
22
|
-
"@primate/core": "^0.1.
|
|
22
|
+
"@rcompat/webview": "^0.8.0",
|
|
23
|
+
"@primate/core": "^0.1.9"
|
|
23
24
|
},
|
|
24
25
|
"type": "module",
|
|
25
26
|
"exports": {
|
package/src/desktop.js
CHANGED
|
@@ -6,19 +6,19 @@ const html = /^.*.html$/u;
|
|
|
6
6
|
|
|
7
7
|
export default async app => {
|
|
8
8
|
const location = app.get("location");
|
|
9
|
-
const http = app.get("http");
|
|
10
9
|
const client = app.runpath(location.client);
|
|
10
|
+
const server_static = app.runpath(location.server, location.static);
|
|
11
11
|
const re = /app..*(?:js|css)$/u;
|
|
12
12
|
|
|
13
|
-
const static_imports = (await
|
|
14
|
-
import static${i} from "${webpath(`./
|
|
15
|
-
static_imports["${webpath(path.debase(
|
|
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
16
|
.join("\n");
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const client_imports = (await Promise.all((await client.collect())
|
|
19
19
|
.map(async (file, i) => {
|
|
20
20
|
const type = file.extension === ".css" ? "style" : "js";
|
|
21
|
-
const src =
|
|
21
|
+
const src = `/${file.debase(client).name}`;
|
|
22
22
|
const path = `./${file.debase(`${app.path.build}/`)}`;
|
|
23
23
|
return {
|
|
24
24
|
src,
|
|
@@ -31,7 +31,7 @@ export default async app => {
|
|
|
31
31
|
const d = app.runpath(location.server, location.pages);
|
|
32
32
|
const pages = await Promise.all((await collect(d, html, { recursive: true }))
|
|
33
33
|
.map(async file => `${file}`.replace(`${d}/`, _ => "")));
|
|
34
|
-
const app_js =
|
|
34
|
+
const app_js = client_imports.find($import => $import.src.endsWith(".js"));
|
|
35
35
|
|
|
36
36
|
const assets_scripts = `
|
|
37
37
|
import Webview from "@primate/native/platform/${app.build_target}";
|
|
@@ -41,10 +41,12 @@ export default async app => {
|
|
|
41
41
|
const static_imports = {};
|
|
42
42
|
${static_imports}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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) => `{
|
|
48
50
|
src: "${$import.src}",
|
|
49
51
|
code: file${i},
|
|
50
52
|
type: "${$import.type}",
|
|
@@ -54,7 +56,7 @@ export default async app => {
|
|
|
54
56
|
${app_js === undefined ? "" :
|
|
55
57
|
`
|
|
56
58
|
const imports = {
|
|
57
|
-
app: "${join(
|
|
59
|
+
app: "${join("/", client_imports.find($import =>
|
|
58
60
|
$import.src.includes("app") && $import.src.endsWith(".js")).src).webpath()}"
|
|
59
61
|
};
|
|
60
62
|
// importmap
|
|
@@ -73,8 +75,10 @@ export default async app => {
|
|
|
73
75
|
assets,
|
|
74
76
|
loader: await loader({
|
|
75
77
|
page_imports,
|
|
78
|
+
client_imports,
|
|
76
79
|
static_imports,
|
|
77
80
|
pages_app: "${app.get("pages.app")}",
|
|
81
|
+
static_root: "${app.get("http.static.root")}",
|
|
78
82
|
Webview,
|
|
79
83
|
}),
|
|
80
84
|
target: "${app.build_target}",
|
package/src/public/loader.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import serve_asset from "primate/serve-asset";
|
|
2
2
|
import file from "@rcompat/fs/file";
|
|
3
|
+
import map from "@rcompat/object/map";
|
|
3
4
|
|
|
4
5
|
const load = async resource_map =>
|
|
5
6
|
Object.fromEntries(await Promise.all(Object.entries(resource_map).map(
|
|
@@ -8,11 +9,13 @@ const load = async resource_map =>
|
|
|
8
9
|
export default async ({
|
|
9
10
|
pages_app,
|
|
10
11
|
page_imports,
|
|
12
|
+
client_imports,
|
|
11
13
|
static_imports,
|
|
14
|
+
static_root,
|
|
12
15
|
Webview,
|
|
13
16
|
}) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
17
|
+
const clients = map(client_imports, ([key, url]) => [key, file(url)]);
|
|
18
|
+
const statics = map(static_imports, ([key, url]) => [key, file(url)]);
|
|
16
19
|
const pages = await load(page_imports);
|
|
17
20
|
|
|
18
21
|
return {
|
|
@@ -20,13 +23,16 @@ export default async ({
|
|
|
20
23
|
return pages[name] ?? pages[pages_app];
|
|
21
24
|
},
|
|
22
25
|
asset(pathname) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
return serve_asset(
|
|
26
|
+
const client_file = clients[pathname];
|
|
27
|
+
if (client_file !== undefined) {
|
|
28
|
+
return serve_asset(client_file);
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
}
|
|
30
36
|
}
|
|
31
37
|
},
|
|
32
38
|
webview() {
|