olum-compiler 0.2.7 → 0.5.1

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.
Files changed (58) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +1 -1
  3. package/bin/build.js +9 -0
  4. package/bin/compiler.js +23 -0
  5. package/bin/copySrc.js +22 -0
  6. package/bin/dev.js +47 -0
  7. package/bin/index.js +1 -24
  8. package/bin/mimes.json +340 -0
  9. package/bin/server.js +77 -0
  10. package/bin/watcher.js +6 -0
  11. package/bin/ws.js +54 -0
  12. package/lib/attr.js +39 -0
  13. package/lib/clean.js +4 -0
  14. package/lib/colors.js +72 -0
  15. package/lib/compPlaceholder.js +10 -0
  16. package/lib/compiler.js +21 -0
  17. package/lib/cssParser.js +87 -0
  18. package/lib/domEvents.js +112 -0
  19. package/lib/events.js +48 -0
  20. package/lib/for.js +71 -0
  21. package/lib/getImports.js +48 -0
  22. package/lib/getTempPath.js +13 -0
  23. package/lib/helpers.js +509 -0
  24. package/lib/htmlParser.js +71 -0
  25. package/lib/if.js +65 -0
  26. package/lib/jsParser.js +31 -0
  27. package/lib/lineCounter.js +31 -0
  28. package/lib/log.txt +0 -0
  29. package/lib/mode.js +12 -0
  30. package/lib/models.js +51 -0
  31. package/lib/parser.js +170 -0
  32. package/lib/placeholder.js +76 -0
  33. package/lib/regex.js +12 -0
  34. package/lib/show.js +22 -0
  35. package/lib/sourcemap.js +34 -0
  36. package/lib/styles.js +32 -0
  37. package/lib/toJs.js +12 -0
  38. package/lib/tokens.js +14 -0
  39. package/package.json +8 -40
  40. package/babel.config.json +0 -4
  41. package/compiler.js +0 -486
  42. package/tasks/build.js +0 -24
  43. package/tasks/bundle.js +0 -33
  44. package/tasks/catchall.js +0 -39
  45. package/tasks/clean.js +0 -18
  46. package/tasks/compile.js +0 -32
  47. package/tasks/copy-build.js +0 -33
  48. package/tasks/desktop.js +0 -63
  49. package/tasks/dev.js +0 -18
  50. package/tasks/index.js +0 -12
  51. package/tasks/linux.js +0 -255
  52. package/tasks/logger.js +0 -19
  53. package/tasks/mac.js +0 -8
  54. package/tasks/reload.js +0 -7
  55. package/tasks/server.js +0 -26
  56. package/tasks/watch.js +0 -44
  57. package/tasks/windows.js +0 -8
  58. package/webpack.config.js +0 -152
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright 2021 Eissa Saber
3
+ Copyright 2026 Eissa Saber
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <p align="center"><img width="100" src="https://olumjs.github.io/logo.png" alt="Olum logo"></p>
1
+ <p align="center"><img width="100" src="https://github.com/olumjs.png" alt="Olum logo"></p>
2
2
  <p align="center">
3
3
  <a href="https://www.npmjs.com/package/olum-compiler" target="_blank"><img src="https://img.shields.io/npm/v/olum-compiler" alt="npm"></a>
4
4
  <img src="https://img.shields.io/npm/dm/olum-compiler" alt="npm">
