| 176 | } |
| 177 | |
| 178 | loaddata() { |
| 179 | if (this.isNode()) { |
| 180 | this.fs = this.fs ? this.fs : require('fs') |
| 181 | this.path = this.path ? this.path : require('path') |
| 182 | const curDirDataFilePath = this.path.resolve(this.dataFile) |
| 183 | const rootDirDataFilePath = this.path.resolve( |
| 184 | process.cwd(), |
| 185 | this.dataFile |
| 186 | ) |
| 187 | const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) |
| 188 | const isRootDirDataFile = |
| 189 | !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) |
| 190 | if (isCurDirDataFile || isRootDirDataFile) { |
| 191 | const datPath = isCurDirDataFile |
| 192 | ? curDirDataFilePath |
| 193 | : rootDirDataFilePath |
| 194 | try { |
| 195 | return JSON.parse(this.fs.readFileSync(datPath)) |
| 196 | } catch (e) { |
| 197 | return {} |
| 198 | } |
| 199 | } else return {} |
| 200 | } else return {} |
| 201 | } |
| 202 | |
| 203 | writedata() { |
| 204 | if (this.isNode()) { |