@cocreate/cli 1.19.8 → 1.20.1
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 +14 -0
- package/package.json +3 -2
- package/src/coc.js +0 -0
- package/src/commands/fs/automated.js +2 -6
- package/src/commands/fs/bump.js +3 -6
- package/src/commands/fs/config.js +0 -1
- package/src/commands/fs/contribution.js +0 -4
- package/src/commands/fs/gitignore.js +4 -11
- package/src/commands/fs/manual.js +7 -9
- package/src/commands/fs/readme.js +0 -1
- package/src/commands/fs/remove.js +0 -2
- package/src/commands/fs/replace.js +0 -1
- package/src/commands/fs/webpack.js +2 -2
- package/src/commands/other/config.sh +4 -0
- package/src/commands/other/nginxConfigManager.js +107 -0
- package/src/commands/other/nodeCertManager.js +148 -0
- package/src/commands/other/test.js +43 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.20.1](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.20.0...v1.20.1) (2023-04-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update demo domains clean code ([aafd70d](https://github.com/CoCreate-app/CoCreate-cli/commit/aafd70d2c29d7bb0837e8e90c0c12d8025899587))
|
|
7
|
+
|
|
8
|
+
# [1.20.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.19.8...v1.20.0) (2023-04-23)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* nodeCertManager and nginxConfigManager ([4e3d714](https://github.com/CoCreate-app/CoCreate-cli/commit/4e3d7148765951e1df3cd1fc06151723cc3434f6))
|
|
14
|
+
|
|
1
15
|
## [1.19.8](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.19.7...v1.19.8) (2023-04-13)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
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/coc.js
CHANGED
|
File without changes
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let glob = require("glob");
|
|
2
2
|
let fs = require('fs');
|
|
3
|
-
const prettier = require("prettier");
|
|
4
3
|
const path = require("path")
|
|
5
4
|
|
|
6
5
|
function globUpdater(er, files) {
|
|
@@ -20,7 +19,6 @@ function globUpdater(er, files) {
|
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
function update(YmlPath) {
|
|
23
|
-
// component name
|
|
24
22
|
let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substring(9);
|
|
25
23
|
let fileContent = `name: Automated Workflow
|
|
26
24
|
'on':
|
|
@@ -108,12 +106,10 @@ jobs:
|
|
|
108
106
|
uses: CoCreate-app/CoCreate-docs@master
|
|
109
107
|
|
|
110
108
|
`;
|
|
111
|
-
let formated = prettier.format(fileContent, { semi: false, parser: "yaml" });
|
|
112
|
-
// console.log(fileContent);
|
|
113
109
|
// process.exit()
|
|
114
110
|
if (fs.existsSync(YmlPath))
|
|
115
|
-
|
|
116
|
-
fs.writeFileSync(YmlPath,
|
|
111
|
+
fs.unlinkSync(YmlPath)
|
|
112
|
+
fs.writeFileSync(YmlPath, fileContent)
|
|
117
113
|
|
|
118
114
|
}
|
|
119
115
|
|
package/src/commands/fs/bump.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
let fs = require('fs');
|
|
3
|
-
const prettier = require("prettier");
|
|
4
3
|
let list = require('../../../repositories.js');
|
|
5
4
|
const path = require("path")
|
|
6
5
|
|
|
@@ -62,16 +61,14 @@ function bumpVersion(filePath, name) {
|
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
let
|
|
66
|
-
let formated = prettier.format(str, { semi: false, parser: "json" });
|
|
64
|
+
let fileContent = JSON.stringify(object, null, 4)
|
|
67
65
|
|
|
68
66
|
filePath = filePath.replace('/package.json', '')
|
|
69
67
|
let Path = path.resolve(filePath, 'package.json')
|
|
70
|
-
if (fs.existsSync(Path))
|
|
68
|
+
if (fs.existsSync(Path))
|
|
71
69
|
fs.unlinkSync(Path)
|
|
72
|
-
}
|
|
73
70
|
|
|
74
|
-
fs.writeFileSync(Path,
|
|
71
|
+
fs.writeFileSync(Path, fileContent)
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
let fs = require('fs');
|
|
2
2
|
const prettier = require("prettier");
|
|
3
3
|
const path = require("path")
|
|
4
|
-
const { promisify } = require('util');
|
|
5
|
-
const exec = promisify(require('child_process').exec)
|
|
6
4
|
let list = require('../repositories.js');
|
|
7
5
|
|
|
8
6
|
|
|
@@ -35,13 +33,11 @@ let metaYarnLink = list.map(meta => {
|
|
|
35
33
|
(async() => {
|
|
36
34
|
for (let meta of metaYarnLink) {
|
|
37
35
|
await update(meta)
|
|
38
|
-
// await updateYarnLink(metaYarnLink[0])
|
|
39
36
|
}
|
|
40
37
|
})();
|
|
41
38
|
|
|
42
39
|
|
|
43
40
|
function update(param) {
|
|
44
|
-
// component name
|
|
45
41
|
if (!param) return;
|
|
46
42
|
let { packageObj, absolutePath } = param;
|
|
47
43
|
let { name, description } = packageObj;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let glob = require("glob");
|
|
2
2
|
let fs = require('fs');
|
|
3
|
-
const prettier = require("prettier");
|
|
4
3
|
const path = require("path")
|
|
5
4
|
|
|
6
5
|
function globUpdater(er, files) {
|
|
@@ -13,22 +12,16 @@ function globUpdater(er, files) {
|
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
function update(
|
|
17
|
-
// component name
|
|
18
|
-
let name = path.basename(path.resolve(path.dirname(YmlPath), '../..')).substring(9);
|
|
15
|
+
function update(Path) {
|
|
19
16
|
let fileContent = `# ignore
|
|
20
17
|
node_modules
|
|
21
18
|
dist
|
|
22
19
|
.npmrc
|
|
23
20
|
|
|
24
21
|
`;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (fs.existsSync(YmlPath))
|
|
29
|
-
fs.unlinkSync(YmlPath)
|
|
30
|
-
fs.writeFileSync(YmlPath, formated)
|
|
31
|
-
|
|
22
|
+
if (fs.existsSync(Path))
|
|
23
|
+
fs.unlinkSync(Path)
|
|
24
|
+
fs.writeFileSync(Path, fileContent)
|
|
32
25
|
|
|
33
26
|
}
|
|
34
27
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let glob = require("glob");
|
|
2
2
|
let fs = require('fs');
|
|
3
|
-
const prettier = require("prettier");
|
|
4
3
|
const path = require("path")
|
|
5
4
|
|
|
6
5
|
function globUpdater(er, files) {
|
|
@@ -19,9 +18,9 @@ function globUpdater(er, files) {
|
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
|
|
22
|
-
function update(
|
|
21
|
+
function update(Path) {
|
|
23
22
|
// component name
|
|
24
|
-
let name = path.basename(path.resolve(path.dirname(
|
|
23
|
+
let name = path.basename(path.resolve(path.dirname(Path), '../..')).substring(9);
|
|
25
24
|
let fileContent = `name: Manual Workflow
|
|
26
25
|
on:
|
|
27
26
|
workflow_dispatch:
|
|
@@ -68,12 +67,11 @@ jobs:
|
|
|
68
67
|
invalidations: \${{ github.event.inputs.invalidations }}
|
|
69
68
|
|
|
70
69
|
`;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
fs.
|
|
76
|
-
fs.writeFileSync(YmlPath, formated)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (fs.existsSync(Path))
|
|
73
|
+
fs.unlinkSync(Path)
|
|
74
|
+
fs.writeFileSync(Path, fileContent)
|
|
77
75
|
|
|
78
76
|
}
|
|
79
77
|
|
|
@@ -31,9 +31,9 @@ function update(webpackPath) {
|
|
|
31
31
|
let entry;
|
|
32
32
|
|
|
33
33
|
if (fs.existsSync( path.resolve(dir, './src/index.js') ))
|
|
34
|
-
|
|
34
|
+
entry = "./src/index.js";
|
|
35
35
|
else
|
|
36
|
-
|
|
36
|
+
entry = './src/' + name + '.js';
|
|
37
37
|
|
|
38
38
|
// get component name in came case "cocreate" less
|
|
39
39
|
let componentName = toCamelCase(name);
|
|
@@ -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'])
|
|
105
|
+
// deleteServer(['cocreate.app'])
|
|
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
|
+
});
|