Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update release script to provide better zip compression #154

Merged
merged 8 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
}
},
"devDependencies": {
"@types/archiver": "^5.3.1",
"@types/bluebird": "^3.5.36",
"@types/electron-devtools-installer": "^2.2.0",
"@types/electron-json-storage": "^4.0.0",
"@types/keymirror": "^0.1.1",
Expand All @@ -71,12 +73,14 @@
"@types/ssh2": "^0.5.44",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.8.0",
"archiver": "^5.3.0",
"babel-core": "6.26.0",
"babel-loader": "7.1.3",
"babel-preset-env": "1.6.1",
"babel-preset-react": "6.24.1",
"babel-preset-stage-3": "6.24.1",
"better-npm-run": "0.1.0",
"bluebird": "^3.7.2",
"chai": "4.1.2",
"css-loader": "^4.3.0",
"electron": ">=7.2.4",
Expand Down
63 changes: 50 additions & 13 deletions release.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
/* eslint-disable */

import archiver from 'archiver';
import { map } from 'bluebird';
import fs from 'fs';
import minimist from 'minimist';
import packager, { Options } from 'electron-packager';
import packager, { Options, PlatformOption, TargetArch } from 'electron-packager';
import path from 'path';
import { spawn } from 'child_process';

interface Args extends minimist.ParsedArgs {
arch?: TargetArch;
platform?: PlatformOption;
shouldZip?: boolean;
}

async function zip(srcPath: string) {
const theZipper = archiver('zip', { zlib: { level: 9 } }); // level 9 uses max compression
const outputZipFilePath = `${srcPath}.zip`;
const output = fs.createWriteStream(outputZipFilePath);

theZipper
.directory(srcPath, false)
.pipe(output)
.on('finish', () => {
console.log(`Finished zipping ${outputZipFilePath}`);
})
.on('error', (err) => {
console.error(`Failed to zip file with source path ${srcPath} -- err: ${err}`);
});

await theZipper.finalize();
}

/* General release command: 'ts-node release.ts'
* For a specific target: 'ts-node release.ts --platform=... --arch=...'
* For a specific target: 'ts-node release.ts --platform=... --arch=... --shouldZip=...'
*/
async function pack(args: minimist.ParsedArgs) {
async function pack(args: Args) {
const packageOptions: Options = {
dir: __dirname, // source dir
name: 'dawn',
Expand All @@ -22,19 +48,30 @@ async function pack(args: minimist.ParsedArgs) {
});

// platform is either 'darwin', 'linux', or 'win32'
packageOptions.platform = args.platform ? args.platform : 'all';
packageOptions.platform = args.platform ?? 'all';
console.log('Packaging for: ', packageOptions.platform);

const appPaths: (string | boolean)[] = await packager(packageOptions);
const appPaths: Array<string | boolean> = await packager(packageOptions);

appPaths.map((appPath: string | boolean) => {
if (appPath == true) {
return;
}
console.log(`Zipping ${appPath}`);
// Should zip the packages for each platform by default
const shouldZip = args.shouldZip ?? true;

spawn('zip', ['-r', `${appPath}.zip`, `${appPath}`], { stdio: 'inherit' });
});
if (!shouldZip) {
return;
}

// If appPath is a boolean, then we assume package for platform already exists, so no need to do anything
const appPathsToZip = appPaths.filter((appPath) => typeof appPath == 'string') as string[];

map(
appPathsToZip,
async (appPath: string) => {
console.log(`Zipping ${appPath}`);

await zip(appPath);
},
{ concurrency: appPaths.length }
);
}

pack(minimist(process.argv.slice(2))).then(() => console.log('Packaging Done'));
Loading