package/bin/build.js ADDED
@@ -0,0 +1,9 @@
1
+ const path = require("path");
2
+ const mode = require("../lib/mode");
3
+ console.log("build.js");
4
+
5
+ const files = [
6
+ path.resolve(__dirname, "../core/devtool.js"),
7
+ path.resolve(__dirname, "../lib/parser.js")
8
+ ];
9
+ // mode(files, false); // related to isDev prop
@@ -0,0 +1,23 @@
1
+ const spawn = require("cross-spawn");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const colors = require("../lib/colors");
5
+
6
+ let num = 0;
7
+ module.exports = function () {
8
+ num++;
9
+ return new Promise(resolve => {
10
+ // wipeout log.txt
11
+ const logFilePath = path.resolve(__dirname, "../lib/log.txt");
12
+ fs.writeFileSync(logFilePath, "");
13
+ // compile
14
+ const compilerPath = path.resolve(__dirname, "../lib/compiler.js");
15
+ const result = spawn.sync("node", [compilerPath], { stdio: "inherit" });
16
+ if (result.signal) {
17
+ if (result.signal === "SIGKILL" || result.signal === "SIGTERM") console.log("Failed to run compiler @ " + compilerPath);
18
+ process.exit(1);
19
+ }
20
+ resolve();
21
+ console.log(colors("white", "Build no."), colors("yellow", num));
22
+ });
23
+ };
package/bin/copySrc.js ADDED
@@ -0,0 +1,22 @@
1
+ // todo check changed files only to be copied, use this project https://github.com/eissapk/diff
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const { copy, remove } = require("../lib/helpers");
5
+
6
+ const entryPoint = path.resolve(__dirname, "../../../src");
7
+ const entryPoint2 = path.resolve(__dirname, "../../../public");
8
+ module.exports = function copySrc() {
9
+ return new Promise((resolve, reject) => {
10
+ try {
11
+ // clean
12
+ if (fs.existsSync(path.resolve(__dirname, "../public"))) remove(path.resolve(__dirname, "../public"));
13
+ if (fs.existsSync(path.resolve(__dirname, "../src"))) remove(path.resolve(__dirname, "../src"));
14
+ // copy
15
+ copy(entryPoint, path.resolve(__dirname, "../src"));
16
+ copy(entryPoint2, path.resolve(__dirname, "../public"));
17
+ resolve();
18
+ } catch (err) {
19
+ reject();
20
+ }
21
+ });
22
+ };
package/bin/dev.js ADDED
@@ -0,0 +1,47 @@
1
+ const serve = require("./server");
2
+ const watch = require("./watcher");
3
+ const compile = require("./compiler");
4
+ const copySrc = require("./copySrc");
5
+ const WebSocket = require("ws");
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+
9
+ let instance;
10
+ const entryPoint = path.resolve(__dirname, "../public");
11
+ serve(entryPoint).then(({ server, wsPort, PORT, log }) => {
12
+ // initial compiling
13
+ copySrc().then(() => {
14
+ compile().then(() => {
15
+ server.listen(PORT, () => console.log(log));
16
+ // console.log("initial compiling");
17
+ watch.on("change", handleChange);
18
+ const wss = new WebSocket.Server({ port: wsPort });
19
+ wss.on("connection", (ws) => {
20
+ instance = ws;
21
+ ws.send(JSON.stringify({ msg: "connected" }));
22
+ });
23
+ });
24
+ });
25
+ });
26
+
27
+ function getLogs() {
28
+ const logFilePath = path.resolve(__dirname, "../lib/log.txt");
29
+ if (fs.existsSync(logFilePath)) {
30
+ return fs.readFileSync(logFilePath).toString();
31
+ } else {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ function handleChange(file) {
37
+ copySrc()
38
+ .then(() => {
39
+ if (file.endsWith("css") && instance) return instance.send(JSON.stringify({ msg: "css" }));
40
+ compile().then(() => {
41
+ const logs = getLogs();
42
+ if (logs && instance) return instance.send(JSON.stringify({ msg: "warn", data: logs }));
43
+ instance ? instance.send(JSON.stringify({ msg: "reload" })) : null;
44
+ });
45
+ })
46
+ .catch(console.error);
47
+ }
package/bin/index.js CHANGED
@@ -1,33 +1,10 @@
1
1
  #!/usr/bin/env node
2
-
3
- /**
4
- * @name olum-compiler
5
- * @copyright 2021
6
- * @author Eissa Saber
7
- * @license MIT
8
- */
9
-
10
- "use strict";
11
-
12
- const process = require("process");
13
- process.on("unhandledRejection", err => {
14
- throw new Error(err);
15
- });
16
-
17
- // check node version
18
- const requiredNodeMajorVer = +require("../package.json").engines.node.replace(/\<|\>|\=/gi,"").split(".")[0];
19
- const currentNodeMajorVer = +process.version.replace(/v/gi, "").split(".")[0];
20
- if (currentNodeMajorVer < requiredNodeMajorVer) {
21
- console.error(`\nYour node version is "${currentNodeMajorVer}" which is not compatible with 'olum-compiler', Please upgrade to "${requiredNodeMajorVer}" or higher\n`);
22
- process.exit(1);
23
- }
24
-
25
2
  const path = require("path");
26
3
  const spawn = require("cross-spawn");
27
4
  const script = process.argv[2];
28
5
 
29
6
  if (typeof script !== undefined && ["dev", "build"].includes(script)) {
30
- const result = spawn.sync("gulp", [script, "--gulpfile", path.resolve(__dirname, "../tasks")], { stdio: "inherit" });
7
+ const result = spawn.sync("node", [path.resolve(__dirname, script + ".js")], { stdio: "inherit" });
31
8
 
32
9
  if (result.signal) {
33
10
  if (result.signal === "SIGKILL" || result.signal === "SIGTERM") console.log("Failed to run " + script + " script!");
package/bin/mimes.json ADDED
@@ -0,0 +1,340 @@
1
+ [
2
+ {
3
+ "ext": ".aac",
4
+ "mime": "audio/aac"
5
+ },
6
+ {
7
+ "ext": ".abw",
8
+ "mime": "application/x-abiword"
9
+ },
10
+ {
11
+ "ext": ".arc",
12
+ "mime": "application/x-freearc"
13
+ },
14
+ {
15
+ "ext": ".avif",
16
+ "mime": "image/avif"
17
+ },
18
+ {
19
+ "ext": ".avi",
20
+ "mime": "video/x-msvideo"
21
+ },
22
+ {
23
+ "ext": ".azw",
24
+ "mime": "application/vnd.amazon.ebook"
25
+ },
26
+ {
27
+ "ext": ".bin",
28
+ "mime": "application/octet-stream"
29
+ },
30
+ {
31
+ "ext": ".bmp",
32
+ "mime": "image/bmp"
33
+ },
34
+ {
35
+ "ext": ".bz",
36
+ "mime": "application/x-bzip"
37
+ },
38
+ {
39
+ "ext": ".bz2",
40
+ "mime": "application/x-bzip2"
41
+ },
42
+ {
43
+ "ext": ".cda",
44
+ "mime": "application/x-cdf"
45
+ },
46
+ {
47
+ "ext": ".csh",
48
+ "mime": "application/x-csh"
49
+ },
50
+ {
51
+ "ext": ".css",
52
+ "mime": "text/css"
53
+ },
54
+ {
55
+ "ext": ".csv",
56
+ "mime": "text/csv"
57
+ },
58
+ {
59
+ "ext": ".doc",
60
+ "mime": "application/msword"
61
+ },
62
+ {
63
+ "ext": ".docx",
64
+ "mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
65
+ },
66
+ {
67
+ "ext": ".eot",
68
+ "mime": "application/vnd.ms-fontobject"
69
+ },
70
+ {
71
+ "ext": ".epub",
72
+ "mime": "application/epub+zip"
73
+ },
74
+ {
75
+ "ext": ".gz",
76
+ "mime": "application/gzip"
77
+ },
78
+ {
79
+ "ext": ".gif",
80
+ "mime": "image/gif"
81
+ },
82
+ {
83
+ "ext": ".htm",
84
+ "mime": "text/html"
85
+ },
86
+ {
87
+ "ext": ".html",
88
+ "mime": "text/html"
89
+ },
90
+ {
91
+ "ext": ".ico",
92
+ "mime": "image/vnd.microsoft.icon"
93
+ },
94
+ {
95
+ "ext": ".ics",
96
+ "mime": "text/calendar"
97
+ },
98
+ {
99
+ "ext": ".jar",
100
+ "mime": "application/java-archive"
101
+ },
102
+ {
103
+ "ext": ".jpeg",
104
+ "mime": "image/jpeg"
105
+ },
106
+ {
107
+ "ext": ".jpg",
108
+ "mime": "image/jpeg"
109
+ },
110
+ {
111
+ "ext": ".js",
112
+ "mime": "text/javascript"
113
+ },
114
+ {
115
+ "ext": ".json",
116
+ "mime": "application/json"
117
+ },
118
+ {
119
+ "ext": ".jsonld",
120
+ "mime": "application/ld+json"
121
+ },
122
+ {
123
+ "ext": ".mid",
124
+ "mime": "audio/midi"
125
+ },
126
+ {
127
+ "ext": ".midi",
128
+ "mime": "audio/x-midi"
129
+ },
130
+ {
131
+ "ext": ".mjs",
132
+ "mime": "text/javascript"
133
+ },
134
+ {
135
+ "ext": ".mp3",
136
+ "mime": "audio/mpeg"
137
+ },
138
+ {
139
+ "ext": ".mp4",
140
+ "mime": "video/mp4"
141
+ },
142
+ {
143
+ "ext": ".mpeg",
144
+ "mime": "video/mpeg"
145
+ },
146
+ {
147
+ "ext": ".mpkg",
148
+ "mime": "application/vnd.apple.installer+xml"
149
+ },
150
+ {
151
+ "ext": ".odp",
152
+ "mime": "application/vnd.oasis.opendocument.presentation"
153
+ },
154
+ {
155
+ "ext": ".ods",
156
+ "mime": "application/vnd.oasis.opendocument.spreadsheet"
157
+ },
158
+ {
159
+ "ext": ".odt",
160
+ "mime": "application/vnd.oasis.opendocument.text"
161
+ },
162
+ {
163
+ "ext": ".oga",
164
+ "mime": "audio/ogg"
165
+ },
166
+ {
167
+ "ext": ".ogv",
168
+ "mime": "video/ogg"
169
+ },
170
+ {
171
+ "ext": ".ogx",
172
+ "mime": "application/ogg"
173
+ },
174
+ {
175
+ "ext": ".opus",
176
+ "mime": "audio/opus"
177
+ },
178
+ {
179
+ "ext": ".otf",
180
+ "mime": "font/otf"
181
+ },
182
+ {
183
+ "ext": ".png",
184
+ "mime": "image/png"
185
+ },
186
+ {
187
+ "ext": ".pdf",
188
+ "mime": "application/pdf"
189
+ },
190
+ {
191
+ "ext": ".php",
192
+ "mime": "application/x-httpd-php"
193
+ },
194
+ {
195
+ "ext": ".ppt",
196
+ "mime": "application/vnd.ms-powerpoint"
197
+ },
198
+ {
199
+ "ext": ".pptx",
200
+ "mime": "application/vnd.openxmlformats-officedocument.presentationml.presentation"
201
+ },
202
+ {
203
+ "ext": ".rar",
204
+ "mime": "application/vnd.rar"
205
+ },
206
+ {
207
+ "ext": ".rtf",
208
+ "mime": "application/rtf"
209
+ },
210
+ {
211
+ "ext": ".sh",
212
+ "mime": "application/x-sh"
213
+ },
214
+ {
215
+ "ext": ".svg",
216
+ "mime": "image/svg+xml"
217
+ },
218
+ {
219
+ "ext": ".swf",
220
+ "mime": "application/x-shockwave-flash"
221
+ },
222
+ {
223
+ "ext": ".tar",
224
+ "mime": "application/x-tar"
225
+ },
226
+ {
227
+ "ext": ".tiff",
228
+ "mime": "image/tiff"
229
+ },
230
+ {
231
+ "ext": ".tif",
232
+ "mime": "image/tiff"
233
+ },
234
+ {
235
+ "ext": ".ts",
236
+ "mime": "video/mp2t"
237
+ },
238
+ {
239
+ "ext": ".ttf",
240
+ "mime": "font/ttf"
241
+ },
242
+ {
243
+ "ext": ".txt",
244
+ "mime": "text/plain"
245
+ },
246
+ {
247
+ "ext": ".vsd",
248
+ "mime": "application/vnd.visio"
249
+ },
250
+ {
251
+ "ext": ".wav",
252
+ "mime": "audio/wav"
253
+ },
254
+ {
255
+ "ext": ".weba",
256
+ "mime": "audio/webm"
257
+ },
258
+ {
259
+ "ext": ".webm",
260
+ "mime": "video/webm"
261
+ },
262
+ {
263
+ "ext": ".webp",
264
+ "mime": "image/webp"
265
+ },
266
+ {
267
+ "ext": ".woff",
268
+ "mime": "font/woff"
269
+ },
270
+ {
271
+ "ext": ".woff2",
272
+ "mime": "font/woff2"
273
+ },
274
+ {
275
+ "ext": ".xhtml",
276
+ "mime": "application/xhtml+xml"
277
+ },
278
+ {
279
+ "ext": ".xls",
280
+ "mime": "application/vnd.ms-excel"
281
+ },
282
+ {
283
+ "ext": ".xlsx",
284
+ "mime": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
285
+ },
286
+ {
287
+ "ext": ".xml",
288
+ "mime": "application/xml"
289
+ },
290
+
291
+ {
292
+ "ext": ".xml",
293
+ "mime": "text/xml"
294
+ },
295
+
296
+ {
297
+ "ext": ".xml",
298
+ "mime": ".xml"
299
+ },
300
+
301
+ {
302
+ "ext": ".xml",
303
+ "mime": "application/atom+xml"
304
+ },
305
+
306
+ {
307
+ "ext": ".xml",
308
+ "mime": "application/xml"
309
+ },
310
+
311
+ {
312
+ "ext": ".xul",
313
+ "mime": "application/vnd.mozilla.xul+xml"
314
+ },
315
+ {
316
+ "ext": ".zip",
317
+ "mime": "application/zip"
318
+ },
319
+ {
320
+ "ext": ".3gp",
321
+ "mime": "video/3gpp"
322
+ },
323
+ {
324
+ "ext": ".3gp",
325
+ "mime": "audio/3gpp"
326
+ },
327
+ {
328
+ "ext": ".3g2",
329
+ "mime": "video/3gpp2"
330
+ },
331
+
332
+ {
333
+ "ext": ".3g2",
334
+ "mime": "audio/3gpp2"
335
+ },
336
+ {
337
+ "ext": ".7z",
338
+ "mime": "application/x-7z-compressed"
339
+ }
340
+ ]
package/bin/server.js ADDED
@@ -0,0 +1,77 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const http = require("http");
4
+ // const http2 = require("http2");
5
+ const jsdom = require("jsdom");
6
+ const colors = require("../lib/colors");
7
+ const mimes = require("./mimes.json");
8
+ const wsPort = 8090;
9
+
10
+ function handleWsFile() {
11
+ let file = fs.readFileSync(path.resolve(__dirname, "./ws.js")).toString();
12
+ file = file.replace(/{{port}}/, wsPort);
13
+ file = "<script>" + file + "</script>";
14
+ return file;
15
+ }
16
+
17
+ function getPath(entry, url) {
18
+ entry = entry.endsWith("/") ? entry : entry + "/";
19
+ url = url.startsWith("/") ? url.slice(1) : url;
20
+ let trial_1 = path.resolve(entry + url);
21
+ let trial_2 = path.resolve(entry + "../" + url);
22
+ // console.log("getPath", { entry, url, trial_1, trial_2 });
23
+
24
+ if (fs.existsSync(trial_1)) return trial_1;
25
+ else if (fs.existsSync(trial_2)) return trial_2;
26
+ else return null;
27
+ }
28
+ // todo handle https
29
+ /**
30
+ *
31
+ * @param {*} entry must be an absolute path
32
+ * @param {*} port optional port, default is 8000
33
+ */
34
+ function serve(entry, port) {
35
+ return new Promise((resolve, reject) => {
36
+ const PORT = port ? port : process.env.PORT || 8000;
37
+ const domain = `http://localhost:${PORT}`;
38
+
39
+ const server = http.createServer(handler);
40
+ function handler(req, res) {
41
+ if (req.url == "/") {
42
+ let indexPath = entry + "/index.html";
43
+ if (!fs.existsSync(indexPath)) indexPath = entry + "/index.htm";
44
+
45
+ fs.readFile(indexPath, (err, content) => {
46
+ if (err) {
47
+ console.log(err);
48
+ return reject(err);
49
+ }
50
+ const dom = new jsdom.JSDOM(content.toString()).window.document;
51
+ const html = dom.querySelector("html");
52
+ const wsContent = handleWsFile();
53
+ dom.body.insertAdjacentHTML("beforeend", wsContent);
54
+ res.writeHead(200, { "content-type": "text/html" });
55
+ res.end("<!DOCTYPE html>" + html.outerHTML);
56
+ });
57
+ }
58
+ // handle files paths and mime types
59
+ const finalPath = getPath(entry, req.url);
60
+ if (finalPath) {
61
+ const isFile = fs.statSync(finalPath).isFile();
62
+ if (isFile) {
63
+ const ext = path.extname(finalPath).toLowerCase();
64
+ const obj = mimes.find(item => (ext === item.ext.toLowerCase() ? item : null));
65
+ if (obj) {
66
+ res.writeHead(200, { "Content-Type": obj.mime });
67
+ fs.createReadStream(finalPath).pipe(res);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ const log = colors("cyan", "Serving ") + colors("green", domain);
73
+ resolve({ server: server, wsPort: wsPort, PORT: PORT, log: log });
74
+ });
75
+ }
76
+
77
+ module.exports = serve;
package/bin/watcher.js ADDED
@@ -0,0 +1,6 @@
1
+ const chokidar = require("chokidar");
2
+ const path = require("path");
3
+ const entryPoint = path.resolve(__dirname, "../../../src");
4
+ // let ignoreRegex = /\_\.js$/;
5
+ // module.exports = chokidar.watch(entryPoint, {ignored: ignoreRegex, persistent: true });
6
+ module.exports = chokidar.watch(entryPoint, { persistent: true });
package/bin/ws.js ADDED
@@ -0,0 +1,54 @@
1
+ (() => {
2
+ if ("WebSocket" in window) {
3
+ const parse = str => str.replace(/>/g, "&gt;").replace(/</g, "&lt;");
4
+ const interval = 500;
5
+ const maxAttempts = 30;
6
+ let attempts = 0;
7
+ const socketUrl = "ws://localhost:{{port}}";
8
+ let socket = new WebSocket(socketUrl);
9
+
10
+ socket.onmessage = function (res) {
11
+ const obj = JSON.parse(res.data);
12
+ if (obj.msg === "connected") enabled();
13
+ if (obj.msg === "reload") window.location.reload();
14
+ else if (obj.msg === "css") css();
15
+ else if (obj.msg === "warn") {
16
+ const stderr = obj.data.trim();
17
+ const arr = stderr.split("<<Olum Warning>>");
18
+ const markup = arr
19
+ .map(item => {
20
+ if (item.trim() !== "") return `<pre style="border-bottom: 1px solid #ccc; padding-bottom:10px;">${parse(item)}</pre>`;
21
+ })
22
+ .join("");
23
+ document.body.innerHTML = markup;
24
+ }
25
+ };
26
+
27
+ function enabled() {
28
+ let key = "IS_FIRST_TIME_OLUM_HOT_RELOAD";
29
+ if (sessionStorage && !sessionStorage.getItem(key)) {
30
+ sessionStorage.setItem(key, true);
31
+ // if (olum) olum.logs.log("Olum hot-reload enabled.");
32
+ // else console.log("Olum hot-reload enabled.");
33
+ console.log("Olum hot-reload enabled.");
34
+ }
35
+ }
36
+
37
+ function css() {
38
+ const sheets = document.querySelectorAll("link[rel='stylesheet']");
39
+ sheets.forEach(sheet => sheet.replaceWith(sheet));
40
+ }
41
+
42
+ socket.addEventListener("close", () => {
43
+ const reloadIfCanConnect = () => {
44
+ attempts++;
45
+ if (attempts > maxAttempts) return console.error("Could not reconnect to dev server.");
46
+ socket = new WebSocket(socketUrl);
47
+ socket.addEventListener("error", () => setTimeout(reloadIfCanConnect, interval));
48
+ };
49
+ reloadIfCanConnect();
50
+ });
51
+ } else {
52
+ console.error("Upgrade your browser. This Browser is doesn't support WebSocket for Live-Reloading.");
53
+ }
54
+ })();
package/lib/attr.js ADDED
@@ -0,0 +1,39 @@
1
+ const { getLineInfo } = require("./lineCounter");
2
+ const path = require("path");
3
+
4
+ function handleAttr(body, counter, filePath) {
5
+ let name = path.basename(filePath).replace(/\.html/i, "");
6
+ name = name.slice(0, 1).toLowerCase() + name.slice(1); // make compName camel case
7
+
8
+ const elms = new Array().slice.call(body.querySelectorAll("*"));
9
+ elms.forEach((item) => {
10
+ const attrs = item.getAttributeNames();
11
+ if (attrs.length) {
12
+ // {identifier} shorthand: <img {src} /> → <img src="{src}" /> → src="${src}" in template -- inspired by svelete
13
+ attrs.filter(attr => /^\{\w+\}$/.test(attr)).forEach(attr => {
14
+ const attrName = attr.slice(1, -1);
15
+ item.removeAttribute(attr);
16
+ item.setAttribute(attrName, "{" + attrName + "}");
17
+ });
18
+
19
+ const dynamicAttrs = attrs.filter((attr) => attr.startsWith(":"));
20
+ if (dynamicAttrs.length) {
21
+ dynamicAttrs.forEach((attrName) => {
22
+ let attrValue = item.getAttribute(attrName);
23
+ if (attrValue) {
24
+ attrName = attrName.trim().slice(1);
25
+ attrValue = attrValue.trim();
26
+ let chain = "-[[-${JSON.parse(JSON.stringify(" + attrValue + "))}-]]-";
27
+ chain = chain.replace(/{/g, "&lt;-olum-&gt;"); // using <-olum-> (&lt;-olum-&gt;) as placeholder for "{"
28
+ // // console.log({chain});
29
+ // item.setAttribute("data-o-attr-" + attrName, chain);
30
+ item.setAttribute(attrName, chain);
31
+ item.removeAttribute(":"+attrName);
32
+ }
33
+ });
34
+ }
35
+ }
36
+ });
37
+ }
38
+
39
+ module.exports = handleAttr;
package/lib/clean.js ADDED
@@ -0,0 +1,4 @@
1
+ const { htmlComment } = require("./regex");
2
+ module.exports = function clean(str) {
3
+ return str.replace(htmlComment, "").trim();
4
+ };