Skip to content

Commit 447e388

Browse files
committed
@cocreate/cli/check-coc.js to install gloablly if does not exist
1 parent b215270 commit 447e388

File tree

2 files changed

+103
-101
lines changed

2 files changed

+103
-101
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"start": "npx webpack --config webpack.config.js",
2929
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
3030
"dev": "npx webpack --config webpack.config.js --watch",
31-
"docs": "node ./node_modules/@cocreate/docs/src/index.js"
31+
"docs": "node ./node_modules/@cocreate/docs/src/index.js",
32+
"postinstall": "node ./node_modules/@cocreate/cli/check-coc.js"
3233
},
3334
"repository": {
3435
"type": "git",
@@ -48,6 +49,7 @@
4849
"devDependencies": {
4950
"@babel/core": "^7.9.6",
5051
"@babel/preset-env": "^7.9.6",
52+
"@cocreate/cli": "^1.29.3",
5153
"babel-loader": "^8.1.0",
5254
"clean-webpack-plugin": "^3.0.0",
5355
"file-loader": "^6.2.0",

src/server.js

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,106 @@ let socket = new socketClient("ws");
44

55
crud.setSocket(socket);
66

7-
var api = ( ()=> {
8-
return {
9-
send_response: (wsManager, socket, obj, send_response) => {
10-
wsManager.send(socket, send_response, obj)
11-
},
12-
13-
handleError: (wsManager, socket, action, error, component) => {
14-
const response = {
15-
'object': 'error',
16-
'data':error || error.response || error.response.data || error.response.body || error.message || error,
17-
};
18-
wsManager.send(socket, component, { action, response })
19-
},
20-
21-
getOrg: async (config, component) => {
22-
23-
socket.create({
24-
namespace: config["organization_id"],
25-
room: null,
26-
host: config["host"]
27-
})
28-
29-
let org = await crud.readDocument({
30-
collection: "organizations",
31-
key: config["key"],
32-
organization_id: config["organization_id"],
33-
document: {
34-
_id: config["organization_id"]
35-
}
36-
37-
});
38-
39-
if (!org || !org.document && !org.document[0]) {
40-
console.log(component," Error GET ORG in : ",e);
41-
return false;
42-
}
43-
44-
return org.document[0];
45-
},
46-
47-
getOrgInRoutesbyHostname : async (config, hostname) => {
48-
var socket_config = {
49-
"config": {
50-
"key": config["config"]["key"],
51-
"organization_id": config["config"]["organization_id"],
52-
},
53-
"prefix": "ws",
54-
"host": "server.cocreate.app:8088"
55-
};
56-
57-
socket.create({
58-
namespace: socket_config.config.organization_id,
59-
room: null,
60-
host: socket_config.host
61-
})
62-
63-
let data2 = await crud.readDocument({
64-
collection: "organizations",
65-
filter: {
66-
query: [{
67-
name: 'domains',
68-
operator: "$in",
69-
value: [hostname]
70-
}],
71-
},
72-
key: config["config"]["key"],
73-
organization_id: config["config"]["organization_id"]
74-
});
75-
76-
var org = data2.document[0]
77-
78-
var socket_config = {
79-
"config": {
80-
"key": org["key"],
81-
"organization_id": org["_id"].toString(),
82-
},
83-
"prefix": "ws",
84-
"host": "server.cocreate.app:8088"
85-
}
86-
87-
//other connection
88-
socket.create({
89-
namespace: socket_config.config.organization_id,
90-
room: null,
91-
host: socket_config.host
92-
})
93-
94-
let myOrg = await crud.readDocument({
95-
collection: "organizations",
96-
key: org["key"],
97-
organization_id: org["_id"],
98-
document: {
99-
_id: org["_id"]
100-
}
101-
});
102-
let result = {'row':myOrg,'socket_config':socket_config};
103-
return result;
104-
}
105-
106-
}
7+
var api = (() => {
8+
return {
9+
send_response: (wsManager, socket, obj, send_response) => {
10+
wsManager.send(socket, send_response, obj)
11+
},
12+
13+
handleError: (wsManager, socket, action, error, component) => {
14+
const response = {
15+
'object': 'error',
16+
'data': error || error.response || error.response.data || error.response.body || error.message || error,
17+
};
18+
wsManager.send(socket, component, { action, response })
19+
},
20+
21+
getOrg: async (config, component) => {
22+
23+
socket.create({
24+
namespace: config["organization_id"],
25+
room: null,
26+
host: config["host"]
27+
})
28+
29+
let org = await crud.readDocument({
30+
collection: "organizations",
31+
key: config["key"],
32+
organization_id: config["organization_id"],
33+
document: {
34+
_id: config["organization_id"]
35+
}
36+
37+
});
38+
39+
if (!org || !org.document && !org.document[0]) {
40+
console.log(component, " Error GET ORG in : ", e);
41+
return false;
42+
}
43+
44+
return org.document[0];
45+
},
46+
47+
getOrgInRoutesbyHostname: async (config, hostname) => {
48+
var socket_config = {
49+
"config": {
50+
"key": config["config"]["key"],
51+
"organization_id": config["config"]["organization_id"],
52+
},
53+
"prefix": "ws",
54+
"host": "server.cocreate.app:8088"
55+
};
56+
57+
socket.create({
58+
namespace: socket_config.config.organization_id,
59+
room: null,
60+
host: socket_config.host
61+
})
62+
63+
let data2 = await crud.readDocument({
64+
collection: "organizations",
65+
filter: {
66+
query: [{
67+
name: 'hosts',
68+
operator: "$in",
69+
value: [hostname]
70+
}],
71+
},
72+
key: config["config"]["key"],
73+
organization_id: config["config"]["organization_id"]
74+
});
75+
76+
var org = data2.document[0]
77+
78+
var socket_config = {
79+
"config": {
80+
"key": org["key"],
81+
"organization_id": org["_id"].toString(),
82+
},
83+
"prefix": "ws",
84+
"host": "server.cocreate.app:8088"
85+
}
86+
87+
//other connection
88+
socket.create({
89+
namespace: socket_config.config.organization_id,
90+
room: null,
91+
host: socket_config.host
92+
})
93+
94+
let myOrg = await crud.readDocument({
95+
collection: "organizations",
96+
key: org["key"],
97+
organization_id: org["_id"],
98+
document: {
99+
_id: org["_id"]
100+
}
101+
});
102+
let result = { 'row': myOrg, 'socket_config': socket_config };
103+
return result;
104+
}
105+
106+
}
107107
})();
108108

109109
module.exports = api;

0 commit comments

Comments
 (0)