mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-54325 Have web app build script return error codes on failure (#24723)
* MM-54325 Have web app build script return error codes on failure * Make web app --runner option not return an error code
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
const chalk = require('chalk');
|
||||
const concurrently = require('concurrently');
|
||||
|
||||
const {getPlatformCommands} = require('./utils.js');
|
||||
const {getExitCode, getPlatformCommands} = require('./utils.js');
|
||||
|
||||
async function buildAll() {
|
||||
console.log(chalk.inverse.bold('Building subpackages...') + '\n');
|
||||
@@ -20,9 +20,9 @@ async function buildAll() {
|
||||
);
|
||||
|
||||
await result;
|
||||
} catch (e) {
|
||||
console.error(chalk.inverse.bold.red('Failed to build subpackages'), e);
|
||||
return;
|
||||
} catch (closeEvents) {
|
||||
console.error(chalk.inverse.bold.red('Failed to build subpackages'), closeEvents);
|
||||
return getExitCode(closeEvents);
|
||||
}
|
||||
|
||||
console.log('\n' + chalk.inverse.bold('Subpackages built! Building web app...') + '\n');
|
||||
@@ -34,12 +34,15 @@ async function buildAll() {
|
||||
{command: 'npm:build --workspace=channels', name: 'webapp', prefixColor: 'cyan'},
|
||||
]);
|
||||
await result;
|
||||
} catch (e) {
|
||||
console.error(chalk.inverse.bold.red('Failed to build web app'), e);
|
||||
return;
|
||||
} catch (closeEvents) {
|
||||
console.error(chalk.inverse.bold.red('Failed to build web app'), closeEvents);
|
||||
return getExitCode(closeEvents);
|
||||
}
|
||||
|
||||
console.log('\n' + chalk.inverse.bold('Web app built! '));
|
||||
console.log('\n' + chalk.inverse.bold('Web app built!'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
buildAll();
|
||||
buildAll().then((exitCode) => {
|
||||
process.exitCode = exitCode;
|
||||
});
|
||||
|
||||
@@ -25,7 +25,16 @@ async function watchAllWithDevServer() {
|
||||
killOthers: 'failure',
|
||||
},
|
||||
);
|
||||
await result;
|
||||
|
||||
let exitCode = 0;
|
||||
try {
|
||||
await result;
|
||||
} catch (closeEvents) {
|
||||
exitCode = getExitCode(closeEvents, 0);
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
watchAllWithDevServer();
|
||||
watchAllWithDevServer().then((exitCode) => {
|
||||
process.exit(exitCode);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ const chalk = require('chalk');
|
||||
const concurrently = require('concurrently');
|
||||
|
||||
const {makeRunner} = require('./runner.js');
|
||||
const {getPlatformCommands} = require('./utils.js');
|
||||
const {getExitCode, getPlatformCommands} = require('./utils.js');
|
||||
|
||||
async function watchAll(useRunner) {
|
||||
if (!useRunner) {
|
||||
@@ -41,9 +41,18 @@ async function watchAll(useRunner) {
|
||||
}
|
||||
});
|
||||
|
||||
await result;
|
||||
let exitCode = 0;
|
||||
try {
|
||||
await result;
|
||||
} catch (closeEvents) {
|
||||
exitCode = getExitCode(closeEvents, 0);
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
const useRunner = process.argv[2] === '--runner' || process.env.MM_USE_WEBAPP_RUNNER;
|
||||
|
||||
watchAll(useRunner);
|
||||
watchAll(useRunner).then((exitCode) => {
|
||||
process.exit(exitCode);
|
||||
});
|
||||
|
||||
|
||||
@@ -42,6 +42,21 @@ function getColorForWorkspace(workspace) {
|
||||
return index === -1 ? chalk.white : workspaceColors[index % workspaceColors.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("concurrently").CloseEvent[]} closeEvents - An array of CloseEvents thrown by concurrently when waiting on a result
|
||||
* @param {number} codeOnSignal - Which error code to return when the process is interrupted
|
||||
*/
|
||||
function getExitCode(closeEvents, codeOnSignal = 1) {
|
||||
const exitCode = closeEvents.find((event) => !event.killed && event.exitCode > 0)?.exitCode;
|
||||
|
||||
if (typeof exitCode === 'string') {
|
||||
return codeOnSignal
|
||||
} else {
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getExitCode,
|
||||
getPlatformCommands,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user