mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-03 06:07:19 +02:00
Update build.ts
This commit is contained in:
parent
fa82f0ba95
commit
11ef014c74
114
build.ts
114
build.ts
@ -6,10 +6,10 @@ import txtScriptHeader from "./src/assets/header_script.txt" with { type: "text"
|
||||
import txtMetaHeader from "./src/assets/header_meta.txt" with { type: "text" };
|
||||
|
||||
enum BuildTarget {
|
||||
ALL = 'all',
|
||||
ANDROID_APP = 'android-app',
|
||||
MOBILE = 'mobile',
|
||||
WEBOS = 'webos',
|
||||
ALL = 'all',
|
||||
ANDROID_APP = 'android-app',
|
||||
MOBILE = 'mobile',
|
||||
WEBOS = 'webos',
|
||||
}
|
||||
|
||||
const postProcess = (str: string): string => {
|
||||
@ -21,86 +21,86 @@ const postProcess = (str: string): string => {
|
||||
// Replace "globalThis." with "var";
|
||||
str = str.replaceAll('globalThis.', 'var ');
|
||||
|
||||
// Add ADDITIONAL CODE block
|
||||
str = str.replace('var DEFAULT_FLAGS', '\n/* ADDITIONAL CODE */\n\nvar DEFAULT_FLAGS');
|
||||
// Add ADDITIONAL CODE block
|
||||
str = str.replace('var DEFAULT_FLAGS', '\n/* ADDITIONAL CODE */\n\nvar DEFAULT_FLAGS');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
const build = async (target: BuildTarget, version: string, config: any={}) => {
|
||||
console.log('-- Target:', target);
|
||||
const startTime = performance.now();
|
||||
console.log('-- Target:', target);
|
||||
const startTime = performance.now();
|
||||
|
||||
let outputScriptName = 'better-xcloud';
|
||||
if (target !== BuildTarget.ALL) {
|
||||
outputScriptName += `.${target}`;
|
||||
}
|
||||
let outputMetaName = outputScriptName;
|
||||
outputScriptName += '.user.js';
|
||||
outputMetaName += '.meta.js';
|
||||
let outputScriptName = 'better-xcloud';
|
||||
if (target !== BuildTarget.ALL) {
|
||||
outputScriptName += `.${target}`;
|
||||
}
|
||||
let outputMetaName = outputScriptName;
|
||||
outputScriptName += '.user.js';
|
||||
outputMetaName += '.meta.js';
|
||||
|
||||
const outDir = './dist';
|
||||
const outDir = './dist';
|
||||
|
||||
let output = await Bun.build({
|
||||
entrypoints: ['src/index.ts'],
|
||||
outdir: outDir,
|
||||
naming: outputScriptName,
|
||||
minify: {
|
||||
syntax: true,
|
||||
},
|
||||
define: {
|
||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||
'Bun.env.SCRIPT_VERSION': JSON.stringify(version),
|
||||
},
|
||||
});
|
||||
let output = await Bun.build({
|
||||
entrypoints: ['src/index.ts'],
|
||||
outdir: outDir,
|
||||
naming: outputScriptName,
|
||||
minify: {
|
||||
syntax: true,
|
||||
},
|
||||
define: {
|
||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||
'Bun.env.SCRIPT_VERSION': JSON.stringify(version),
|
||||
},
|
||||
});
|
||||
|
||||
if (!output.success) {
|
||||
console.log(output);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!output.success) {
|
||||
console.log(output);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const {path} = output.outputs[0];
|
||||
// Get generated file
|
||||
let result = postProcess(await readFile(path, 'utf-8'));
|
||||
const {path} = output.outputs[0];
|
||||
// Get generated file
|
||||
let result = postProcess(await readFile(path, 'utf-8'));
|
||||
|
||||
// Replace [[VERSION]] with real value
|
||||
const scriptHeader = txtScriptHeader.replace('[[VERSION]]', version);
|
||||
// Replace [[VERSION]] with real value
|
||||
const scriptHeader = txtScriptHeader.replace('[[VERSION]]', version);
|
||||
|
||||
// Save to script
|
||||
await Bun.write(path, scriptHeader + result);
|
||||
console.log(`---- [${target}] done in ${performance.now() - startTime} ms`);
|
||||
// Save to script
|
||||
await Bun.write(path, scriptHeader + result);
|
||||
console.log(`---- [${target}] done in ${performance.now() - startTime} ms`);
|
||||
|
||||
// Create meta file
|
||||
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
||||
// Create meta file
|
||||
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
||||
}
|
||||
|
||||
const buildTargets = [
|
||||
BuildTarget.ALL,
|
||||
// BuildTarget.ANDROID_APP,
|
||||
// BuildTarget.MOBILE,
|
||||
// BuildTarget.WEBOS,
|
||||
BuildTarget.ALL,
|
||||
// BuildTarget.ANDROID_APP,
|
||||
// BuildTarget.MOBILE,
|
||||
// BuildTarget.WEBOS,
|
||||
];
|
||||
|
||||
const { values, positionals } = parseArgs({
|
||||
args: Bun.argv,
|
||||
options: {
|
||||
version: {
|
||||
type: 'string',
|
||||
args: Bun.argv,
|
||||
options: {
|
||||
version: {
|
||||
type: 'string',
|
||||
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
});
|
||||
|
||||
if (!values['version']) {
|
||||
console.log('Missing --version param');
|
||||
sys.exit(-1);
|
||||
console.log('Missing --version param');
|
||||
sys.exit(-1);
|
||||
}
|
||||
|
||||
console.log('Building: ', values['version']);
|
||||
|
||||
const config = {};
|
||||
for (const target of buildTargets) {
|
||||
await build(target, values['version'], config);
|
||||
await build(target, values['version']!!, config);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user