From ea493ef07c37be8d2b5c40a69a2924c9872ed6d9 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Thu, 12 Sep 2024 10:08:24 +0200 Subject: [PATCH 1/2] chore: node launch debug config --- .vscode/launch.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 07c0bcc..4c65a95 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,6 +18,17 @@ "windows": { "program": "${workspaceFolder}\\node_modules\\jest\\bin\\jest.js" } + }, + { + "type": "node", + "request": "launch", + "name": "Debug pull-components", + "program": "${workspaceFolder}/dist/cli.mjs", + "args": ["pull-components", "--space", "6274026"], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "sourceMaps": true, + "outFiles": ["${workspaceFolder}/dist/**/*.js"] } ] } \ No newline at end of file From 1c9d51f2a5608b8a2951f9c1d6b1a4c3e12da4e6 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Thu, 12 Sep 2024 10:32:38 +0200 Subject: [PATCH 2/2] fix: create internal component tags for push-components --- .vscode/launch.json | 2 +- src/tasks/push-components.js | 42 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4c65a95..00d4fb0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,7 +24,7 @@ "request": "launch", "name": "Debug pull-components", "program": "${workspaceFolder}/dist/cli.mjs", - "args": ["pull-components", "--space", "6274026"], + "args": ["push-components", "components.295017.json", "--space", "295018"], "cwd": "${workspaceFolder}", "console": "integratedTerminal", "sourceMaps": true, diff --git a/src/tasks/push-components.js b/src/tasks/push-components.js index 1117e22..78a2dcf 100644 --- a/src/tasks/push-components.js +++ b/src/tasks/push-components.js @@ -64,6 +64,21 @@ const createContentList = (content, key) => { else return !isEmpty(content) ? [content] : [] } +const getSpaceInternalTags = (client, spaceId) => { + return client.get(`spaces/${spaceId}/internal_tags`).then((response) => response.data.internal_tags || []); +} + +const createComponentInternalTag =(client, spaceId, tag) => { + return client.post(`spaces/${spaceId}/internal_tags`, { + internal_tag: { + name: tag.name, + object_type: "component" + } + }) + .then((response) => response.data.internal_tag || {}) + .catch((error) => Promise.reject(error)); +} + const pushComponents = async (api, { source, presetsSource }) => { try { const rawComponents = await getDataFromPath(source) @@ -133,7 +148,9 @@ const pushComponentsGroups = async (api, group) => { } const push = async (api, components, componentsGroups = [], presets = []) => { - const presetsLib = new PresetsLib({ oauthToken: api.accessToken, targetSpaceId: api.spaceId }) + const targetSpaceId = api.spaceId + const presetsLib = new PresetsLib({ oauthToken: api.accessToken, targetSpaceId, }) + const apiClient = api.getClient() try { const componentGroupsTree = buildComponentsGroupsTree(componentsGroups) @@ -157,6 +174,29 @@ const push = async (api, components, componentsGroups = [], presets = []) => { delete components[i].component_group_name } + const { internal_tags_list, internal_tag_ids } = components[i]; + const existingTags = await getSpaceInternalTags(apiClient, targetSpaceId); + + let processedInternalTagsIds = []; + if(internal_tags_list.length > 0) { + await internal_tags_list.forEach(async (tag) => { + const existingTag = existingTags.find(({ name }) => tag.name === name); + if(!existingTag) { + try { + const response = await createComponentInternalTag(apiClient, targetSpaceId, tag); + processedInternalTagsIds.push(response.id); + } catch (e) { + console.error(chalk.red("X") + ` Internal tag ${tag} creation failed: ${e.message}`); + } + } else { + processedInternalTagsIds.push(existingTag.id); + } + }) + } + + components[i].internal_tag_ids = processedInternalTagsIds || internal_tag_ids; + + const schema = components[i].schema if (schema) { Object.keys(schema).forEach(field => {