From 4419b0327f4c54b0c6ecc54fd3b18f252935222e Mon Sep 17 00:00:00 2001 From: Filipe Leandro Date: Fri, 18 Sep 2020 16:09:36 -0300 Subject: [PATCH 1/4] ENG-1287 fixing typo --- bin/index.js | 4 ++-- lib/actions.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/index.js b/bin/index.js index e147a66..db90a3e 100755 --- a/bin/index.js +++ b/bin/index.js @@ -2,7 +2,7 @@ const program = require('commander'); -const { generateFromNpm, generateFromGit, generateFromEnv, generateInteractivly } = require('../lib/actions'); +const { generateFromNpm, generateFromGit, generateFromEnv, generateInteractively } = require('../lib/actions'); const version = require('../package.json').version; program.storeOptionsAsProperties(false); @@ -46,5 +46,5 @@ program if (process.argv.length > 2) { program.parse(process.argv); } else { - generateInteractivly(); + generateInteractively(); } diff --git a/lib/actions.js b/lib/actions.js index 5355a67..3977a65 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -108,5 +108,5 @@ module.exports = { generateFromNpm, generateFromGit, generateFromEnv, - generateInteractivly: generateInteractively, + generateInteractively, }; From 46aeceddea375d00172983fb4724f1d9e870525c Mon Sep 17 00:00:00 2001 From: Filipe Leandro Date: Fri, 18 Sep 2020 16:09:58 -0300 Subject: [PATCH 2/4] ENG-1287 adding support for extracting labels --- lib/env-bundler.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/env-bundler.js b/lib/env-bundler.js index 1edb032..cf8e54e 100644 --- a/lib/env-bundler.js +++ b/lib/env-bundler.js @@ -22,6 +22,7 @@ const ALL_TYPES = [ 'plugin', 'category', 'resource', + 'label', ]; var coreBaseApi, k8ssvcApi, clientId, clientSecret, apiUrlTable; @@ -78,6 +79,10 @@ const componentDetailExtractors = { components.map((c) => { return { value: c.path, name: `${c.path}` }; }), + label: (components) => + components.map((c) => { + return { value: c.key, name: `${c.titles.en} (${c.key})` }; + }), }; const componentIdExtractors = { @@ -114,6 +119,9 @@ const componentIdExtractors = { resource: (c) => { return c.path; }, + label: (c) => { + return c.key; + }, }; const componentCodeExtractors = { @@ -150,6 +158,9 @@ const componentCodeExtractors = { resource: (c) => { return c.path; }, + label: (c) => { + return c.key; + }, }; const componentResponseProcessor = { @@ -165,7 +176,7 @@ const componentResponseProcessor = { return pages; }, - pageModel: async (response) => { + pageModel: async (response, token) => { return response.data.payload; }, fragment: async (response, token) => { @@ -185,7 +196,7 @@ const componentResponseProcessor = { return fragments.map(f => objectMapper(f, schema)); }, - widget: async (response) => { + widget: async (response, token) => { return response.data.payload; }, contentType: async (response, token) => { @@ -200,16 +211,16 @@ const componentResponseProcessor = { return contentTypes; }, - contentModel: async (response) => { + contentModel: async (response, token) => { return response.data.payload; }, - plugin: async (response) => { + plugin: async (response, token) => { return response.data._embedded.entandoPlugins; }, - group: async (response) => { + group: async (response, token) => { return response.data.payload; }, - category: async (response) => { + category: async (response, token) => { const categories = response.data.payload; const schema = { code: 'code', @@ -224,6 +235,9 @@ const componentResponseProcessor = { const files = await recursiveTraverseFileTree(response.data.payload, token); return files; }, + label: async (response, token) => { + return response.data.payload; + }, }; function canonizeCode (code) { @@ -342,6 +356,7 @@ const collectQuestions = [ { name: 'Content Types', value: 'contentType' }, { name: 'Groups', value: 'group' }, { name: 'Categories', value: 'category' }, + { name: 'Labels', value: 'label' }, { name: 'File Browser', value: 'resource' }, ], }, @@ -352,7 +367,8 @@ const collectQuestions = [ message: 'Which components do you want to include in the bundle?', choices: async (answers) => { const type = answers.componentType; - return componentDetailExtractors[type](componentCache[type]); + const components = await getComponents(type); + return componentDetailExtractors[type](components); }, default: async (answers) => { if (hasProperty(allAnswers, answers.componentType)) { @@ -428,7 +444,7 @@ async function saveComponentsDescriptor (type, location, componentIds) { await fs.promises.mkdir(`${location}/${typePlural}`, { recursive: true }); let descriptors = []; - if (type === 'group' || type === 'category') { // Should group in a single descriptor + if (type === 'group' || type === 'category' || type === 'label') { // Should group in a single descriptor console.log(`Processing ${typePlural}`); const descriptorName = `${typePlural}/${typePlural}-descriptor.yaml`; fs.promises.writeFile(`${location}/${descriptorName}`, yaml.safeDump(components)); @@ -531,6 +547,7 @@ async function setupEnvironment (options) { pageConfiguration: `${coreBaseApi}/api/pages/{code}/configuration`, page: `${coreBaseApi}/api/pages?status=published`, group: `${coreBaseApi}/api/groups`, + label: `${coreBaseApi}/api/labels`, category: `${coreBaseApi}/api/categories`, contentType: `${coreBaseApi}/api/plugins/cms/contentTypes`, contentTypeDetails: `${coreBaseApi}/api/plugins/cms/contentTypes/{code}`, From 0797b5baa71a78915210f5ee37f5dd286de807fc Mon Sep 17 00:00:00 2001 From: Filipe Leandro Date: Fri, 18 Sep 2020 17:39:38 -0300 Subject: [PATCH 3/4] ENG-1287 improved retries with exponential push back and fixed bug with file browser extraction; --- lib/env-bundler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/env-bundler.js b/lib/env-bundler.js index cf8e54e..1d8e417 100644 --- a/lib/env-bundler.js +++ b/lib/env-bundler.js @@ -6,7 +6,8 @@ const yaml = require('js-yaml'); const objectMapper = require('object-mapper'); const axiosRetry = require('axios-retry'); -axiosRetry(axios, { retries: 3 }); // Configure retries when extracting data +// Configure retries when extracting data +axiosRetry(axios, { retries: 5, retryDelay: axiosRetry.exponentialDelay}); var allAnswers = {}; var componentCache = {}; @@ -292,7 +293,7 @@ async function getComponents (type) { async function recursiveTraverseFileTree (root, token) { const rootTraversed = await Promise.all(root.map(async (resource) => { if (resource.directory === true) { - const result = await axios.get(apiUrlTable.resource.replace('{path}', resource.path), { + const result = await axios.get(apiUrlTable.resourceDetails.replace('{path}', resource.path), { headers: { Authorization: `Bearer ${token}` }, }); From f915f086afb773d062d035350357c2dcad2f61d6 Mon Sep 17 00:00:00 2001 From: Filipe Leandro Date: Fri, 18 Sep 2020 17:46:30 -0300 Subject: [PATCH 4/4] ENG-1287 fixing issue with file browser traversion; --- lib/env-bundler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env-bundler.js b/lib/env-bundler.js index 1d8e417..813887e 100644 --- a/lib/env-bundler.js +++ b/lib/env-bundler.js @@ -293,7 +293,7 @@ async function getComponents (type) { async function recursiveTraverseFileTree (root, token) { const rootTraversed = await Promise.all(root.map(async (resource) => { if (resource.directory === true) { - const result = await axios.get(apiUrlTable.resourceDetails.replace('{path}', resource.path), { + const result = await axios.get(apiUrlTable.resource.replace('currentPath=', `currentPath=${resource.path}`), { headers: { Authorization: `Bearer ${token}` }, });