refactor: fs imports
This commit is contained in:
parent
34065ad0c5
commit
2e12da70d9
3 changed files with 8 additions and 10 deletions
|
@ -1,11 +1,12 @@
|
|||
import * as fs from "fs";
|
||||
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
|
||||
|
||||
export default defineNitroPlugin(async () => {
|
||||
console.log("Copying components to public folder...");
|
||||
const rawKeys = await useStorage().getKeys("assets:components");
|
||||
rawKeys.forEach(async (key) => {
|
||||
const cleanKey = key.replace("assets:components:", "");
|
||||
const content = await useStorage().getItem(key);
|
||||
if (!fs.existsSync("./public/.output")) fs.mkdirSync("./public/.output");
|
||||
fs.writeFileSync(`./public/.output/${cleanKey}`, content.toString());
|
||||
if (!existsSync("./public/.output")) mkdirSync("./public/.output");
|
||||
writeFileSync(`./public/.output/${cleanKey}`, content.toString());
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as fs from "fs";
|
||||
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
|
||||
|
||||
export default defineNitroPlugin(async () => {
|
||||
console.log("Building registry of custom elements...");
|
||||
|
@ -19,10 +19,10 @@ export default defineNitroPlugin(async () => {
|
|||
|
||||
const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`;
|
||||
|
||||
if (!fs.existsSync("./public/.output")) {
|
||||
fs.mkdirSync("./public/.output");
|
||||
if (!existsSync("./public/.output")) {
|
||||
mkdirSync("./public/.output");
|
||||
}
|
||||
fs.writeFileSync(
|
||||
writeFileSync(
|
||||
"./public/.output/registry.js",
|
||||
[...imports, registryObject, customElementsDefine].join(";")
|
||||
);
|
||||
|
|
|
@ -60,14 +60,11 @@ function doSetUp(html: string) {
|
|||
|
||||
const setupMap = {};
|
||||
serverScripts.forEach((script: string) => {
|
||||
console.log(script);
|
||||
|
||||
const constructor = `
|
||||
new Function(\`${script}\`);
|
||||
`;
|
||||
const evalStore = eval(constructor);
|
||||
Object.assign(setupMap, new evalStore());
|
||||
console.log(">>> from server", setupMap);
|
||||
});
|
||||
|
||||
return html.replace("{{name}}", setupMap["name"]);
|
||||
|
|
Loading…
Reference in a new issue