cob-cli 2.38.2 → 2.39.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/bin/cob-cli.js
CHANGED
|
@@ -11,6 +11,7 @@ const customize = require("../lib/commands/customize");
|
|
|
11
11
|
const test = require("../lib/commands/test");
|
|
12
12
|
const deploy = require("../lib/commands/deploy");
|
|
13
13
|
const updateFromServer = require("../lib/commands/updateFromServer");
|
|
14
|
+
const getDefs = require("../lib/commands/getDefs");
|
|
14
15
|
const { upgradeRepo } = require("../lib/commands/upgradeRepo");
|
|
15
16
|
|
|
16
17
|
/*******************************************/
|
|
@@ -78,4 +79,10 @@ program
|
|
|
78
79
|
.description('Upgrade current repository to the last cob-cli version structure')
|
|
79
80
|
.action( upgradeRepo );
|
|
80
81
|
|
|
82
|
+
program
|
|
83
|
+
.command('getDefs')
|
|
84
|
+
.option('-e --environment <name>', 'environment to use')
|
|
85
|
+
.description('Updates local copy with definitions on server')
|
|
86
|
+
.action( getDefs );
|
|
87
|
+
|
|
81
88
|
program.parse(process.argv);
|
|
@@ -7,7 +7,6 @@ const axios = require("axios");
|
|
|
7
7
|
const git = require("simple-git");
|
|
8
8
|
const ncp = require("ncp");
|
|
9
9
|
const { Transform } = require("stream");
|
|
10
|
-
const fg = require("fast-glob");
|
|
11
10
|
const fs = require("fs-extra");
|
|
12
11
|
|
|
13
12
|
const customizationsVersionsFile = "customizations.json";
|
|
@@ -151,7 +150,7 @@ async function applyCustomizations(customizationRepos) {
|
|
|
151
150
|
await customization.actions(customizationRepo.name, answers, copyAndMerge);
|
|
152
151
|
} else {
|
|
153
152
|
// Default actions
|
|
154
|
-
|
|
153
|
+
copyAndMerge(customizationRepo.name, customizationDir, answers);
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
// Update customizations.json file
|
|
@@ -160,7 +159,7 @@ async function applyCustomizations(customizationRepos) {
|
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
/* ************************************************************************ */
|
|
163
|
-
|
|
162
|
+
function copyAndMerge(customizationRepoName, source, substitutions = {}) {
|
|
164
163
|
console.log("\n Copying template files for " + colors.blue(customizationRepoName) + "...");
|
|
165
164
|
|
|
166
165
|
let excludedFiles = RegExp(
|
|
@@ -178,62 +177,54 @@ async function copyAndMerge(customizationRepoName, source, substitutions = {}) {
|
|
|
178
177
|
// Source is on cob-cli customizationRepo and Destination on the server repo
|
|
179
178
|
const target = process.cwd() // Always copy to directory where command is being executed, ie, the root directory of the server repo
|
|
180
179
|
const substitutionRegex = /__(((?!word).)*)__/g;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
rename
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
},
|
|
202
|
-
transform(read, write) {
|
|
203
|
-
const replaceVarsTransformFunction = new Transform({
|
|
204
|
-
transform: (chunk, encoding, done) => {
|
|
205
|
-
if(/\ufffd/.test(chunk) === true) {
|
|
206
|
-
// If chunk is binary don't change anything
|
|
207
|
-
done(null, chunk)
|
|
208
|
-
} else {
|
|
209
|
-
// Otherwise change any existing substitution
|
|
210
|
-
done(null,chunk.toString().replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match))
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
})
|
|
214
|
-
read.pipe(replaceVarsTransformFunction).pipe(write)
|
|
180
|
+
ncp(
|
|
181
|
+
source,
|
|
182
|
+
target,
|
|
183
|
+
{
|
|
184
|
+
clobber: true,
|
|
185
|
+
filter: (src) => src.match(excludedFiles) == null,
|
|
186
|
+
rename: function(target) {
|
|
187
|
+
// Don't rename __MERGE__ templates, they will be handled by the merge method
|
|
188
|
+
if (target.match(/__MERGE__/)) {
|
|
189
|
+
setTimeout(()=>mergeFiles(customizationRepoName, target),200)
|
|
190
|
+
return target
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//get finalTarget from target with any existing substitution
|
|
194
|
+
const finalTarget = target.replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match);
|
|
195
|
+
|
|
196
|
+
//if the directory of finalTarget doesn't exists it means that a replacement ocurred on the dirpath (ie, there was a /__.+__/ was on the dirpath), in which case we need to create the desired directory and remove the one just created by ncp
|
|
197
|
+
if (!fs.existsSync(path.dirname(finalTarget))) {
|
|
198
|
+
fs.mkdirSync(path.dirname(finalTarget), { recursive: true })
|
|
199
|
+
fs.rmdirSync(target.substring(0,target.lastIndexOf("__")+2), { recursive: true,force: false }) //NOTE: won't handle more than 1 substitution on the same dirpath
|
|
215
200
|
}
|
|
201
|
+
return finalTarget;
|
|
216
202
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
203
|
+
transform(read, write) {
|
|
204
|
+
const replaceVarsTransformFunction = new Transform({
|
|
205
|
+
transform: (chunk, encoding, done) => {
|
|
206
|
+
if(/\ufffd/.test(chunk) === true) {
|
|
207
|
+
// If chunk is binary don't change anything
|
|
208
|
+
done(null, chunk)
|
|
209
|
+
} else {
|
|
210
|
+
// Otherwise change any existing substitution
|
|
211
|
+
done(null,chunk.toString().replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match))
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
read.pipe(replaceVarsTransformFunction).pipe(write)
|
|
225
216
|
}
|
|
226
|
-
|
|
227
|
-
|
|
217
|
+
},
|
|
218
|
+
(error) => {
|
|
219
|
+
if(error) {
|
|
220
|
+
console.log(error.map((e) => e.message).join("\n"))
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
)
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
/* ************************************************************************ */
|
|
231
|
-
|
|
232
|
-
const mergeFiles = await fg(["**/*.__MERGE__.*"], {
|
|
233
|
-
onlyFiles: false,
|
|
234
|
-
dot: true,
|
|
235
|
-
});
|
|
236
|
-
for (let mergeFile of mergeFiles) {
|
|
227
|
+
function mergeFiles(block,mergeFile) {
|
|
237
228
|
let prodFile = mergeFile.replace(/\.__MERGE__/, "");
|
|
238
229
|
let blockMark = block == undefined ? "" : block;
|
|
239
230
|
if (!fs.existsSync(prodFile)) {
|
|
@@ -266,7 +257,6 @@ async function mergeFiles(block) {
|
|
|
266
257
|
fs.writeFileSync(prodFile, prodFileContent);
|
|
267
258
|
|
|
268
259
|
fs.unlinkSync(mergeFile);
|
|
269
|
-
}
|
|
270
260
|
}
|
|
271
261
|
|
|
272
262
|
/* ************************************************************************ */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require('colors');
|
|
2
|
+
const { getCurrentCommandEnviroment } = require("../task_lists/common_enviromentHandler");
|
|
3
|
+
const { checkRepoVersion } = require("../commands/upgradeRepo");
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const spawn = require('child_process').spawn;
|
|
6
|
+
|
|
7
|
+
async function getDefs(args) {
|
|
8
|
+
try {
|
|
9
|
+
checkRepoVersion()
|
|
10
|
+
const cmdEnv = await getCurrentCommandEnviroment(args)
|
|
11
|
+
|
|
12
|
+
console.log(`Getting definitions from ${cmdEnv.serverStr} to branch ${cmdEnv.branchStr} ...` );
|
|
13
|
+
const getDefs = spawn(path.resolve(__dirname,"..","task_lists","getDefs.sh"),[cmdEnv.server, cmdEnv.name, path.resolve(__dirname) ])
|
|
14
|
+
getDefs.stdout.on('data', function (data) { console.log(" " + data.toString()); });
|
|
15
|
+
getDefs.on('exit', function () { console.log('Done!'); });
|
|
16
|
+
} catch(err) {
|
|
17
|
+
console.error("\n",err.message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
module.exports = getDefs;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
IFS=$'\n'
|
|
2
|
+
SERVER=${1}
|
|
3
|
+
ENVIRONMENT=${2}
|
|
4
|
+
COBCLIPATH=${3}
|
|
5
|
+
|
|
6
|
+
echo "mkdir -p recordm/definitions/\\c"
|
|
7
|
+
mkdir -p recordm/definitions/
|
|
8
|
+
|
|
9
|
+
echo "rm -f recordm/definitions/$ENVIRONMENT\\c"
|
|
10
|
+
rm -f recordm/definitions/$ENVIRONMENT/*
|
|
11
|
+
|
|
12
|
+
DIR=recordm/definitions/$ENVIRONMENT
|
|
13
|
+
echo "mkdir -p $DIR"
|
|
14
|
+
mkdir -p $DIR
|
|
15
|
+
|
|
16
|
+
for def in $(ssh $SERVER "curl -sS -b ~/.cob-cookie http://localhost:40280/recordm/definitions" | jq .[] -c | node $COBCLIPATH/../../node_modules/cmd-line-importer/processor.js --transformer "JSON.stringify([entry.id,entry.name])"); do
|
|
17
|
+
echo " getting def: $def ...\\c"
|
|
18
|
+
ssh $SERVER "curl -sS -b ~/.cob-cookie http://localhost:40280/recordm/definitions/$(echo $def | jq '.[0]')" | jq --sort-keys . | grep -v "\"defaultValue\":" > $DIR/$(echo $def | jq .[1] | tr -d '"').json
|
|
19
|
+
done
|
|
@@ -64,7 +64,6 @@ async function otherFilesContiousReload(cmdEnv) {
|
|
|
64
64
|
ignoreInitial: true
|
|
65
65
|
});
|
|
66
66
|
watcher.process.on('all', async (eventType, changedFile) => {
|
|
67
|
-
console.log(eventType, changedFile);
|
|
68
67
|
// Não é preciso fazer nada para directorias que só existem no servidor
|
|
69
68
|
let product = changedFile.split("/")[0];
|
|
70
69
|
let productDir = resolveCobPath(cmdEnv.server, "serverLive", product).split(":")[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cob-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.39.1",
|
|
4
4
|
"description": "A command line utility to help Cult of Bits partners develop with higher speed and reusing common code and best practices.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"repository": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@webpack-cli/serve": "^2.0.1",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
|
+
"cmd-line-importer": "^1.0.0",
|
|
21
22
|
"colors": "^1.4.0",
|
|
22
23
|
"commander": "^5.1.0",
|
|
23
24
|
"concurrently": "^5.3.0",
|