mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 15:47:18 +02:00
Support build different targets
This commit is contained in:
parent
02bd375fc8
commit
9a18d1697e
54
build.ts
54
build.ts
@ -1,5 +1,12 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
import { watch, readFile } from "node:fs/promises"
|
import { watch, readFile } from "node:fs/promises";
|
||||||
|
|
||||||
|
enum BuildTarget {
|
||||||
|
ALL = 'all',
|
||||||
|
ANDROID_APP = 'android-app',
|
||||||
|
MOBILE = 'mobile',
|
||||||
|
WEBOS = 'webos',
|
||||||
|
}
|
||||||
|
|
||||||
const postProcess = (str: string): string => {
|
const postProcess = (str: string): string => {
|
||||||
// Unescape unicode charaters
|
// Unescape unicode charaters
|
||||||
@ -13,34 +20,45 @@ const postProcess = (str: string): string => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const build = (config?: any={}) => {
|
const build = async (target: BuildTarget, config?: any={}) => {
|
||||||
|
console.log('--- Building:', target);
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
|
|
||||||
return Bun.build({
|
let outputFileName = 'better-xcloud';
|
||||||
|
if (target !== BuildTarget.ALL) {
|
||||||
|
outputFileName += `.${target}`;
|
||||||
|
}
|
||||||
|
outputFileName += '.user.js';
|
||||||
|
|
||||||
|
let output = await Bun.build({
|
||||||
entrypoints: ['src/index.ts'],
|
entrypoints: ['src/index.ts'],
|
||||||
outdir: './dist',
|
outdir: './dist',
|
||||||
}).then(async (output) => {
|
naming: outputFileName,
|
||||||
|
define: {
|
||||||
|
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!output.success) {
|
if (!output.success) {
|
||||||
console.log(output);
|
console.log(output);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {path} = output.outputs[0];
|
const {path} = output.outputs[0];
|
||||||
let result = postProcess(await readFile(path, 'utf-8'));
|
let result = postProcess(await readFile(path, 'utf-8'));
|
||||||
await Bun.write(
|
const header = await readFile('src/header.txt', 'utf-8');
|
||||||
path,
|
await Bun.write(path, header + result);
|
||||||
await readFile('src/header.txt', 'utf-8') + result
|
console.log(`[${target}] done in ${performance.now() - startTime} ms`);
|
||||||
);
|
|
||||||
console.log(`done in ${performance.now() - startTime} ms`);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildTargets = [
|
||||||
|
BuildTarget.ALL,
|
||||||
|
BuildTarget.ANDROID_APP,
|
||||||
|
BuildTarget.MOBILE,
|
||||||
|
// BuildTarget.WEBOS,
|
||||||
|
];
|
||||||
|
|
||||||
const config = {};
|
const config = {};
|
||||||
await build(config);
|
for (const target of buildTargets) {
|
||||||
|
await build(target, 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);
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"build": "build.ts",
|
"build": "build.ts"
|
||||||
"build-watch": "build.ts --watch"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest"
|
"@types/bun": "latest"
|
||||||
|
8
src/build-config.ts
Normal file
8
src/build-config.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const BuildConfig = {
|
||||||
|
TARGET: Bun.env.BUILD_TARGET,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBuildConfig = () => {
|
||||||
|
console.log(BuildConfig);
|
||||||
|
return BuildConfig;
|
||||||
|
};
|
@ -1,3 +1,4 @@
|
|||||||
|
import { getBuildConfig } from "./build-config" with { type: "macro" };
|
||||||
import "./utils/global";
|
import "./utils/global";
|
||||||
import { BxEvent } from "./modules/bx-event";
|
import { BxEvent } from "./modules/bx-event";
|
||||||
import { BX_FLAGS } from "./modules/bx-flags";
|
import { BX_FLAGS } from "./modules/bx-flags";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user