| 643 | } |
| 644 | |
| 645 | loaddata() { |
| 646 | if (this.isNode()) { |
| 647 | this.fs = this.fs ? this.fs : require('fs') |
| 648 | this.path = this.path ? this.path : require('path') |
| 649 | const curDirDataFilePath = this.path.resolve(this.dataFile) |
| 650 | const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) |
| 651 | const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) |
| 652 | const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) |
| 653 | if (isCurDirDataFile || isRootDirDataFile) { |
| 654 | const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath |
| 655 | try { |
| 656 | return JSON.parse(this.fs.readFileSync(datPath)) |
| 657 | } catch (e) { |
| 658 | return {} |
| 659 | } |
| 660 | } else return {} |
| 661 | } else return {} |
| 662 | } |
| 663 | |
| 664 | writedata() { |
| 665 | if (this.isNode()) { |