mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
* First chunk of new release script * Re-ordered build steps to combine error codes and releases * Reorganized build files; added stub publish script * First pass at publis script. Also collect and print dry-run commits/publish commands. * Deleted old react-release-manager scripts * Cleaned up release package.json * Basic README instructions * Removed unnecessary 'async' keyword from a method * Wordsmithing * Tweaked README * Renamed build -> build-commands and publish -> publish-commands to avoid conflict with .gitignore * Bump pre-release package versions differently * Prettier * Improved CircleCI API token setup instructions message * Lint fix * Typofix
69 lines
1.4 KiB
JavaScript
69 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const chalk = require('chalk');
|
|
const {dots} = require('cli-spinners');
|
|
const {exec} = require('child-process-promise');
|
|
const logUpdate = require('log-update');
|
|
|
|
const execRead = async (command, options) => {
|
|
const {stdout} = await exec(command, options);
|
|
|
|
return stdout.trim();
|
|
};
|
|
|
|
const unexecutedCommands = [];
|
|
|
|
const execUnlessDry = async (command, {cwd, dry}) => {
|
|
if (dry) {
|
|
unexecutedCommands.push(`${command} # {cwd: ${cwd}}`);
|
|
} else {
|
|
await exec(command, {cwd});
|
|
}
|
|
};
|
|
|
|
const getUnexecutedCommands = () => {
|
|
if (unexecutedCommands.length > 0) {
|
|
return chalk`
|
|
The following commands were not executed because of the {bold --dry} flag:
|
|
{gray ${unexecutedCommands.join('\n')}}
|
|
`;
|
|
} else {
|
|
return '';
|
|
}
|
|
};
|
|
|
|
const logPromise = async (promise, text, completedLabel = '') => {
|
|
const {frames, interval} = dots;
|
|
|
|
let index = 0;
|
|
|
|
const id = setInterval(() => {
|
|
index = ++index % frames.length;
|
|
logUpdate(
|
|
`${chalk.yellow(frames[index])} ${text} ${chalk.gray('- this may take a few seconds')}`
|
|
);
|
|
}, interval);
|
|
|
|
try {
|
|
const returnValue = await promise;
|
|
|
|
clearInterval(id);
|
|
|
|
logUpdate(`${chalk.green('✓')} ${text} ${chalk.gray(completedLabel)}`);
|
|
logUpdate.done();
|
|
|
|
return returnValue;
|
|
} catch (error) {
|
|
logUpdate.clear();
|
|
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
execRead,
|
|
execUnlessDry,
|
|
getUnexecutedCommands,
|
|
logPromise,
|
|
};
|