Skip to content

Commit

Permalink
fix: Parsing error resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jan 27, 2021
1 parent 9c55e8d commit 119f7f2
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 114 deletions.
44 changes: 0 additions & 44 deletions CoCreate.config.1.js

This file was deleted.

61 changes: 36 additions & 25 deletions CoCreate.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
module.exports = {
socket: {
config: {
apiKey: "c2b08663-06e3-440c-ef6f-13978b42883a",
securityKey: "f26baf68-e3a9-45fc-effe-502e47116265",
organization_Id: "5de0387b12e200ea63204d6c"
},
config: {
apiKey: "c2b08663-06e3-440c-ef6f-13978b42883a",
securityKey: "f26baf68-e3a9-45fc-effe-502e47116265",
organization_Id: "5de0387b12e200ea63204d6c",
host: "server.cocreate.app:8088"
},

sources: [{

sources: [
{
path: "./test_files/test.html",
collection: "static_html",
document_id: "5f08bf3da588c11bf8ead4b3",
name: "html",
data:{
name: "html",
description:"test descrition"
}
},
],

crud: [
{
collection: "test",
document_id: "",
domains: ["cocreate.app"],
route: "/docs/boilerplate",
document_id: "6010e012f80ce138be7eed01",
data:{
// collection: "test",
// document_id: "",
domains: ["cocreate.app"],
route: "/docs/boilerplate",
}
}
],

directory: "./test_files/",
extensions: [
"js",
"css",
"html"
],
ignores: [
"node_modules",
"vendor",
"bower_components",
"archive"
]

extract: {
directory: "./test_files/",
extensions: [
"js",
"css",
"html"
],
ignores: [
"node_modules",
"vendor",
"bower_components",
"archive"
],
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# CoCreate-docs
A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable.
Document generator. Easy configuration using data-attributes and highly styleable.


![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)
![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-docs?style=for-the-badge)
![GitHub package.json version](https://img.shields.io/github/package-json/v/CoCreate-app/CoCreate-docs?style=for-the-badge)
![GitHub](https://img.shields.io/github/license/CoCreate-app/CoCreate-docs?style=for-the-badge)
![GitHub labels](https://img.shields.io/github/labels/CoCreate-app/CoCreate-docs/help%20wanted?style=for-the-badge)

Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions src/index.backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const CoCreateExtract = require('./extract')
const fs = require('fs');
const path = require('path');
let config;

let jsConfig = path.resolve(process.cwd(), 'CoCreate.config.js');
let jsonConfig = path.resolve(process.cwd(), 'CoCreate.config.json')
if (fs.existsSync(jsConfig))
config = require(jsConfig);
else if (fs.existsSync(jsonConfig)) {
// let content = fs.readFileSync(jsonConfig, 'utf8').toString();
// console.log(jsonConfig, content);
config = require(jsonConfig)
// config = JSON.parse(content);
}
else {
console.log('config not found.')
}


const { directory, ignores, extensions, socket, sources } = config;
const { CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
/**
* Socket init
*/
CoCreateSocketInit(socket)

/**
* Extract comments
*/
let result = CoCreateExtract(directory, ignores, extensions);
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')


/**
* Store data into db
*/
// result.forEach((docs) => {
// docs.forEach((doc) => {
// if (!doc.document_id) {
// CoCreateCreateDocument(doc, socket.config);
// } else {
// CoCreateUpdateDocument(doc, socket.config);
// }
// })
// })

/**
* update document by config sources
*/



sources.forEach(({ path, collection, document_id, name, category, ...rest }) => {
if (!path) return;
// let content = fs.readFileSync(path, 'utf8');
// console.log(content)
process.exit()
if (content) {
CoCreateUpdateDocument({
collection,
document_id,
data: {
[name]: content,
category,
...rest
},
upsert: true
}, socket.config);
}
})

106 changes: 67 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,93 @@ let jsonConfig = path.resolve(process.cwd(), 'CoCreate.config.json')
if (fs.existsSync(jsConfig))
config = require(jsConfig);
else if (fs.existsSync(jsonConfig)) {
// let content = fs.readFileSync(jsonConfig, 'utf8').toString();
// console.log(jsonConfig, content);
config = require(jsonConfig)
// config = JSON.parse(content);
}
else {
process.exit()
console.log('config not found.')
}


const { directory, ignores, extensions, socket, sources } = config;
const { crud, extract, sources } = config;
const { CoCreateSocketInit, CoCreateUpdateDocument, CoCreateCreateDocument } = require("./socket_process.js")
/**
* Socket init
*/
CoCreateSocketInit(socket)
CoCreateSocketInit(config.config)

/**
* Extract comments
* Extract comments and store into db
*/
let result = CoCreateExtract(directory, ignores, extensions);
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')

if (extract) {
let result = CoCreateExtract(extract.directory, extract.ignores, extract.extensions);
fs.writeFileSync('result.json', JSON.stringify(result), 'utf8')

result.forEach((docs) => {
docs.forEach((doc) => {
if (!doc.collection) return;
if (!doc.document_id) {
CoCreateCreateDocument(doc, config.config);
} else {
CoCreateUpdateDocument(doc, config.config);
}
})
})
}

/**
* Store data into db
*/
// result.forEach((docs) => {
// docs.forEach((doc) => {
// if (!doc.document_id) {
// CoCreateCreateDocument(doc, socket.config);
// } else {
// CoCreateUpdateDocument(doc, socket.config);
// }
// })
// })

/**
* update document by config sources
* update and create document by config crud
*/

if (crud) {
crud.forEach(({collection, document_id, data}) => {
if (!document_id) {
CoCreateCreateDocument({
collection,
data
}, config.config);
} else {
CoCreateUpdateDocument({
collection,
document_id,
data,
upsert: true
}, config.config);

}
})
}

/**
* Store html files by config sources
**/
if (sources) {
sources.forEach(({path, collection, document_id, data}) => {
if (!path) return;

let content = fs.readFileSync(path, 'utf8');
const {name, ...rest} = data;

sources.forEach(({ path, collection, document_id, name, category, ...rest }) => {
if (!path) return;
// let content = fs.readFileSync(path, 'utf8');
// console.log(content)
process.exit()
if (content) {
CoCreateUpdateDocument({
collection,
document_id,
data: {
if (content && name && collection) {
let storeData = {
[name]: content,
category,
...rest
},
upsert: true
}, socket.config);
}
})
};
if (!document_id) {
CoCreateCreateDocument({
collection,
data: storeData,
}, config.config)
} else {
CoCreateUpdateDocument({
collection,
document_id,
data: storeData,
upsert: true
}, config.config)
}
}
})
}


8 changes: 4 additions & 4 deletions src/socket_process.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const CoCreateSocket = require('./CoCreate-socket')

module.exports.CoCreateSocketInit = function (socket) {
module.exports.CoCreateSocketInit = function (config) {
CoCreateSocket.create({
namespace: socket.config.organization_Id,
namespace: config.organization_Id,
room: null,
host: socket.host
host: config.host
})
CoCreateSocket.setGlobalScope(socket.config.organization_Id);
CoCreateSocket.setGlobalScope(config.organization_Id);
}

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

0 comments on commit 119f7f2

Please sign in to comment.