Skip to content

Commit b2fc905

Browse files
committed
Update custom Node tasks to prevent error while compiling CSS, JS on watch.
1 parent 39bed93 commit b2fc905

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

node_tasks/config/watchCSS.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {deleteAsync} from 'del';
1010
import path from 'node:path';
1111
// import this app's useful class.
1212
import FS from "../Libraries/FS.mjs";
13+
import TextStyles from "../Libraries/TextStyles.mjs";
1314
// import based class.
1415
import MinCSS from "../Libraries/MinCSS.mjs";
1516

@@ -178,7 +179,11 @@ export default class WatchCSS {
178179

179180
watcher.on('all', async (event, file, stats) => {
180181
await this.#displayFileChanged(event, file, REPO_DIR);
181-
await this.#applyChanges(event, file);
182+
try {
183+
await this.#applyChanges(event, file);
184+
} catch (err) {
185+
console.error(TextStyles.txtError('Error! '), err);
186+
}
182187
console.log(' Finish task for file changed (' + event + ').');
183188
});
184189
}// run

node_tasks/config/watchJS.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {deleteAsync} from 'del';
1010
import path from 'node:path';
1111
// import this app's useful class.
1212
import FS from "../Libraries/FS.mjs";
13+
import TextStyles from "../Libraries//TextStyles.mjs";
1314
// import sub class.
1415
import JsBundler from './inc/jsBundler.mjs';
1516

@@ -128,7 +129,18 @@ export default class WatchJS {
128129

129130
watcher.on('all', async (event, file, stats) => {
130131
await this.#displayFileChanged(event, file, REPO_DIR);
131-
await this.#applyChanges(event, file);
132+
try {
133+
await this.#applyChanges(event, file);
134+
} catch (err) {
135+
let errorMessage = ' Error! ' + err.message;
136+
if (err.filename) {
137+
errorMessage += "\n" + ' File: ' + err.filename;
138+
}
139+
if (err.line) {
140+
errorMessage += "\n" + ' Line: ' + err.line;
141+
}
142+
console.error(TextStyles.txtError(errorMessage));
143+
}
132144
console.log(' Finish task for file changed (' + event + ').');
133145
});
134146
}// run

0 commit comments

Comments
 (0)