2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-16 19:31:05 +00:00
|
|
|
/* eslint-disable no-console */
|
2019-03-28 17:09:26 +00:00
|
|
|
import { join, resolve } from 'path';
|
|
|
|
import { readdir as readdirCallback } from 'fs';
|
|
|
|
|
|
|
|
import pify from 'pify';
|
|
|
|
|
2021-11-10 00:56:56 +00:00
|
|
|
import * as Errors from '../types/errors';
|
|
|
|
import { getCliOptions } from './common';
|
2019-03-28 17:09:26 +00:00
|
|
|
import { writeSignature } from './signature';
|
|
|
|
import * as packageJson from '../../package.json';
|
|
|
|
|
|
|
|
const readdir = pify(readdirCallback);
|
|
|
|
|
|
|
|
const OPTIONS = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Print this help and exit.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['private', 'p'],
|
|
|
|
type: 'string',
|
|
|
|
help: 'Path to private key file (default: ./private.key)',
|
|
|
|
default: 'private.key',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['update', 'u'],
|
|
|
|
type: 'string',
|
|
|
|
help: 'Path to the update package (default: the .exe or .zip in ./release)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['version', 'v'],
|
|
|
|
type: 'string',
|
|
|
|
help: `Version number of this package (default: ${packageJson.version})`,
|
|
|
|
default: packageJson.version,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
type OptionsType = {
|
|
|
|
private: string;
|
|
|
|
update: string;
|
|
|
|
version: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const cliOptions = getCliOptions<OptionsType>(OPTIONS);
|
|
|
|
go(cliOptions).catch(error => {
|
2021-11-10 00:56:56 +00:00
|
|
|
console.error('Something went wrong!', Errors.toLogFormat(error));
|
2019-03-28 17:09:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
async function go(options: OptionsType) {
|
|
|
|
const { private: privateKeyPath, version } = options;
|
|
|
|
|
2021-12-03 22:49:15 +00:00
|
|
|
let updatePaths: Array<string>;
|
|
|
|
if (options.update) {
|
|
|
|
updatePaths = [options.update];
|
|
|
|
} else {
|
|
|
|
updatePaths = await findUpdatePaths();
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 22:49:15 +00:00
|
|
|
await Promise.all(
|
|
|
|
updatePaths.map(async updatePath => {
|
|
|
|
console.log('Signing with...');
|
|
|
|
console.log(` version: ${version}`);
|
|
|
|
console.log(` update file: ${updatePath}`);
|
|
|
|
console.log(` private key file: ${privateKeyPath}`);
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2021-12-03 22:49:15 +00:00
|
|
|
await writeSignature(updatePath, version, privateKeyPath);
|
|
|
|
})
|
|
|
|
);
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const IS_EXE = /\.exe$/;
|
|
|
|
const IS_ZIP = /\.zip$/;
|
2021-12-03 22:49:15 +00:00
|
|
|
async function findUpdatePaths(): Promise<Array<string>> {
|
2019-03-28 17:09:26 +00:00
|
|
|
const releaseDir = resolve('release');
|
|
|
|
const files: Array<string> = await readdir(releaseDir);
|
|
|
|
|
|
|
|
const max = files.length;
|
2021-12-03 22:49:15 +00:00
|
|
|
const results = new Array<string>();
|
2019-03-28 17:09:26 +00:00
|
|
|
for (let i = 0; i < max; i += 1) {
|
|
|
|
const file = files[i];
|
|
|
|
const fullPath = join(releaseDir, file);
|
|
|
|
|
|
|
|
if (IS_EXE.test(file) || IS_ZIP.test(file)) {
|
2021-12-03 22:49:15 +00:00
|
|
|
results.push(fullPath);
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 22:49:15 +00:00
|
|
|
if (results.length === 0) {
|
|
|
|
throw new Error("No suitable file found in 'release' folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|