mirror of
https://gitlab.com/vyla-entertainment/TV.git
synced 2026-11-12 11:07:21 -05:00
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
import { spawnSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const root = process.cwd();
|
|
const win = process.platform === 'win32';
|
|
const androidDir = path.join(root, 'android');
|
|
|
|
const run = (cmd, args, cwd = root) => {
|
|
const r = spawnSync(cmd, args, { cwd, stdio: 'inherit', shell: win });
|
|
if (r.status !== 0) process.exit(r.status || 1);
|
|
};
|
|
|
|
const sdk = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
|
|
const lp = path.join(androidDir, 'local.properties');
|
|
if (!fs.existsSync(lp)) {
|
|
if (!sdk) {
|
|
console.error('Set ANDROID_HOME environment variable.');
|
|
process.exit(1);
|
|
}
|
|
fs.writeFileSync(lp, 'sdk.dir=' + sdk.replace(/\\/g, '\\\\') + '\n');
|
|
}
|
|
|
|
const ghCheck = spawnSync('gh', ['--version'], { shell: win, stdio: 'ignore' });
|
|
if (ghCheck.status !== 0) {
|
|
console.error('GitHub CLI (gh) is not installed or not in PATH.');
|
|
process.exit(1);
|
|
}
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
const version = pkg.version || '1.0.0';
|
|
const tag = `v${version}`;
|
|
|
|
run('node', ['scripts/build-android.mjs']);
|
|
run('npx', ['cap', 'sync', 'android']);
|
|
run(win ? 'gradlew.bat' : './gradlew', ['assembleRelease'], androidDir);
|
|
|
|
const relDir = path.join(androidDir, 'app/build/outputs/apk/release');
|
|
const apkCandidates = [
|
|
path.join(relDir, 'app-release.apk'),
|
|
path.join(relDir, 'app-release-unsigned.apk'),
|
|
path.join(androidDir, 'app/build/outputs/apk/debug/app-debug.apk')
|
|
];
|
|
|
|
const sourceApk = apkCandidates.find(p => fs.existsSync(p));
|
|
if (!sourceApk) {
|
|
console.error('Build succeeded but no output APK was found.');
|
|
process.exit(1);
|
|
}
|
|
|
|
const distDir = path.join(root, 'release');
|
|
fs.rmSync(distDir, { recursive: true, force: true });
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
|
|
const targetApkName = `Vyla-TV_${version}.apk`;
|
|
const targetApk = path.join(distDir, targetApkName);
|
|
fs.copyFileSync(sourceApk, targetApk);
|
|
|
|
const manifest = {
|
|
name: 'Vyla TV',
|
|
version,
|
|
package: targetApkName,
|
|
releaseDate: new Date().toISOString()
|
|
};
|
|
const manifestPath = path.join(distDir, 'manifest.json');
|
|
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
|
|
spawnSync('git', ['tag', '-a', tag, '-m', `Release ${tag}`], { shell: win, stdio: 'inherit' });
|
|
spawnSync('git', ['push', 'origin', tag], { shell: win, stdio: 'inherit' });
|
|
|
|
run('gh', [
|
|
'release',
|
|
'create',
|
|
tag,
|
|
targetApk,
|
|
manifestPath,
|
|
'--title',
|
|
`Vyla TV Release ${tag}`,
|
|
'--notes',
|
|
`Automated Release ${tag}`
|
|
]); |