| 13 | * applition class |
| 14 | */ |
| 15 | module.exports = class Application { |
| 16 | /** |
| 17 | * constructor |
| 18 | */ |
| 19 | constructor(options = {}) { |
| 20 | assert(options.ROOT_PATH, 'options.ROOT_PATH must be set'); |
| 21 | if (!options.APP_PATH) { |
| 22 | let appPath = path.join(options.ROOT_PATH, 'app'); |
| 23 | if (!options.transpiler && !helper.isDirectory(appPath)) { |
| 24 | appPath = path.join(options.ROOT_PATH, 'src'); |
| 25 | } |
| 26 | options.APP_PATH = appPath; |
| 27 | } |
| 28 | if (!options.RUNTIME_PATH) { |
| 29 | options.RUNTIME_PATH = path.join(options.ROOT_PATH, 'runtime'); |
| 30 | } |
| 31 | this.options = options; |
| 32 | } |
| 33 | /** |
| 34 | * notify error |
| 35 | */ |
| 36 | notifier(err) { |
| 37 | if (!this.options.notifier) return; |
| 38 | let notifier = this.options.notifier; |
| 39 | if (!helper.isArray(notifier)) { |
| 40 | notifier = [notifier]; |
| 41 | } |
| 42 | notifier[0](Object.assign({ |
| 43 | title: 'ThinkJS Transpile Error', |
| 44 | message: err.message |
| 45 | }, notifier[1])); |
| 46 | } |
| 47 | /** |
| 48 | * watcher callback |
| 49 | */ |
| 50 | _watcherCallBack(fileInfo) { |
| 51 | let transpiler = this.options.transpiler; |
| 52 | if (transpiler) { |
| 53 | if (!helper.isArray(transpiler)) { |
| 54 | transpiler = [transpiler]; |
| 55 | } |
| 56 | const ret = transpiler[0]({ |
| 57 | srcPath: fileInfo.path, |
| 58 | outPath: this.options.APP_PATH, |
| 59 | file: fileInfo.file, |
| 60 | options: transpiler[1] |
| 61 | }); |
| 62 | if (helper.isError(ret)) { |
| 63 | console.error(ret.stack); |
| 64 | this.notifier(ret); |
| 65 | return false; |
| 66 | } |
| 67 | if (think.logger) { |
| 68 | think.logger.info(`transpile file ${fileInfo.file} success`); |
| 69 | } |
| 70 | } |
| 71 | // reload all workers |
| 72 | if (this.masterInstance) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…