Skip to content

Commit 1201389

Browse files
committed
fix: (replace json config with js)
1 parent 24be390 commit 1201389

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
const CoCreateExtract = require('./extract')
22
const fs = require('fs');
33
const path = require('path');
4-
const { directory, ignores, extensions, socket, sources} = require(path.resolve(process.cwd(), 'CoCreate.config.json'));
54

6-
const {CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
5+
let config;
6+
7+
let jsConfig = path.resolve(process.cwd(), 'CoCreate.config.js');
8+
let jsonConfig = path.resolve(process.cwd(), 'CoCreate.config.json')
9+
if (fs.exists(jsConfig))
10+
config = require(jsConfig);
11+
else
12+
config = require(jsonConfig);
13+
14+
15+
16+
const { directory, ignores, extensions, socket, sources } = config;
17+
18+
const { CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
719
/**
820
* Socket init
921
*/
@@ -22,8 +34,9 @@ fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')
2234
result.forEach((docs) => {
2335
docs.forEach((doc) => {
2436
if (!doc.document_id) {
25-
CoCreateCreateDocument(doc, socket.config);
26-
} else {
37+
CoCreateCreateDocument(doc, socket.config);
38+
}
39+
else {
2740
CoCreateUpdateDocument(doc, socket.config);
2841
}
2942
})
@@ -32,7 +45,7 @@ result.forEach((docs) => {
3245
/**
3346
* update document by config sources
3447
*/
35-
sources.forEach(({path, collection, document_id, name, category, ...rest}) => {
48+
sources.forEach(({ path, collection, document_id, name, category, ...rest }) => {
3649
let content = fs.readFileSync(path, 'utf8');
3750
if (content) {
3851
CoCreateUpdateDocument({
@@ -47,4 +60,3 @@ sources.forEach(({path, collection, document_id, name, category, ...rest}) => {
4760
}, socket.config);
4861
}
4962
})
50-

0 commit comments

Comments
 (0)