mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
show error page when babel compile error
This commit is contained in:
parent
be3fbff5ab
commit
8ffe441267
@ -90,6 +90,12 @@ export default class extends think.http.base {
|
||||
//set module config, can not set config in request
|
||||
this.http._config = think.getModuleConfig(this.http.module);
|
||||
|
||||
//babel compile error
|
||||
if(think.compileError){
|
||||
this.http.error = think.compileError;
|
||||
return think.statusAction(500, this.http);
|
||||
}
|
||||
|
||||
await this.hook('logic_before');
|
||||
await this.execLogic().catch(err => {
|
||||
//ignore prevent reject promise
|
||||
|
||||
@ -16,6 +16,11 @@ export default class extends think.base {
|
||||
* @type {Object}
|
||||
*/
|
||||
compiledMtime = {};
|
||||
/**
|
||||
* compiled error files
|
||||
* @type {Array}
|
||||
*/
|
||||
compiledErrorFiles = [];
|
||||
/**
|
||||
* init
|
||||
* @param {String} srcPath []
|
||||
@ -46,6 +51,7 @@ export default class extends think.base {
|
||||
fs.writeFileSync(`${this.outPath}/${file}`, content);
|
||||
return;
|
||||
}
|
||||
|
||||
let startTime = Date.now();
|
||||
try{
|
||||
let data = babel.transform(content, {
|
||||
@ -61,11 +67,16 @@ export default class extends think.base {
|
||||
}
|
||||
think.mkdir(path.dirname(`${this.outPath}/${file}`));
|
||||
fs.writeFileSync(`${this.outPath}/${file}`, data.code);
|
||||
return true;
|
||||
}catch(e){
|
||||
|
||||
think.log(colors => {
|
||||
return colors.red(`compile file ${file} error`);
|
||||
}, 'BABEL');
|
||||
think.log(e);
|
||||
|
||||
e.message = 'Babel Compile Error: ' + e.message;
|
||||
think.compileError = e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -75,6 +86,11 @@ export default class extends think.base {
|
||||
compile(){
|
||||
let files = think.getFiles(this.srcPath);
|
||||
let changedFiles = [];
|
||||
|
||||
if(!this.compiledErrorFiles.length){
|
||||
think.compileError = null;
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
let extname = path.extname(file);
|
||||
//if is not js file, only copy
|
||||
@ -92,10 +108,18 @@ export default class extends think.base {
|
||||
}
|
||||
}
|
||||
if(!this.compiledMtime[file] || mTime > this.compiledMtime[file]){
|
||||
this.compileFile(file);
|
||||
let ret = this.compileFile(file);
|
||||
changedFiles.push(path.normalize(`${this.outPath}/${file}`));
|
||||
this.compiledMtime[file] = mTime;
|
||||
return;
|
||||
|
||||
if(ret){
|
||||
let index = this.compiledErrorFiles.indexOf(file);
|
||||
if(index > -1){
|
||||
this.compiledErrorFiles.splice(index, 1);
|
||||
}
|
||||
}else{
|
||||
this.compiledErrorFiles.push(file);
|
||||
}
|
||||
}
|
||||
});
|
||||
//notify auto reload service to clear file cache
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user