OneLauncher-Cracked/packages/scripts/utils/patch.ts
Pauline 28b1f9f0e3
Feature: Package API (#75) (i'm just going to merge this because the other branches are inactive)
* feat: Start work on package api

* feat: Browser Context Controller

* feat: Add packages to cluster metadata
feat: Change structure of Package

* 🐛 fix: format

* 🔨 feat: Add more functions wrapping around Modrinth

* 🔨 feat: Start working on browser frontend

* feat: BrowserPackage work + markdown support

* 🐛 fix: fmt

Signed-off-by: Pauline <git@ethanlibs.co>

* 🚧 wip: h

Signed-off-by: Pauline <git@ethanlibs.co>

* feat: Download button for packages for suitable clusters + tweaks

* 🚧 wip: markdown and stuff

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: some patches

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: remove react bloat

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore(pkg/infer): try to reduce reused code

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore: bump deps

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: markdown innerhtml

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: h

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: tweak

Signed-off-by: Pauline <git@ethanlibs.co>

* 🚧 wip: idk

Signed-off-by: Pauline <git@ethanlibs.co>

* fix: Gamemode compile error
chore: Add missing and remove unused libraries
feat: usePreventLeave hook
feat: ClusterOverview edit mode continues with navigation (assuming there was a navigation attempt) after pressing Yes or No for save

* feat: Add reload clusters button on home page

* feat: More information provided to BrowserPackage

* fix: Minor fixes (Navbar isActive, Markdown click prevention, Markdown list styling)

* 🐛 fix: h

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: highlighting

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: forge modern

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore: bump deps

Signed-off-by: Pauline <git@ethanlibs.co>

* fix: Markdown-it issue + Added promptOpener hook for Markdown links

* feat: Made BrowserPackage sidebar sticky

* refactor: Package system (not yet in a working state)

* 🚧 wip: bump deps temp

Signed-off-by: Pauline <git@ethanlibs.co>

* feat: Added a package manager

* ✨ feature: start prisma work, but it doesnt break anything so we can keep it until its done. also fix some stuff

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: pushing

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: linting

Signed-off-by: Pauline <git@ethanlibs.co>

* ✨ feature: start ingress integration

Signed-off-by: Pauline <git@ethanlibs.co>

* feat: Package Manager should work now 👍

* fix: Package manager tracing spam

* feat: Added tauri commands for cluster packages
format: Auto formatted frontend + backend

* 🐛 fix: tmp

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore: format

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: specta extension

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: github actions

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: alias

Signed-off-by: Pauline <git@ethanlibs.co>

* chore: Some tweaks and fixes

* chore: Rebase + gitignore bindings.ts

* chore: Remove bindings.ts

* 🐛 fix: migrate

Signed-off-by: Pauline <git@ethanlibs.co>

* 🚧 wip: not sure

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: finalize prisma init schema

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore: format

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: bump deps

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: system deps

Signed-off-by: Pauline <git@ethanlibs.co>

* fix: solid-router navigation issue

* feat: Added new BrowserMain page

* feat: Tweaks + new package list view

* 🐛 fix: bump + format (todo: tauri2, etc)

Signed-off-by: Pauline <git@ethanlibs.co>

* 🐛 fix: devx (fixes #126)

Signed-off-by: Pauline <git@ethanlibs.co>

* 🔨 chore: migrate to consola

Signed-off-by: Pauline <git@ethanlibs.co>

---------

Signed-off-by: Pauline <git@ethanlibs.co>
Co-authored-by: LynithDev <61880709+LynithDev@users.noreply.github.com>
2024-08-31 16:23:24 -04:00

130 lines
3.9 KiB
TypeScript

import process from 'node:process';
import fs from 'node:fs/promises';
import { type } from 'node:os';
import { existsSync, readFileSync } from 'node:fs';
import { join, resolve } from 'pathe';
import { execa } from 'execa';
import semver from 'semver';
import consola from 'consola';
import type { CheckedEnvironment } from '.';
const UPDATEKEY_LOCK_VERSION = '1';
export async function tauriUpdateKey(env: CheckedEnvironment): Promise<string | undefined> {
if (process.env.TAURI_SIGNING_PRIVATE_KEY)
return;
const privateKeyPath = resolve(join(env.__deps, 'tauri.key'));
const publicKeyPath = resolve(join(env.__deps, 'tauri.key.pub'));
const updatekeyPath = resolve(join(env.__deps, 'updatekey_lock'));
if (existsSync(updatekeyPath))
if (readFileSync(updatekeyPath, 'utf-8') === UPDATEKEY_LOCK_VERSION)
return;
const readKeys = () => Promise.all([
fs.readFile(publicKeyPath, 'utf-8'),
fs.readFile(privateKeyPath, 'utf-8'),
]);
const keys = { privateKey: '', publicKey: '' };
try {
[keys.publicKey, keys.privateKey] = await readKeys();
if (keys.privateKey === '' || keys.publicKey === '')
consola.error(new Error(`empty keys`));
}
catch (error) {
if (env.__debug) {
consola.warn(`failed to read updater keys`);
consola.error(error);
}
const quote = type() === 'Windows_NT' ? '"' : '\'';
await execa`pnpm exec tauri signer generate --ci -w ${quote}${privateKeyPath}${quote}`;
[keys.publicKey, keys.privateKey] = await readKeys();
if (keys.privateKey === '' || keys.publicKey === '')
throw new Error(`empty keys`);
}
process.env.TAURI_SIGNING_PRIVATE_KEY = keys.privateKey;
process.env.TAURI_SIGNING_PRIVATE_KEY_PASSWORD = '';
await fs.writeFile(updatekeyPath, UPDATEKEY_LOCK_VERSION, 'utf-8');
return keys.publicKey;
}
export async function patchTauri(env: CheckedEnvironment, targets: string[], args: string[]): Promise<string[]> {
if (args.findIndex(a => ['-c', '--config'].includes(a)) !== -1)
throw new Error('custom tauri build configuration is not supported!');
const osType = type();
const tauriPatch: {
build: {
features: string[];
};
bundle: {
macOS: { minimumSystemVersion: string };
};
plugins: {
updater: { pubkey?: string };
};
} = {
build: {
features: [],
},
bundle: {
macOS: { minimumSystemVersion: '' },
},
plugins: {
updater: {},
},
};
const tauriRoot = join(env.__root, 'apps', 'desktop');
const tauriConfig = JSON.parse(await fs.readFile(join(tauriRoot, 'tauri.conf.json'), 'utf-8'));
switch (args[0]) {
case 'dev':
tauriPatch.build.features.push('devtools');
break;
case 'build':
if (tauriConfig.bundle?.createUpdaterArtifacts !== false) {
const pubKey = await tauriUpdateKey(env);
if (pubKey != null)
tauriPatch.plugins.updater.pubkey = pubKey;
}
break;
}
if (osType === 'Darwin') {
const macOSStore = {
defaultArm64: '11.0', // arm64 support was added in macOS 11.0 (but the safari feature support is bad)
minimumVersion: tauriConfig?.bundle?.macOS?.minimumSystemVersion,
};
if (
(targets.includes('aarch64-apple-darwin')
|| (targets.length === 0 && process.arch === 'arm64'))
&& (macOSStore.minimumVersion == null || semver.lt(
semver.coerce(macOSStore.minimumVersion)!,
semver.coerce(macOSStore.defaultArm64)!,
))
) {
macOSStore.minimumVersion = macOSStore.defaultArm64;
consola.log(`[aarch64-apple-darwin]: setting minimum system version to ${macOSStore.minimumVersion}`);
}
if (macOSStore.minimumVersion) {
process.env.MACOSX_DEPLOYMENT_TARGET = macOSStore.minimumVersion;
tauriPatch.bundle.macOS.minimumSystemVersion = macOSStore.minimumVersion;
}
else {
throw new Error('no minimum macOS version found!');
}
}
const tauriPatchC = join(tauriRoot, 'tauri.conf.patch.json');
await fs.writeFile(tauriPatchC, JSON.stringify(tauriPatch, null, 2));
args.splice(1, 0, '-c', tauriPatchC);
return [tauriPatchC];
}