mm_config 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config.json CHANGED
@@ -1,3 +1,6 @@
1
1
  {
2
+ "name": "test",
3
+ "state": 2,
4
+ "sort": 2,
2
5
  "age": 26
3
6
  }
package/index.js CHANGED
@@ -1,4 +1,8 @@
1
- require("mm_expand");
1
+ const JSON5 = require('json5')
2
+ const {
3
+ writeFileSync,
4
+ readFileSync
5
+ } = require('fs');
2
6
 
3
7
  /**
4
8
  * 重够配置,同步保存
@@ -10,16 +14,21 @@ module.exports = function(_config, _jsonFile) {
10
14
  _jsonFile = this.filename;
11
15
  }
12
16
  if (!_config) {
13
- _config = _jsonFile.loadJson();
14
- if (!_config) {
17
+ var str = readFileSync(_jsonFile, 'utf-8');
18
+ if (!str) {
15
19
  _config = {};
20
+ } else {
21
+ _config = JSON5.parse(str);
16
22
  }
17
23
  }
18
24
  return new Proxy(_config, {
25
+ get: function(obj, prop, value) {
26
+ return value;
27
+ },
19
28
  set: function(obj, prop, value) {
20
29
  obj[prop] = value;
21
30
  if (_jsonFile) {
22
- _jsonFile.saveJson(obj);
31
+ writeFileSync(_jsonFile, JSON.stringify(obj, null, 4), 'utf-8');
23
32
  }
24
33
  }
25
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_config",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "这是超级美眉配置同步器,用于更改配置同步保存为JSON文件",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,6 +23,6 @@
23
23
  },
24
24
  "homepage": "https://github.com/qiuwenwu/mm_config#readme",
25
25
  "dependencies": {
26
- "mm_expand": "^1.5.3"
26
+ "json5": "^2.2.3"
27
27
  }
28
28
  }
package/test.js CHANGED
@@ -7,12 +7,12 @@ async function test(){
7
7
  // }, "./config.json");
8
8
 
9
9
  this.filename = "./config.json";
10
- // var config = conf({
11
- // name: "demo",
12
- // state: 2
13
- // });
14
- // config.name = "test";
15
- // config.sort = 2;
10
+ var config = conf({
11
+ name: "demo",
12
+ state: 2
13
+ });
14
+ config.name = "test";
15
+ config.sort = 2;
16
16
 
17
17
  config = conf(null, this.filename);
18
18
  console.log(config);