@awesomeness-js/server 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/package.json +1 -1
- package/src/fetchPage.js +24 -0
package/package.json
CHANGED
package/src/fetchPage.js
CHANGED
|
@@ -51,6 +51,23 @@ export default async function fetchPage(
|
|
|
51
51
|
return pageFnName;
|
|
52
52
|
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
function pageNamespaceInit(pageFnName) {
|
|
56
|
+
|
|
57
|
+
const parts = pageFnName.split(".");
|
|
58
|
+
const inits = [];
|
|
59
|
+
|
|
60
|
+
for (let i = 2; i < parts.length - 1; i++) {
|
|
61
|
+
|
|
62
|
+
inits.push(
|
|
63
|
+
`${parts.slice(0, i + 1).join(".")} = ${parts.slice(0, i + 1).join(".")} || {};`
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return inits.join("\n");
|
|
69
|
+
|
|
70
|
+
}
|
|
54
71
|
|
|
55
72
|
|
|
56
73
|
// initialize if not already available
|
|
@@ -156,6 +173,7 @@ export default async function fetchPage(
|
|
|
156
173
|
}) => {
|
|
157
174
|
|
|
158
175
|
const fnName = pageFn(path, awesomenessRequest);
|
|
176
|
+
const namespaceInit = pageNamespaceInit(fnName);
|
|
159
177
|
|
|
160
178
|
content = content.replaceAll(`import ui from '#ui';`, "");
|
|
161
179
|
content = content.replaceAll(`import ui from "#ui";`, "");
|
|
@@ -165,6 +183,12 @@ export default async function fetchPage(
|
|
|
165
183
|
content = content.replaceAll("export default async", `${fnName} = async`);
|
|
166
184
|
content = content.replaceAll("export default", `${fnName} =`);
|
|
167
185
|
|
|
186
|
+
if (namespaceInit) {
|
|
187
|
+
|
|
188
|
+
content = `${namespaceInit}\n${content}`;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
168
192
|
return content;
|
|
169
193
|
|
|
170
194
|
},
|