Skip to content

Commit

Permalink
actually handle build errors during dev cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo committed Nov 7, 2023
1 parent f0a8d3a commit 6f04c9d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ if (process.env.NODE_ENV === 'development') {
wait = setTimeout(() => {
wait = false;
}, 1000);

console.log('\x1b[2mRebuilding static...\x1b[0m');
const begin = process.hrtime.bigint();
execFileSync('npm', ['run', 'build'], {encoding: 'utf8'});
const duration = (Number(process.hrtime.bigint() - begin) / 1e9).toFixed(2);
console.log(`\x1b[2mRebuilt static in ${duration} s\x1b[0m`);
try {
execFileSync('npm', ['run', 'build'], {encoding: 'utf8', stdio: 'pipe'});
const duration = (Number(process.hrtime.bigint() - begin) / 1e9).toFixed(2);
console.log(`\x1b[2mRebuilt static in ${duration} s\x1b[0m`);
} catch (err: any) {
const duration = (Number(process.hrtime.bigint() - begin) / 1e9).toFixed(2);
console.error(`\x1b[31m${err.message.split('\n').slice(1, -1).join('\n')}\x1b[0m`);
console.log(`\x1b[2mFailed build after ${duration} s\x1b[0m`);
}
});
}

Expand Down

0 comments on commit 6f04c9d

Please sign in to comment.