From 791adbf173b9e4a18f82341a389d1d4fd650ad44 Mon Sep 17 00:00:00 2001 From: Pauline Date: Wed, 18 Sep 2024 16:25:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20chore:=20script=20fixies=20x2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pauline --- packages/scripts/dedupe.sh | 2 +- packages/scripts/prepare.ts | 6 ++-- packages/scripts/setup.sh | 5 ++- packages/scripts/tauri.ts | 6 ++-- packages/scripts/utils/index.ts | 1 + packages/scripts/utils/patch.ts | 16 ++++++--- packages/scripts/utils/triple.ts | 58 +++++++++++++++++--------------- 7 files changed, 55 insertions(+), 39 deletions(-) diff --git a/packages/scripts/dedupe.sh b/packages/scripts/dedupe.sh index 9257518f..3bcd455e 100755 --- a/packages/scripts/dedupe.sh +++ b/packages/scripts/dedupe.sh @@ -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 diff --git a/packages/scripts/prepare.ts b/packages/scripts/prepare.ts index e1e8fc47..d5e04cca 100644 --- a/packages/scripts/prepare.ts +++ b/packages/scripts/prepare.ts @@ -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(` diff --git a/packages/scripts/setup.sh b/packages/scripts/setup.sh index f84c912d..a00fb556 100755 --- a/packages/scripts/setup.sh +++ b/packages/scripts/setup.sh @@ -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 diff --git a/packages/scripts/tauri.ts b/packages/scripts/tauri.ts index 722e9b74..398f0b19 100644 --- a/packages/scripts/tauri.ts +++ b/packages/scripts/tauri.ts @@ -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); } diff --git a/packages/scripts/utils/index.ts b/packages/scripts/utils/index.ts index 8765826d..fbff9fd2 100644 --- a/packages/scripts/utils/index.ts +++ b/packages/scripts/utils/index.ts @@ -54,6 +54,7 @@ export async function awaitLock(file: string): Promise { 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 { diff --git a/packages/scripts/utils/patch.ts b/packages/scripts/utils/patch.ts index f7d1b3d9..9415d202 100644 --- a/packages/scripts/utils/patch.ts +++ b/packages/scripts/utils/patch.ts @@ -19,15 +19,16 @@ export async function tauriUpdateKey(env: CheckedEnvironment): Promise { + 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]; } diff --git a/packages/scripts/utils/triple.ts b/packages/scripts/utils/triple.ts index fa94af8c..4a6ca15d 100644 --- a/packages/scripts/utils/triple.ts +++ b/packages/scripts/utils/triple.ts @@ -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 = { 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]; }