-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { SpawnSyncReturns } from 'child_process'; | ||
|
||
export function assertSpawnSyncResult( | ||
result: SpawnSyncReturns<string>, | ||
name: string | ||
) { | ||
if (result.status === null) { | ||
if (result.signal !== null) { | ||
throw new Error(`${name} terminated due to signal ${result.signal}`); | ||
} | ||
|
||
// not supposed to be possible to get here, but just in case | ||
throw new Error(`${name} terminated with no status or signal`); | ||
} | ||
|
||
if (result.status !== 0) { | ||
throw new Error(`${name} failed with exit code ${result.status}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { existsSync } from 'fs'; | ||
import { assertSpawnSyncResult } from './helpers'; | ||
import type { InstalledAppInfo, Package } from './types'; | ||
import { spawnSync } from 'child_process'; | ||
|
||
function exec(command: string, args: string[]) { | ||
console.log(command, ...args); | ||
|
||
assertSpawnSyncResult( | ||
spawnSync(command, args, { | ||
encoding: 'utf8', | ||
stdio: 'inherit', | ||
}), | ||
`${command} ${args.join(' ')}` | ||
); | ||
} | ||
|
||
export async function installMacDMG( | ||
appName: string, | ||
{ filepath }: Package | ||
): Promise<InstalledAppInfo> { | ||
const fullDestinationPath = `/Applications/${appName}.app`; | ||
|
||
if (existsSync(fullDestinationPath)) { | ||
throw new Error(`${fullDestinationPath} already exists`); | ||
} | ||
|
||
exec('hdiutil', ['attach', filepath]); | ||
try { | ||
exec('cp', ['-r', `/Volumes/${appName}/${appName}.app`, '/Applications']); | ||
} finally { | ||
exec('hdiutil', ['detach', `/Volumes/${appName}`]); | ||
} | ||
|
||
return Promise.resolve({ | ||
appName, | ||
appPath: `/Applications/${appName}.app`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type Package = { | ||
filename: string; | ||
filepath: string; | ||
}; | ||
|
||
export type InstalledAppInfo = { | ||
appName: string; | ||
appPath: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters