mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
chore(scripts): convert shell scripts to cross-platform ESM
Signed-off-by: hazre <[email protected]>
This commit is contained in:
1 parent
bacb087be6
commit
612aa2f87e
5 files changed
+200
-163
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#MISE description="Copy CEF runtime libs next to the built binary"
|
||||
# Copy the CEF runtime (libcef.so + resources) next to a built binary so the app
|
||||
# is self-contained: works standalone, when launched by the OS via a sable://
|
||||
# deep link, or from a release package. Pair with the rpath=$ORIGIN that
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#MISE description="Package CEF build into deb/rpm/AppImage"
|
||||
# Package the Linux CEF build into deb/rpm/AppImage. Used by CI and locally.
|
||||
# Run after the binary is built (pnpm tauri:cef build).
|
||||
# Usage: scripts/cef-package.sh [version]
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env node
|
||||
//MISE description="Replace logo/icon assets in public/ from SVG inputs via ffmpeg"
|
||||
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { existsSync, mkdirSync, copyFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createInterface } from 'node:readline';
|
||||
import { PrefixedLogger, createTextHelpers } from './utils/console-style.js';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const BASE_DIR = resolve(__dirname, '..');
|
||||
|
||||
const logger = new PrefixedLogger('[replace-logo]');
|
||||
const { red } = createTextHelpers({ useColor: logger.useColor });
|
||||
|
||||
/**
|
||||
* Display a question on stdin and return the user's trimmed response.
|
||||
* @param {string} question - The prompt text to display.
|
||||
* @returns {Promise<string>} The user's input with surrounding whitespace removed.
|
||||
*/
|
||||
function prompt(question) {
|
||||
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
||||
return new Promise((resolve_) => {
|
||||
rl.question(question, (answer) => {
|
||||
rl.close();
|
||||
resolve_(answer.trim());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Print CLI usage instructions to stdout. */
|
||||
function usage() {
|
||||
logger.info(`Usage: run this script and provide four file paths when prompted.
|
||||
It will replace icons in the repository public/ tree using ffmpeg.
|
||||
|
||||
You will be prompted for:
|
||||
- maskless (borderless) logo (used for maskable icons)
|
||||
- circular logo (used for circular icons)
|
||||
- highlight variant (icon for highlight indicator)
|
||||
- unread variant (icon for unread indicator)
|
||||
|
||||
Requires: ffmpeg, base64`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an SVG to a PNG at the given square dimension using ffmpeg.
|
||||
* Creates the output directory if it doesn't already exist.
|
||||
* @param {string} input - Absolute path to the source SVG file.
|
||||
* @param {string} output - Absolute path for the generated PNG.
|
||||
* @param {string | number} size - Width and height in pixels.
|
||||
*/
|
||||
function ffmpegCmd(input, output, size) {
|
||||
mkdirSync(dirname(output), { recursive: true });
|
||||
logger.info(`Generating ${output} (${size} x ${size})`);
|
||||
execFileSync(
|
||||
'ffmpeg',
|
||||
['-y', '-width', String(size), '-height', String(size), '-i', input, output],
|
||||
{
|
||||
stdio: 'pipe',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a file path has an SVG extension (case-insensitive).
|
||||
* @param {string} filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isSvg(filePath) {
|
||||
return filePath.toLowerCase().endsWith('.svg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point. Prompts for four SVG logo variants, validates them,
|
||||
* then renders PNGs at every required size and copies SVGs into public/res/svg/.
|
||||
* @param {string[]} args - CLI arguments (supports --help / -h).
|
||||
*/
|
||||
async function main(args) {
|
||||
if (args.includes('--help') || args.includes('-h')) {
|
||||
usage();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const maskless = await prompt('Path to maskless (borderless) logo: ');
|
||||
const circular = await prompt('Path to circular logo: ');
|
||||
const highlight = await prompt('Path to highlight variant: ');
|
||||
const unread = await prompt('Path to unread variant: ');
|
||||
|
||||
for (const f of [maskless, circular, highlight, unread]) {
|
||||
if (!existsSync(f)) {
|
||||
logger.error(`${red('File not found:')} ${f}`);
|
||||
process.exit(2);
|
||||
}
|
||||
if (!isSvg(f)) {
|
||||
logger.error(`${red('Input must be an SVG:')} ${f}`);
|
||||
process.exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {[number, string][]} */
|
||||
const CIRCULAR_TARGETS = [
|
||||
[512, 'public/favicon.png'],
|
||||
[2560, 'public/full_res_sable.png'],
|
||||
[144, 'public/res/logo/logo-144x144.png'],
|
||||
[192, 'public/res/logo/logo-192x192.png'],
|
||||
[256, 'public/res/logo/logo-256x256.png'],
|
||||
[36, 'public/res/logo/logo-36x36.png'],
|
||||
[384, 'public/res/logo/logo-384x384.png'],
|
||||
[48, 'public/res/logo/logo-48x48.png'],
|
||||
[512, 'public/res/logo/logo-512x512.png'],
|
||||
[72, 'public/res/logo/logo-72x72.png'],
|
||||
[96, 'public/res/logo/logo-96x96.png'],
|
||||
];
|
||||
|
||||
logger.info('Replacing circular icons...');
|
||||
for (const [size, out] of CIRCULAR_TARGETS) {
|
||||
ffmpegCmd(circular, resolve(BASE_DIR, out), size);
|
||||
}
|
||||
|
||||
/** @type {[number, string][]} */
|
||||
const MASKABLE_TARGETS = [
|
||||
[114, 'public/res/logo-maskable/logo-maskable-114x114.png'],
|
||||
[120, 'public/res/logo-maskable/logo-maskable-120x120.png'],
|
||||
[144, 'public/res/logo-maskable/logo-maskable-144x144.png'],
|
||||
[152, 'public/res/logo-maskable/logo-maskable-152x152.png'],
|
||||
[167, 'public/res/logo-maskable/logo-maskable-167x167.png'],
|
||||
[180, 'public/res/logo-maskable/logo-maskable-180x180.png'],
|
||||
[192, 'public/res/logo-maskable/logo-maskable-192x192.png'],
|
||||
[256, 'public/res/logo-maskable/logo-maskable-256x256.png'],
|
||||
[36, 'public/res/logo-maskable/logo-maskable-36x36.png'],
|
||||
[384, 'public/res/logo-maskable/logo-maskable-384x384.png'],
|
||||
[48, 'public/res/logo-maskable/logo-maskable-48x48.png'],
|
||||
[512, 'public/res/logo-maskable/logo-maskable-512x512.png'],
|
||||
[57, 'public/res/logo-maskable/logo-maskable-57x57.png'],
|
||||
[60, 'public/res/logo-maskable/logo-maskable-60x60.png'],
|
||||
[72, 'public/res/logo-maskable/logo-maskable-72x72.png'],
|
||||
[76, 'public/res/logo-maskable/logo-maskable-76x76.png'],
|
||||
[96, 'public/res/logo-maskable/logo-maskable-96x96.png'],
|
||||
];
|
||||
|
||||
logger.info('Replacing maskable icons (using maskless input)...');
|
||||
for (const [size, out] of MASKABLE_TARGETS) {
|
||||
ffmpegCmd(maskless, resolve(BASE_DIR, out), size);
|
||||
}
|
||||
|
||||
logger.info('Handling SVG assets in public/res/svg/...');
|
||||
const svgDir = resolve(BASE_DIR, 'public/res/svg');
|
||||
mkdirSync(svgDir, { recursive: true });
|
||||
|
||||
logger.info(`Copying circular SVG to ${svgDir}/logo.svg`);
|
||||
copyFileSync(circular, resolve(svgDir, 'logo.svg'));
|
||||
|
||||
logger.info(`Copying maskable SVG to ${svgDir}/logo-maskable.svg`);
|
||||
copyFileSync(maskless, resolve(svgDir, 'logo-maskable.svg'));
|
||||
|
||||
copyFileSync(highlight, resolve(svgDir, 'highlight.svg'));
|
||||
copyFileSync(unread, resolve(svgDir, 'unread.svg'));
|
||||
|
||||
logger.info('All done. Please review the generated files.');
|
||||
}
|
||||
|
||||
main(process.argv.slice(2));
|
||||
@@ -1,126 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
readonly BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
usage(){
|
||||
cat <<EOF
|
||||
Usage: run this script and provide four file paths when prompted.
|
||||
It will replace icons in the repository `public/` tree using ffmpeg.
|
||||
|
||||
You will be prompted for:
|
||||
- maskless (borderless) logo (used for maskable icons)
|
||||
- circular logo (used for circular icons)
|
||||
- highlight variant (icon for highlight indicator)
|
||||
- unread variant (icon for unread indicator)
|
||||
|
||||
Requires: ffmpeg, base64
|
||||
EOF
|
||||
}
|
||||
|
||||
if [[ "${1-}" == "--help" || "${1-}" == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
read -rp "Path to maskless (borderless) logo: " MASKLESS
|
||||
read -rp "Path to circular logo: " CIRCULAR
|
||||
read -rp "Path to highlight variant: " HIGHLIGHT
|
||||
read -rp "Path to unread variant: " UNREAD
|
||||
|
||||
for f in "$MASKLESS" "$CIRCULAR" "$HIGHLIGHT" "$UNREAD"; do
|
||||
if [[ ! -f "$f" ]]; then
|
||||
echo "File not found: $f" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "${f,,}" != *.svg ]]; then
|
||||
echo "Input must be an SVG: $f" >&2
|
||||
exit 3
|
||||
fi
|
||||
done
|
||||
|
||||
ffmpeg_cmd(){
|
||||
local in="$1" out="$2" size="$3"
|
||||
mkdir -p "$(dirname "$out")"
|
||||
echo "Generating $out ($size x $size)"
|
||||
ffmpeg -y -width "$size" -height "$size" -i "$in" "$out" 2>/dev/null
|
||||
}
|
||||
|
||||
# All inputs are required to be SVG. Use ffmpeg to render SVGs to PNG targets
|
||||
# and copy SVGs directly to the svg assets directory.
|
||||
|
||||
is_svg(){
|
||||
local f="$1"
|
||||
[[ "${f,,}" == *.svg ]]
|
||||
}
|
||||
|
||||
echo "Replacing circular icons..."
|
||||
|
||||
declare -a CIRCULAR_TARGETS=(
|
||||
"512:$BASE_DIR/public/favicon.png"
|
||||
"2560:$BASE_DIR/public/full_res_sable.png"
|
||||
"144:$BASE_DIR/public/res/logo/logo-144x144.png"
|
||||
"192:$BASE_DIR/public/res/logo/logo-192x192.png"
|
||||
"256:$BASE_DIR/public/res/logo/logo-256x256.png"
|
||||
"36:$BASE_DIR/public/res/logo/logo-36x36.png"
|
||||
"384:$BASE_DIR/public/res/logo/logo-384x384.png"
|
||||
"48:$BASE_DIR/public/res/logo/logo-48x48.png"
|
||||
"512:$BASE_DIR/public/res/logo/logo-512x512.png"
|
||||
"72:$BASE_DIR/public/res/logo/logo-72x72.png"
|
||||
"96:$BASE_DIR/public/res/logo/logo-96x96.png"
|
||||
)
|
||||
|
||||
for entry in "${CIRCULAR_TARGETS[@]}"; do
|
||||
size=${entry%%:*}
|
||||
out=${entry#*:}
|
||||
ffmpeg_cmd "$CIRCULAR" "$out" "$size"
|
||||
done
|
||||
|
||||
echo "Replacing maskable icons (using maskless input)..."
|
||||
|
||||
declare -a MASKABLE_TARGETS=(
|
||||
"114:$BASE_DIR/public/res/logo-maskable/logo-maskable-114x114.png"
|
||||
"120:$BASE_DIR/public/res/logo-maskable/logo-maskable-120x120.png"
|
||||
"144:$BASE_DIR/public/res/logo-maskable/logo-maskable-144x144.png"
|
||||
"152:$BASE_DIR/public/res/logo-maskable/logo-maskable-152x152.png"
|
||||
"167:$BASE_DIR/public/res/logo-maskable/logo-maskable-167x167.png"
|
||||
"180:$BASE_DIR/public/res/logo-maskable/logo-maskable-180x180.png"
|
||||
"192:$BASE_DIR/public/res/logo-maskable/logo-maskable-192x192.png"
|
||||
"256:$BASE_DIR/public/res/logo-maskable/logo-maskable-256x256.png"
|
||||
"36:$BASE_DIR/public/res/logo-maskable/logo-maskable-36x36.png"
|
||||
"384:$BASE_DIR/public/res/logo-maskable/logo-maskable-384x384.png"
|
||||
"48:$BASE_DIR/public/res/logo-maskable/logo-maskable-48x48.png"
|
||||
"512:$BASE_DIR/public/res/logo-maskable/logo-maskable-512x512.png"
|
||||
"57:$BASE_DIR/public/res/logo-maskable/logo-maskable-57x57.png"
|
||||
"60:$BASE_DIR/public/res/logo-maskable/logo-maskable-60x60.png"
|
||||
"72:$BASE_DIR/public/res/logo-maskable/logo-maskable-72x72.png"
|
||||
"76:$BASE_DIR/public/res/logo-maskable/logo-maskable-76x76.png"
|
||||
"96:$BASE_DIR/public/res/logo-maskable/logo-maskable-96x96.png"
|
||||
)
|
||||
|
||||
for entry in "${MASKABLE_TARGETS[@]}"; do
|
||||
size=${entry%%:*}
|
||||
out=${entry#*:}
|
||||
ffmpeg_cmd "$MASKLESS" "$out" "$size"
|
||||
done
|
||||
|
||||
echo "Handling SVG assets in public/res/svg/..."
|
||||
|
||||
SVG_DIR="$BASE_DIR/public/res/svg"
|
||||
mkdir -p "$SVG_DIR"
|
||||
|
||||
# logo.svg from circular input (inputs are SVG so copy directly)
|
||||
echo "Copying circular SVG to $SVG_DIR/logo.svg"
|
||||
cp "$CIRCULAR" "$SVG_DIR/logo.svg"
|
||||
|
||||
# logo-maskable.svg from maskless input
|
||||
echo "Copying maskable SVG to $SVG_DIR/logo-maskable.svg"
|
||||
cp "$MASKLESS" "$SVG_DIR/logo-maskable.svg"
|
||||
|
||||
# highlight.svg
|
||||
cp "$HIGHLIGHT" "$SVG_DIR/highlight.svg"
|
||||
|
||||
# unread.svg
|
||||
cp "$UNREAD" "$SVG_DIR/unread.svg"
|
||||
|
||||
echo "All done. Please review the generated files."
|
||||
+35
-37
@@ -1,18 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Script to run tauri commands for a given runtime (wry or cef) with prepended CLI args.
|
||||
*
|
||||
* Usage:
|
||||
* script/tauri <runtime> <command> [prepended-args...]
|
||||
*
|
||||
* Examples:
|
||||
* script/tauri cef dev --verbose
|
||||
* script/tauri cef dev -- --verbose
|
||||
* Both will run: tauri dev --features cef -- --verbose --no-default-features
|
||||
*/
|
||||
//MISE description="Run Tauri CLI with platform-specific feature flags"
|
||||
//USAGE arg "<platform>" help="Target" default="wry" choices "wry" "cef" "android" "ios"
|
||||
|
||||
import { run } from '@tauri-apps/cli';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import process from 'node:process';
|
||||
@@ -27,19 +18,19 @@ const __dirname = dirname(__filename);
|
||||
const cmdlineArgs = process.argv.slice(2);
|
||||
|
||||
if (cmdlineArgs.length < 2) {
|
||||
logger.error('Usage: node scripts/tauri <runtime> <command> [prepended-args...]');
|
||||
logger.error('Usage: node scripts/tauri <platform> <command> [prepended-args...]');
|
||||
logger.error(` ${dim('platform:')} wry, cef, android, or ios`);
|
||||
logger.error(` ${dim('command:')} dev or build`);
|
||||
logger.error(` ${dim('runtime:')} wry or cef`);
|
||||
logger.error(
|
||||
` ${dim('prepended-args:')} Arguments to prepend to the cargo args (-- separator is optional)`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [runtime, cmd, ...tauriArgs] = cmdlineArgs;
|
||||
const [platform, cmd, ...tauriArgs] = cmdlineArgs;
|
||||
|
||||
if (!['wry', 'cef'].includes(runtime)) {
|
||||
logger.error(`Invalid runtime: ${runtime}. Must be 'wry' or 'cef'`);
|
||||
const MOBILE = ['android', 'ios'];
|
||||
const DESKTOP = ['wry', 'cef'];
|
||||
|
||||
if (![...DESKTOP, ...MOBILE].includes(platform)) {
|
||||
logger.error(`Invalid platform: ${platform}. Must be wry, cef, android, or ios`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!['dev', 'build'].includes(cmd)) {
|
||||
@@ -47,23 +38,30 @@ if (!['dev', 'build'].includes(cmd)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
tauriArgs.unshift('--features', `${runtime},updater`);
|
||||
// tauri's Linux bundler can't package CEF; scripts/cef-package.sh does that.
|
||||
if (runtime === 'cef' && cmd === 'build' && !tauriArgs.includes('--no-bundle')) {
|
||||
tauriArgs.unshift('--no-bundle');
|
||||
}
|
||||
if (!tauriArgs.includes('--')) {
|
||||
tauriArgs.push('--');
|
||||
}
|
||||
tauriArgs.push('--no-default-features');
|
||||
|
||||
const args = [cmd, ...tauriArgs];
|
||||
|
||||
process.chdir(join(__dirname, '..'));
|
||||
|
||||
logger.info(`${dim('Running:')} tauri ${args.join(' ')}`);
|
||||
if (MOBILE.includes(platform)) {
|
||||
logger.info(`${dim('Running:')} tauri ${[platform, cmd, ...tauriArgs].join(' ')}`);
|
||||
const child = spawn('tauri', [platform, cmd, ...tauriArgs], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
});
|
||||
child.on('exit', (code) => process.exit(code ?? 1));
|
||||
} else {
|
||||
const args = [cmd, '--features', `${platform},updater`, ...tauriArgs];
|
||||
if (!tauriArgs.includes('--')) {
|
||||
args.push('--');
|
||||
}
|
||||
args.push('--no-default-features');
|
||||
|
||||
run(args, 'tauri').catch((error) => {
|
||||
logger.error(`Failed to run tauri: ${error?.message ?? error}`);
|
||||
process.exit(1);
|
||||
});
|
||||
if (platform === 'cef' && cmd === 'build' && !tauriArgs.includes('--no-bundle')) {
|
||||
args.unshift('--no-bundle');
|
||||
}
|
||||
|
||||
logger.info(`${dim('Running:')} tauri ${args.join(' ')}`);
|
||||
|
||||
run(args, 'tauri').catch((error) => {
|
||||
logger.error(`Failed to run tauri: ${error?.message ?? error}`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user