Skip to content

Commit

Permalink
prevent exit when error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadhabibi14 committed Aug 2, 2023
1 parent 73e867f commit 6538112
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ const {sum} = require( 'lodash' );
const parse5 = require( 'parse5' );
const notifier = require('node-notifier');

process.on('unhandledRejection', error => {
// console.error('Error ', error)
notifier.notify({
title: 'Error occurs',
message: `${error}`
});
})

const [watch, serve, minify, debug, logVars] = ['--watch', '--serve', '--minify', '--debug', '--log-vars'].map( s =>
process.argv.includes( s )
);
Expand Down Expand Up @@ -88,7 +96,6 @@ const svelteJsPathResolver = {

function createBuilder( entryPoints ) {
console.log( 'pages:', entryPoints );
console.log('createBuilder');

// TODO ::::::
return esbuild.build( {
Expand All @@ -100,13 +107,7 @@ function createBuilder( entryPoints ) {
incremental: !!watch,
sourcemap: false,
minify,
} ).catch(() => {
console.log('error');
notifier.notify({
title: 'Error occurs',
message: 'error'
});
});
} )
}

function layoutFor( path, content = {} ) {
Expand Down Expand Up @@ -276,8 +277,6 @@ function layoutFor( path, content = {} ) {
let cache = {};

function saveFiles( files = builder, layoutChanged = false ) {
console.log('saveFiles');

const output = {};
let unchanged = 0;
// path = bla.svelte.js or bla.svelte.css
Expand Down Expand Up @@ -305,7 +304,14 @@ function layoutFor( path, content = {} ) {

// for each .html files need to be generated
Object.entries( output ).forEach( ( [path, data] ) => {
const renderedSvelte = compile( path + '.svelte' )
let renderedSvelte;
try {
const result = compile( path + '.svelte' );
renderedSvelte = result
} catch (error) {
console.error(error);
console.log('Ini error kok')
}

const content = layoutFor( path, renderedSvelte )( data );

Expand Down
1 change: 1 addition & 0 deletions index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let c = [/* c */];
let d = '/*! d */';
let a
</script>

{a}, {b}, {c}, {d}
Expand Down

0 comments on commit 6538112

Please sign in to comment.