mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Update build script
This commit is contained in:
parent
3eb70498a3
commit
4b1428ffd7
61
build.ts
61
build.ts
@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
import { readFile } from "node:fs/promises";
|
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 {
|
enum BuildTarget {
|
||||||
ALL = 'all',
|
ALL = 'all',
|
||||||
@ -23,20 +27,24 @@ const postProcess = (str: string): string => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const build = async (target: BuildTarget, config: any={}) => {
|
const build = async (target: BuildTarget, version, config: any={}) => {
|
||||||
console.log('--- Building:', target);
|
console.log('-- Target:', target);
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
|
|
||||||
let outputFileName = 'better-xcloud';
|
let outputScriptName = 'better-xcloud';
|
||||||
if (target !== BuildTarget.ALL) {
|
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({
|
let output = await Bun.build({
|
||||||
entrypoints: ['src/index.ts'],
|
entrypoints: ['src/index.ts'],
|
||||||
outdir: './dist',
|
outdir: outDir,
|
||||||
naming: outputFileName,
|
naming: outputScriptName,
|
||||||
define: {
|
define: {
|
||||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||||
},
|
},
|
||||||
@ -48,20 +56,47 @@ const build = async (target: BuildTarget, config: any={}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {path} = output.outputs[0];
|
const {path} = output.outputs[0];
|
||||||
|
// Get generated file
|
||||||
let result = postProcess(await readFile(path, 'utf-8'));
|
let result = postProcess(await readFile(path, 'utf-8'));
|
||||||
const header = await readFile('src/header.txt', 'utf-8');
|
|
||||||
await Bun.write(path, header + result);
|
// Replace [[VERSION]] with real value
|
||||||
console.log(`[${target}] done in ${performance.now() - startTime} ms`);
|
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 = [
|
const buildTargets = [
|
||||||
BuildTarget.ALL,
|
BuildTarget.ALL,
|
||||||
BuildTarget.ANDROID_APP,
|
// BuildTarget.ANDROID_APP,
|
||||||
BuildTarget.MOBILE,
|
// BuildTarget.MOBILE,
|
||||||
// BuildTarget.WEBOS,
|
// 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 = {};
|
const config = {};
|
||||||
for (const target of buildTargets) {
|
for (const target of buildTargets) {
|
||||||
await build(target, config);
|
await build(target, values['version'], config);
|
||||||
}
|
}
|
||||||
|
5
src/header_meta.txt
Normal file
5
src/header_meta.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name Better xCloud
|
||||||
|
// @namespace https://github.com/redphx
|
||||||
|
// @version [[VERSION]]
|
||||||
|
// ==/UserScript==
|
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud (Beta)
|
// @name Better xCloud (Beta)
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 3.5.3
|
// @version [[VERSION]]
|
||||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
// @author redphx
|
// @author redphx
|
||||||
// @license MIT
|
// @license MIT
|
||||||
@ -9,7 +9,7 @@
|
|||||||
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
|
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
|
||||||
// @run-at document-start
|
// @run-at document-start
|
||||||
// @grant none
|
// @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
|
// @downloadURL https://github.com/redphx/better-xcloud/releases/latest/download/better-xcloud.user.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
'use strict';
|
'use strict';
|
Loading…
x
Reference in New Issue
Block a user