forked from andyburke/boxcutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (41 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const Delver = require( 'delver' );
const extend = require( 'extend' );
const fs = require( 'fs' );
let Boxcutter = {};
Boxcutter.load = function( filename ) {
const self = this;
self.package = extend( true, {}, require( filename ) );
};
Boxcutter.save = function( filename, _options, _callback ) {
const self = this;
const callback = typeof _callback === 'function' ? _callback : typeof _options === 'function' ? _options : null;
_options = typeof _options === 'object' ? _options : null;
const options = extend( true, {}, {
json: {
indent: 2
}
}, _options );
self.package = self.package || {};
const packageString = JSON.stringify( self.package, options.json.replacer, options.json.indent );
if ( callback ) {
fs.writeFile( filename, packageString, callback );
}
else {
fs.writeFileSync( filename, packageString );
}
};
Boxcutter.get = function( key ) {
const self = this;
self.package = self.package || {};
return Delver.get( self.package, key );
};
Boxcutter.set = function( key, value ) {
const self = this;
self.package = self.package || {};
return Delver.set( self.package, key, value );
};
module.exports = Object.assign( function() {}, {
prototype: Boxcutter
} );
module.exports.Boxcutter = Boxcutter;