File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @dataparty/api" ,
33 "private" : false ,
4- "version" : " 1.2.8 " ,
4+ "version" : " 1.2.9 " ,
55 "main" : " dist/dataparty.js" ,
66 "browser" : " src/index-browser.js" ,
77 "source" : " src/index.js" ,
Original file line number Diff line number Diff line change 33const fs = require ( 'fs' )
44const deepSet = require ( 'deep-set' )
55const reach = require ( '../utils/reach' )
6- const logger = require ( 'debug' ) ( 'dataparty.config.memory ' ) ;
6+ const logger = require ( 'debug' ) ( 'dataparty.config.json-file ' ) ;
77
88/**
99 * @class
1010 * @implements {Config}
1111 */
1212class JsonFileConfig {
1313
14- constructor ( defaults ) {
14+ constructor ( defaults = { } ) {
1515 this . path = reach ( defaults , 'basePath' ) + '/config.json'
1616 this . defaults = defaults || { }
1717 this . content = Object . assign ( { } , this . defaults )
1818 }
1919
2020 async load ( ) {
21- if ( ! fs . existsSync ( this . path ) ) { return }
22-
23- let rawdata = fs . readFileSync ( this . path )
21+ logger ( 'check exists' , this . path )
22+ if ( fs . existsSync ( this . path ) ) {
23+
24+ logger ( 'does exist ... reading' )
25+
26+ let rawdata = fs . readFileSync ( this . path , { encoding : 'utf8' } )
27+
28+ logger ( 'read raw data' )
29+
30+ if ( rawdata ) {
31+ logger ( 'reading content' )
32+ this . content = JSON . parse ( rawdata )
33+ }
2434
25- if ( rawdata && rawdata . length > 0 ) {
26- this . content = JSON . parse ( rawdata )
35+ }
36+ else {
37+ logger ( 'does not exist' )
38+ await this . save ( )
2739 }
2840 }
2941
3042 async start ( ) {
3143 await this . load ( )
32- return this
44+ logger ( 'started' )
3345 }
3446
3547 clear ( ) {
You can’t perform that action at this time.
0 commit comments