olum-compiler 2.0.3 → 2.0.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/lib/helpers.js +19 -6
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -33,9 +33,20 @@ const cleanParentheses = (filePath, type = "name") => {
|
|
|
33
33
|
|
|
34
34
|
const cleanNumbersPrefix = (name, type = "name") => {
|
|
35
35
|
if (type === "url") {
|
|
36
|
-
|
|
36
|
+
const trimmedDigit =
|
|
37
|
+
name.match(/(?:^|\/)(\d+)-/)?.[1] ?? name.match(/-(\d+)$/)?.[1] ?? "";
|
|
38
|
+
return {
|
|
39
|
+
name: name.replace(/(^|\/)\d+-/g, "$1"),
|
|
40
|
+
trimmedDigit,
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
|
|
44
|
+
const trimmedDigit =
|
|
45
|
+
name.match(/^(\d+)/)?.[1] ?? name.match(/(\d+)$/)?.[1] ?? "";
|
|
46
|
+
return {
|
|
47
|
+
name: name.replace(/\d+-?/g, ""),
|
|
48
|
+
trimmedDigit,
|
|
49
|
+
};
|
|
39
50
|
};
|
|
40
51
|
|
|
41
52
|
function isUpper(char) {
|
|
@@ -717,8 +728,8 @@ function toComponentName(file) {
|
|
|
717
728
|
function generateImports(manifest) {
|
|
718
729
|
return Object.values(manifest)
|
|
719
730
|
.map(({ page }) => {
|
|
720
|
-
const
|
|
721
|
-
return `import ${
|
|
731
|
+
const { name, trimmedDigit } = cleanNumbersPrefix(toComponentName(page));
|
|
732
|
+
return `import ${name}${trimmedDigit ? "_" + trimmedDigit : ""} from "./${page.replace(/.html$/, ".js")}";`;
|
|
722
733
|
})
|
|
723
734
|
.join("\n");
|
|
724
735
|
}
|
|
@@ -753,8 +764,10 @@ function generateRoutes(manifest) {
|
|
|
753
764
|
const result = `export const routes = [
|
|
754
765
|
${routes
|
|
755
766
|
.map(({ path, comp }) => {
|
|
756
|
-
|
|
757
|
-
|
|
767
|
+
const { name } = cleanNumbersPrefix(path, "url");
|
|
768
|
+
const _comp = cleanNumbersPrefix(comp);
|
|
769
|
+
paths.push(name);
|
|
770
|
+
return ` { path: "${name}", comp: ${_comp.name}${_comp.trimmedDigit ? "_" + _comp.trimmedDigit : ""} }`;
|
|
758
771
|
})
|
|
759
772
|
.join(",\n")}
|
|
760
773
|
];`;
|