cob-cli 2.39.0 → 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.
@@ -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
- await copyAndMerge(customizationRepo.name, customizationDir, answers);
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
- async function copyAndMerge(customizationRepoName, source, substitutions = {}) {
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
- return new Promise((resolve, reject) => {
182
- ncp(
183
- source,
184
- target,
185
- {
186
- clobber: true,
187
- filter: (src) => src.match(excludedFiles) == null,
188
- rename: function(target) {
189
- // Don't rename __MERGE__ templates, they will be handled by the merge method
190
- if (target.match(/__MERGE__/)) return target;
191
-
192
- //get finalTarget from target with any existing substitution
193
- const finalTarget = target.replace(substitutionRegex, (match,g1) => substitutions[g1] ? substitutions[g1] : match);
194
-
195
- //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
196
- if (!fs.existsSync(path.dirname(finalTarget))) {
197
- fs.mkdirSync(path.dirname(finalTarget), { recursive: true })
198
- fs.rmdirSync(target.substring(0,target.lastIndexOf("__")+2), { recursive: true,force: false }) //NOTE: won't handle more than 1 substitution on the same dirpath
199
- }
200
- return finalTarget;
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
- async (error) => {
218
- // If no error occurred then proced with merging files
219
- if(!error) {
220
- await mergeFiles(customizationRepoName);
221
- resolve();
222
- } else {
223
- reject(error.map((e) => e.message).join("\n"))
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
- async function mergeFiles(block) {
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
  /* ************************************************************************ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cob-cli",
3
- "version": "2.39.0",
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": {