| 662 | } |
| 663 | |
| 664 | writedata() { |
| 665 | if (this.isNode()) { |
| 666 | this.fs = this.fs ? this.fs : require('fs') |
| 667 | this.path = this.path ? this.path : require('path') |
| 668 | const curDirDataFilePath = this.path.resolve(this.dataFile) |
| 669 | const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) |
| 670 | const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) |
| 671 | const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) |
| 672 | const jsondata = JSON.stringify(this.data) |
| 673 | if (isCurDirDataFile) { |
| 674 | this.fs.writeFileSync(curDirDataFilePath, jsondata) |
| 675 | } else if (isRootDirDataFile) { |
| 676 | this.fs.writeFileSync(rootDirDataFilePath, jsondata) |
| 677 | } else { |
| 678 | this.fs.writeFileSync(curDirDataFilePath, jsondata) |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | lodash_get(source, path, defaultValue = undefined) { |
| 684 | const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.') |