@primate/core 0.1.3 → 0.1.5
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 +3 -3
- package/src/build/app.js +17 -23
- package/src/build/hook/build.js +19 -14
- package/src/build/targets/web.js +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Primate core",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"@rcompat/build": "^0.4.0",
|
|
22
22
|
"@rcompat/cli": "^0.5.1",
|
|
23
23
|
"@rcompat/crypto": "^0.5.0",
|
|
24
|
-
"@rcompat/fs": "^0.
|
|
24
|
+
"@rcompat/fs": "^0.5.0",
|
|
25
25
|
"@rcompat/function": "^0.4.0",
|
|
26
|
-
"@rcompat/http": "^0.5.
|
|
26
|
+
"@rcompat/http": "^0.5.3",
|
|
27
27
|
"@rcompat/invariant": "^0.5.0",
|
|
28
28
|
"@rcompat/object": "^0.5.0",
|
|
29
29
|
"@rcompat/package": "^0.7.0",
|
package/src/build/app.js
CHANGED
|
@@ -29,38 +29,32 @@ export default async (root, config) => {
|
|
|
29
29
|
modules: await module_loader(root, config.modules ?? []),
|
|
30
30
|
fonts: [],
|
|
31
31
|
// copy files to build folder, potentially transforming them
|
|
32
|
-
async stage(source, directory,
|
|
32
|
+
async stage(source, directory, apply_defines = false) {
|
|
33
33
|
const { define = {} } = this.get("build", {});
|
|
34
|
+
const defines = Object.entries(define);
|
|
34
35
|
|
|
35
36
|
if (!await source.exists()) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
const target_base = this.runpath(directory);
|
|
40
|
-
const defines = Object.entries(define);
|
|
41
|
-
|
|
42
|
-
// first, copy everything
|
|
43
|
-
await source.copy(target_base);
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const rel_path = join(directory, abs_path.debase(source));
|
|
54
|
-
if (directory.path === client_location && rel_path.path.endsWith(".css")) {
|
|
55
|
-
const contents = await abs_path.text();
|
|
56
|
-
const font_regex = /@font-face\s*\{.+?url\("(.+?\.woff2)"\).+?\}/gus;
|
|
57
|
-
this.fonts.push(...[...contents.matchAll(font_regex)].map(match => match[1]));
|
|
58
|
-
}
|
|
59
|
-
const target = await target_base.join(rel_path.debase(directory));
|
|
60
|
-
await target.directory.create();
|
|
42
|
+
if (!apply_defines || defines.length === 0) {
|
|
43
|
+
// copy everything
|
|
44
|
+
await source.copy(target_base);
|
|
45
|
+
} else {
|
|
46
|
+
// copy files individually, transform them using a defines mapper
|
|
47
|
+
const mapper = text =>
|
|
48
|
+
defines.reduce((replaced, [key, substitution]) =>
|
|
49
|
+
replaced.replaceAll(key, substitution), text);
|
|
61
50
|
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
await Promise.all((await source.collect()).map(async abs_path => {
|
|
52
|
+
const rel_path = join(directory, abs_path.debase(source));
|
|
53
|
+
const target = await target_base.join(rel_path.debase(directory));
|
|
54
|
+
await target.directory.create();
|
|
55
|
+
await target.write(mapper(await abs_path.text()));
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
64
58
|
},
|
|
65
59
|
async compile(component) {
|
|
66
60
|
const { server, client, components } = this.get("location");
|
package/src/build/hook/build.js
CHANGED
|
@@ -11,8 +11,7 @@ import manifest from "@rcompat/package/manifest";
|
|
|
11
11
|
import root from "@rcompat/package/root";
|
|
12
12
|
import copy_includes from "./copy_includes.js";
|
|
13
13
|
import $router from "./router.js";
|
|
14
|
-
|
|
15
|
-
const html = /^.*.html$/u;
|
|
14
|
+
import webpath from "@rcompat/fs/webpath";
|
|
16
15
|
|
|
17
16
|
const pre = async (app, mode, target) => {
|
|
18
17
|
let target$ = target;
|
|
@@ -54,12 +53,12 @@ const write_directories = async (build_directory, app) => {
|
|
|
54
53
|
for (const name of app.server_build) {
|
|
55
54
|
const d = app.runpath(name);
|
|
56
55
|
const e = await Promise.all((await collect(d, js_re, { recursive: true }))
|
|
57
|
-
.map(async
|
|
56
|
+
.map(async path => `${path}`.replace(d, _ => "")));
|
|
58
57
|
const files_js = `
|
|
59
58
|
const ${name} = [];
|
|
60
|
-
${e.map((
|
|
61
|
-
`import * as ${name}${i} from "
|
|
62
|
-
${name}.push(["${
|
|
59
|
+
${e.map((path, i) =>
|
|
60
|
+
`import * as ${name}${i} from "${webpath(`../${name}${path}`)}";
|
|
61
|
+
${name}.push(["${webpath(path.slice(1, -".js".length))}", ${name}${i}]);`,
|
|
63
62
|
).join("\n")}
|
|
64
63
|
export default ${name};`;
|
|
65
64
|
await build_directory.join(`${name}.js`).write(files_js);
|
|
@@ -70,16 +69,16 @@ const write_components = async (build_directory, app) => {
|
|
|
70
69
|
const location = app.get("location");
|
|
71
70
|
const d2 = app.runpath(location.server, location.components);
|
|
72
71
|
const e = await Promise.all((await collect(d2, js_re, { recursive: true }))
|
|
73
|
-
.map(async
|
|
72
|
+
.map(async path => `${path}`.replace(d2, _ => "")));
|
|
74
73
|
const components_js = `
|
|
75
74
|
const components = [];
|
|
76
75
|
${e.map((component, i) =>
|
|
77
|
-
`import * as component${i} from "
|
|
78
|
-
components.push(["${component.slice(1, -".js".length)}", component${i}]);`,
|
|
76
|
+
`import * as component${i} from "${webpath(`../server/components${component}`)}";
|
|
77
|
+
components.push(["${webpath(component.slice(1, -".js".length))}", component${i}]);`,
|
|
79
78
|
).join("\n")}
|
|
80
79
|
|
|
81
80
|
${app.roots.map((root, i) => `
|
|
82
|
-
import * as root${i} from "${root}";
|
|
81
|
+
import * as root${i} from "${webpath(`../server/${root.name}`)}";
|
|
83
82
|
components.push(["${root.name}", root${i}]);
|
|
84
83
|
`).join("\n")}
|
|
85
84
|
|
|
@@ -114,8 +113,14 @@ const post = async (app, mode, target) => {
|
|
|
114
113
|
const location = app.get("location");
|
|
115
114
|
const defaults = join(import.meta.dirname, "../defaults");
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
// stage routes
|
|
117
|
+
await app.stage(app.path.routes, location.routes);
|
|
118
|
+
|
|
119
|
+
// stage types
|
|
120
|
+
await app.stage(app.path.types, location.types);
|
|
121
|
+
|
|
122
|
+
// stage components, transforming defines
|
|
123
|
+
await app.stage(app.path.components, location.components, true);
|
|
119
124
|
|
|
120
125
|
const directory = app.runpath(location.routes);
|
|
121
126
|
for (const path of await directory.collect()) {
|
|
@@ -123,9 +128,9 @@ const post = async (app, mode, target) => {
|
|
|
123
128
|
?.(directory, path.debase(`${directory}/`));
|
|
124
129
|
}
|
|
125
130
|
// copy framework pages
|
|
126
|
-
await app.stage(defaults, location.pages
|
|
131
|
+
await app.stage(defaults, location.pages);
|
|
127
132
|
// overwrite transformed pages to build
|
|
128
|
-
await app.stage(app.path.pages, location.pages
|
|
133
|
+
await app.stage(app.path.pages, location.pages);
|
|
129
134
|
|
|
130
135
|
// copy static files to build/server/static
|
|
131
136
|
await app.stage(app.path.static, join(location.server, location.static));
|
package/src/build/targets/web.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import collect from "@rcompat/fs/collect";
|
|
2
|
+
import webpath from "@rcompat/fs/webpath";
|
|
2
3
|
|
|
3
4
|
const html = /^.*.html$/u;
|
|
4
5
|
|
|
@@ -20,9 +21,9 @@ export default async app => {
|
|
|
20
21
|
});
|
|
21
22
|
const d = app.runpath(location.pages);
|
|
22
23
|
const pages = await Promise.all((await collect(d, html, { recursive: true }))
|
|
23
|
-
.map(async file => `${file}`.
|
|
24
|
+
.map(async file => `${file.debase(d)}`.slice(1)));
|
|
24
25
|
const pages_str = pages.map(page =>
|
|
25
|
-
`"${page}": await join(import.meta.url, "
|
|
26
|
+
`"${page}": await join(import.meta.url, "${webpath(`../${location.pages}/${page}`)}").text(),`).join("\n");
|
|
26
27
|
|
|
27
28
|
const assets_scripts = `
|
|
28
29
|
import file from "@rcompat/fs/file";
|
|
@@ -80,11 +81,11 @@ export default async app => {
|
|
|
80
81
|
},
|
|
81
82
|
async asset(pathname) {
|
|
82
83
|
const root_asset = buildroot.join(\`client/\${pathname}\`);
|
|
83
|
-
if (await await root_asset.isFile) {
|
|
84
|
+
if (await await root_asset.isFile()) {
|
|
84
85
|
return serve_asset(root_asset);
|
|
85
86
|
}
|
|
86
87
|
const static_asset = buildroot.join(\`client/static/\${pathname}\`);
|
|
87
|
-
if (await static_asset.isFile) {
|
|
88
|
+
if (await static_asset.isFile()) {
|
|
88
89
|
return serve_asset(static_asset);
|
|
89
90
|
}
|
|
90
91
|
},
|