Comparing version
#!/usr/bin/env node | ||
import { Command as u } from "commander"; | ||
import { readFileSync as s, writeFileSync as i, existsSync as f, mkdirSync as g } from "fs"; | ||
import m from "path"; | ||
import { compile as b } from "./compiler.js"; | ||
import { readFileSync as s, writeFileSync as i, existsSync as f, mkdirSync as b } from "fs"; | ||
import c from "path"; | ||
import { compile as g } from "./compiler.js"; | ||
import { optimize as y, optimizeStrings as S, optimizeFunctions as v } from "./optimizer.js"; | ||
import { createServer as w, build as x } from "vite"; | ||
import p from "./vite.js"; | ||
import { execSync as c } from "child_process"; | ||
import { execSync as m } from "child_process"; | ||
import { t as C } from "./jsx-Bwrm210x.js"; | ||
@@ -15,12 +15,12 @@ const o = { | ||
try { | ||
const e = s(r, "utf-8"), d = t(e), a = m.parse(r), l = m.join(a.dir, `${a.name}.result${a.ext}`); | ||
const n = s(r, "utf-8"), d = t(n), a = c.parse(r), l = c.join(a.dir, `${a.name}.result${a.ext}`); | ||
i(l, d); | ||
} catch (e) { | ||
console.error("An error occurred during the compilation process:", e); | ||
} catch (n) { | ||
console.error("An error occurred during the compilation process:", n); | ||
} | ||
} | ||
}, n = new u(); | ||
n.command("init").action(async () => { | ||
}, e = new u(); | ||
e.command("init").action(async () => { | ||
f("./.gitignore") || i("./.gitignore", `node_modules | ||
dist`), c("npm init -y"), c("npm install"), c("npm link battuta"), g("./src"), i("./src/main.tsx", `import { render } from "battuta/runtime" | ||
dist`), m("npm init -y"), m("npm install battuta --verbose"), b("./src"), i("./src/main.tsx", `import { render } from "battuta/runtime" | ||
@@ -50,21 +50,21 @@ function App() { | ||
}`); | ||
const e = JSON.parse(s("./package.json", "utf-8")); | ||
e.scripts = { | ||
const n = JSON.parse(s("./package.json", "utf-8")); | ||
n.scripts = { | ||
dev: "battuta dev", | ||
build: "battuta bundle" | ||
}, i("./package.json", JSON.stringify(e, null, 4)); | ||
}, i("./package.json", JSON.stringify(n, null, 4)); | ||
}); | ||
n.command("dev").action(async () => { | ||
e.command("dev").action(async () => { | ||
const t = await w({ plugins: [p()] }); | ||
await t.listen(), t.printUrls(), t.bindCLIShortcuts({ print: !0 }); | ||
}); | ||
n.command("bundle").option("-m, --minify <boolean>", "Minify the chunks", !0).action(async (t) => { | ||
e.command("bundle").option("-m, --minify <boolean>", "Minify the chunks", !0).action(async (t) => { | ||
await x({ plugins: [p()], build: { minify: t.minify } }); | ||
}); | ||
n.command(o.pattern("compile")).action(o.wrap((t) => b(t).code)); | ||
n.command(o.pattern("compile:jsx")).action(o.wrap((t) => C(t).code)); | ||
n.command(o.pattern("optimize")).action(o.wrap((t) => y(t).code)); | ||
n.command(o.pattern("optimize:strings")).action(o.wrap((t) => S(t).code)); | ||
n.command(o.pattern("optimize:functions")).action(o.wrap((t) => v(t).code)); | ||
n.name("battuta").description("CLI tool for battuta").version("0.0.0"); | ||
n.parse(process.argv); | ||
e.command(o.pattern("compile")).action(o.wrap((t) => g(t).code)); | ||
e.command(o.pattern("compile:jsx")).action(o.wrap((t) => C(t).code)); | ||
e.command(o.pattern("optimize")).action(o.wrap((t) => y(t).code)); | ||
e.command(o.pattern("optimize:strings")).action(o.wrap((t) => S(t).code)); | ||
e.command(o.pattern("optimize:functions")).action(o.wrap((t) => v(t).code)); | ||
e.name("battuta").description("CLI tool for battuta").version("0.0.0"); | ||
e.parse(process.argv); |
@@ -31,3 +31,3 @@ import { t as f } from "./jsx-Bwrm210x.js"; | ||
enforce: "pre", | ||
load: (t) => t !== "index.html" ? void 0 : a("./index.html") ? o("./index.html") : l, | ||
load: (t) => t !== "index.html" ? void 0 : a("./index.html") ? o("./index.html", "utf-8") : l, | ||
resolveId: (t, e, r) => { | ||
@@ -39,3 +39,3 @@ if (r.isEntry) return "index.html"; | ||
if (e.url !== "/") return i(); | ||
const n = a("./index.html") ? o("./index.html") : l; | ||
const n = a("./index.html") ? o("./index.html", "utf-8") : l; | ||
r.setHeader("Content-Type", "text/html"), r.statusCode = 200, r.end(n); | ||
@@ -42,0 +42,0 @@ }); |
{ | ||
"name": "battuta", | ||
"private": false, | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"type": "module", | ||
@@ -73,3 +73,3 @@ "license": "MIT", | ||
"@types/three": "^0.169.0", | ||
"battuta": "github:BobochD-Brew/battuta.git#3c5eb8359d69133a2473721be532b51676534886", | ||
"battuta": "0.0.1", | ||
"typescript": "^5.5.3", | ||
@@ -76,0 +76,0 @@ "vite-plugin-dts": "^4.0.3", |
58543
-0.09%