|
| 1 | +import { downloadArtifact } from '@electron/get'; |
| 2 | +import * as zip from 'cross-zip'; |
| 3 | +import * as fs from 'fs-extra'; |
| 4 | +import * as path from 'path'; |
| 5 | + |
| 6 | +const asarsDir = path.resolve(__dirname, 'test', 'fixtures', 'asars'); |
| 7 | +const appsDir = path.resolve(__dirname, 'test', 'fixtures', 'apps'); |
| 8 | + |
| 9 | +const templateApp = async ( |
| 10 | + name: string, |
| 11 | + arch: string, |
| 12 | + modify: (appPath: string) => Promise<void>, |
| 13 | +) => { |
| 14 | + const electronZip = await downloadArtifact({ |
| 15 | + artifactName: 'electron', |
| 16 | + version: '27.0.0', |
| 17 | + platform: 'darwin', |
| 18 | + arch, |
| 19 | + }); |
| 20 | + const appPath = path.resolve(appsDir, name); |
| 21 | + zip.unzipSync(electronZip, appsDir); |
| 22 | + await fs.rename(path.resolve(appsDir, 'Electron.app'), appPath); |
| 23 | + await fs.remove(path.resolve(appPath, 'Contents', 'Resources', 'default_app.asar')); |
| 24 | + await modify(appPath); |
| 25 | +}; |
| 26 | + |
| 27 | +export default async () => { |
| 28 | + await fs.remove(appsDir); |
| 29 | + await fs.mkdirp(appsDir); |
| 30 | + await templateApp('Asar.app', 'arm64', async (appPath) => { |
| 31 | + await fs.copy( |
| 32 | + path.resolve(asarsDir, 'app.asar'), |
| 33 | + path.resolve(appPath, 'Contents', 'Resources', 'app.asar'), |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + await templateApp('X64Asar.app', 'x64', async (appPath) => { |
| 38 | + await fs.copy( |
| 39 | + path.resolve(asarsDir, 'app.asar'), |
| 40 | + path.resolve(appPath, 'Contents', 'Resources', 'app.asar'), |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + await templateApp('NoAsar.app', 'arm64', async (appPath) => { |
| 45 | + await fs.copy( |
| 46 | + path.resolve(asarsDir, 'app'), |
| 47 | + path.resolve(appPath, 'Contents', 'Resources', 'app'), |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + await templateApp('X64NoAsar.app', 'x64', async (appPath) => { |
| 52 | + await fs.copy( |
| 53 | + path.resolve(asarsDir, 'app'), |
| 54 | + path.resolve(appPath, 'Contents', 'Resources', 'app'), |
| 55 | + ); |
| 56 | + }); |
| 57 | +}; |
0 commit comments