olum-compiler 0.9.2 → 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/lib/helpers.js +0 -51
- 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/lib/helpers.js
CHANGED
|
@@ -663,56 +663,6 @@ ${routes
|
|
|
663
663
|
];`;
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
-
const routerParamsParser = `<script>
|
|
667
|
-
/**
|
|
668
|
-
* Extract route params from a file path and pathname.
|
|
669
|
-
*
|
|
670
|
-
* @param {string} filePath
|
|
671
|
-
* @param {string} pathname
|
|
672
|
-
* @returns {Record<string, string | string[]>}
|
|
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;
|
|
713
|
-
}
|
|
714
|
-
</script>`;
|
|
715
|
-
|
|
716
666
|
const libsMap = {
|
|
717
667
|
development: {
|
|
718
668
|
olum: "/node_modules/olum/dist/olum.js",
|
|
@@ -749,5 +699,4 @@ module.exports.rewriteImports = rewriteImports;
|
|
|
749
699
|
module.exports.generateRouteManifest = generateRouteManifest;
|
|
750
700
|
module.exports.generateImports = generateImports;
|
|
751
701
|
module.exports.generateRoutes = generateRoutes;
|
|
752
|
-
module.exports.routerParamsParser = routerParamsParser;
|
|
753
702
|
module.exports.libsMap = libsMap;
|