diff --git a/bin/ecs.mjs b/bin/ecs.mjs index b8ddf67..eb8debc 100755 --- a/bin/ecs.mjs +++ b/bin/ecs.mjs @@ -1,6 +1,6 @@ import { join, relative } from "node:path" import { existsSync } from "node:fs" -import { readdir, readFile, writeFile } from "node:fs/promises" +import { readdir, readFile, rm, unlink, writeFile } from "node:fs/promises" import { Script } from "node:vm" import { Parcel } from "@parcel/core" import { fileURLToPath } from "node:url" @@ -33,6 +33,17 @@ async function main(args) { async function build() { const config = await getConfig() + // clean dist + if (existsSync(config.dist)) { + for (const file of await readdir(config.dist, { withFileTypes: true })) { + if (file.isDirectory()) { + await rm(join(config.dist, file.name), { recursive: true }) + } else { + await unlink(join(config.dist, file.name)) + } + } + } + let bundler = new Parcel({ entries: config.htmlFiles.map((file) => join(config.src, file)), config: "@parcel/config-default", diff --git a/lib/builtin/systems/html.ts b/lib/builtin/systems/html.ts index 6634b7a..9e3ec9c 100644 --- a/lib/builtin/systems/html.ts +++ b/lib/builtin/systems/html.ts @@ -112,29 +112,10 @@ export function renderHtmlRoot(): void { render(e, el) } - diffRender(root.element, el, false) + diffRender(root.element, el) } -function diffRender(old: Element, next: HTMLElement, deleteAttributes = true): void { - // check attributes - const oldAttrs = old.attributes - const nextAttrs = next.attributes - for (let i = 0; i < nextAttrs.length; i++) { - const nextAttr = nextAttrs[i]! - const oldAttr = oldAttrs.getNamedItem(nextAttr.name) - if (!oldAttr || oldAttr.value !== nextAttr.value) { - old.setAttribute(nextAttr.name, nextAttr.value) - } - } - if (deleteAttributes) { - for (let i = 0; i < oldAttrs.length; i++) { - const oldAttr = oldAttrs[i]! - if (nextAttrs.getNamedItem(oldAttr.name) === null) { - old.removeAttribute(oldAttr.name) - } - } - } - +function diffRender(old: Element, next: HTMLElement) { if (old.childNodes.length !== next.childNodes.length) { old.innerHTML = next.innerHTML return