🔨 chore: script fixies x2
Signed-off-by: Pauline <git@ethanlibs.co>
This commit is contained in:
parent
2ed2891678
commit
791adbf173
7 changed files with 55 additions and 39 deletions
|
|
@ -4,7 +4,7 @@ set -euo pipefail
|
|||
|
||||
__dirname="$(CDPATH='' cd "$(dirname "$0")" && pwd -P)"
|
||||
|
||||
# TODO: make it work with macOS
|
||||
# TODO: make it work with macOS grep
|
||||
grep -Po '^\s+"[\w-]+\s+\d(\.\d+)*[^"]*"' "${__dirname}/../../Cargo.lock" \
|
||||
| xargs printf '%s\n' \
|
||||
| sort -u -k 1b,2V
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { parse as parseTOML } from 'smol-toml';
|
|||
import { checkEnvironment, which } from './utils';
|
||||
import { getTriple } from './utils/triple';
|
||||
|
||||
consola.info('checking the development environment...');
|
||||
const env = checkEnvironment(import.meta);
|
||||
const triple = getTriple();
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ if ((await Promise.all([which`cargo`, which`rustc`, which`pnpm`])).some(f => !f)
|
|||
`,
|
||||
);
|
||||
|
||||
consola.info('generating cargo configuration file.');
|
||||
consola.start('generating cargo configuration file...');
|
||||
|
||||
interface ConfigStore {
|
||||
isWin: boolean;
|
||||
|
|
@ -60,10 +61,11 @@ try {
|
|||
const template = await readFile(join(env.__root, '.cargo', 'config.toml.mustache'), { encoding: 'utf8' });
|
||||
const rendered = mustache.render(template, configStore).replace(/\n{2,}/g, '\n');
|
||||
|
||||
consola.info('validating rendered cargo.toml file');
|
||||
consola.info('validating rendered cargo.toml file...');
|
||||
parseTOML(rendered);
|
||||
|
||||
await writeFile(join(env.__root, '.cargo', 'config.toml'), rendered, { mode: 0o751, flag: 'w+' });
|
||||
consola.success('successfully prepared the development environment!');
|
||||
}
|
||||
catch (error) {
|
||||
consola.error(`
|
||||
|
|
|
|||
|
|
@ -55,12 +55,13 @@ esac
|
|||
if [ "${CI:-}" != "true" ]; then
|
||||
echo 'onelauncher development environment setup:'
|
||||
echo 'to set up your machine for onelauncher development, this script will install some required dependencies with your system package manager'
|
||||
echo 'you can audit this script, it is documented inline at `packages/scripts/setup.sh`'
|
||||
echo
|
||||
echo 'press enter to continue'
|
||||
read -r
|
||||
|
||||
# checks if pnpm is installed
|
||||
if ! has pnpm; then
|
||||
if ! has pnpm git; then
|
||||
err 'pnpm was not found.' \
|
||||
"ensure the 'pnpm' command is in your \$PATH." \
|
||||
'you must use pnpm for this project; yarn and npm will not work:' \
|
||||
|
|
@ -80,6 +81,8 @@ fi
|
|||
# installs system-specific dependencies
|
||||
case "$(uname)" in
|
||||
"Darwin")
|
||||
# we assume that developer tools and brew are already installed, as they
|
||||
# are prerequisites to most installations of rustup and pnpm.
|
||||
if [ "$(uname -m)" = 'x86_64' ] && ! [ "${CI:-}" = "true" ]; then
|
||||
brew install nasm
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ try {
|
|||
}
|
||||
}
|
||||
|
||||
consola.info('starting tauri...');
|
||||
consola.start('initializing tauri...');
|
||||
await execa({ cwd: __desktop })('pnpm', ['exec', 'tauri', ...args]);
|
||||
|
||||
consola.info('build completed, fixing linux build');
|
||||
consola.success('build completed, fixing linux build...');
|
||||
if (args[0] === 'build' && bundles.some(b => b === 'deb' || b === 'all')) {
|
||||
const linuxTargets = targets.filter(t => t.includes('-linux-'));
|
||||
if (linuxTargets.length > 0)
|
||||
|
|
@ -93,7 +93,7 @@ catch (error) {
|
|||
}
|
||||
}
|
||||
finally {
|
||||
consola.info('cleaning up');
|
||||
consola.info('cleaning up...');
|
||||
cleanup();
|
||||
env.__exit(store.code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ export async function awaitLock(file: string): Promise<void> {
|
|||
if (!(await which`flock`))
|
||||
throw new Error('flock is not installed!');
|
||||
|
||||
consola.start(`waiting for file lock on ${file}`);
|
||||
const store = { locked: false };
|
||||
while (!store.locked)
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -19,15 +19,16 @@ export async function tauriUpdateKey(env: CheckedEnvironment): Promise<string |
|
|||
fs.readFile(privateKeyPath, 'utf-8'),
|
||||
]);
|
||||
|
||||
consola.start('generating tauri updater keys...');
|
||||
const keys = { privateKey: '', publicKey: '' };
|
||||
try {
|
||||
[keys.publicKey, keys.privateKey] = await readKeys();
|
||||
if (keys.privateKey === '' || keys.publicKey === '')
|
||||
consola.error(new Error(`empty keys`));
|
||||
consola.error(new Error(`empty old updater keys, regenerating...`));
|
||||
}
|
||||
catch (error) {
|
||||
if (env.__debug) {
|
||||
consola.warn(`failed to read updater keys`);
|
||||
consola.warn(`failed to read updater keys!`);
|
||||
consola.error(error);
|
||||
}
|
||||
|
||||
|
|
@ -36,15 +37,18 @@ export async function tauriUpdateKey(env: CheckedEnvironment): Promise<string |
|
|||
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`);
|
||||
throw new Error(`empty updater keys generated by cli!`);
|
||||
}
|
||||
|
||||
consola.success('successfully generated tauri updater keys!');
|
||||
console.info(keys.publicKey);
|
||||
process.env.TAURI_SIGNING_PRIVATE_KEY = keys.privateKey;
|
||||
process.env.TAURI_SIGNING_PRIVATE_KEY_PASSWORD = '';
|
||||
return keys.publicKey;
|
||||
}
|
||||
|
||||
export async function patchTauri(env: CheckedEnvironment, targets: string[], args: string[]): Promise<string[]> {
|
||||
consola.start('patching tauri configuration...');
|
||||
if (args.findIndex(a => ['--config', '-c'].includes(a)) !== -1)
|
||||
throw new Error('custom tauri build configuration is not supported!');
|
||||
|
||||
|
|
@ -74,6 +78,7 @@ export async function patchTauri(env: CheckedEnvironment, targets: string[], arg
|
|||
const tauriRoot = join(env.__root, 'apps', 'desktop');
|
||||
const tauriConfig = JSON.parse(await fs.readFile(join(tauriRoot, 'tauri.conf.json'), 'utf-8'));
|
||||
|
||||
consola.info('determining tauri patch arguments...');
|
||||
switch (args[0]) {
|
||||
case 'dev':
|
||||
tauriPatch.build.features.push('devtools');
|
||||
|
|
@ -93,6 +98,7 @@ export async function patchTauri(env: CheckedEnvironment, targets: string[], arg
|
|||
}
|
||||
|
||||
if (osType === 'Darwin') {
|
||||
consola.info('patching macOS bundle configuration...');
|
||||
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,
|
||||
|
|
@ -107,7 +113,7 @@ export async function patchTauri(env: CheckedEnvironment, targets: string[], arg
|
|||
))
|
||||
) {
|
||||
macOSStore.minimumVersion = macOSStore.defaultArm64;
|
||||
consola.log(`[aarch64-apple-darwin]: setting minimum system version to ${macOSStore.minimumVersion}`);
|
||||
consola.debug(`setting minimum macOS version to ${macOSStore.minimumVersion}...`);
|
||||
}
|
||||
|
||||
if (macOSStore.minimumVersion) {
|
||||
|
|
@ -120,8 +126,10 @@ export async function patchTauri(env: CheckedEnvironment, targets: string[], arg
|
|||
}
|
||||
|
||||
const tauriPatchC = join(tauriRoot, 'tauri.conf.patch.json');
|
||||
consola.debug(`writing patched tauri configuration to ${tauriPatchC}`);
|
||||
await fs.writeFile(tauriPatchC, JSON.stringify(tauriPatch, null, 2));
|
||||
|
||||
args.splice(1, 0, '-c', tauriPatchC);
|
||||
consola.success('successfully patched tauri configuration!');
|
||||
return [tauriPatchC];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
import { machine, type } from 'node:os';
|
||||
import { env } from 'node:process';
|
||||
import os from 'node:os';
|
||||
import process from 'node:process';
|
||||
import { consola } from 'consola';
|
||||
import { execa } from 'execa';
|
||||
|
||||
const state: { __debug: boolean; libc: 'musl' | 'glibc' } = {
|
||||
__debug: env.NODE_ENV === 'debug',
|
||||
const state: { debug: boolean; libc: 'musl' | 'glibc' } = {
|
||||
debug: process.env.NODE_ENV === 'debug',
|
||||
libc: 'glibc',
|
||||
};
|
||||
|
||||
if (type() === 'Linux')
|
||||
if (os.type() === 'Linux')
|
||||
try {
|
||||
if ((await execa`ldd /bin/ls`).stdout.includes('musl'))
|
||||
state.libc = 'musl';
|
||||
}
|
||||
catch (error) {
|
||||
if (state.__debug) {
|
||||
if (state.debug) {
|
||||
consola.warn('failed to check libs type');
|
||||
consola.error(error);
|
||||
}
|
||||
|
|
@ -26,40 +26,42 @@ const OS_TYPE: Record<string, string> = {
|
|||
linux: 'Linux',
|
||||
};
|
||||
|
||||
type TripleID = ['Darwin' | 'Windows_NT', 'x86_64' | 'aarch64'] | ['Linux', 'x86_64' | 'aarch64', 'musl' | 'glibc'];
|
||||
type TripleID =
|
||||
| ['Darwin' | 'Windows_NT', 'x86_64' | 'aarch64']
|
||||
| ['Linux', 'x86_64' | 'aarch64', 'musl' | 'glibc'];
|
||||
|
||||
export function getTriple(): TripleID {
|
||||
const tripleState: {
|
||||
_libc: typeof state.libc;
|
||||
_os: string;
|
||||
_arch: string;
|
||||
libc: typeof state.libc;
|
||||
os: string;
|
||||
arch: string;
|
||||
} = {
|
||||
_libc: state.libc,
|
||||
_os: '',
|
||||
_arch: '',
|
||||
libc: state.libc,
|
||||
os: '',
|
||||
arch: '',
|
||||
};
|
||||
|
||||
if (env.TARGET_TRIPLE) {
|
||||
const target = env.TARGET_TRIPLE.split('-');
|
||||
tripleState._os = OS_TYPE[target[2] ?? ''] as string;
|
||||
tripleState._arch = target[0] as string;
|
||||
if (tripleState._os === 'Linux')
|
||||
tripleState._libc = target[3]?.includes('musl') ? 'musl' : 'glibc';
|
||||
if (process.env.TARGET_TRIPLE) {
|
||||
const target = process.env.TARGET_TRIPLE.split('-');
|
||||
tripleState.os = OS_TYPE[target[2] ?? ''] as string;
|
||||
tripleState.arch = target[0] as string;
|
||||
if (tripleState.os === 'Linux')
|
||||
tripleState.libc = target[3]?.includes('musl') ? 'musl' : 'glibc';
|
||||
}
|
||||
else {
|
||||
tripleState._os = type();
|
||||
tripleState._arch = machine();
|
||||
if (tripleState._arch === 'arm64')
|
||||
tripleState._arch = 'aarch64';
|
||||
tripleState.os = os.type();
|
||||
tripleState.arch = os.machine();
|
||||
if (tripleState.arch === 'arm64')
|
||||
tripleState.arch = 'aarch64';
|
||||
}
|
||||
|
||||
if (tripleState._arch !== 'x86_64' && tripleState._arch !== 'aarch64')
|
||||
if (tripleState.arch !== 'x86_64' && tripleState.arch !== 'aarch64')
|
||||
throw new Error(`Unsuported architecture`);
|
||||
|
||||
if (tripleState._os === 'Linux')
|
||||
return [tripleState._os, tripleState._arch, tripleState._libc];
|
||||
else if (tripleState._os !== 'Darwin' && tripleState._os !== 'Windows_NT')
|
||||
if (tripleState.os === 'Linux')
|
||||
return [tripleState.os, tripleState.arch, tripleState.libc];
|
||||
else if (tripleState.os !== 'Darwin' && tripleState.os !== 'Windows_NT')
|
||||
throw new Error(`Unsuported OS`);
|
||||
|
||||
return [tripleState._os, tripleState._arch];
|
||||
return [tripleState.os, tripleState.arch];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue