Skip to content

Commit 5c5247e

Browse files
committed
upate
1 parent 27549ca commit 5c5247e

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# ignore app.js
1+
# ignore
2+
node_modules

CoCreate.config.1.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
socket: {
3+
config: {
4+
apiKey: "c2b08663-06e3-440c-ef6f-13978b42883a",
5+
securityKey: "f26baf68-e3a9-45fc-effe-502e47116265",
6+
organization_Id: "5de0387b12e200ea63204d6c"
7+
},
8+
host: "server.cocreate.app:8088"
9+
},
10+
11+
sources: [{
12+
path: "./test_files/test.html",
13+
collection: "static_html",
14+
document_id: "5f08bf3da588c11bf8ead4b3",
15+
name: "html",
16+
},
17+
],
18+
19+
crud: [{
20+
collection: "test",
21+
document_id: "",
22+
data:{collection: "test",
23+
document_id: "",
24+
domains: ["cocreate.app"],
25+
route: "/docs/boilerplate",
26+
}
27+
}
28+
],
29+
30+
extract: {
31+
directory: "./test_files/",
32+
extensions: [
33+
"js",
34+
"css",
35+
"html"
36+
],
37+
ignores: [
38+
"node_modules",
39+
"vendor",
40+
"bower_components",
41+
"archive"
42+
],
43+
}
44+
}

src/index.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const CoCreateExtract = require('./extract')
2+
const fs = require('fs');
3+
const path = require('path');
4+
let config;
5+
6+
let jsConfig = path.resolve(process.cwd(), 'CoCreate.config.js');
7+
let jsonConfig = path.resolve(process.cwd(), 'CoCreate.config.json')
8+
if (fs.existsSync(jsConfig))
9+
config = require(jsConfig);
10+
else if (fs.existsSync(jsonConfig)) {
11+
// let content = fs.readFileSync(jsonConfig, 'utf8').toString();
12+
// console.log(jsonConfig, content);
13+
config = require(jsonConfig)
14+
// config = JSON.parse(content);
15+
}
16+
else {
17+
console.log('config not found.')
18+
}
19+
20+
21+
const { directory, ignores, extensions, socket, sources } = config;
22+
const { CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
23+
/**
24+
* Socket init
25+
*/
26+
CoCreateSocketInit(socket)
27+
28+
/**
29+
* Extract comments
30+
*/
31+
let result = CoCreateExtract(directory, ignores, extensions);
32+
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')
33+
34+
35+
/**
36+
* Store data into db
37+
*/
38+
// result.forEach((docs) => {
39+
// docs.forEach((doc) => {
40+
// if (!doc.document_id) {
41+
// CoCreateCreateDocument(doc, socket.config);
42+
// } else {
43+
// CoCreateUpdateDocument(doc, socket.config);
44+
// }
45+
// })
46+
// })
47+
48+
/**
49+
* update document by config sources
50+
*/
51+
52+
53+
54+
sources.forEach(({ path, collection, document_id, name, category, ...rest }) => {
55+
if (!path) return;
56+
// let content = fs.readFileSync(path, 'utf8');
57+
// console.log(content)
58+
process.exit()
59+
if (content) {
60+
CoCreateUpdateDocument({
61+
collection,
62+
document_id,
63+
data: {
64+
[name]: content,
65+
category,
66+
...rest
67+
},
68+
upsert: true
69+
}, socket.config);
70+
}
71+
})
72+

0 commit comments

Comments
 (0)