@primate/core 0.1.2 → 0.1.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Primate core",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
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, filter) {
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
- const location = this.get("location");
46
- const client_location = join(location.client, location.static).path;
47
- const mapper = text =>
48
- defines.reduce((replaced, [key, substitution]) =>
49
- replaced.replaceAll(key, substitution), text);
50
-
51
- // then, copy and transform whitelisted paths using mapper
52
- await Promise.all((await source.collect(filter)).map(async abs_path => {
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
- defines.length > 0 && await target.write(mapper(await abs_path.text()));
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");
@@ -12,8 +12,6 @@ import root from "@rcompat/package/root";
12
12
  import copy_includes from "./copy_includes.js";
13
13
  import $router from "./router.js";
14
14
 
15
- const html = /^.*.html$/u;
16
-
17
15
  const pre = async (app, mode, target) => {
18
16
  let target$ = target;
19
17
  if (app.targets[target$] === undefined) {
@@ -114,8 +112,14 @@ const post = async (app, mode, target) => {
114
112
  const location = app.get("location");
115
113
  const defaults = join(import.meta.dirname, "../defaults");
116
114
 
117
- await Promise.all(["routes", "types", "components"].map(directory =>
118
- app.stage(app.path[directory], location[directory])));
115
+ // stage routes
116
+ await app.stage(app.path.routes, location.routes);
117
+
118
+ // stage types
119
+ await app.stage(app.path.types, location.types);
120
+
121
+ // stage components, transforming defines
122
+ await app.stage(app.path.components, location.components, true);
119
123
 
120
124
  const directory = app.runpath(location.routes);
121
125
  for (const path of await directory.collect()) {
@@ -123,9 +127,9 @@ const post = async (app, mode, target) => {
123
127
  ?.(directory, path.debase(`${directory}/`));
124
128
  }
125
129
  // copy framework pages
126
- await app.stage(defaults, location.pages, html);
130
+ await app.stage(defaults, location.pages);
127
131
  // overwrite transformed pages to build
128
- await app.stage(app.path.pages, location.pages, html);
132
+ await app.stage(app.path.pages, location.pages);
129
133
 
130
134
  // copy static files to build/server/static
131
135
  await app.stage(app.path.static, join(location.server, location.static));
@@ -81,7 +81,7 @@ export default async app => {
81
81
  async asset(pathname) {
82
82
  const root_asset = buildroot.join(\`client/\${pathname}\`);
83
83
  if (await await root_asset.isFile) {
84
- return serve_asset(asset);
84
+ return serve_asset(root_asset);
85
85
  }
86
86
  const static_asset = buildroot.join(\`client/static/\${pathname}\`);
87
87
  if (await static_asset.isFile) {