backend-manager 3.2.161 → 3.2.163

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.161",
3
+ "version": "3.2.163",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
package/src/cli/cli.js CHANGED
@@ -1247,26 +1247,34 @@ async function execute(command, cwd) {
1247
1247
  async function cmd_configGet(self, filePath) {
1248
1248
  return new Promise(function(resolve, reject) {
1249
1249
  const finalPath = `${self.firebaseProjectPath}/${filePath || 'functions/.runtimeconfig.json'}`;
1250
- // execute(`firebase functions:config:get > ${finalPath}`)
1251
- // .then(r => {
1252
- // console.log(chalk.green(`Saving config to: ${finalPath}`));
1253
- // console.log(r);
1254
- // resolve(require(finalPath));
1255
- // })
1256
- // .catch(e => {
1257
- // console.error(e);
1258
- // reject(e);
1259
- // })
1260
- let cmd = exec(`firebase functions:config:get > ${finalPath}`, function (error, stdout, stderr) {
1261
- if (error) {
1262
- console.error(error);
1263
- reject(error);
1264
- } else {
1265
- console.log(chalk.green(`Saving config to: ${finalPath}`));
1266
- console.log(stdout);
1267
- resolve(require(finalPath));
1268
- }
1269
- });
1250
+
1251
+ const max = 10;
1252
+ let retries = 0;
1253
+
1254
+ function _attempt() {
1255
+ exec(`firebase functions:config:get > ${finalPath}`, function (error, stdout, stderr) {
1256
+ if (error) {
1257
+ console.error(chalk.red(`Failed to get config: ${error}`));
1258
+
1259
+ // If retries are exhausted, reject
1260
+ if (retries++ > max) {
1261
+ return reject(error);
1262
+ }
1263
+
1264
+ // Retry
1265
+ const delay = 2500 * retries
1266
+ console.error(chalk.yellow(`Retrying config:get ${retries}/${max} in ${delay}ms...`));
1267
+ setTimeout(_attempt, delay);
1268
+ } else {
1269
+ console.log(chalk.green(`Saving config to: ${finalPath}`));
1270
+ console.log(stdout);
1271
+ resolve(require(finalPath));
1272
+ }
1273
+ });
1274
+ }
1275
+
1276
+ // Start the attempts
1277
+ _attempt();
1270
1278
  });
1271
1279
  }
1272
1280
 
@@ -3,6 +3,7 @@ const moment = require('moment');
3
3
  const jetpack = require('fs-jetpack');
4
4
  const powertools = require('node-powertools');
5
5
  const uuidv4 = require('uuid').v4;
6
+ const { get, set } = require('lodash');
6
7
  const path = require('path');
7
8
  const { Octokit } = require('@octokit/rest');
8
9
 
@@ -101,7 +102,10 @@ Module.prototype.main = function () {
101
102
  await self.extractImages();
102
103
 
103
104
  // Set defaults
104
- const formattedContent = powertools.template(POST_TEMPLATE, payload.data.payload);
105
+ const formattedContent = powertools.template(
106
+ POST_TEMPLATE,
107
+ formatClone(payload.data.payload),
108
+ );
105
109
 
106
110
  // Insert ads
107
111
  const articleWithAds = insertAds(formattedContent, 6, 4000);
@@ -333,6 +337,20 @@ Module.prototype.uploadPost = function (content) {
333
337
  });
334
338
  };
335
339
 
340
+ function formatClone(payload) {
341
+ powertools.getKeys(payload).forEach((item) => {
342
+ const value = get(payload, item);
343
+ const isArray = Array.isArray(value);
344
+
345
+ // If it's an array, format as JSON so it appears in frontmatter as an array
346
+ if (isArray) {
347
+ set(payload, item, JSON.stringify(value));
348
+ }
349
+ });
350
+
351
+ return payload;
352
+ }
353
+
336
354
  function hyphenate(s) {
337
355
  return s
338
356
  // Remove everything that is not a letter or a number