Update build script

This commit is contained in:
redphx 2024-04-27 10:05:47 +07:00
parent 3eb70498a3
commit 4b1428ffd7
3 changed files with 55 additions and 15 deletions

View File

@ -1,5 +1,9 @@
#!/usr/bin/env bun
import { readFile } from "node:fs/promises";
import { parseArgs } from "node:util";
import { sys } from "typescript";
import txtScriptHeader from "./src/header_script.txt" with { type: "text" };
import txtMetaHeader from "./src/header_meta.txt" with { type: "text" };
enum BuildTarget {
ALL = 'all',
@ -23,20 +27,24 @@ const postProcess = (str: string): string => {
return str;
}
const build = async (target: BuildTarget, config: any={}) => {
console.log('--- Building:', target);
const build = async (target: BuildTarget, version, config: any={}) => {
console.log('-- Target:', target);
const startTime = performance.now();
let outputFileName = 'better-xcloud';
let outputScriptName = 'better-xcloud';
if (target !== BuildTarget.ALL) {
outputFileName += `.${target}`;
outputScriptName += `.${target}`;
}
outputFileName += '.user.js';
let outputMetaName = outputScriptName;
outputScriptName += '.user.js';
outputMetaName += '.meta.js';
const outDir = './dist';
let output = await Bun.build({
entrypoints: ['src/index.ts'],
outdir: './dist',
naming: outputFileName,
outdir: outDir,
naming: outputScriptName,
define: {
'Bun.env.BUILD_TARGET': JSON.stringify(target),
},
@ -48,20 +56,47 @@ const build = async (target: BuildTarget, config: any={}) => {
}
const {path} = output.outputs[0];
// Get generated file
let result = postProcess(await readFile(path, 'utf-8'));
const header = await readFile('src/header.txt', 'utf-8');
await Bun.write(path, header + result);
console.log(`[${target}] done in ${performance.now() - startTime} ms`);
// 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`);
// Create meta file
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
}
const buildTargets = [
BuildTarget.ALL,
BuildTarget.ANDROID_APP,
BuildTarget.MOBILE,
// BuildTarget.ANDROID_APP,
// BuildTarget.MOBILE,
// BuildTarget.WEBOS,
];
const { values, positionals } = parseArgs({
args: Bun.argv,
options: {
version: {
type: 'string',
},
},
strict: true,
allowPositionals: true,
});
if (!values['version']) {
console.log('Missing --version param');
sys.exit(-1);
}
console.log('Building: ', values['version']);
const config = {};
for (const target of buildTargets) {
await build(target, config);
await build(target, values['version'], config);
}

5
src/header_meta.txt Normal file
View File

@ -0,0 +1,5 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version [[VERSION]]
// ==/UserScript==

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Better xCloud (Beta)
// @namespace https://github.com/redphx
// @version 3.5.3
// @version [[VERSION]]
// @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx
// @license MIT
@ -9,7 +9,7 @@
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
// @run-at document-start
// @grant none
// @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/main/better-xcloud.meta.js
// @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/typescript/dist/better-xcloud.meta.js
// @downloadURL https://github.com/redphx/better-xcloud/releases/latest/download/better-xcloud.user.js
// ==/UserScript==
'use strict';