-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Write a build script in bun to splatter dist into root
Doing this because it simplifies the usage of the package and npm doesn't seem to give me a way of telling it to do this. Could be wrong and I hope I am.
- Loading branch information
Showing
2 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>", | ||
"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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
})() |