cob-cli 2.39.0 → 2.39.2
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/lib/commands/customize.js +62 -54
- package/package.json +1 -1
|
@@ -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,69 +177,79 @@ 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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
+
let filesToMerge = []
|
|
181
|
+
ncp(
|
|
182
|
+
source,
|
|
183
|
+
target,
|
|
184
|
+
{
|
|
185
|
+
clobber: true,
|
|
186
|
+
filter: (src) => src.match(excludedFiles) == null,
|
|
187
|
+
rename: function(target) {
|
|
188
|
+
// Don't rename __MERGE__ templates, they will be handled by the merge method
|
|
189
|
+
if (target.match(/__MERGE__/)) {
|
|
190
|
+
const newTmpName = target.replace(/__MERGE__/, customizationRepoName+"__MERGE__")
|
|
191
|
+
filesToMerge.push(newTmpName)
|
|
192
|
+
return newTmpName
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
//get finalTarget from target with any existing substitution
|
|
196
|
+
const finalTarget = target.replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match);
|
|
197
|
+
|
|
198
|
+
//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
|
|
199
|
+
if (!fs.existsSync(path.dirname(finalTarget))) {
|
|
200
|
+
fs.mkdirSync(path.dirname(finalTarget), { recursive: true })
|
|
201
|
+
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
202
|
}
|
|
203
|
+
return finalTarget;
|
|
216
204
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
205
|
+
transform(read, write) {
|
|
206
|
+
const replaceVarsTransformFunction = new Transform({
|
|
207
|
+
transform: (chunk, encoding, done) => {
|
|
208
|
+
if(chunk.toString().indexOf("_log.css") > 0) console.log(chunk.toString())
|
|
209
|
+
if(/\ufffd/.test(chunk) === true) {
|
|
210
|
+
// If chunk is binary don't change anything
|
|
211
|
+
done(null, chunk)
|
|
212
|
+
} else {
|
|
213
|
+
// Otherwise change any existing substitution
|
|
214
|
+
done(null,chunk.toString().replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match))
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
read.pipe(replaceVarsTransformFunction).pipe(write)
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
(error) => {
|
|
222
|
+
if(error) {
|
|
223
|
+
console.log(error.map((e) => e.message).join("\n"))
|
|
224
|
+
} else {
|
|
225
|
+
// Only run this on the last call
|
|
226
|
+
for(let file of filesToMerge) {
|
|
227
|
+
//Allow a little time for file to be written to disk
|
|
228
|
+
setTimeout(() => mergeFiles(customizationRepoName, file), 200)
|
|
224
229
|
}
|
|
225
230
|
}
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
}
|
|
232
|
+
)
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
/* ************************************************************************ */
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
let
|
|
236
|
+
function mergeFiles(block,mergeFile) {
|
|
237
|
+
if (!fs.existsSync(mergeFile)) {
|
|
238
|
+
//Already processed
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let prodFileRexp = new RegExp(block + "__MERGE__.");
|
|
243
|
+
let prodFile = mergeFile.replace(prodFileRexp, "");
|
|
238
244
|
let blockMark = block == undefined ? "" : block;
|
|
239
245
|
if (!fs.existsSync(prodFile)) {
|
|
240
246
|
// If prod file does not exist creates it
|
|
241
247
|
console.log(" Creating " + prodFile);
|
|
242
248
|
fs.closeSync(fs.openSync(prodFile, "w"));
|
|
243
249
|
} else {
|
|
250
|
+
fs.open(prodFile, "a+",(err, fd) => {
|
|
251
|
+
fs.fdatasync(fd /*, optional callback here */);
|
|
252
|
+
})
|
|
244
253
|
console.log(" Merging " + prodFile + " " + block);
|
|
245
254
|
}
|
|
246
255
|
let prodFileContent = fs.readFileSync(prodFile).toString();
|
|
@@ -266,7 +275,6 @@ async function mergeFiles(block) {
|
|
|
266
275
|
fs.writeFileSync(prodFile, prodFileContent);
|
|
267
276
|
|
|
268
277
|
fs.unlinkSync(mergeFile);
|
|
269
|
-
}
|
|
270
278
|
}
|
|
271
279
|
|
|
272
280
|
/* ************************************************************************ */
|
package/package.json
CHANGED