Skip to content

Commit

Permalink
chore(deps): upgrade to ora esm version
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Jul 12, 2024
1 parent 1137355 commit 8ed69ba
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 38 deletions.
182 changes: 181 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dependencies": {
"@badisi/latest-version": "^7.0.6",
"@colors/colors": "^1.6.0",
"ora": "5.4.1",
"ora": "^8.0.1",
"semver": "^7.6.2"
},
"engines": {
Expand Down
74 changes: 38 additions & 36 deletions projects/lib/src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
bgBlue, bgGreen, bgMagenta, bgRed, bgYellow, black, blue, cyan, gray, green, magenta, red, white, yellow
} from '@colors/colors/safe';
import { spawn as childProcessSpawn } from 'child_process';
import ora from 'ora';

interface BufferOutput {
stream: NodeJS.WriteStream;
Expand Down Expand Up @@ -89,43 +88,46 @@ export const logAction = (message: string): Rule =>
* @returns {Rule}
*/
export const spawn = (command: string, args: string[], showOutput = false): Rule =>
async (): Promise<void> => new Promise((resolve, reject) => {
const bufferedOutput: BufferOutput[] = [];
const verbose = showOutput || process.argv.includes('--verbose');
const cmdText = `${command} ${args.join(' ')}`;
async (): Promise<void> => {
const ora = (await import('ora')).default;
return new Promise((resolve, reject) => {
const bufferedOutput: BufferOutput[] = [];
const verbose = showOutput || process.argv.includes('--verbose');
const cmdText = `${command} ${args.join(' ')}`;

const spinner = ora({ text: cyan(cmdText) });
if (!verbose) {
spinner.start();
}
const spinner = ora({ text: cyan(cmdText) });
if (!verbose) {
spinner.start();
}

const childProcess = childProcessSpawn(command, args, {
stdio: (verbose) ? 'inherit' : 'pipe',
shell: true
});
childProcess.once('disconnect', resolve);
childProcess.once('error', error => reject(error));
childProcess.on('close', (code: number) => {
if (code === 0) {
if (!verbose) {
spinner.succeed(cyan(cmdText));
spinner.stop();
}
return resolve();
} else {
if (!verbose) {
spinner.fail(red(`${cmdText}\n`));
bufferedOutput.forEach(({ stream, data }) => stream.write(data));
const childProcess = childProcessSpawn(command, args, {
stdio: (verbose) ? 'inherit' : 'pipe',
shell: true
});
childProcess.once('disconnect', resolve);
childProcess.once('error', error => reject(error));
childProcess.on('close', (code: number) => {
if (code === 0) {
if (!verbose) {
spinner.succeed(cyan(cmdText));
spinner.stop();
}
return resolve();
} else {
if (!verbose) {
spinner.fail(red(`${cmdText}\n`));
bufferedOutput.forEach(({ stream, data }) => stream.write(data));
}
return reject(new UnsuccessfulWorkflowExecution());
}
return reject(new UnsuccessfulWorkflowExecution());
});
if (!verbose) {
childProcess.stdout?.on('data', (data: Buffer) =>
bufferedOutput.push({ stream: process.stdout, data: data })
);
childProcess.stderr?.on('data', (data: Buffer) =>
bufferedOutput.push({ stream: process.stderr, data: data })
);
}
});
if (!verbose) {
childProcess.stdout?.on('data', (data: Buffer) =>
bufferedOutput.push({ stream: process.stdout, data: data })
);
childProcess.stderr?.on('data', (data: Buffer) =>
bufferedOutput.push({ stream: process.stderr, data: data })
);
}
});
};

0 comments on commit 8ed69ba

Please sign in to comment.