Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

feat: add --install flag to auto-install macOS apps to /Applications

Mihai - Alexandru Chindrișb330ca79f469
diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts
index 607a2d03..ecae1567 100644
--- a/bin/builders/BaseBuilder.ts
+++ b/bin/builders/BaseBuilder.ts
@@ -300,6 +300,46 @@ export default abstract class BaseBuilder {
const binaryPath = this.getRawBinaryPath(name);
logger.success('✔ Raw binary located in', path.resolve(binaryPath));
}
+
+ // Auto-install to /Applications on macOS
+ if (IS_MAC && fileType === 'dmg' && this.options.install) {
+ await this.installDmgToApplications(distPath, name);
+ }
+ }
+
+ private async installDmgToApplications(
+ dmgPath: string,
+ appName: string,
+ ): Promise<void> {
+ const { execa } = await import('execa');
+ const volumePath = `/Volumes/${appName}`;
+ const appSource = path.join(volumePath, `${appName}.app`);
+ const appDest = `/Applications/${appName}.app`;
+
+ try {
+ logger.info(`- Installing ${appName} to /Applications...`);
+
+ await execa('hdiutil', ['attach', dmgPath]);
+
+ // Remove existing installation if present
+ if (await fsExtra.pathExists(appDest)) {
+ await fsExtra.remove(appDest);
+ }
+
+ await fsExtra.copy(appSource, appDest);
+ await execa('hdiutil', ['detach', volumePath]);
+ await fsExtra.remove(dmgPath);
+
+ logger.success(`✔ ${appName} installed to /Applications`);
+ logger.success(`✔ Installer DMG removed`);
+ } catch (error) {
+ // Attempt cleanup on failure
+ try {
+ await execa('hdiutil', ['detach', volumePath]).catch(() => {});
+ } catch {}
+ logger.error(`✕ Failed to install ${appName}: ${error}`);
+ logger.info(` The DMG is still available at: ${dmgPath}`);
+ }
}
protected getFileType(target: string): string {
diff --git a/bin/defaults.ts b/bin/defaults.ts
index d0c39120..e919f5da 100644
--- a/bin/defaults.ts
+++ b/bin/defaults.ts
@@ -50,6 +50,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
minHeight: 0,
ignoreCertificateErrors: false,
newWindow: false,
+ install: false,
};
// Just for cli development
diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.ts
index af345dc4..b07df71a 100644
--- a/bin/helpers/cli-program.ts
+++ b/bin/helpers/cli-program.ts
@@ -242,6 +242,11 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
.default(DEFAULT.newWindow)
.hideHelp(),
)
+ .option(
+ '--install',
+ 'Auto-install app to /Applications (macOS) after build and remove installer',
+ DEFAULT.install,
+ )
.version(packageJson.version, '-v, --version')
.configureHelp({
sortSubcommands: true,
diff --git a/bin/types.ts b/bin/types.ts
index 23215291..b2cd86f3 100644
--- a/bin/types.ts
+++ b/bin/types.ts
@@ -123,6 +123,9 @@ export interface PakeCliOptions {
// Allow new window for third-party login, default false
newWindow: boolean;
+
+ // Auto-install app to /Applications (macOS) after build, default false
+ install: boolean;
}
export interface PakeAppOptions extends PakeCliOptions {
diff --git a/dist/cli.js b/dist/cli.js
index 1bb9cf04..b101cb9f 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -962,6 +962,38 @@ class BaseBuilder {
const binaryPath = this.getRawBinaryPath(name);
logger.success('✔ Raw binary located in', path.resolve(binaryPath));
}
+ // Auto-install to /Applications on macOS
+ if (IS_MAC && fileType === 'dmg' && this.options.install) {
+ await this.installDmgToApplications(distPath, name);
+ }
+ }
+ async installDmgToApplications(dmgPath, appName) {
+ const { execa } = await import('execa');
+ const volumePath = `/Volumes/${appName}`;
+ const appSource = path.join(volumePath, `${appName}.app`);
+ const appDest = `/Applications/${appName}.app`;
+ try {
+ logger.info(`- Installing ${appName} to /Applications...`);
+ await execa('hdiutil', ['attach', dmgPath]);
+ // Remove existing installation if present
+ if (await fsExtra.pathExists(appDest)) {
+ await fsExtra.remove(appDest);
+ }
+ await fsExtra.copy(appSource, appDest);
+ await execa('hdiutil', ['detach', volumePath]);
+ await fsExtra.remove(dmgPath);
+ logger.success(`✔ ${appName} installed to /Applications`);
+ logger.success(`✔ Installer DMG removed`);
+ }
+ catch (error) {
+ // Attempt cleanup on failure
+ try {
+ await execa('hdiutil', ['detach', volumePath]).catch(() => { });
+ }
+ catch { }
+ logger.error(`✕ Failed to install ${appName}: ${error}`);
+ logger.info(` The DMG is still available at: ${dmgPath}`);
+ }
}
getFileType(target) {
return target;
@@ -2051,6 +2083,7 @@ const DEFAULT_PAKE_OPTIONS = {
minHeight: 0,
ignoreCertificateErrors: false,
newWindow: false,
+ install: false,
};
function validateNumberInput(value) {
@@ -2210,6 +2243,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with
.addOption(new Option('--new-window', 'Allow new window for third-party login')
.default(DEFAULT_PAKE_OPTIONS.newWindow)
.hideHelp())
+ .option('--install', 'Auto-install app to /Applications (macOS) after build and remove installer', DEFAULT_PAKE_OPTIONS.install)
.version(packageJson.version, '-v, --version')
.configureHelp({
sortSubcommands: true,
diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.ts
index bb1870bf..949955c9 100644
--- a/tests/unit/cli-options.test.ts
+++ b/tests/unit/cli-options.test.ts
@@ -21,4 +21,11 @@ describe('CLI options', () => {
expect(option).toBeDefined();
expect(option?.defaultValue).toBe('');
});
+
+ it('registers --install option', () => {
+ const option = program.options.find((item) => item.long === '--install');
+
+ expect(option).toBeDefined();
+ expect(option?.defaultValue).toBe(false);
+ });
});