diff --git a/package.json b/package.json index f1f4328..d99db38 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,28 @@ { "name": "pui-jsx", "version": "0.2.0", - "main": "dist/index.js", + "main": "index.js", "type": "module", - "types": "dist/index.d.ts", + "types": "index.d.ts", "files": [ - "dist", + "index.js", + "jsx-dev-runtime.js", + "jsx-node-builder.js", + "jsx-runtime.js", + "static", + "types.js", + "index.d.ts", + "jsx-dev-runtime.d.ts", + "jsx-node-builder.d.ts", + "jsx-runtime.d.ts", + "types.d.ts", "README.md" ], "author": "jmnuf ", "scripts": { "build": "tsc -p tsconfig.build.json", "test": "bun test", - "pub": "bun run test && bun run build && npm publish" + "pub": "bun run publish.build.ts" }, "devDependencies": { "@types/bun": "latest" diff --git a/publish.build.ts b/publish.build.ts new file mode 100644 index 0000000..db346bb --- /dev/null +++ b/publish.build.ts @@ -0,0 +1,80 @@ +import pkg from "./package.json"; +import { readdir, mkdir, rm } from "node:fs/promises"; + +async function rm_rf(path: string) { + try { + await rm(path, { recursive: true, force: true }); + return true; + } catch (err) { + console.error(err); + return false; + } +} + +async function cpy(input: string, output: string) { + const f = Bun.file(input); + try { + await Bun.write(output, f); + return true; + } catch (err) { + console.error(err); + return false; + } +} + +(async function main() { + const { $ } = Bun; + let shellResult; + // bun run test && bun run build && npm publish + shellResult = await $`bun run test`.nothrow(); + if (shellResult.exitCode != 0) { + return; + } + shellResult = await $`bun run build`.nothrow(); + if (shellResult.exitCode != 0) { + return; + } + const files = pkg.files; + + try { + for (const f of files) { + if (f === "README.md") continue; + if (f === "static") { + await mkdir("./static"); + const dir = await readdir(`./dist/${f}`); + for (const f of dir) { + console.log("[dist/static]", f, "exists:", await Bun.file(`./dist/static/${f}`).exists()); + await cpy(`./dist/static/${f}`, `./static/${f}`); + } + continue; + } + console.log("[dist]", f, "exists:", await Bun.file(`./dist/${f}`).exists()); + await cpy(`./dist/${f}`, `./${f}`); + } + } catch (err) { + console.error(err); + await rm_rf("./static"); + return; + } + + process.stdout.write("Press enter to continue... "); + for await (const _ of console) { + break; + } + + // await $`npm publish`.nothrow(); + + try { + for (const f of files) { + if (f === "README.md") continue; + if (f === "static") { + await rm_rf("./static"); + continue; + } + await rm(`./${f}`, { force: true }); + } + } catch (err) { + console.error(err); + } + +})()