mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-02 01:40:57 +01:00
chore(build): move exports.d.ts
to index.d.ts
in build step
This commit is contained in:
parent
e08f13897a
commit
8de63be6ba
3 changed files with 30 additions and 4 deletions
30
build.ts
30
build.ts
|
@ -1,3 +1,17 @@
|
|||
import { write } from "bun";
|
||||
import { copyFile } from "fs/promises";
|
||||
import { unlink } from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
// changes the extension of a path to `newExt`
|
||||
function withExtension(filePath: string, newExt: string): string {
|
||||
const dir = path.dirname(filePath);
|
||||
const base = path.basename(filePath, path.extname(filePath));
|
||||
|
||||
const newFilePath = path.join(dir, `${base}.${newExt}`);
|
||||
return newFilePath;
|
||||
}
|
||||
|
||||
// extracts the Luau exports section from a given file path
|
||||
async function extractLuauExports(file: string): Promise<string | null> {
|
||||
const input = await Bun.file(file).text();
|
||||
|
@ -15,10 +29,20 @@ async function extractLuauExports(file: string): Promise<string | null> {
|
|||
return null;
|
||||
}
|
||||
|
||||
const OUT_DIR = "./out";
|
||||
const EXPORTS_TS_FILE = "./src/exports.ts";
|
||||
const EXPORTS_LUAU_FILE = "./out/init.luau";
|
||||
const EXPORTS_LUAU_FILE = path.join(OUT_DIR, "init.luau");
|
||||
|
||||
console.log("extract and export Luau type thunk");
|
||||
await extractLuauExports(EXPORTS_TS_FILE).then((exports) => Bun.write(EXPORTS_LUAU_FILE, exports!));
|
||||
await extractLuauExports(EXPORTS_TS_FILE)
|
||||
.then(async (exports) => {
|
||||
console.log("extract and export luau type thunk");
|
||||
await write(EXPORTS_LUAU_FILE, exports!);
|
||||
})
|
||||
.finally(async () => {
|
||||
console.log("export ts definition files");
|
||||
|
||||
const luauExportsFile = path.join(OUT_DIR, path.basename(withExtension(EXPORTS_TS_FILE, "d.ts")));
|
||||
await write(path.join(OUT_DIR, "index.d.ts"), Bun.file(luauExportsFile));
|
||||
});
|
||||
|
||||
export {}; // treat as esmodule
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"types": "out/index.d.ts",
|
||||
"files": [
|
||||
"out",
|
||||
"!out/exports.d.ts",
|
||||
"!**/*.tsbuildinfo"
|
||||
],
|
||||
"publishConfig": {
|
||||
|
|
|
@ -25,5 +25,6 @@
|
|||
"declaration": true
|
||||
},
|
||||
|
||||
"include": ["src/**/*.ts"]
|
||||
// exclude build script
|
||||
"exclude": ["build.ts"]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue