Skip to content

Commit

Permalink
fix script debug
Browse files Browse the repository at this point in the history
  • Loading branch information
BearToCode committed Aug 5, 2023
1 parent 5036ad3 commit b21c1c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
5 changes: 1 addition & 4 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ spinner.color = 'red';

for (const [index, pkg] of packages.entries()) {
spinner.text = `Building ${pkg} [${index + 1}/${packages.length}]`;
let stdout, stderr;
try {
({ stdout, stderr } = await execAsync(`cd packages/${pkg} && npm run build`));
await execAsync(`npm run build`, `./packages/${pkg}`);
} catch (e) {
spinner.fail(`Failed to build ${pkg}: \n ${e}`);
console.log(`\nstdout:\n\n${stdout}`);
console.error(`\nstderr:\n\n${stderr}`);
process.exit(1);
}
}
Expand Down
30 changes: 25 additions & 5 deletions scripts/packages.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import util from 'util';
import * as childProcess from 'child_process';

/**
* Asynchronous version of `child_process.exec`.
*/
export const execAsync = util.promisify(childProcess.exec);
export const execAsync = (command, cwd = undefined) =>
new Promise((resolve, reject) => {
const child = childProcess.spawn(command, { cwd, shell: true });
let out = '';

child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
out += 'stdout: ' + data.toString();
});

child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
out += 'stderr: ' + data.toString();
});

child.on('error', (e) => {
console.log(out);
console.log(e);
});

child.on('close', function (code) {
if (code != 0) reject(out);
resolve();
});
});

/**
* List of all the packages.
Expand Down

0 comments on commit b21c1c3

Please sign in to comment.