Skip to content

Commit 119f7f2

Browse files
committed
fix: Parsing error resolved
1 parent 9c55e8d commit 119f7f2

File tree

7 files changed

+182
-114
lines changed

7 files changed

+182
-114
lines changed

CoCreate.config.1.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

CoCreate.config.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
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-
},
2+
config: {
3+
apiKey: "c2b08663-06e3-440c-ef6f-13978b42883a",
4+
securityKey: "f26baf68-e3a9-45fc-effe-502e47116265",
5+
organization_Id: "5de0387b12e200ea63204d6c",
86
host: "server.cocreate.app:8088"
97
},
10-
11-
sources: [{
8+
9+
sources: [
10+
{
1211
path: "./test_files/test.html",
1312
collection: "static_html",
1413
document_id: "5f08bf3da588c11bf8ead4b3",
15-
name: "html",
14+
data:{
15+
name: "html",
16+
description:"test descrition"
17+
}
1618
},
19+
],
20+
21+
crud: [
1722
{
1823
collection: "test",
19-
document_id: "",
20-
domains: ["cocreate.app"],
21-
route: "/docs/boilerplate",
24+
document_id: "6010e012f80ce138be7eed01",
25+
data:{
26+
// collection: "test",
27+
// document_id: "",
28+
domains: ["cocreate.app"],
29+
route: "/docs/boilerplate",
30+
}
2231
}
2332
],
24-
25-
directory: "./test_files/",
26-
extensions: [
27-
"js",
28-
"css",
29-
"html"
30-
],
31-
ignores: [
32-
"node_modules",
33-
"vendor",
34-
"bower_components",
35-
"archive"
36-
]
33+
34+
extract: {
35+
directory: "./test_files/",
36+
extensions: [
37+
"js",
38+
"css",
39+
"html"
40+
],
41+
ignores: [
42+
"node_modules",
43+
"vendor",
44+
"bower_components",
45+
"archive"
46+
],
47+
}
3748
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# CoCreate-docs
2-
A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable.
2+
Document generator. Easy configuration using data-attributes and highly styleable.
3+
34

45
![GitHub file size in bytes](https://img.shields.io/github/size/CoCreate-app/CoCreate-docs/dist/CoCreate-docs.min.js?label=minified%20size&style=for-the-badge)
5-
![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-docs?style=for-the-badge)
6+
![GitHub package.json version](https://img.shields.io/github/package-json/v/CoCreate-app/CoCreate-docs?style=for-the-badge)
67
![GitHub](https://img.shields.io/github/license/CoCreate-app/CoCreate-docs?style=for-the-badge)
78
![GitHub labels](https://img.shields.io/github/labels/CoCreate-app/CoCreate-docs/help%20wanted?style=for-the-badge)
89

File renamed without changes.

src/index.backup.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+

src/index.js

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,93 @@ let jsonConfig = path.resolve(process.cwd(), 'CoCreate.config.json')
88
if (fs.existsSync(jsConfig))
99
config = require(jsConfig);
1010
else if (fs.existsSync(jsonConfig)) {
11-
// let content = fs.readFileSync(jsonConfig, 'utf8').toString();
12-
// console.log(jsonConfig, content);
1311
config = require(jsonConfig)
14-
// config = JSON.parse(content);
1512
}
1613
else {
14+
process.exit()
1715
console.log('config not found.')
1816
}
1917

20-
21-
const { directory, ignores, extensions, socket, sources } = config;
18+
const { crud, extract, sources } = config;
2219
const { CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
2320
/**
2421
* Socket init
2522
*/
26-
CoCreateSocketInit(socket)
23+
CoCreateSocketInit(config.config)
2724

2825
/**
29-
* Extract comments
26+
* Extract comments and store into db
3027
*/
31-
let result = CoCreateExtract(directory, ignores, extensions);
32-
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')
33-
28+
if (extract) {
29+
let result = CoCreateExtract(extract.directory, extract.ignores, extract.extensions);
30+
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')
31+
32+
result.forEach((docs) => {
33+
docs.forEach((doc) => {
34+
if (!doc.collection) return;
35+
if (!doc.document_id) {
36+
CoCreateCreateDocument(doc, config.config);
37+
} else {
38+
CoCreateUpdateDocument(doc, config.config);
39+
}
40+
})
41+
})
42+
}
3443

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-
// })
4744

4845
/**
49-
* update document by config sources
46+
* update and create document by config crud
5047
*/
5148

49+
if (crud) {
50+
crud.forEach(({collection, document_id, data}) => {
51+
if (!document_id) {
52+
CoCreateCreateDocument({
53+
collection,
54+
data
55+
}, config.config);
56+
} else {
57+
CoCreateUpdateDocument({
58+
collection,
59+
document_id,
60+
data,
61+
upsert: true
62+
}, config.config);
63+
64+
}
65+
})
66+
}
5267

68+
/**
69+
* Store html files by config sources
70+
**/
71+
if (sources) {
72+
sources.forEach(({path, collection, document_id, data}) => {
73+
if (!path) return;
74+
75+
let content = fs.readFileSync(path, 'utf8');
76+
const {name, ...rest} = data;
5377

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: {
78+
if (content && name && collection) {
79+
let storeData = {
6480
[name]: content,
65-
category,
6681
...rest
67-
},
68-
upsert: true
69-
}, socket.config);
70-
}
71-
})
82+
};
83+
if (!document_id) {
84+
CoCreateCreateDocument({
85+
collection,
86+
data: storeData,
87+
}, config.config)
88+
} else {
89+
CoCreateUpdateDocument({
90+
collection,
91+
document_id,
92+
data: storeData,
93+
upsert: true
94+
}, config.config)
95+
}
96+
}
97+
})
98+
}
99+
72100

src/socket_process.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const CoCreateSocket = require('./CoCreate-socket')
22

3-
module.exports.CoCreateSocketInit = function (socket) {
3+
module.exports.CoCreateSocketInit = function (config) {
44
CoCreateSocket.create({
5-
namespace: socket.config.organization_Id,
5+
namespace: config.organization_Id,
66
room: null,
7-
host: socket.host
7+
host: config.host
88
})
9-
CoCreateSocket.setGlobalScope(socket.config.organization_Id);
9+
CoCreateSocket.setGlobalScope(config.organization_Id);
1010
}
1111

1212
module.exports.CoCreateUpdateDocument = function (info, config) {

0 commit comments

Comments
 (0)