use .output dir

This commit is contained in:
Ayo 2023-10-08 09:35:53 +02:00
parent fcc1f999f7
commit ef2be56efd
6 changed files with 6 additions and 42 deletions

View file

@ -5,7 +5,7 @@ export default defineNitroPlugin(async () => {
rawKeys.forEach(async (key) => { rawKeys.forEach(async (key) => {
const cleanKey = key.replace("assets:components:", ""); const cleanKey = key.replace("assets:components:", "");
const content = await useStorage().getItem(key); const content = await useStorage().getItem(key);
if (!fs.existsSync("./public/output")) fs.mkdirSync("./public/output"); if (!fs.existsSync("./public/.output")) fs.mkdirSync("./public/.output");
fs.writeFileSync(`./public/output/${cleanKey}`, content.toString()); fs.writeFileSync(`./public/.output/${cleanKey}`, content.toString());
}); });
}); });

View file

@ -19,11 +19,11 @@ export default defineNitroPlugin(async () => {
const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`; const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`;
if (!fs.existsSync("./public/output")) { if (!fs.existsSync("./public/.output")) {
fs.mkdirSync("./public/output"); fs.mkdirSync("./public/.output");
} }
fs.writeFileSync( fs.writeFileSync(
"./public/output/registry.js", "./public/.output/registry.js",
[...imports, registryObject, customElementsDefine].join(";") [...imports, registryObject, customElementsDefine].join(";")
); );
}); });

View file

@ -1,10 +0,0 @@
import WebComponent from "https://unpkg.com/web-component-base/index.js";
export default class ClickableText extends WebComponent {
onInit() {
this.onclick = () => alert("Thank you for clicking the text!");
}
get template() {
return `<span style="cursor:pointer">Click me too!</span>`;
}
}

View file

@ -1,24 +0,0 @@
import WebComponent from "https://unpkg.com/web-component-base/index.js";
export default class HelloWorld extends WebComponent {
name = "";
static properties = ["name"];
onInit() {
console.log(`Greeting for ${this.name} initialized`);
let count = 0;
this.onclick = () => {
console.log("Clicked!");
this.setAttribute("name", `I was clicked ${++count} times`);
};
this.setAttribute("title", "Click me please");
}
onChanges(changes) {
console.log(changes);
}
get template() {
return `<button style="cursor:pointer">Hello ${this.name}!</button>`;
}
}

View file

@ -1,2 +0,0 @@
import C0 from "./clickable-text.js";import C1 from "./hello-world.js";const registry = {
"clickable-text": C0,"hello-world": C1};Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})

View file

@ -12,7 +12,7 @@ export default eventHandler(async (event) => {
// temporary; use ultrahtml later // temporary; use ultrahtml later
const registryScript = const registryScript =
'<script type="module" src="./output/registry.js"></script>'; '<script type="module" src="./.output/registry.js"></script>';
html = html.toString().replace("</head>", registryScript + "</head>"); html = html.toString().replace("</head>", registryScript + "</head>");
return html ?? new Response("Not found", { status: 404 }); return html ?? new Response("Not found", { status: 404 });