Skip to content

Commit

Permalink
chore: atomic build script
Browse files Browse the repository at this point in the history
move errors and completion steps to each phase's own hooks
  • Loading branch information
barelyhuman committed Dec 3, 2023
1 parent d0b7607 commit 84b2331
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,40 @@ buildContext.add('cjs', {
})

buildContext.hook('esm:complete', async () => {
await writeFile(
'./dist/esm/package.json',
JSON.stringify({ type: 'module' }),
'utf8'
)

process.stdout.write('[custom-builder] ESM Built\n')
})

buildContext.hook('cjs:complete', async () => {
await writeFile(
'./dist/cjs/package.json',
JSON.stringify({ type: 'commonjs' }),
'utf8'
)

process.stdout.write('[custom-builder] CJS Built\n')
})

buildContext.hook('esm:error', async errors => {
process.stdout.write('[custom-builder] ESM Error:\n')
errors.map(x => console.error(x))
})

buildContext.hook('cjs:error', async errors => {
process.stdout.write('[custom-builder] CJS Error:\n')
console.error(errors)
errors.map(x => console.error(x))
})

buildContext.hook('error', async error => {
console.error(error)
})

buildContext.hook('complete', async () => {
process.stdout.write('[custom-builder] Built\n')

await writeFile(
'./dist/cjs/package.json',
JSON.stringify({ type: 'commonjs' }),
'utf8'
)

await writeFile(
'./dist/esm/package.json',
JSON.stringify({ type: 'module' }),
'utf8'
)

tsc.build({
basePath: process.cwd(),
compilerOptions: {
Expand All @@ -81,6 +84,8 @@ buildContext.hook('complete', async () => {
exclude: ['**/*.test.ts', '**/*.spec.ts'],
})

process.stdout.write('[custom-builder] Done\n')

if (isDev) return

process.exit(0)
Expand Down

0 comments on commit 84b2331

Please sign in to comment.