chocola 1.1.9 → 1.1.10

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/compiler/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { throwError, genRandomId, incrementAlfabet } from "./utils.js";
1
+ import { throwError, genRandomId, incrementAlfabet, isWebLink } from "./utils.js";
2
2
  import { JSDOM } from "jsdom";
3
3
  import path from "path";
4
4
  import { promises as fs } from "fs";
@@ -188,6 +188,16 @@ ${letter}RUNTIME(${letter}, ${JSON.stringify(ctx)});`);
188
188
 
189
189
  await fs.writeFile(path.join(outDirPath, "index.html"), prettyHtml);
190
190
 
191
+ const newIndex = await fs.readFile(path.join(outDirPath, "index.html"), "utf8");
192
+ const newDoc = new JSDOM(newIndex);
193
+ const newElements = Array.from(newDoc.querySelectorAll("*"));
194
+
195
+ for (const el of newElements) {
196
+ let src = el.getAttribute("src") || el.getAttribute("href");
197
+ if (src && !isWebLink(src)) {
198
+ await fs.copyFile(path.join(__srcdir, src), path.join(outDirPath, src));
199
+ }
200
+ }
191
201
 
192
202
  console.log(`
193
203
  ▄▄ ▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄ ██
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from "fs";
2
2
  import { loadWithAssets, throwError, genRandomId } from "./utils.js";
3
3
  import { readMyFile, checkFile } from "./fs.js";
4
+ import { JSDOM } from "jsdom";
4
5
  import path from "path";
5
6
 
6
7
  /**
@@ -122,3 +123,21 @@ export async function processIcons(link, __rootdir, __srcdir, outDirPath) {
122
123
  throwError(err)
123
124
  }
124
125
  }
126
+
127
+ export async function copyResources(__srcdir, outDirPath) {
128
+ const newIndex = await fs.readFile(path.join(outDirPath, "index.html"), "utf8");
129
+ const newDoc = new JSDOM(newIndex);
130
+ const newElements = Array.from(newDoc.window.document.querySelectorAll("*"));
131
+
132
+ for (const el of newElements) {
133
+ const src = el.getAttribute("src") || el.getAttribute("href");
134
+
135
+ if (src && !isWebLink(src)) {
136
+ const srcPath = path.join(__srcdir, src);
137
+ const destPath = path.join(outDirPath, src);
138
+
139
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
140
+ await fs.copyFile(srcPath, destPath);
141
+ }
142
+ }
143
+ }
package/compiler/utils.js CHANGED
@@ -64,3 +64,12 @@ export function incrementAlfabet(letters) {
64
64
  }
65
65
  return "a" + arr.join("");
66
66
  }
67
+
68
+ export function isWebLink(str) {
69
+ try {
70
+ const url = new URL(str);
71
+ return url.protocol === "http:" || url.protocol === "https:";
72
+ } catch (e) {
73
+ return false;
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chocola",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "Chocola pipeline for web apps.",
5
5
  "keywords": [
6
6
  "web",