| 'use strict'
|
| |
| |
| |
|
|
|
|
| const path = require('path')
|
| const os = require('os')
|
|
|
| const PLATFORM = 'darwin'
|
|
|
|
|
| function getWritableCandidates(appDirName) {
|
| const candidates = []
|
| candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Chahuadev', appDirName))
|
| candidates.push(path.join(os.tmpdir(), appDirName))
|
| return candidates
|
| }
|
|
|
|
|
|
|
| function normalizeExecName(cmd) {
|
| return String(cmd || '').trim()
|
| }
|
|
|
|
|
|
|
| function shouldUseShell(cmd) {
|
| return false
|
| }
|
|
|
|
|
| function buildShellSpawn(cmd, args) {
|
| return { file: cmd, args: args || [] }
|
| }
|
|
|
|
|
|
|
| function getPtySpawnOptions() {
|
| return {}
|
| }
|
|
|
|
|
| function resolveNodeRuntime() {
|
| return 'node'
|
| }
|
|
|
|
|
| function _quoteBash(s) {
|
| return `'${String(s || '').replace(/'/g, `'"'"'`)}'`
|
| }
|
|
|
| function rewriteLinuxBuildCommand(cwd) {
|
| const script = [
|
| 'set -euo pipefail',
|
| `cd ${_quoteBash(cwd)}`,
|
| 'npm install',
|
| 'if npm run | grep -q "build:linux"; then npm run build:linux; else npx electron-builder --linux AppImage --x64 --publish never; fi'
|
| ].join('; ')
|
| return {
|
| cmd: 'bash',
|
| args: ['-lc', script],
|
| rewriteInfo: {
|
| applied: true,
|
| kind: 'launcher-linux-build-inline-bash',
|
| targetProjectPath: cwd
|
| }
|
| }
|
| }
|
|
|
| // ── Protected OS path bases ───────────────────────────────────────────────────
|
| // Base list covers standard macOS paths.
|
| // We also scan /Volumes at runtime to protect externally mounted volumes
|
| // (Time Machine disks, network shares, disk images, external drives, etc.)
|
|
|
| function _readMacVolumes() {
|
| try {
|
| const fs = require('fs')
|
| // /Volumes contains all mounted filesystems; the boot volume is a symlink → '/'
|
| // Filter out symlinks to avoid double-protecting the root partition.
|
| return fs.readdirSync('/Volumes').reduce((acc, name) => {
|
| const full = `/Volumes/${name}`
|
| try {
|
| const stat = fs.lstatSync(full)
|
| if (!stat.isSymbolicLink()) acc.push(full)
|
| } catch { /* ignore vanished entries */ }
|
| return acc
|
| }, [])
|
| } catch {
|
| return []
|
| }
|
| }
|
|
|
| function getProtectedPathBases() {
|
| const homeDir = os.homedir()
|
| return [
|
| '/System', '/Library', '/Applications',
|
| '/private', '/usr', '/bin', '/sbin',
|
| '/var', '/etc', '/opt',
|
| path.join(homeDir, 'Library'),
|
| ..._readMacVolumes()
|
| ]
|
| }
|
|
|
| module.exports = {
|
| PLATFORM,
|
| getWritableCandidates,
|
| normalizeExecName,
|
| shouldUseShell,
|
| buildShellSpawn,
|
| getPtySpawnOptions,
|
| resolveNodeRuntime,
|
| rewriteLinuxBuildCommand,
|
| getProtectedPathBases
|
| }
|
| |