@cocreate/cli 1.19.7 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.20.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.19.8...v1.20.0) (2023-04-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * nodeCertManager and nginxConfigManager ([4e3d714](https://github.com/CoCreate-app/CoCreate-cli/commit/4e3d7148765951e1df3cd1fc06151723cc3434f6))
7
+
8
+ ## [1.19.8](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.19.7...v1.19.8) (2023-04-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * replaced substr with substring ([5e2d166](https://github.com/CoCreate-app/CoCreate-cli/commit/5e2d166a4dc8ee07616fc9aff38845bed98f2a1e))
14
+
1
15
  ## [1.19.7](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.19.6...v1.19.7) (2023-04-11)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/cli",
3
- "version": "1.19.7",
3
+ "version": "1.20.0",
4
4
  "description": "Polyrepo management bash CLI tool. Run all git commands and yarn commands on multiple repositories. Also includes a few custom macros for cloning, installing, etc.",
5
5
  "keywords": [
6
6
  "cli",
@@ -37,7 +37,8 @@
37
37
  "replace": "nodejs src/commands/replace.js",
38
38
  "webpack": "nodejs src/commands/fs/webpack.js",
39
39
  "docs": "node ./node_modules/@cocreate/docs/src/index.js",
40
- "hosting": "node ./node_modules/@cocreate/hosting/src/index.js"
40
+ "hosting": "node ./node_modules/@cocreate/hosting/src/index.js",
41
+ "permissions": "chmod +rwx /home/ubuntu/.nvm/versions/node/v19.8.1/bin/coc"
41
42
  },
42
43
  "repository": {
43
44
  "type": "git",
package/src/addMeta.js CHANGED
@@ -7,7 +7,7 @@ module.exports = async function addMeta(repos, failed, directory) {
7
7
  let packageManager;
8
8
  for (let i = 0; i < repos.length; i++) {
9
9
  repos[i].name = path.basename(repos[i].path);
10
- repos[i].plainName = repos[i].name.substr(9);
10
+ repos[i].plainName = repos[i].name.substring(9);
11
11
 
12
12
  if (directory) {
13
13
  repos[i].absolutePath = path.resolve(directory, repos[i].path);
package/src/coc.js CHANGED
@@ -50,7 +50,7 @@ if (config['c'] && fs.existsSync(config['c'])) {
50
50
  } else if (fs.existsSync(packageJsonPath)) {
51
51
  let repoPath = path.resolve(process.cwd());
52
52
  let packageObj = require(packageJsonPath);
53
- let repoUrl = packageObj.repository.url.substr(12);
53
+ let repoUrl = packageObj.repository.url.substring(12);
54
54
  repos = [{
55
55
  path: `${repoPath}`,
56
56
  repo: `${repoUrl}`
@@ -21,7 +21,7 @@ function globUpdater(er, files) {
21
21
 
22
22
  function update(YmlPath) {
23
23
  // component name
24
- let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substr(9);
24
+ let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substring(9);
25
25
  let fileContent = `name: Automated Workflow
26
26
  'on':
27
27
  push:
@@ -14,15 +14,15 @@ function globUpdater(er, files) {
14
14
 
15
15
 
16
16
  function update(MdPath) {
17
- let name = path.basename(path.resolve(path.dirname(MdPath), './')).substr(9);
17
+ let name = path.basename(path.resolve(path.dirname(MdPath), './')).substring(9);
18
18
  let document_id = '';
19
19
  let replaceContent = fs.readFileSync(MdPath).toString();
20
20
 
21
21
 
22
- let content_source = replaceContent.substr(replaceContent.indexOf("sources"));
23
- let content1 = content_source.substr(content_source.indexOf("document_id"));
24
- let content2 = content1.substr(content1.indexOf(':'));
25
- document_id = content2.substr(3, content2.indexOf(',') - 4);
22
+ let content_source = replaceContent.substring(replaceContent.indexOf("sources"));
23
+ let content1 = content_source.substring(content_source.indexOf("document_id"));
24
+ let content2 = content1.substring(content1.indexOf(':'));
25
+ document_id = content2.substring(3, content2.indexOf(',') - 4);
26
26
 
27
27
 
28
28
  let fileContent = `module.exports = {
@@ -21,7 +21,7 @@ let metaYarnLink = list.map(meta => {
21
21
  let packageObj = require(packagejson);
22
22
 
23
23
  let packageName = name.startsWith('cocreate-') ?
24
- '@cocreate/' + name.substr(9) : packageObj.name;
24
+ '@cocreate/' + name.substring(9) : packageObj.name;
25
25
 
26
26
  return { ...meta, name, packageName, absolutePath, packageObj }
27
27
  }
@@ -45,7 +45,7 @@ function update(param) {
45
45
  if (!param) return;
46
46
  let { packageObj, absolutePath } = param;
47
47
  let { name, description } = packageObj;
48
- let shortName = name.substr(10);
48
+ let shortName = name.substring(10);
49
49
  let fileContent = `# CoCreate-${shortName}
50
50
  ${description} Take it for a spin in our [playground!](https://cocreate.app/docs/${shortName})
51
51
 
@@ -15,7 +15,7 @@ function globUpdater(er, files) {
15
15
 
16
16
  function update(YmlPath) {
17
17
  // component name
18
- let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substr(9);
18
+ let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substring(9);
19
19
  let fileContent = `# ignore
20
20
  node_modules
21
21
  dist
@@ -21,7 +21,7 @@ function globUpdater(er, files) {
21
21
 
22
22
  function update(YmlPath) {
23
23
  // component name
24
- let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substr(9);
24
+ let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substring(9);
25
25
  let fileContent = `name: Manual Workflow
26
26
  on:
27
27
  workflow_dispatch:
@@ -21,7 +21,7 @@ let metaYarnLink = list.map(meta => {
21
21
  let packageObj = require(packagejson);
22
22
 
23
23
  let packageName = name.startsWith('cocreate-') ?
24
- '@cocreate/' + name.substr(9) : packageObj.name;
24
+ '@cocreate/' + name.substring(9) : packageObj.name;
25
25
 
26
26
  return { ...meta, name, packageName, absolutePath, packageObj }
27
27
  }
@@ -44,7 +44,7 @@ function update(param) {
44
44
  if (!param) return;
45
45
  let { packageObj, absolutePath } = param;
46
46
  let { name, description } = packageObj;
47
- let shortName = name.substr(10);
47
+ let shortName = name.substring(10);
48
48
  let fileContent = `# CoCreate-${shortName}
49
49
  ${description} Take it for a spin in our [playground!](https://cocreate.app/docs/${shortName})
50
50
 
@@ -18,7 +18,7 @@ function update(mdPath) {
18
18
  do{
19
19
  nameDir = path.dirname(nameDir);
20
20
  }while(! path.basename(nameDir).startsWith('CoCreate-'))
21
- let name = path.basename(nameDir).substr(9);
21
+ let name = path.basename(nameDir).substring(9);
22
22
  // console.log(name);
23
23
  // process.exit();
24
24
  let replaceContent = fs.readFileSync(mdPath).toString()
@@ -38,7 +38,7 @@ function update(webpackPath) {
38
38
  // get component name in came case "cocreate" less
39
39
  let componentName = toCamelCase(name);
40
40
  if (componentName.startsWith('CoCreate'))
41
- componentName = componentName.substr(8);
41
+ componentName = componentName.substring(8);
42
42
 
43
43
  if (componentName === componentName.toUpperCase())
44
44
  componentName = componentName.toLowerCase();
@@ -175,7 +175,7 @@ function toCamelCase(str) {
175
175
  if (index !== -1) {
176
176
  let t = str.substring(0, index);
177
177
  t += String.fromCharCode(str.charCodeAt(index + 1) - 32);
178
- t += str.substr(index + 2);
178
+ t += str.substring(index + 2);
179
179
  str = t;
180
180
  }
181
181
  else break;
@@ -184,7 +184,7 @@ function toCamelCase(str) {
184
184
  }
185
185
 
186
186
  function lowerCaseFirstChar(str) {
187
- return String.fromCharCode(str.charCodeAt(0) + 32) + str.substr(1);
187
+ return String.fromCharCode(str.charCodeAt(0) + 32) + str.substring(1);
188
188
  }
189
189
 
190
190
 
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -ex
2
+ export config_PATH=/home/ubuntu/CoCreateDev/CoCreate-components/CoCreate-file-server/src/text.txt
3
+ sed -i 's/max_execution_time = 30/max_execution_time = 60/' $config_PATH
4
+ sed -i 's/memory_limit = 128M/memory_limit = 256M/' $config_PATH
@@ -0,0 +1,107 @@
1
+ const util = require('node:util');
2
+ const exec = util.promisify(require('node:child_process').exec);
3
+ let fs = require('fs');
4
+
5
+ const available = "/etc/nginx/sites-available/"
6
+ const enabled = "/etc/nginx/sites-enabled/"
7
+
8
+ async function createServer(hosts) {
9
+ const response = {}
10
+ if (!Array.isArray(hosts))
11
+ hosts = [hosts]
12
+
13
+ for (let host of hosts) {
14
+ const hostParts = host.split('.')
15
+ const domain = hostParts[0];
16
+ const tld = hostParts[1];
17
+ const server = `
18
+ server {
19
+ server_name ~^(?<sub>.+)\.${domain}\.${tld} ${host};
20
+
21
+ location / {
22
+ proxy_pass http://localhost:3000;
23
+ proxy_set_header Host $host;
24
+ proxy_set_header X-Real-IP $remote_addr;
25
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26
+ proxy_set_header X-Forwarded-Proto $scheme;
27
+ fastcgi_buffers 16 16k;
28
+ fastcgi_buffer_size 32k;
29
+ proxy_buffer_size 128k;
30
+ proxy_buffers 4 256k;
31
+ proxy_busy_buffers_size 256k;
32
+
33
+ }
34
+
35
+ location /ws/ {
36
+ proxy_pass http://localhost:3000;
37
+ proxy_set_header Host $host;
38
+ proxy_set_header X-Real-IP $remote_addr;
39
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
40
+ proxy_set_header X-Forwarded-Proto $scheme;
41
+ proxy_set_header Upgrade $http_upgrade;
42
+ proxy_set_header Connection "Upgrade";
43
+ fastcgi_buffers 16 16k;
44
+ fastcgi_buffer_size 32k;
45
+ proxy_buffer_size 128k;
46
+ proxy_buffers 4 256k;
47
+ proxy_busy_buffers_size 256k;
48
+
49
+ }
50
+
51
+ location /api/ {
52
+ proxy_pass http://localhost:3002;
53
+ proxy_set_header Host $host;
54
+ proxy_set_header X-Real-IP $remote_addr;
55
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
56
+ proxy_set_header X-Forwarded-Proto $scheme;
57
+ proxy_set_header Upgrade $http_upgrade;
58
+ proxy_set_header Connection "Upgrade";
59
+ fastcgi_buffers 16 16k;
60
+ fastcgi_buffer_size 32k;
61
+ proxy_buffer_size 128k;
62
+ proxy_buffers 4 256k;
63
+ proxy_busy_buffers_size 256k;
64
+ }
65
+
66
+ listen 443 ssl http2;
67
+ ssl_certificate /etc/letsencrypt/live/${host}/fullchain.pem;
68
+ ssl_certificate_key /etc/letsencrypt/live/${host}/privkey.pem;
69
+ include /etc/letsencrypt/options-ssl-nginx.conf;
70
+ ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
71
+
72
+ }
73
+
74
+ `;
75
+ fs.writeFileSync(`${available}${host}`, server)
76
+
77
+ if (!fs.existsSync(`${enabled}${host}`))
78
+ await exec(`sudo ln -s ${available}${host} ${enabled}`);
79
+
80
+ let test = await exec(`sudo nginx -t`);
81
+ if (test.stderr.includes('test is successful')) {
82
+ await exec(`sudo systemctl reload nginx`);
83
+ console.log('test passed reloading nginx', host)
84
+ response[host] = true
85
+ } else {
86
+ console.log('test failed', host)
87
+ response[host] = false
88
+ }
89
+ }
90
+ return response
91
+ }
92
+
93
+ async function deleteServer(hosts) {
94
+ const response = {}
95
+ if (!Array.isArray(hosts))
96
+ hosts = [hosts]
97
+ for (let host of hosts) {
98
+ fs.unlinkSync(`${available}${host}`)
99
+ response[host] = true
100
+ }
101
+ return response
102
+ }
103
+
104
+ // createServer(['cocreate.app', 'cocreate.ai'])
105
+ // deleteServer(['cocreate.com'])
106
+
107
+ module.exports = {createServer, deleteServer}
@@ -0,0 +1,148 @@
1
+ const util = require('node:util');
2
+ const exec = require('node:child_process').exec;
3
+ const dns = require('dns');
4
+ const child_process = require('child_process');
5
+ const spawn = child_process.spawn;
6
+
7
+ const localip = '3.231.17.247'
8
+ const certificates = new Map()
9
+
10
+
11
+ async function checkDns(host) {
12
+ return new Promise((resolve, reject) => {
13
+
14
+ try {
15
+ dns.resolve(host, 'A', (err, records) => {
16
+ if (records && records[0] === localip) {
17
+ resolve(true)
18
+ } else {
19
+ console.log('host A record need to point to', localip)
20
+ resolve(false)
21
+ }
22
+ if (err)
23
+ console.log(host, err);
24
+ });
25
+ } catch(err) {
26
+ console.log('certificate', err)
27
+ }
28
+ });
29
+ }
30
+
31
+ async function createCert(host) {
32
+ try {
33
+ // let hosts = await exec(`sudo openssl x509 -dates -noout -in /etc/letsencrypt/live/${host}/fullchain.pem`);
34
+ // console.log('hostst check', hosts)
35
+ let test = await checkDns(host)
36
+ console.log('checked dns from creatCert', test)
37
+ if (test) {
38
+ await exec(`sudo certbot certonly --manual -d *.${host} -d ${host} --agree-tos --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory`);
39
+ let exitCode = await spawn('sudo', ['certbot', 'certonly', '--manual', '-d', `*.${host}`, '-d', host, '--agree-tos', '--preferred-challenges', 'dns-01', '--server', 'https://acme-v02.api.letsencrypt.org/directory'], { stdio: 'inherit', cwd: process.cwd() })
40
+ if (exitCode !== 0) {
41
+ failed.push({ name: false, des: `creating directory failed` })
42
+ } else
43
+ console.log(true)
44
+
45
+ // return true
46
+ } else
47
+ return false
48
+ } catch(err) {
49
+ return false
50
+ }
51
+ }
52
+
53
+ async function deleteCert(host) {
54
+ try {
55
+ await exec(`sudo certbot delete --cert-name ${host}`);
56
+ return true
57
+ } catch(err) {
58
+ return false
59
+ }
60
+ }
61
+
62
+ async function checkCert(host) {
63
+ try {
64
+ let hosts = await exec(`host ${host}`);
65
+ console.log('hostst check', hosts)
66
+
67
+ if (certificates.has(host))
68
+ return true
69
+ else {
70
+ let certs = await exec(`sudo openssl x509 -dates -noout -in /etc/letsencrypt/live/${host}/fullchain.pem`);
71
+ let cert = certs.stdout.split('\n')
72
+ let issued = Date.parse(cert[0].replace('notBefore=', ''))
73
+ let expires = Date.parse(cert[1].replace('notAfter=', ''))
74
+ let currentDate = new Date()
75
+
76
+ if (!issued || !expires)
77
+ console.log('not defined', {issued, expires})
78
+ else if (!isNaN(expires)) {
79
+ if (currentDate < expires) {
80
+ certificates.set(host, {issued, expires})
81
+ return true
82
+ } else {
83
+ let cert = await createCert(host)
84
+ return cert
85
+ }
86
+ } else {
87
+ let cert = await createCert(host)
88
+ return cert
89
+ }
90
+ }
91
+ } catch(err) {
92
+ let cert = await createCert(host)
93
+ if (cert)
94
+ certificates.set(host, {issued, expires})
95
+ return cert
96
+ }
97
+ }
98
+
99
+ async function test(host) {
100
+ try {
101
+
102
+
103
+ await exec(`sudo certbot certonly --manual --test-cert -d *.${host} -d ${host} --agree-tos --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory`);
104
+ let exitCode = await spawn('sudo', ['certbot', 'certonly', '--manual', '--test-cert', '-d', `*.${host}`, '-d', host, '--agree-tos', '--preferred-challenges', 'dns-01', '--server', 'https://acme-v02.api.letsencrypt.org/directory'], { stdio: 'inherit', cwd: process.cwd() })
105
+ if (exitCode !== 0) {
106
+ failed.push({ name: false, des: `creating directory failed` })
107
+ } else
108
+ console.log(true)
109
+
110
+ // let child = exec('su -')
111
+ // child.stdin.write("testserver\n");
112
+
113
+ // child.stdout.on('data', (data) => {
114
+ // console.log(`stdout: "${data}"`);
115
+ // });
116
+
117
+ // child.stdin.end(); // EOF
118
+
119
+ // child.on('close', (code) => {
120
+ // console.log(`Child process exited with code ${code}.`);
121
+ // });
122
+
123
+ // exitCode.on("data", data => {
124
+ // console.log('test')
125
+ // })
126
+ // let test = exitCode
127
+ // if (exitCode !== 0) {
128
+ // exitCode.write('test', (err) => {
129
+ // if (err) throw Error(err.message)
130
+ // })
131
+ // } else {
132
+ // exitCode.write('test', (err) => {
133
+ // if (err) throw Error(err.message)
134
+ // })
135
+ // }
136
+
137
+ // return true
138
+ // return false
139
+ } catch(err) {
140
+ process.exit(1)
141
+ // return false
142
+ }
143
+ }
144
+
145
+
146
+ test('cocreate.app')
147
+
148
+ module.exports = {checkDns, checkCert, createCert, deleteCert}
@@ -0,0 +1,43 @@
1
+ const { spawn, exec } = require('child_process');
2
+ var child = spawn('npm', ['login'], {stdio: [ 'pipe', 'pipe', 'pipe' ], shell: true });
3
+ // var child = exec('npm login');
4
+
5
+ process.stdout.pipe(child.stdout);
6
+ process.stderr.pipe(child.stderr);
7
+ process.stdin.pipe(child.stdin);
8
+
9
+
10
+ child.stdout.on('data', function (data) {
11
+ // exec('\n')
12
+ // console.log('stdout: ' + data, '\n\n\n\n\n\n\n');
13
+ child.stdin.write('newwrite\n'); //my command takes a markdown string...
14
+ child.stdin.end('newend\n');
15
+ // process.stdout.pipe(child.stdout);
16
+ // process.stderr.pipe(child.stderr);
17
+ // process.stdin.pipe(child.stdin);
18
+ process.stdin.write('test\n');
19
+ process.stdin.end('test\n');
20
+
21
+ });
22
+ // console.log(child)
23
+ // child.stdout.pipe(process.stdout);
24
+ // child.stderr.pipe(process.stderr);
25
+ // process.stdin.pipe(child.stdin);
26
+
27
+ child.on('exit', () => {
28
+ console.log('exiting')
29
+ process.exit()
30
+ })
31
+
32
+ child.on('close', (code) => {
33
+ console.log(`Child process exited with code ${code}.`);
34
+ });
35
+ child.on('spawn', (code) => {
36
+ console.log(`Child process spawn with code ${code}.`);
37
+ });
38
+ child.on('message', (code) => {
39
+ console.log(`Child process message with code ${code}.`);
40
+ });
41
+ child.on('disconnect', (code) => {
42
+ console.log(`Child process disconnect with code ${code}.`);
43
+ });