cob-cli 2.50.0 → 2.51.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/bin/cob-cli.js +0 -31
- package/lib/commands/deploy.js +0 -9
- package/lib/commands/test.js +9 -27
- package/lib/commands/updateFromServer.js +13 -149
- package/lib/task_lists/common_enviromentHandler.js +5 -5
- package/lib/task_lists/common_helpers.js +13 -59
- package/lib/task_lists/common_syncFiles.js +0 -4
- package/lib/task_lists/test_customUIsContinuosReload.js +7 -36
- package/lib/task_lists/test_otherFilesContiousReload.js +16 -37
- package/lib/task_lists/updateFromServer_validate.js +3 -3
- package/lib/webpack/webpack.config.js +1 -1
- package/package.json +1 -5
- package/lib/commands/cleanup.js +0 -106
- package/lib/commands/package.js +0 -20
- package/lib/commands/tagDefs.js +0 -67
- package/lib/task_lists/common_definitions.js +0 -26
- package/lib/task_lists/common_operationState.js +0 -28
- package/lib/task_lists/package_execute.js +0 -45
- package/lib/task_lists/tagDefs_execute.js +0 -121
- package/lib/task_lists/updateFromServer_definitions.js +0 -135
- package/lib/task_lists/updateFromServer_domains.js +0 -50
- package/lib/task_lists/updateFromServer_groups.js +0 -111
- package/lib/task_lists/updateFromServer_instances.js +0 -76
- package/lib/task_lists/updateFromServer_kibana.js +0 -88
package/bin/cob-cli.js
CHANGED
|
@@ -10,10 +10,7 @@ const init = require("../lib/commands/init");
|
|
|
10
10
|
const customize = require("../lib/commands/customize");
|
|
11
11
|
const test = require("../lib/commands/test");
|
|
12
12
|
const deploy = require("../lib/commands/deploy");
|
|
13
|
-
const cleanup = require("../lib/commands/cleanup");
|
|
14
|
-
const package = require("../lib/commands/package");
|
|
15
13
|
const updateFromServer = require("../lib/commands/updateFromServer");
|
|
16
|
-
const tagDefs = require("../lib/commands/tagDefs.js");
|
|
17
14
|
const getDefs = require("../lib/commands/getDefs");
|
|
18
15
|
const generateMermaid = require("../lib/commands/generateMermaid");
|
|
19
16
|
const { upgradeRepo } = require("../lib/commands/upgradeRepo");
|
|
@@ -76,30 +73,12 @@ program
|
|
|
76
73
|
.description('Deploy customization to the server')
|
|
77
74
|
.action( deploy );
|
|
78
75
|
|
|
79
|
-
program
|
|
80
|
-
.command('cleanup')
|
|
81
|
-
.option('-e --environment <name>', 'environment to use')
|
|
82
|
-
.option('-s --servername <servername>', 'use <servername>.cultofbits.pt (i.e. name without the FQDN)')
|
|
83
|
-
.option('-l --localOnly', 'only clean local state, skip server cleanup')
|
|
84
|
-
.option('-V --verbose', 'verbose execution of tasks', increaseVerbosity, 0)
|
|
85
|
-
.description('Clean up repository state after an interrupted test or deploy')
|
|
86
|
-
.action( cleanup );
|
|
87
|
-
|
|
88
|
-
program
|
|
89
|
-
.command('package')
|
|
90
|
-
.option('-e --environment <name>', 'environment to use')
|
|
91
|
-
.option('-V --verbose', 'verbose execution of tasks', increaseVerbosity, 0)
|
|
92
|
-
.description('Package customization for out-of-band deploying')
|
|
93
|
-
.action( package );
|
|
94
|
-
|
|
95
76
|
program
|
|
96
77
|
.command('updateFromServer')
|
|
97
78
|
.description('Updates local copy with current files on server, in case of changes made out of standard process.')
|
|
98
79
|
.option('-e --environment <name>', 'environment to use')
|
|
99
80
|
.option('-s --servername <servername>', 'use <servername>.cultofbits.pt (i.e. name without the FQDN)')
|
|
100
81
|
.option('-V --verbose', 'verbose execution of tasks', increaseVerbosity, 0)
|
|
101
|
-
.option('-c --code', 'By adding this flag you indicate that you want to bring the code and not the data')
|
|
102
|
-
.option('--cookie <path>', '')
|
|
103
82
|
.action( updateFromServer );
|
|
104
83
|
|
|
105
84
|
program
|
|
@@ -112,16 +91,6 @@ program
|
|
|
112
91
|
.option('-e --environment <name>', 'environment to use')
|
|
113
92
|
.description('Updates local copy with definitions on server')
|
|
114
93
|
.action( getDefs );
|
|
115
|
-
|
|
116
|
-
program
|
|
117
|
-
.command('tagDefs')
|
|
118
|
-
.description('Allows the user to tag un-tagged Changes in Definitions configured on exported solutions.')
|
|
119
|
-
.option('-e --environment <name>', 'environment to use')
|
|
120
|
-
.option('-s --servername <servername>', 'use <servername>.cultofbits.pt (i.e. name without the FQDN)')
|
|
121
|
-
.option('-V --verbose', 'verbose execution of tasks', increaseVerbosity, 0)
|
|
122
|
-
.option('--all', 'tag all Definitions of all exported solutions. Use with care!')
|
|
123
|
-
.option('--cookie <path>', '')
|
|
124
|
-
.action( tagDefs );
|
|
125
94
|
|
|
126
95
|
program
|
|
127
96
|
.command('generateMermaid')
|
package/lib/commands/deploy.js
CHANGED
|
@@ -4,16 +4,11 @@ const { confirmExecutionOfChanges } = require("../task_lists/common_syncFiles");
|
|
|
4
4
|
const { validateDeployConditions } = require("../task_lists/deploy_validate");
|
|
5
5
|
const { executeTasks } = require("../task_lists/deploy_execute");
|
|
6
6
|
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
7
|
-
const { saveOperationState, clearOperationState, checkNoInterruptedRun } = require("../task_lists/common_operationState");
|
|
8
7
|
|
|
9
8
|
async function deploy(args) {
|
|
10
|
-
let stateSaved = false
|
|
11
9
|
try {
|
|
12
10
|
checkRepoVersion()
|
|
13
11
|
const cmdEnv = await getCurrentCommandEnviroment(args)
|
|
14
|
-
await checkNoInterruptedRun()
|
|
15
|
-
saveOperationState(cmdEnv.name, cmdEnv.servername)
|
|
16
|
-
stateSaved = true
|
|
17
12
|
if(args.resync) args.force = true;
|
|
18
13
|
|
|
19
14
|
console.log(`Checking conditions to deploy ${cmdEnv.branchStr} to ${cmdEnv.serverStr}...` );
|
|
@@ -26,14 +21,12 @@ async function deploy(args) {
|
|
|
26
21
|
changes = await confirmExecutionOfChanges(cmdEnv)
|
|
27
22
|
} catch (err) {
|
|
28
23
|
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
29
|
-
if (stateSaved) clearOperationState()
|
|
30
24
|
throw err
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
if(changes.length == 0) {
|
|
34
28
|
if(!args.force) {
|
|
35
29
|
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
36
|
-
if (stateSaved) clearOperationState()
|
|
37
30
|
throw new Error("Canceled:".yellow + " nothing todo\n")
|
|
38
31
|
}
|
|
39
32
|
console.log(" Just updating deploy information.")
|
|
@@ -41,11 +34,9 @@ async function deploy(args) {
|
|
|
41
34
|
|
|
42
35
|
await executeTasks(cmdEnv, args).run();
|
|
43
36
|
|
|
44
|
-
if (stateSaved) clearOperationState()
|
|
45
37
|
console.log("\nDone!".green, "\nEnjoy!")
|
|
46
38
|
|
|
47
39
|
} catch(err) {
|
|
48
|
-
if (stateSaved) clearOperationState()
|
|
49
40
|
console.error("\n",err.message);
|
|
50
41
|
}
|
|
51
42
|
}
|
package/lib/commands/test.js
CHANGED
|
@@ -6,30 +6,18 @@ const { otherFilesContiousReload } = require("../task_lists/test_otherFilesConti
|
|
|
6
6
|
const { getCurrentCommandEnviroment } = require("../task_lists/common_enviromentHandler");
|
|
7
7
|
const { getKeypress } = require("../task_lists/common_helpers");
|
|
8
8
|
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
9
|
-
const { saveOperationState, clearOperationState, checkNoInterruptedRun } = require("../task_lists/common_operationState");
|
|
10
9
|
|
|
11
|
-
async function test (args) {
|
|
10
|
+
async function test (args) {
|
|
12
11
|
let restoreChanges, error = "";
|
|
13
12
|
let cmdEnv
|
|
14
13
|
let spawned
|
|
15
|
-
let stateSaved = false
|
|
16
|
-
|
|
17
|
-
let rejectOnSignal;
|
|
18
|
-
const signalPromise = new Promise((_, reject) => { rejectOnSignal = reject; });
|
|
19
|
-
const handleSignal = () => rejectOnSignal(new Error('signal'));
|
|
20
|
-
process.once('SIGTERM', handleSignal);
|
|
21
|
-
process.once('SIGHUP', handleSignal);
|
|
22
|
-
|
|
23
14
|
try {
|
|
24
15
|
checkRepoVersion()
|
|
25
16
|
console.log("Start testing… ")
|
|
26
17
|
cmdEnv = await getCurrentCommandEnviroment(args)
|
|
27
|
-
await checkNoInterruptedRun()
|
|
28
|
-
saveOperationState(cmdEnv.name, cmdEnv.servername)
|
|
29
|
-
stateSaved = true
|
|
30
18
|
|
|
31
19
|
if(!args.localOnly) {
|
|
32
|
-
await validateTestingConditions(cmdEnv, args)
|
|
20
|
+
await validateTestingConditions(cmdEnv, args)
|
|
33
21
|
await cmdEnv.applyCurrentCommandEnvironmentChanges()
|
|
34
22
|
restoreChanges = await otherFilesContiousReload(cmdEnv)
|
|
35
23
|
} else {
|
|
@@ -39,22 +27,16 @@ async function test (args) {
|
|
|
39
27
|
|
|
40
28
|
let key;
|
|
41
29
|
do {
|
|
42
|
-
key = await
|
|
43
|
-
if(key == "o") opn(
|
|
44
|
-
} while( key != "q" && key != "ctrl+c" )
|
|
30
|
+
key = await getKeypress()
|
|
31
|
+
if(key == "o") opn("http://localhost:8040/recordm/index.html")
|
|
32
|
+
} while( key != "q" && key != "ctrl+c" )
|
|
45
33
|
|
|
46
|
-
} catch (err) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log("\n",error)
|
|
50
|
-
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
error = err.message
|
|
36
|
+
console.log("\n",error)
|
|
51
37
|
} finally {
|
|
52
|
-
process.off('SIGTERM', handleSignal);
|
|
53
|
-
process.off('SIGHUP', handleSignal);
|
|
54
|
-
try { process.stdin.setRawMode(false); } catch {}
|
|
55
|
-
cmdEnv && await cmdEnv.unApplyCurrentCommandEnvironmentChanges() // Repõe as configurações
|
|
56
38
|
restoreChanges && await restoreChanges()
|
|
57
|
-
|
|
39
|
+
cmdEnv && await cmdEnv.unApplyCurrentCommandEnvironmentChanges() // Repõe as configurações
|
|
58
40
|
spawned && await spawned.stop();
|
|
59
41
|
// Dá tempo aos subprocessos para morrer (acho que já não é preciso)
|
|
60
42
|
setTimeout(() => {
|
|
@@ -1,167 +1,31 @@
|
|
|
1
1
|
require('colors');
|
|
2
2
|
const { getCurrentCommandEnviroment } = require("../task_lists/common_enviromentHandler");
|
|
3
3
|
const { copyFiles } = require("../task_lists/common_syncFiles");
|
|
4
|
-
const { promptCredentials, readYamlFile } = require("../task_lists/common_helpers.js");
|
|
5
4
|
const { validateUpdateFromServerConditions } = require("../task_lists/updateFromServer_validate");
|
|
6
|
-
const { getGroupsFromServer } = require("../task_lists/updateFromServer_groups");
|
|
7
|
-
const { getDefinitionsFromServer } = require("../task_lists/updateFromServer_definitions");
|
|
8
|
-
const { getInstancesFromServer } = require("../task_lists/updateFromServer_instances");
|
|
9
|
-
const { getKibanaFromServer } = require("../task_lists/updateFromServer_kibana");
|
|
10
|
-
const { getDomainsFromServer } = require("../task_lists/updateFromServer_domains");
|
|
11
5
|
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
12
|
-
const axios = require('axios');
|
|
13
|
-
const tough = require('tough-cookie');
|
|
14
|
-
const fs = require("fs/promises");
|
|
15
|
-
const axiosCookieJarSupport = require('axios-cookiejar-support')
|
|
16
|
-
const path = require('path')
|
|
17
|
-
const FileCookieStore = require('file-cookie-store');
|
|
18
6
|
|
|
19
7
|
async function updateFromServer(args) {
|
|
20
8
|
try {
|
|
21
9
|
checkRepoVersion()
|
|
22
10
|
const cmdEnv = await getCurrentCommandEnviroment(args)
|
|
23
11
|
|
|
24
|
-
|
|
12
|
+
await validateUpdateFromServerConditions(cmdEnv).run()
|
|
25
13
|
|
|
26
|
-
|
|
14
|
+
console.log("\nOk to proceed. Getting files from server's live directories...");
|
|
15
|
+
await cmdEnv.applyCurrentCommandEnvironmentChanges()
|
|
16
|
+
let changes = await copyFiles(cmdEnv, "serverLive", "localCopy", args)
|
|
17
|
+
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let changes = await copyFiles(cmdEnv, "serverLive", "localCopy", args)
|
|
31
|
-
await cmdEnv.unApplyCurrentCommandEnvironmentChanges()
|
|
32
|
-
|
|
33
|
-
if (changes.length == 0) {
|
|
34
|
-
console.log("\nFinished.".green, "Nothing todo, no changes detected.");
|
|
35
|
-
} else {
|
|
36
|
-
console.log("\n " + changes.join("\n "));
|
|
37
|
-
console.log("\nUpdate done!".yellow, "Check", "git status".bold.blue, "and", "git diff".bold.blue, "to see the resulting differences.");
|
|
38
|
-
console.log("Notice that", "any changes since last deploy migth be lost.".underline)
|
|
39
|
-
console.log("Notice also that you will need to do a", "cob-cli deploy --force".bold.blue, "on next deploy.")
|
|
40
|
-
}
|
|
19
|
+
if(changes.length == 0) {
|
|
20
|
+
console.log("\nFinished.".green,"Nothing todo, no changes detected.");
|
|
41
21
|
} else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const cookieJar = new tough.CookieJar()
|
|
47
|
-
axios.defaults.jar = cookieJar
|
|
48
|
-
|
|
49
|
-
if( args.cookie ) {
|
|
50
|
-
const p = path.resolve(args.cookie);
|
|
51
|
-
const cookieFile = new FileCookieStore(p, {auto_sync: false, force_parse: true});
|
|
52
|
-
try{
|
|
53
|
-
let c = await new Promise((resolve, reject) => {
|
|
54
|
-
cookieFile.findCookie(`${cmdEnv.servername}.cultofbits.com`, '/', 'cobtoken', (err, result) => {
|
|
55
|
-
if(err != null) reject(err);
|
|
56
|
-
else resolve(result)
|
|
57
|
-
})
|
|
58
|
-
});
|
|
59
|
-
if(!c){
|
|
60
|
-
throw Error( `couldn't find a cookie for ${cmdEnv.servername} in ${p}`)
|
|
61
|
-
}
|
|
62
|
-
cookieJar.setCookie(c.toString(), `https://${cmdEnv.servername}.cultofbits.com`)
|
|
63
|
-
} catch(e){
|
|
64
|
-
console.error(e)
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
-
const credentials = await promptCredentials()
|
|
70
|
-
await axios.post(`https://${cmdEnv.servername}.cultofbits.com/recordm/security/auth`, credentials, {
|
|
71
|
-
headers: {
|
|
72
|
-
"Content-Type": "application/json",
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log("\n Removing existing Data")
|
|
78
|
-
try{ await fs.access("others/solutionsData") } catch { await fs.mkdir("others/solutionsData") }
|
|
79
|
-
const dataFiles = await fs.readdir("others/solutionsData");
|
|
80
|
-
for (const file of dataFiles) {
|
|
81
|
-
const filePath = path.join("others/solutionsData", file);
|
|
82
|
-
await fs.rm(filePath, {recursive: true, force: true} )
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const solutions = await readYamlFile("solutions.yml")
|
|
86
|
-
|
|
87
|
-
for (const solution of solutions) {
|
|
88
|
-
|
|
89
|
-
console.log("\nStarting updateFromServer of solution " + solution.name)
|
|
90
|
-
|
|
91
|
-
const dataPath = `others/solutionsData/${solution.name}`
|
|
92
|
-
fs.mkdir(dataPath, { recursive: true })
|
|
93
|
-
|
|
94
|
-
if (solution.permissions) {
|
|
95
|
-
await getGroupsFromServer(
|
|
96
|
-
cmdEnv.servername,
|
|
97
|
-
solution.groups,
|
|
98
|
-
dataPath + "/permissions.json",
|
|
99
|
-
solution.name,
|
|
100
|
-
args
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (solution.definitions) {
|
|
105
|
-
const definitionPath = dataPath + '/definitions/'
|
|
106
|
-
fs.mkdir(definitionPath, { recursive: true })
|
|
107
|
-
const viewsPath = dataPath + '/views/'
|
|
108
|
-
fs.mkdir(viewsPath, { recursive: true })
|
|
109
|
-
await getDefinitionsFromServer(
|
|
110
|
-
cmdEnv.servername,
|
|
111
|
-
solution.definitions,
|
|
112
|
-
definitionPath,
|
|
113
|
-
viewsPath,
|
|
114
|
-
solution.name,
|
|
115
|
-
args
|
|
116
|
-
).run()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (solution.instances) {
|
|
120
|
-
const instancesPath = dataPath + '/instances/'
|
|
121
|
-
fs.mkdir(instancesPath, { recursive: true })
|
|
122
|
-
await getInstancesFromServer(
|
|
123
|
-
cmdEnv.servername,
|
|
124
|
-
solution.instances,
|
|
125
|
-
instancesPath,
|
|
126
|
-
solution.name,
|
|
127
|
-
args
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if(solution.kibana){
|
|
132
|
-
const kibanaPath = dataPath + '/kibana/'
|
|
133
|
-
fs.mkdir(kibanaPath, { recursive: true })
|
|
134
|
-
await getKibanaFromServer(
|
|
135
|
-
cmdEnv.servername,
|
|
136
|
-
solution.kibana.spaces,
|
|
137
|
-
kibanaPath,
|
|
138
|
-
solution.name,
|
|
139
|
-
args
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if(solution.domains){
|
|
144
|
-
const domainsPath = dataPath + '/domains/'
|
|
145
|
-
fs.mkdir(domainsPath, { recursive: true })
|
|
146
|
-
await getDomainsFromServer(
|
|
147
|
-
cmdEnv.servername,
|
|
148
|
-
solution.domains.filter,
|
|
149
|
-
domainsPath,
|
|
150
|
-
solution.name,
|
|
151
|
-
args
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
await fs.writeFile('others/solutionsData/_index', solutions.map(c => c.name).join('\n'), 'utf-8')
|
|
22
|
+
console.log("\n " + changes.join("\n "));
|
|
23
|
+
console.log("\nUpdate done!".yellow,"Check","git status".bold.blue,"and","git diff".bold.blue,"to see the resulting differences.");
|
|
24
|
+
console.log("Notice that","any changes since last deploy migth be lost.".underline)
|
|
25
|
+
console.log("Notice also that you will need to do a","cob-cli deploy --force".bold.blue,"on next deploy.")
|
|
158
26
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} catch (err) {
|
|
162
|
-
console.error("\n", err.message);
|
|
27
|
+
} catch(err) {
|
|
28
|
+
console.error("\n",err.message);
|
|
163
29
|
}
|
|
164
30
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
31
|
module.exports = updateFromServer;
|
|
@@ -74,7 +74,7 @@ async function _applySpecific(environmentName) {
|
|
|
74
74
|
if(!fs.existsSync(deleteFile)) {
|
|
75
75
|
if(fs.existsSync(prodFile)) {
|
|
76
76
|
let backupFile = envSpecificFile.replace(/\.ENV__.*__/,".ENV__ORIGINAL_BACKUP__")
|
|
77
|
-
await git().raw(["update-index","--assume-unchanged", prodFile])
|
|
77
|
+
await git().raw(["update-index","--assume-unchanged", prodFile])
|
|
78
78
|
fs.renameSync(prodFile, backupFile)
|
|
79
79
|
} else {
|
|
80
80
|
fs.appendFileSync('.git/info/exclude', "\n" + prodFile)
|
|
@@ -82,7 +82,7 @@ async function _applySpecific(environmentName) {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
fs.renameSync(envSpecificFile, prodFile)
|
|
85
|
-
await git().raw(["update-index","--assume-unchanged", envSpecificFile])
|
|
85
|
+
await git().raw(["update-index","--assume-unchanged", envSpecificFile])
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -94,11 +94,11 @@ async function _undoSpecific(environmentName) {
|
|
|
94
94
|
let prodFile = changedFile.replace(/\.ENV__.*__/,"")
|
|
95
95
|
let originalEnvSpecificFile = changedFile.replace(/\.ENV__.*__/,'.ENV__' + environmentName + '__')
|
|
96
96
|
fs.renameSync(prodFile, originalEnvSpecificFile)
|
|
97
|
-
await git().raw(["update-index","--no-assume-unchanged", originalEnvSpecificFile])
|
|
98
|
-
|
|
97
|
+
await git().raw(["update-index","--no-assume-unchanged", originalEnvSpecificFile])
|
|
98
|
+
|
|
99
99
|
if( changedFile.indexOf("\.ENV__ORIGINAL_BACKUP__") > 0 ) {
|
|
100
100
|
fs.renameSync(changedFile, prodFile)
|
|
101
|
-
await git().raw(["update-index","--no-assume-unchanged", prodFile])
|
|
101
|
+
await git().raw(["update-index","--no-assume-unchanged", prodFile])
|
|
102
102
|
}
|
|
103
103
|
if( changedFile.indexOf("\.ENV__DELETE__") > 0 ) {
|
|
104
104
|
flagDeleteExclude = true
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
const inquirer = require("inquirer")
|
|
2
|
-
const readline = require('readline');
|
|
3
|
-
const yaml = require('js-yaml');
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
|
|
6
1
|
const SERVER_COB_CLI_DIRECTORY = "/opt/cob-cli/";
|
|
7
2
|
|
|
8
3
|
/* **************************************************************************************** */
|
|
@@ -46,64 +41,25 @@ function checkConnectivity(server) {
|
|
|
46
41
|
])
|
|
47
42
|
}
|
|
48
43
|
|
|
49
|
-
|
|
50
44
|
/* ************************************ */
|
|
51
|
-
let readlineSetup = false
|
|
52
45
|
function getKeypress() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
readlineSetup = true
|
|
56
|
-
}
|
|
46
|
+
const readline = require('readline');
|
|
47
|
+
|
|
57
48
|
process.stdin.setRawMode(true);
|
|
49
|
+
readline.emitKeypressEvents(process.stdin);
|
|
58
50
|
const rl = readline.createInterface({
|
|
59
51
|
input: process.stdin
|
|
60
52
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
rl.input.removeListener('keypress', listener)
|
|
70
|
-
rl.close();
|
|
71
|
-
process.stdin.setRawMode(false);
|
|
72
|
-
resolve(letter && letter.toLowerCase() || key.name);
|
|
73
|
-
}
|
|
53
|
+
return new Promise(resolve => rl.input.on("keypress", (letter,key) => {
|
|
54
|
+
if(key.name == "return") {
|
|
55
|
+
console.log("")
|
|
56
|
+
} else {
|
|
57
|
+
if(key.ctrl && key.name == 'c') letter = "ctrl+c"
|
|
58
|
+
rl.close();
|
|
59
|
+
process.stdin.setRawMode(false);
|
|
60
|
+
resolve(letter && letter.toLowerCase() || key.name);
|
|
74
61
|
}
|
|
75
|
-
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/* ************************************ */
|
|
80
|
-
async function promptCredentials() {
|
|
81
|
-
const answers = await inquirer.prompt([
|
|
82
|
-
{
|
|
83
|
-
type: 'text',
|
|
84
|
-
message: 'Enter username:',
|
|
85
|
-
name: 'username',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
type: 'password',
|
|
89
|
-
message: 'Enter password:',
|
|
90
|
-
name: 'password',
|
|
91
|
-
mask: '*',
|
|
92
|
-
},
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
return answers
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/* ************************************ */
|
|
99
|
-
async function readYamlFile(filename) {
|
|
100
|
-
try {
|
|
101
|
-
const data = await fs.readFile(filename, 'utf-8');
|
|
102
|
-
const config = yaml.load(data);
|
|
103
|
-
return config
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error('Error reading YAML file:', error.message);
|
|
106
|
-
}
|
|
62
|
+
}))
|
|
107
63
|
}
|
|
108
64
|
|
|
109
65
|
/* ************************************ */
|
|
@@ -111,7 +67,5 @@ module.exports = {
|
|
|
111
67
|
SERVER_COB_CLI_DIRECTORY : SERVER_COB_CLI_DIRECTORY,
|
|
112
68
|
checkConnectivity: checkConnectivity,
|
|
113
69
|
checkWorkingCopyCleanliness: checkWorkingCopyCleanliness,
|
|
114
|
-
getKeypress: getKeypress
|
|
115
|
-
promptCredentials: promptCredentials,
|
|
116
|
-
readYamlFile: readYamlFile
|
|
70
|
+
getKeypress: getKeypress
|
|
117
71
|
};
|
|
@@ -32,7 +32,6 @@ async function _syncFiles(executionType, cmdEnv, from, to, extraOptions = [], ar
|
|
|
32
32
|
return new Promise(async (resolve, reject) => {
|
|
33
33
|
let fromPath = resolveCobPath(cmdEnv.server, from, product);
|
|
34
34
|
let toPath = resolveCobPath(cmdEnv.server, to, product);
|
|
35
|
-
if (toPath.startsWith('.') && !fs.existsSync(toPath)) fs.mkdirSync(toPath)
|
|
36
35
|
let productExtraOptions = extraOptions.map( option => option.replace(/=.*\|/,"="))
|
|
37
36
|
productExtraOptions = productExtraOptions.filter( option => option.indexOf("|") < 0 )
|
|
38
37
|
|
|
@@ -180,9 +179,6 @@ function resolveCobPath(server, type, product) {
|
|
|
180
179
|
default:
|
|
181
180
|
return server + ':' + "/etc/" + product + "/";
|
|
182
181
|
}
|
|
183
|
-
|
|
184
|
-
case "staging":
|
|
185
|
-
return ".staging/" + product + "/";
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
exports.resolveCobPath = resolveCobPath;
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
const execa = require('execa');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const net = require('net');
|
|
4
3
|
const concurrently = require('concurrently');
|
|
5
4
|
const fs= require('fs');
|
|
6
5
|
const util = require('util');
|
|
7
6
|
const child_process = require('child_process');
|
|
8
7
|
const exec = util.promisify(child_process.exec);
|
|
9
8
|
|
|
10
|
-
function findPort(preferred = 8040) {
|
|
11
|
-
return new Promise((resolve) => {
|
|
12
|
-
const server = net.createServer();
|
|
13
|
-
server.listen(preferred, '0.0.0.0', () => {
|
|
14
|
-
server.close(() => resolve(preferred));
|
|
15
|
-
});
|
|
16
|
-
server.on('error', () => {
|
|
17
|
-
const fallback = net.createServer();
|
|
18
|
-
fallback.listen(0, '0.0.0.0', () => {
|
|
19
|
-
const port = fallback.address().port;
|
|
20
|
-
fallback.close(() => resolve(port));
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
9
|
|
|
27
10
|
async function customUIsContinuosReload(cmdEnv, dashboard) {
|
|
28
11
|
process.env.dash_dir = dashboard
|
|
@@ -39,9 +22,6 @@ async function customUIsContinuosReload(cmdEnv, dashboard) {
|
|
|
39
22
|
throw new Error("Aborted: ".red + " dashboard " + dashboard.bold + " does not exist.\n ")
|
|
40
23
|
}
|
|
41
24
|
|
|
42
|
-
const dashPort = await findPort(8041);
|
|
43
|
-
process.env.dash_port = dashPort;
|
|
44
|
-
|
|
45
25
|
if(dashboardPathIsDirectory) {
|
|
46
26
|
// If we have a dashboard to serve run it from local dashboard directory on 8081 with vue-cli-service
|
|
47
27
|
// it will use its vue.config.js
|
|
@@ -51,15 +31,13 @@ async function customUIsContinuosReload(cmdEnv, dashboard) {
|
|
|
51
31
|
commands.push( {
|
|
52
32
|
command: [
|
|
53
33
|
"cd " + dashboardPath + ";",
|
|
54
|
-
"node_modules/.bin/vue-cli-service serve --port
|
|
55
|
-
].join(" "),
|
|
34
|
+
"node_modules/.bin/vue-cli-service serve --port 8041 2>/dev/null"
|
|
35
|
+
].join(" "),
|
|
56
36
|
name: 'dashboard server',
|
|
57
|
-
prefixColor: "red"
|
|
37
|
+
prefixColor: "red"
|
|
58
38
|
})
|
|
59
39
|
}
|
|
60
40
|
|
|
61
|
-
const port = await findPort(8040);
|
|
62
|
-
|
|
63
41
|
console.log( "\n" + (" NOTE: Press " + "O".bold.red + " to open default browser, " + "CTRL+C".bold.red + " or " + "Q".bold.red + " to stop the tests... ").yellow.bold + "\n\n" )
|
|
64
42
|
|
|
65
43
|
const insideCobCliPath = path.resolve(__dirname, '../../node_modules/.bin/webpack-dev-server');
|
|
@@ -72,9 +50,8 @@ async function customUIsContinuosReload(cmdEnv, dashboard) {
|
|
|
72
50
|
webpackDevServerPath,
|
|
73
51
|
"--config",
|
|
74
52
|
path.resolve(__dirname, "../webpack/webpack.config.js"),
|
|
75
|
-
"--mode=development"
|
|
76
|
-
|
|
77
|
-
].join(" "),
|
|
53
|
+
"--mode=development"
|
|
54
|
+
].join(" "),
|
|
78
55
|
name: 'customUIs server',
|
|
79
56
|
prefixColor: "blue"
|
|
80
57
|
})
|
|
@@ -105,20 +82,14 @@ async function customUIsContinuosReload(cmdEnv, dashboard) {
|
|
|
105
82
|
}
|
|
106
83
|
}
|
|
107
84
|
|
|
108
|
-
|
|
109
|
-
const failurePromise = new Promise((_, reject) => { notifyFailure = reject; });
|
|
110
|
-
|
|
111
|
-
conc.result.catch( _err => {
|
|
85
|
+
conc.result.catch( _err => {
|
|
112
86
|
if(isStopping) return;
|
|
113
87
|
|
|
114
88
|
stopEverything();
|
|
115
|
-
notifyFailure(new Error('processes-failed'));
|
|
116
89
|
});
|
|
117
90
|
|
|
118
91
|
return {
|
|
119
|
-
stop: stopEverything
|
|
120
|
-
failed: failurePromise,
|
|
121
|
-
port
|
|
92
|
+
stop: stopEverything
|
|
122
93
|
};
|
|
123
94
|
}
|
|
124
95
|
exports.customUIsContinuosReload = customUIsContinuosReload;
|
|
@@ -29,7 +29,22 @@ async function otherFilesContiousReload(cmdEnv) {
|
|
|
29
29
|
let restoreChanges = async () => {
|
|
30
30
|
if(watcher.process) watcher.process.close();
|
|
31
31
|
if(changedFiles.size > 0) {
|
|
32
|
-
|
|
32
|
+
console.log("\nRestoring changed files...".yellow);
|
|
33
|
+
let stash = true;
|
|
34
|
+
await git().env('LC_ALL', 'C').stash(["--include-untracked"]).then( value => value.indexOf("Saved") == 0 || (stash = false))
|
|
35
|
+
let lastSha = await getLastDeployedSha(cmdEnv.server)
|
|
36
|
+
await git().checkout(lastSha)
|
|
37
|
+
|
|
38
|
+
await cmdEnv.applyLastEnvironmentDeployedToServerChanges()
|
|
39
|
+
for(let changedFile of changedFiles) {
|
|
40
|
+
await removeFileFromCurrentTest(cmdEnv.server, changedFile);
|
|
41
|
+
}
|
|
42
|
+
await cmdEnv.unApplyLastEnvironmentDeployedToServerChanges()
|
|
43
|
+
|
|
44
|
+
await execa('ssh', [cmdEnv.server,"find " + SERVER_IN_PROGRESS_TEST_FILE + " -size 0 -delete "]) //Remove file if empty
|
|
45
|
+
|
|
46
|
+
await git().checkout("-")
|
|
47
|
+
if (stash) await git().stash(["pop"])
|
|
33
48
|
}
|
|
34
49
|
fs.unlinkSync("."+IN_PROGRESS_TEST_FILE)
|
|
35
50
|
}
|
|
@@ -99,41 +114,6 @@ async function otherFilesContiousReload(cmdEnv) {
|
|
|
99
114
|
}
|
|
100
115
|
exports.otherFilesContiousReload = otherFilesContiousReload
|
|
101
116
|
|
|
102
|
-
/* ************************************ */
|
|
103
|
-
async function restoreServerFilesToLastDeployed(cmdEnv, changedFiles) {
|
|
104
|
-
console.log("\nRestoring changed files...".yellow);
|
|
105
|
-
|
|
106
|
-
// Clean up any env-swap markers left by applyCurrentCommandEnvironmentChanges before
|
|
107
|
-
// stashing. These files are gitignored, so git stash --include-untracked ignores them.
|
|
108
|
-
// If they survive into _undoSpecific(lastEnv) they create ghost env files that are
|
|
109
|
-
// untracked at lastSha, causing "git checkout -" to abort.
|
|
110
|
-
await cmdEnv.unApplyCurrentCommandEnvironmentChanges();
|
|
111
|
-
|
|
112
|
-
let stashed = false;
|
|
113
|
-
await git().env('LC_ALL', 'C').stash(["--include-untracked"])
|
|
114
|
-
.then(value => { stashed = value.indexOf("Saved") === 0; })
|
|
115
|
-
.catch(() => {});
|
|
116
|
-
|
|
117
|
-
const lastSha = await getLastDeployedSha(cmdEnv.server);
|
|
118
|
-
if (!lastSha) throw new Error("Cannot restore server files: no previous deploy found on server.");
|
|
119
|
-
await git().checkout(lastSha);
|
|
120
|
-
|
|
121
|
-
await cmdEnv.applyLastEnvironmentDeployedToServerChanges();
|
|
122
|
-
|
|
123
|
-
for (const changedFile of changedFiles) {
|
|
124
|
-
await removeFileFromCurrentTest(cmdEnv.server, changedFile);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
await cmdEnv.unApplyLastEnvironmentDeployedToServerChanges();
|
|
128
|
-
|
|
129
|
-
await execa('ssh', [cmdEnv.server, "find " + SERVER_IN_PROGRESS_TEST_FILE + " -size 0 -delete"])
|
|
130
|
-
.catch(() => {});
|
|
131
|
-
|
|
132
|
-
await git().checkout("-");
|
|
133
|
-
if (stashed) await git().stash(["pop"]);
|
|
134
|
-
}
|
|
135
|
-
exports.restoreServerFilesToLastDeployed = restoreServerFilesToLastDeployed
|
|
136
|
-
|
|
137
117
|
/* ************************************ */
|
|
138
118
|
async function addFileToCurrentTest(server, changedFile, changedFiles, changeType, restoreChanges) {
|
|
139
119
|
let inUse = "";
|
|
@@ -166,7 +146,6 @@ async function removeFileFromCurrentTest(server, changedFile) {
|
|
|
166
146
|
await execa('ssh', [server, "sed -i '/" + changedFile.split("/").join("\\/") + "/d' " + SERVER_IN_PROGRESS_TEST_FILE]).catch( () => {/* ignore files removed by user */} );
|
|
167
147
|
console.log(" reset ".brightGreen + changedFile);
|
|
168
148
|
}
|
|
169
|
-
exports.removeFileFromCurrentTest = removeFileFromCurrentTest
|
|
170
149
|
|
|
171
150
|
/* ************************************ */
|
|
172
151
|
function checkNoTestsRunningOnServer(server) {
|