mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-03 06:07:19 +02:00
Add build.ts
This commit is contained in:
parent
9a76731c69
commit
9446e39eb0
46
build.ts
Normal file
46
build.ts
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bun
|
||||
import { watch, readFile } from "node:fs/promises"
|
||||
|
||||
const postProcess = (str: string): string => {
|
||||
// Unescape unicode charaters
|
||||
str = unescape((str.replace(/\\u/g, '%u')));
|
||||
// Replace \x00 to normal character
|
||||
str = str.replaceAll(/\\x[A-F0-9]{2}/g, (e) => String.fromCharCode(parseInt(e.substring(2), 16)));
|
||||
|
||||
// Replace "globalThis." with "var";
|
||||
str = str.replaceAll('globalThis.', 'var ');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
const build = (config?: any={}) => {
|
||||
const startTime = performance.now();
|
||||
|
||||
return Bun.build({
|
||||
entrypoints: ['src/index.ts'],
|
||||
outdir: './dist',
|
||||
}).then(async (output) => {
|
||||
if (!output.success) {
|
||||
console.log(output);
|
||||
process.exit(1);
|
||||
}
|
||||
const {path} = output.outputs[0];
|
||||
let result = postProcess(await readFile(path, 'utf-8'));
|
||||
await Bun.write(
|
||||
path,
|
||||
await readFile('src/header.txt', 'utf-8') + result
|
||||
);
|
||||
console.log(`done in ${performance.now() - startTime} ms`);
|
||||
})
|
||||
}
|
||||
|
||||
const config = {};
|
||||
await build(config);
|
||||
|
||||
if (!process.argv.includes('--watch')) process.exit(0);
|
||||
|
||||
for await (const event of watch('./src', {recursive: true})) {
|
||||
const {filename} = event;
|
||||
console.log(filename)
|
||||
await build(config);
|
||||
}
|
@ -2,10 +2,14 @@
|
||||
"name": "better-xcloud",
|
||||
"module": "src/index.ts",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"build": "build.ts",
|
||||
"build-watch": "build.ts --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user