olum-compiler 0.9.0 → 0.9.3
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/bin/copySrc.js +1 -3
- package/bin/index.js +3 -0
- package/lib/helpers.js +10 -49
- package/lib/jsParser.js +1 -0
- package/lib/parser.js +13 -5
- package/package.json +1 -1
package/bin/copySrc.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// todo check changed files only to be copied, use this project https://github.com/eissapk/diff
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
|
-
const { copy, remove,
|
|
4
|
+
const { copy, remove, ls, generateRouteManifest, generateImports, generateRoutes } = require("../lib/helpers");
|
|
5
5
|
const entryPoint = path.resolve(process.cwd(), "src").replace(/\/module/, "");
|
|
6
6
|
const entryPoint2 = path.resolve(process.cwd(), "public").replace(/\/module/, "");
|
|
7
7
|
|
|
@@ -50,8 +50,6 @@ module.exports = function copySrc() {
|
|
|
50
50
|
copy(entryPoint2, path.resolve(__dirname, "../public"), () => {
|
|
51
51
|
const indexHtmlPath = path.resolve(__dirname, "../public/index.html");
|
|
52
52
|
let indexHtmlContent = fs.readFileSync(indexHtmlPath).toString();
|
|
53
|
-
// auto bind router params handler
|
|
54
|
-
indexHtmlContent = indexHtmlContent.replace(/<body>/, `\n<body>\n${routerParamsParser}`);
|
|
55
53
|
// auto bind div#app placeholder and mainjs script to index.html
|
|
56
54
|
indexHtmlContent = indexHtmlContent.replace(/<\/body>/, `\n<div id="app"></div>\n<script defer type="module" src="../src/main.js"></script>\n</body>`);
|
|
57
55
|
fs.writeFileSync(indexHtmlPath, indexHtmlContent);
|
package/bin/index.js
CHANGED
|
@@ -3,6 +3,9 @@ const path = require("path");
|
|
|
3
3
|
const spawn = require("../lib/cross-spawn");
|
|
4
4
|
const script = process.argv[2];
|
|
5
5
|
|
|
6
|
+
if (script == "dev") process.env.NODE_ENV = "development";
|
|
7
|
+
else if (script == "build") process.env.NODE_ENV = "production";
|
|
8
|
+
|
|
6
9
|
if (typeof script !== undefined && ["dev", "build"].includes(script)) {
|
|
7
10
|
const result = spawn.sync("node", [path.resolve(__dirname, script + ".js")], { stdio: "inherit" });
|
|
8
11
|
|
package/lib/helpers.js
CHANGED
|
@@ -663,55 +663,16 @@ ${routes
|
|
|
663
663
|
];`;
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
* Examples:
|
|
675
|
-
* extractParams("/blog/[slug]/page.html", "/blog/hello")
|
|
676
|
-
* -> { slug: "hello" }
|
|
677
|
-
*
|
|
678
|
-
* extractParams("/users/[id]/posts/[postId]/page.html", "/users/5/posts/10")
|
|
679
|
-
* -> { id: "5", postId: "10" }
|
|
680
|
-
*/
|
|
681
|
-
function extractParams(filePath, pathname) {
|
|
682
|
-
const routeParts = filePath
|
|
683
|
-
.replace(/\\/page\\.[^/]+$/, "")
|
|
684
|
-
.split("/")
|
|
685
|
-
.filter(Boolean);
|
|
686
|
-
|
|
687
|
-
const pathParts = pathname.split("/").filter(Boolean);
|
|
688
|
-
|
|
689
|
-
const params = {};
|
|
690
|
-
|
|
691
|
-
let i = routeParts.length - 1;
|
|
692
|
-
let j = pathParts.length - 1;
|
|
693
|
-
|
|
694
|
-
while (i >= 0 && j >= 0) {
|
|
695
|
-
const part = routeParts[i];
|
|
696
|
-
|
|
697
|
-
// [...slug]
|
|
698
|
-
if (part.startsWith("[...") && part.endsWith("]")) {
|
|
699
|
-
params[part.slice(4, -1)] = pathParts.slice(0, j + 1);
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// [slug]
|
|
704
|
-
if (part.startsWith("[") && part.endsWith("]")) {
|
|
705
|
-
params[part.slice(1, -1)] = decodeURIComponent(pathParts[j]);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
i--;
|
|
709
|
-
j--;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return params;
|
|
666
|
+
const libsMap = {
|
|
667
|
+
development: {
|
|
668
|
+
olum: "/node_modules/olum/dist/olum.js",
|
|
669
|
+
router: "/node_modules/olum-router/dist/router.js"
|
|
670
|
+
},
|
|
671
|
+
production: {
|
|
672
|
+
olum: "olum",
|
|
673
|
+
router: "olum-router"
|
|
713
674
|
}
|
|
714
|
-
|
|
675
|
+
}
|
|
715
676
|
|
|
716
677
|
module.exports.isNum = isNum;
|
|
717
678
|
module.exports.id = id;
|
|
@@ -738,4 +699,4 @@ module.exports.rewriteImports = rewriteImports;
|
|
|
738
699
|
module.exports.generateRouteManifest = generateRouteManifest;
|
|
739
700
|
module.exports.generateImports = generateImports;
|
|
740
701
|
module.exports.generateRoutes = generateRoutes;
|
|
741
|
-
module.exports.
|
|
702
|
+
module.exports.libsMap = libsMap;
|
package/lib/jsParser.js
CHANGED
|
@@ -22,6 +22,7 @@ function jsParser(str) {
|
|
|
22
22
|
|
|
23
23
|
content = content.replace(/(<script.*>)/, "");
|
|
24
24
|
content = content.replace(/(<\/script>)$/, "");
|
|
25
|
+
content = content.replace(/onMount\(/, "var mounted = onMount("); // handle onMount hook if imported -- wrape it to another name (mounted) to continue the old flow
|
|
25
26
|
// content = content.replace(exportDefault, "").trim();
|
|
26
27
|
// return "__isInitial__: true,\n__render__(obj, prop) { olum.lifeCycle.render(obj, prop); },\n" + content;
|
|
27
28
|
content = content.replace(/const state/g, "var state"); // todo make this solid
|
package/lib/parser.js
CHANGED
|
@@ -5,7 +5,7 @@ const jsParser = require("./jsParser");
|
|
|
5
5
|
const getImports = require("./getImports");
|
|
6
6
|
const toJs = require("./toJs");
|
|
7
7
|
const path = require("path");
|
|
8
|
-
const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, minifyJS } = require("./helpers");
|
|
8
|
+
const { isFullArr, id, createScopeHandler, getGlobalMethods, getGlobalProps, minifyJS, libsMap } = require("./helpers");
|
|
9
9
|
const createSourceMap = require("./sourcemap");
|
|
10
10
|
|
|
11
11
|
const parser = (str, counter, filePath) => {
|
|
@@ -27,6 +27,14 @@ const parser = (str, counter, filePath) => {
|
|
|
27
27
|
if (imports) {
|
|
28
28
|
const importRegex = /(import)(\s+)?(?!from)/g;
|
|
29
29
|
imports.forEach((item) => {
|
|
30
|
+
// resolve imported libs: olum, olum-router
|
|
31
|
+
if (/from\s+(['"])olum\1/.test(item.statement)) {
|
|
32
|
+
item.statement = item.statement.replace(new RegExp(item.regex, ""), `from "${libsMap[process.env.NODE_ENV].olum}"`)
|
|
33
|
+
}
|
|
34
|
+
if (/from\s+(['"])olum-router\1/.test(item.statement)) {
|
|
35
|
+
item.statement = item.statement.replace(new RegExp(item.regex, ""), `from "${libsMap[process.env.NODE_ENV].olum}"`)
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
if (item.type && item.type == "noFrom") js = js.replace(new RegExp(item.regex, "gm"), "");
|
|
31
39
|
if (!item.type) js = js.replace(new RegExp(item.regex, "g"), "*/");
|
|
32
40
|
});
|
|
@@ -54,8 +62,8 @@ const parser = (str, counter, filePath) => {
|
|
|
54
62
|
let hasMounted = false;
|
|
55
63
|
let hasUnMounted = false;
|
|
56
64
|
|
|
57
|
-
const methodsTobeExcluded = ["mounted", "unMounted"];
|
|
58
|
-
const propsTobeExcluded = ["watcher"];
|
|
65
|
+
const methodsTobeExcluded = ["mounted", "unMounted", "onMount"];
|
|
66
|
+
const propsTobeExcluded = ["watcher", "mounted"];
|
|
59
67
|
|
|
60
68
|
globalProps = getGlobalProps(js);
|
|
61
69
|
globalMethods = getGlobalMethods(js);
|
|
@@ -158,8 +166,8 @@ const parser = (str, counter, filePath) => {
|
|
|
158
166
|
incomingPropsProxy: props,
|
|
159
167
|
${isDev ? `stateProps: ${hasState ? "state" : "null"},` : ""}
|
|
160
168
|
hooks: {
|
|
161
|
-
mounted:
|
|
162
|
-
unMounted:
|
|
169
|
+
mounted: typeof mounted !== "undefined" ? mounted : null,
|
|
170
|
+
unMounted: null,
|
|
163
171
|
isMounted: false,
|
|
164
172
|
isUnMounted: false,
|
|
165
173
|
}
|