Prune frameworks folder before zipping release
This commit is contained in:
parent
4763831d3e
commit
31d2cce309
4 changed files with 51 additions and 88 deletions
|
@ -58,7 +58,7 @@
|
|||
"dev:storybook": "cross-env SIGNAL_ENV=storybook start-storybook -p 6006 -s ./",
|
||||
"dev:sass": "yarn sass --watch",
|
||||
"storybook:axe": "build-storybook && axe-storybook",
|
||||
"build": "run-s --print-label generate build:typed-scss build:webpack build:release build:zip",
|
||||
"build": "run-s --print-label generate build:typed-scss build:webpack build:release",
|
||||
"build:acknowledgments": "node scripts/generate-acknowledgments.js",
|
||||
"build:dev": "run-s --print-label generate build:typed-scss build:webpack",
|
||||
"build:typed-scss": "tsm sticker-creator",
|
||||
|
@ -67,7 +67,6 @@
|
|||
"build:esbuild": "node scripts/esbuild.js",
|
||||
"build:electron": "electron-builder --config.extraMetadata.environment=$SIGNAL_ENV",
|
||||
"build:release": "cross-env SIGNAL_ENV=production yarn build:electron -- --config.directories.output=release",
|
||||
"build:zip": "node ts/scripts/zip-macos-release.js",
|
||||
"preverify:ts": "yarn build:typed-scss",
|
||||
"verify": "run-p --print-label verify:*",
|
||||
"verify:ts": "tsc --noEmit",
|
||||
|
|
|
@ -5,8 +5,10 @@ import type { AfterPackContext } from 'electron-builder';
|
|||
import { afterPack as fuseElectron } from './fuse-electron';
|
||||
import { afterPack as mergeASARs } from './merge-macos-asars';
|
||||
import { afterPack as copyPacks } from './copy-language-packs';
|
||||
import { afterPack as pruneMacOSRelease } from './prune-macos-release';
|
||||
|
||||
export async function afterPack(context: AfterPackContext): Promise<void> {
|
||||
await pruneMacOSRelease(context);
|
||||
await mergeASARs(context);
|
||||
await fuseElectron(context);
|
||||
await copyPacks(context);
|
||||
|
|
48
ts/scripts/prune-macos-release.ts
Normal file
48
ts/scripts/prune-macos-release.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
import type { AfterPackContext } from 'electron-builder';
|
||||
|
||||
export async function afterPack({
|
||||
appOutDir,
|
||||
packager,
|
||||
electronPlatformName,
|
||||
}: AfterPackContext): Promise<void> {
|
||||
if (electronPlatformName !== 'darwin') {
|
||||
return;
|
||||
}
|
||||
|
||||
const { productFilename } = packager.appInfo;
|
||||
|
||||
const frameworkDir = path.join(
|
||||
appOutDir,
|
||||
`${productFilename}.app`,
|
||||
'Contents',
|
||||
'Frameworks',
|
||||
'Electron Framework.framework'
|
||||
);
|
||||
|
||||
const versionsDir = path.join(frameworkDir, 'Versions');
|
||||
const currentVersion = path.join(versionsDir, 'Current');
|
||||
|
||||
const subFolders = await fs.readdir(currentVersion);
|
||||
for (const folder of subFolders) {
|
||||
const sourcePath = path.join(currentVersion, folder);
|
||||
const targetPath = path.join(frameworkDir, folder);
|
||||
|
||||
console.log(
|
||||
'Replacing electron framework symlink with real folder',
|
||||
sourcePath
|
||||
);
|
||||
rimraf.sync(targetPath);
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await fs.rename(sourcePath, targetPath);
|
||||
}
|
||||
|
||||
console.log('Removing duplicate electron framework', versionsDir);
|
||||
rimraf.sync(versionsDir);
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright 2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
import { execSync } from 'child_process';
|
||||
import packageJSON from '../../package.json';
|
||||
|
||||
function zipMacOSRelease(): void {
|
||||
if (process.platform !== 'darwin') {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = fs
|
||||
.readdirSync('release')
|
||||
.filter(file => path.extname(file) === '.zip');
|
||||
if (!files.length) {
|
||||
throw new Error(
|
||||
'No zip file found. Maybe the release did not complete properly?'
|
||||
);
|
||||
}
|
||||
if (files.length !== 2) {
|
||||
throw new Error(
|
||||
'Multiple versions of zip files found, release directory was not cleared.'
|
||||
);
|
||||
}
|
||||
|
||||
for (const zipFile of files) {
|
||||
const zipPath = path.join('release', zipFile);
|
||||
|
||||
console.log('Removing current zip file', zipFile);
|
||||
rimraf.sync(zipPath);
|
||||
|
||||
const postfix = zipFile.includes('arm64') ? '-arm64' : '';
|
||||
|
||||
const appName = `${packageJSON.productName}.app`;
|
||||
const appPath = path.join('release', `mac${postfix}`, appName);
|
||||
|
||||
const tmpPath = path.join('release', `tmp${postfix}`);
|
||||
const appDir = path.dirname(appPath);
|
||||
const tmpZip = path.join(appDir, zipFile);
|
||||
console.log('Creating temporary zip file at', tmpZip);
|
||||
try {
|
||||
execSync(`cd ${appDir} && zip -ro ${zipFile} "${appName}"`);
|
||||
console.log(
|
||||
'Unzipping to remove duplicate electron references from',
|
||||
tmpZip
|
||||
);
|
||||
execSync(`unzip ${tmpZip} -d ${tmpPath}`);
|
||||
} catch (err) {
|
||||
console.log('stdout:', String(err.stdout));
|
||||
console.log('stderr:', String(err.stderr));
|
||||
throw err;
|
||||
}
|
||||
console.log('Removing temporary zip file');
|
||||
rimraf.sync(tmpZip);
|
||||
|
||||
const electronFrameworkPath = path.join(
|
||||
tmpPath,
|
||||
appName,
|
||||
'Contents',
|
||||
'Frameworks',
|
||||
'Electron Framework.framework',
|
||||
'Versions'
|
||||
);
|
||||
console.log('Removing duplicate electron framework', electronFrameworkPath);
|
||||
rimraf.sync(electronFrameworkPath);
|
||||
|
||||
try {
|
||||
console.log('Creating final zip');
|
||||
execSync(`cd ${tmpPath} && zip -ro ${zipFile} "${appName}"`);
|
||||
} catch (err) {
|
||||
console.log('stdout:', String(err.stdout));
|
||||
console.log('stderr:', String(err.stderr));
|
||||
throw err;
|
||||
}
|
||||
console.log('Moving into the final destination', zipPath);
|
||||
fs.renameSync(path.join(tmpPath, zipFile), zipPath);
|
||||
rimraf.sync(tmpPath);
|
||||
}
|
||||
|
||||
console.log('zip-macos-release is done');
|
||||
}
|
||||
|
||||
zipMacOSRelease();
|
Loading…
Add table
Reference in a new issue