2019-05-23 00:44:08 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as _ from 'lodash';
|
|
|
|
|
|
|
|
import {
|
|
|
|
buildOclifInstaller,
|
2019-06-02 14:23:37 +00:00
|
|
|
buildStandaloneZip,
|
2020-01-20 14:01:58 +00:00
|
|
|
catchUncommitted,
|
2024-03-11 18:37:34 +00:00
|
|
|
signFilesForNotarization,
|
2020-08-06 11:20:25 +00:00
|
|
|
testShrinkwrap,
|
2019-05-23 00:44:08 +00:00
|
|
|
} from './build-bin';
|
2019-08-23 03:02:59 +00:00
|
|
|
|
2020-02-03 17:27:06 +00:00
|
|
|
// DEBUG set to falsy for negative values else is truthy
|
|
|
|
process.env.DEBUG = ['0', 'no', 'false', '', undefined].includes(
|
|
|
|
process.env.DEBUG?.toLowerCase(),
|
|
|
|
)
|
|
|
|
? ''
|
|
|
|
: '1';
|
|
|
|
|
2019-05-23 00:44:08 +00:00
|
|
|
/**
|
|
|
|
* Trivial command-line parser. Check whether the command-line argument is one
|
|
|
|
* of the following strings, then call the appropriate functions:
|
|
|
|
* 'build:installer' (to build a native oclif installer)
|
|
|
|
* 'build:standalone' (to build a standalone pkg package)
|
|
|
|
*
|
|
|
|
* @param args Arguments to parse (default is process.argv.slice(2))
|
|
|
|
*/
|
2021-08-26 23:49:54 +00:00
|
|
|
async function parse(args?: string[]) {
|
2019-05-23 00:44:08 +00:00
|
|
|
args = args || process.argv.slice(2);
|
2021-08-26 23:49:54 +00:00
|
|
|
console.error(`[debug] automation/run.ts process.argv=[${process.argv}]`);
|
|
|
|
console.error(`[debug] automation/run.ts args=[${args}]`);
|
2019-05-23 00:44:08 +00:00
|
|
|
if (_.isEmpty(args)) {
|
2021-08-26 23:49:54 +00:00
|
|
|
throw new Error('missing command-line arguments');
|
2019-05-23 00:44:08 +00:00
|
|
|
}
|
2020-01-20 14:01:58 +00:00
|
|
|
const commands: { [cmd: string]: () => void | Promise<void> } = {
|
2019-05-23 00:44:08 +00:00
|
|
|
'build:installer': buildOclifInstaller,
|
2019-06-02 14:23:37 +00:00
|
|
|
'build:standalone': buildStandaloneZip,
|
2024-03-11 18:37:34 +00:00
|
|
|
'sign:binaries': signFilesForNotarization,
|
2020-01-20 14:01:58 +00:00
|
|
|
'catch-uncommitted': catchUncommitted,
|
2020-08-06 11:20:25 +00:00
|
|
|
'test-shrinkwrap': testShrinkwrap,
|
2019-05-23 00:44:08 +00:00
|
|
|
};
|
|
|
|
for (const arg of args) {
|
2023-10-27 14:57:07 +00:00
|
|
|
if (!Object.hasOwn(commands, arg)) {
|
2021-08-26 23:49:54 +00:00
|
|
|
throw new Error(`command unknown: ${arg}`);
|
2019-05-23 00:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const arg of args) {
|
2019-06-02 14:23:37 +00:00
|
|
|
try {
|
|
|
|
const cmdFunc = commands[arg];
|
|
|
|
await cmdFunc();
|
|
|
|
} catch (err) {
|
2021-08-26 23:49:54 +00:00
|
|
|
if (typeof err === 'object') {
|
|
|
|
err.message = `"${arg}": ${err.message}`;
|
|
|
|
}
|
|
|
|
throw err;
|
2019-05-23 00:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 23:49:54 +00:00
|
|
|
/** See jsdoc for parse() function above */
|
|
|
|
export async function run(args?: string[]) {
|
|
|
|
try {
|
|
|
|
await parse(args);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message ? `Error: ${e.message}` : e);
|
|
|
|
process.exitCode = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 14:57:07 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2019-05-23 00:44:08 +00:00
|
|
|
run();
|