From bfa6a65f07ab226d49464c2180929bc5958c6423 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 21 Jan 2026 11:38:19 +0530 Subject: [PATCH 1/3] chore: remove legacy bulk publish code --- package-lock.json | 37 +- .../contentstack-bulk-publish/.editorconfig | 11 - packages/contentstack-bulk-publish/.eslintrc | 3 - packages/contentstack-bulk-publish/.gitignore | 9 - .../contentstack-bulk-publish/.mocharc.json | 13 - packages/contentstack-bulk-publish/.snyk | 10 - packages/contentstack-bulk-publish/LICENSE | 21 - packages/contentstack-bulk-publish/README.md | 1797 --------------- .../contentstack-bulk-publish/bin/run.cmd | 3 - packages/contentstack-bulk-publish/bin/run.js | 7 - .../contentstack-bulk-publish/copyLogs.js | 36 - .../contentstack-bulk-publish/package.json | 100 - .../src/commands/cm/assets/publish.js | 269 --- .../src/commands/cm/assets/unpublish.js | 202 -- .../commands/cm/bulk-publish/cross-publish.js | 295 --- .../src/commands/cm/bulk-publish/index.js | 14 - .../commands/cm/entries/publish-modified.js | 241 -- .../entries/publish-non-localized-fields.js | 237 -- .../cm/entries/publish-only-unpublished.js | 118 - .../src/commands/cm/entries/publish.js | 315 --- .../src/commands/cm/entries/unpublish.js | 213 -- .../commands/cm/entries/update-and-publish.js | 226 -- .../commands/cm/stacks/publish-clear-logs.js | 82 - .../commands/cm/stacks/publish-configure.js | 51 - .../src/commands/cm/stacks/publish-revert.js | 106 - .../src/commands/cm/stacks/publish.js | 112 - .../src/commands/cm/stacks/unpublish.js | 301 --- .../src/config/defaults.json | 5 - .../src/config/dummy.json | 115 - .../src/config/index.js | 71 - .../src/consumer/publish.js | 779 ------- .../src/producer/add-fields.js | 510 ----- .../src/producer/cross-publish.js | 411 ---- .../producer/nonlocalized-field-changes.js | 386 ---- .../src/producer/publish-assets.js | 175 -- .../src/producer/publish-edits.js | 182 -- .../src/producer/publish-entries.js | 323 --- .../src/producer/publish-unpublished-env.js | 199 -- .../src/producer/revert.js | 391 ---- .../src/producer/unpublish.js | 395 ---- .../src/services/publish-only-unpublished.js | 139 -- .../src/util/client.js | 38 - .../src/util/command-helper.js | 25 - .../src/util/common-utility.js | 30 - .../contentstack-bulk-publish/src/util/fs.js | 68 - .../src/util/generate-bulk-publish-url.js | 42 - .../src/util/index.js | 64 - .../src/util/logger.js | 56 - .../src/util/queue.js | 57 - .../src/util/retryfailed.js | 43 - .../src/util/store.js | 83 - .../test/helpers/helper.js | 15 - .../test/helpers/init.js | 4 - .../test/unit/commands/assets/publish.test.js | 116 - .../unit/commands/assets/unpublish.test.js | 114 - .../bulk-publish/cross-publish.test.js | 171 -- .../commands/entries/publish-modified.test.js | 95 - .../publish-non-localized-fields.test.js | 101 - .../entries/publish-only-unpublished.test.js | 109 - .../unit/commands/entries/publish.test.js | 107 - .../unit/commands/entries/unpublish.test.js | 114 - .../entries/update-and-publish.test.js | 101 - .../test/unit/commands/stacks/publish.test.js | 115 - .../unit/commands/stacks/unpublish.test.js | 139 -- packages/contentstack/README.md | 1992 +---------------- packages/contentstack/package.json | 2 - pnpm-lock.yaml | 61 +- 67 files changed, 116 insertions(+), 12656 deletions(-) delete mode 100644 packages/contentstack-bulk-publish/.editorconfig delete mode 100644 packages/contentstack-bulk-publish/.eslintrc delete mode 100644 packages/contentstack-bulk-publish/.gitignore delete mode 100644 packages/contentstack-bulk-publish/.mocharc.json delete mode 100644 packages/contentstack-bulk-publish/.snyk delete mode 100644 packages/contentstack-bulk-publish/LICENSE delete mode 100644 packages/contentstack-bulk-publish/README.md delete mode 100644 packages/contentstack-bulk-publish/bin/run.cmd delete mode 100755 packages/contentstack-bulk-publish/bin/run.js delete mode 100644 packages/contentstack-bulk-publish/copyLogs.js delete mode 100644 packages/contentstack-bulk-publish/package.json delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/index.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-clear-logs.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-revert.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js delete mode 100644 packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js delete mode 100644 packages/contentstack-bulk-publish/src/config/defaults.json delete mode 100644 packages/contentstack-bulk-publish/src/config/dummy.json delete mode 100644 packages/contentstack-bulk-publish/src/config/index.js delete mode 100644 packages/contentstack-bulk-publish/src/consumer/publish.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/add-fields.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/cross-publish.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/nonlocalized-field-changes.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/publish-assets.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/publish-edits.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/publish-entries.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/revert.js delete mode 100644 packages/contentstack-bulk-publish/src/producer/unpublish.js delete mode 100644 packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js delete mode 100644 packages/contentstack-bulk-publish/src/util/client.js delete mode 100644 packages/contentstack-bulk-publish/src/util/command-helper.js delete mode 100644 packages/contentstack-bulk-publish/src/util/common-utility.js delete mode 100644 packages/contentstack-bulk-publish/src/util/fs.js delete mode 100644 packages/contentstack-bulk-publish/src/util/generate-bulk-publish-url.js delete mode 100644 packages/contentstack-bulk-publish/src/util/index.js delete mode 100644 packages/contentstack-bulk-publish/src/util/logger.js delete mode 100644 packages/contentstack-bulk-publish/src/util/queue.js delete mode 100644 packages/contentstack-bulk-publish/src/util/retryfailed.js delete mode 100644 packages/contentstack-bulk-publish/src/util/store.js delete mode 100644 packages/contentstack-bulk-publish/test/helpers/helper.js delete mode 100644 packages/contentstack-bulk-publish/test/helpers/init.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/assets/publish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/assets/unpublish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/bulk-publish/cross-publish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/publish-modified.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/publish-non-localized-fields.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/publish-only-unpublished.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/publish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/unpublish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/entries/update-and-publish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/stacks/publish.test.js delete mode 100644 packages/contentstack-bulk-publish/test/unit/commands/stacks/unpublish.test.js diff --git a/package-lock.json b/package-lock.json index ff06f3f16d..ce5b0853e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1701,10 +1701,6 @@ "resolved": "packages/contentstack-branches", "link": true }, - "node_modules/@contentstack/cli-cm-bulk-publish": { - "resolved": "packages/contentstack-bulk-publish", - "link": true - }, "node_modules/@contentstack/cli-cm-clone": { "resolved": "packages/contentstack-clone", "link": true @@ -26385,7 +26381,6 @@ "@contentstack/cli-auth": "~2.0.0-beta.1", "@contentstack/cli-cm-bootstrap": "~2.0.0-beta.3", "@contentstack/cli-cm-branches": "~1.6.1", - "@contentstack/cli-cm-bulk-publish": "~1.10.3", "@contentstack/cli-cm-clone": "~2.0.0-beta.4", "@contentstack/cli-cm-export": "~2.0.0-beta.4", "@contentstack/cli-cm-export-to-csv": "~1.10.1", @@ -26827,6 +26822,7 @@ "packages/contentstack-bulk-publish": { "name": "@contentstack/cli-cm-bulk-publish", "version": "1.10.3", + "extraneous": true, "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.7.0", @@ -26853,37 +26849,6 @@ "node": ">=14.0.0" } }, - "packages/contentstack-bulk-publish/node_modules/@contentstack/cli-config": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/@contentstack/cli-config/-/cli-config-1.15.3.tgz", - "integrity": "sha512-sZlJt2C28ReIZpFcBNkXy41QDZvMhDzpLfD3EjGLZYGD82/qqT/7mhdsOScigu5PXUmhHI1z+5yx/DaAEAkBnQ==", - "license": "MIT", - "dependencies": { - "@contentstack/cli-command": "~1.6.1", - "@contentstack/cli-utilities": "~1.15.0", - "@oclif/core": "^4.3.0", - "@oclif/plugin-help": "^6.2.28", - "lodash": "^4.17.21" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/contentstack-bulk-publish/node_modules/@contentstack/cli-config/node_modules/@contentstack/cli-command": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/@contentstack/cli-command/-/cli-command-1.6.2.tgz", - "integrity": "sha512-h4I484kSYuelqZnwFhKL9IkaYlHbcZzMv3mhpKZBzIgbATMuI0Li+1haJNo+Ao7JqQmzT+a00QNtTHqpNDjngA==", - "license": "MIT", - "dependencies": { - "@contentstack/cli-utilities": "~1.15.0", - "@oclif/core": "^4.3.0", - "@oclif/plugin-help": "^6.2.28", - "contentstack": "^3.25.3" - }, - "engines": { - "node": ">=14.0.0" - } - }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", "version": "2.0.0-beta.4", diff --git a/packages/contentstack-bulk-publish/.editorconfig b/packages/contentstack-bulk-publish/.editorconfig deleted file mode 100644 index beffa3084e..0000000000 --- a/packages/contentstack-bulk-publish/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/packages/contentstack-bulk-publish/.eslintrc b/packages/contentstack-bulk-publish/.eslintrc deleted file mode 100644 index e56091ba65..0000000000 --- a/packages/contentstack-bulk-publish/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "oclif" -} diff --git a/packages/contentstack-bulk-publish/.gitignore b/packages/contentstack-bulk-publish/.gitignore deleted file mode 100644 index 9d9449d87a..0000000000 --- a/packages/contentstack-bulk-publish/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*-debug.log -*-error.log -/.nyc_output -/dist -/tmp -/yarn.lock -logs -coverage -node_modules diff --git a/packages/contentstack-bulk-publish/.mocharc.json b/packages/contentstack-bulk-publish/.mocharc.json deleted file mode 100644 index 50e4a68045..0000000000 --- a/packages/contentstack-bulk-publish/.mocharc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "recursive": true, - "spec": [ - "test/unit/commands/assets/publish.test.js", - "test/unit/commands/assets/unpublish.test.js", - "test/unit/commands/bulk-publish/cross-publish.test.js", - "test/unit/commands/entries/publish.test.js", - "test/unit/commands/entries/unpublish.test.js" - ], - "reporter": "dot", - "timeout": 60000, - "exit": true -} \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/.snyk b/packages/contentstack-bulk-publish/.snyk deleted file mode 100644 index 8c40bf8ed4..0000000000 --- a/packages/contentstack-bulk-publish/.snyk +++ /dev/null @@ -1,10 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.25.1 -# ignores vulnerabilities until expiry date; change duration by modifying expiry date -ignore: - SNYK-JS-TMP-11501554: - - '*': - reason: 'https://contentstack.atlassian.net/browse/IS-5312' - expires: 2025-11-06T14:03:53.4141Z - created: 2025-08-08T14:03:53.4141Z -patch: {} \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/LICENSE b/packages/contentstack-bulk-publish/LICENSE deleted file mode 100644 index ffb4ad010b..0000000000 --- a/packages/contentstack-bulk-publish/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Contentstack - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md deleted file mode 100644 index d1f85c3261..0000000000 --- a/packages/contentstack-bulk-publish/README.md +++ /dev/null @@ -1,1797 +0,0 @@ -# @contentstack/cli-cm-bulk-publish - -It is Contentstack’s CLI plugin to perform bulk publish/unpublish operations on entries and assets in Contentstack. Refer to the [Bulk Publish and Unpublish documentation](https://www.contentstack.com/docs/developers/cli/bulk-publish-and-unpublish) to learn more about its commands. - -[![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE) - - -* [@contentstack/cli-cm-bulk-publish](#contentstackcli-cm-bulk-publish) -* [Usage](#usage) -* [Commands](#commands) - - -# Usage - - -```sh-session -$ npm install -g @contentstack/cli-cm-bulk-publish -$ csdx COMMAND -running command... -$ csdx (--version) -@contentstack/cli-cm-bulk-publish/1.10.3 darwin-arm64 node-v24.12.0 -$ csdx --help [COMMAND] -USAGE - $ csdx COMMAND -... -``` - - -# Commands - - -* [`csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmassetspublish--a-value---retry-failed-value--e-value---folder-uid-value---bulk-publish-value--c-value--y---locales-value---branch-value---delivery-token-value---source-env-value) -* [`csdx cm:assets:unpublish`](#csdx-cmassetsunpublish) -* [`csdx cm:bulk-publish`](#csdx-cmbulk-publish) -* [`csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]`](#csdx-cmentriesupdate-and-publish--a-value---retry-failed-value---bulk-publish-value---content-types-value--t-value--e-value--c-value--y---locales-value---branch-value) -* [`csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmassetspublish--a-value---retry-failed-value--e-value---folder-uid-value---bulk-publish-value--c-value--y---locales-value---branch-value---delivery-token-value---source-env-value) -* [`csdx cm:bulk-publish:clear`](#csdx-cmbulk-publishclear) -* [`csdx cm:bulk-publish:configure`](#csdx-cmbulk-publishconfigure) -* [`csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries] [--include-variants]`](#csdx-cmbulk-publishcross-publish--a-value---retry-failed-value---bulk-publish-value---content-type-value---locales-value---source-env-value---environments-value---delivery-token-value--c-value--y---branch-value---onlyassets---onlyentries---include-variants) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants) -* [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value) -* [`csdx cm:bulk-publish:revert`](#csdx-cmbulk-publishrevert) -* [`csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]`](#csdx-csdx-cmstacksunpublish--a-value--e-value--c-value--y---locale-value---branch-value---retry-failed-value---bulk-unpublish-value---content-type-value---delivery-token-value---only-assets---only-entries) -* [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants) -* [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:unpublish`](#csdx-cmentriesunpublish) -* [`csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]`](#csdx-cmentriesupdate-and-publish--a-value---retry-failed-value---bulk-publish-value---content-types-value--t-value--e-value--c-value--y---locales-value---branch-value) -* [`csdx cm:stacks:publish`](#csdx-cmstackspublish) -* [`csdx cm:stacks:publish-clear-logs`](#csdx-cmstackspublish-clear-logs) -* [`csdx cm:stacks:publish-configure`](#csdx-cmstackspublish-configure) -* [`csdx cm:stacks:publish-revert`](#csdx-cmstackspublish-revert) -* [`csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]`](#csdx-csdx-cmstacksunpublish--a-value--e-value--c-value--y---locale-value---branch-value---retry-failed-value---bulk-unpublish-value---content-type-value---delivery-token-value---only-assets---only-entries) - -## `csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]` - -Publish assets to the specified environments - -``` -USAGE - $ csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish - ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the assets from the - main branch will be published. - -a, --alias= Alias (name) for the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which assets will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --delivery-token= The delivery token of the source environment. - --folder-uid= (optional) The UID of the Assets’ folder from which the assets need to be published. - The default value is cs_root. - --retry-failed= Use this option to retry publishing the failed assets from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - --source-env= Source environment - -DESCRIPTION - Publish assets to the specified environments - The assets command is used to publish assets from the specified stack, to the specified environments - - Note: Environment(s) and Locale(s) are required to execute the command successfully - But, if retryFailed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:assets - -EXAMPLES - General Usage - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:assets:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:assets:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:assets:publish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --source-env - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --stack-api-key flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY] -``` - -_See code: [src/commands/cm/assets/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js)_ - -## `csdx cm:assets:unpublish` - -Unpublish assets from given environment - -``` -USAGE - $ csdx cm:assets:unpublish [-a ] [-k ] [-e ] [-c ] [-y] [--locale ] [--branch - ] [--retry-failed ] [--bulk-unpublish ] [--api-version ] [--delivery-token ] - -FLAGS - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) Path of an optional configuration JSON file containing all the options for a - single run. Refer to the configure command to create a configuration file. - -e, --environment= The name of the environment from where entries/assets need to be unpublished. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the --alias - flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --branch= [default: main] The name of the branch where you want to perform the bulk unpublish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be unpublished. - --bulk-unpublish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --delivery-token= The delivery token of the source environment. - --locale= Locale from which entries/assets will be unpublished, e.g., en-us. - --retry-failed= (optional) Use this option to retry unpublishing the failed entries from the logfile. - Specify the name of the logfile that lists failed unpublish calls. If this option is - used, it will override all other flags. - -DESCRIPTION - Unpublish assets from given environment - The unpublish command is used for unpublishing assets from the given environment - - Note: Environment (Source Environment) and Locale are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - -EXAMPLES - General Usage - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]` - - $ csdx cm:assets:unpublish --config [PATH TO CONFIG FILE] - - $ csdx cm:assets:unpublish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:assets:unpublish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] -``` - -_See code: [src/commands/cm/assets/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js)_ - -## `csdx cm:bulk-publish` - -Bulk Publish script for managing entries and assets - -``` -USAGE - $ csdx cm:bulk-publish - -DESCRIPTION - Bulk Publish script for managing entries and assets -``` - -_See code: [src/commands/cm/bulk-publish/index.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/index.js)_ - -## `csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]` - -Add fields from updated content types to their respective entries - -``` -USAGE - $ csdx cm:bulk-publish:add-fields cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] - [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -t, --contentTypes=... The Contenttypes from which entries will be published. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type ID whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --force Update and publish all entries even if no fields have been added. - --retry-failed= Use this option to retry publishing the failed entries from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - -DESCRIPTION - Add fields from updated content types to their respective entries - The update-and-publish command is used to update existing entries with the updated schema of the respective content - type - - Note: Content types, Environments and Locales are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:add-fields - -EXAMPLES - General Usage - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:update-and-publish --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:update-and-publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:update-and-publish --retry-failed [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --stack-api-key - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] -``` - -## `csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]` - -Publish assets to the specified environments - -``` -USAGE - $ csdx cm:bulk-publish:assets cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] - [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] - [--source-env ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the assets from the - main branch will be published. - -a, --alias= Alias (name) for the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which assets will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --delivery-token= The delivery token of the source environment. - --folder-uid= (optional) The UID of the Assets’ folder from which the assets need to be published. - The default value is cs_root. - --retry-failed= Use this option to retry publishing the failed assets from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - --source-env= Source environment - -DESCRIPTION - Publish assets to the specified environments - The assets command is used to publish assets from the specified stack, to the specified environments - - Note: Environment(s) and Locale(s) are required to execute the command successfully - But, if retryFailed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:assets - -EXAMPLES - General Usage - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:assets:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:assets:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:assets:publish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --source-env - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --stack-api-key flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY] -``` - -## `csdx cm:bulk-publish:clear` - -Clear the log folder - -``` -USAGE - $ csdx cm:bulk-publish:clear [--log-files-count] [-y] - -FLAGS - -y, --yes Delete all files without asking for confirmation - --log-files-count List number of log files - -DESCRIPTION - Clear the log folder - -ALIASES - $ csdx cm:bulk-publish:clear - -EXAMPLES - $ csdx cm:stacks:publish-clear-logs - - $ csdx cm:stacks:publish-clear-logs --log-files-count - - $ csdx cm:stacks:publish-clear-logs --yes - - $ csdx cm:stacks:publish-clear-logs -y -``` - -## `csdx cm:bulk-publish:configure` - -The configure command is used to generate a configuration file for publish scripts. - -``` -USAGE - $ csdx cm:bulk-publish:configure [-a ] [-k ] - -FLAGS - -a, --alias= Name (alias) of the management token you want to use. You must use either the --alias - flag or the --stack-api-key flag. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the --alias - flag. - -DESCRIPTION - The configure command is used to generate a configuration file for publish scripts. - -ALIASES - $ csdx cm:bulk-publish:configure - -EXAMPLES - $ csdx cm:stacks:publish-configure - - $ csdx cm:stacks:publish-configure -a - - $ csdx cm:stacks:publish-configure --alias - - $ csdx cm:stacks:publish-configure --stack-api-key -``` - -## `csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries] [--include-variants]` - -Publish entries and assets from one environment to other environments - -``` -USAGE - $ csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] - [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] - [--branch ] [--onlyAssets] [--onlyEntries] [--include-variants] - -FLAGS - -B, --branch= [default: main] Specify the branch to fetch the content (by default the main branch is - selected) - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -k, --stack-api-key= Stack API key to be used - -y, --yes Agree to process the command with the current configuration - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --content-type=... The Contenttypes from which entries will be published - --delivery-token= The delivery token of the source environment. - --environments=... Destination Environments - --include-variants Include Variants flag will publish all associated variant entries. - --locales= Source locale - --onlyAssets Unpublish only assets - --onlyEntries Unpublish only entries - --retry-failed= (optional) Retry publishing failed entries from the logfile (this flag overrides all - other flags) - --source-env= Source Env - -DESCRIPTION - Publish entries and assets from one environment to other environments - The cross-publish command is used to publish entries and assets from one environment to other environments - - Note: Content Type, Environment, Destination Environment(s) and Locale are required to execute the command - successfully - But, if retryFailed flag is set, then only a logfile is required - - -EXAMPLES - General Usage - - $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]` - - $ csdx cm:bulk-publish:cross-publish --config [PATH TO CONFIG FILE] - - $ csdx cm:bulk-publish:cross-publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:bulk-publish:cross-publish --retry-failed [LOG FILE NAME] - - $ csdx cm:bulk-publish:cross-publish -r [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] - - - - Using --include-variants flag - - $ csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] [--include-variants] -``` - -_See code: [src/commands/cm/bulk-publish/cross-publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js)_ - -## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]` - -Publish entries from multiple contenttypes to multiple environments and locales - -``` -USAGE - $ csdx cm:bulk-publish:entries cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] - [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch - ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the - options for a single run. Refer to the configure command to create a configuration - file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. This flag is - set to true, by default. - --content-types=... The UID of the content type(s) whose entries you want to publish in bulk. In case of - multiple content types, specify the IDs separated by spaces. - --delivery-token= The delivery token of the source environment. - --entry-uid= Entry Uid for publish all associated variant entries. - --include-variants Include Variants flag will publish all associated variant entries with base entry. - --publish-all-content-types (optional) Set it to true to bulk publish entries from all content types. If the - --content-types option is already used, then you cannot use this option. - --retry-failed= (optional) Use this option to retry publishing the failed entries/ assets from the - logfile. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags. - --source-env= Source environment - -DESCRIPTION - Publish entries from multiple contenttypes to multiple environments and locales - The publish command is used to publish entries from the specified content types, to the - specified environments and locales - - Note: Content Types, Environments and Locales are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:entries - -EXAMPLES - General Usage - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish --retry-failed [LOG FILE NAME] - - $ csdx cm:entries:publish -r [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --source-env - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --stack-api-key - - $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --include-variants - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants] - - - - Using --entry-uid and --include-variants - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants] -``` - -## `csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` - -Publish edited entries from a specified content type to the given locales and environments - -``` -USAGE - $ csdx cm:bulk-publish:entry-edits cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] - [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch - ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don't mention the branch name, then by default the entries from main - branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment(s) on which the entries will be published. In case of - multiple environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type(s) whose edited entries you want to publish in bulk. In - case of multiple content types, specify the IDs separated by spaces. - --retry-failed= (optional) Use this option to retry publishing the failed entries/assets from the - logfile. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags - --source-env= The name of the source environment where the entries were initially published. - -DESCRIPTION - Publish edited entries from a specified content type to the given locales and environments - The publish-modified command is used to publish entries from the specified content types, to the - specified environments and locales - - Note: Content type(s), Source Environment, Destination Environment(s) and Locale(s) are required to execute the - command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:entry-edits - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:publish-modified --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-modified -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish-modified --retry-failed [LOG FILE NAME] - - $ csdx cm:entries:publish-modified -r [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --stack-api-key - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY] -``` - -## `csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]` - -Publish non-localized fields for the given content types, from a particular source environment to the specified environments - -``` -USAGE - $ csdx cm:bulk-publish:nonlocalized-field-changes cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] - [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch - ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --retry-failed= Use this option to retry publishing the failed entries from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - --source-env= The name of the source environment. - -DESCRIPTION - Publish non-localized fields for the given content types, from a particular source environment to the specified - environments - The non-localized field changes command is used to publish non-localized field changes from the given content types to - the specified environments - - Note: Content types, Environments and Source Environment are required to execute this command successfully. - But, if retryFailed flag is set, then only a logfile is required - -ALIASES - $ csdx cm:bulk-publish:nonlocalized-field-changes - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]` - - $ csdx cm:entries:publish-non-localized-fields --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-non-localized-fields -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:entries:publish-non-localized-fields --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV] -``` - -## `csdx cm:bulk-publish:revert` - -Revert publish operations by using a log file - -``` -USAGE - $ csdx cm:bulk-publish:revert [--retry-failed ] [--log-file ] - -FLAGS - --log-file= Path of the success logfile of a particular publish action. - --retry-failed= (optional) Use this option to retry publishing the failed entries from the logfile. Specify - the name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - -DESCRIPTION - Revert publish operations by using a log file - The revert command is used to revert all publish operations performed using bulk-publish script. - A log file name is required to execute revert command - - -ALIASES - $ csdx cm:bulk-publish:revert - -EXAMPLES - Using --log-file - - cm:bulk-publish:revert --log-file [LOG FILE NAME] - - - - Using --retry-failed - - cm:bulk-publish:revert --retry-failed [LOG FILE NAME] -``` - -## `csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]` - -Unpublish entries or assets of given content types from the specified environment - -``` -USAGE - $ csdx cm:bulk-publish:unpublish csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] - [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token - ] [--only-assets] [--only-entries] - -FLAGS - -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -e, --environment= Source Environment - -k, --stack-api-key= Stack API key to be used - -l, --locale= Locale filter - -y, --yes Agree to process the command with the current configuration - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's - bulkpublish API will be used to unpublish the entries and assets - --content-type= Content type filter - --delivery-token= The delivery token of the source environment. - --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) - -DESCRIPTION - Unpublish entries or assets of given content types from the specified environment - The unpublish command is used to unpublish entries or assets from given environment - - Environment (Source Environment) and Locale are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - A content type can be specified for unpublishing entries, but if no content-type(s) is/are specified and --only-assets - is not used, - then all entries from all content types will be unpublished from the source environment - - Note: --only-assets can be used to unpublish only assets and --only-entries can be used to unpublish only entries. - (--only-assets and --only-entries cannot be used together at the same time) - - -ALIASES - $ csdx cm:bulk-publish:unpublish - -EXAMPLES - General Usage - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] ----delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]` - - $ csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE] - - $ csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME] - - - - No content type - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] (Will unpublish all entries from all content types and assets from the source environment) - - - - Using --only-assets - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-assets (Will unpublish only assets from the source environment) - - - - Using --only-entries - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, all entries, from the source environment) - - $ csdx cm:stacks:unpublish --contentType [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, (from CONTENT TYPE) from the source environment) - - - - Using --branch flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] -``` - -## `csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` - -Publish unpublished entries from the source environment, to other environments and locales - -``` -USAGE - $ csdx cm:bulk-publish:unpublished-entries cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish - ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] - [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don't mention the branch name, then by default the entries from main - branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -b, --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. It is true, by - default. - -c, --config= (optional) The path of the optional configuration JSON file containing all the - options for a single run. Refer to the configure command to create a configuration - file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].. - --content-types=... The UID of the content type(s) whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --locales= Locale in which entries will be published, e.g., en-us - --retry-failed= (optional) Use this option to retry publishing the failed entries from the logfile. It - is optional. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags. - --source-env= The name of the source environment where the entries were initially published. - -DESCRIPTION - Publish unpublished entries from the source environment, to other environments and locales - The publish-only-unpublished command is used to publish unpublished entries from the source environment, to other - environments and locales - - Note: Content type(s), Source Environment, Destination Environment(s) and Source Locale are required to execute the - command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:unpublished-entries - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] -source-env [SOURCE ENV] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]` - - $ csdx cm:entries:publish-only-unpublished --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-only-unpublished -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish-only-unpublished --retry-failed [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV] - - - - Using --stack-api-key - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV] -``` - -## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]` - -Publish entries from multiple contenttypes to multiple environments and locales - -``` -USAGE - $ csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] - [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token - ] [--source-env ] [--entry-uid ] [--include-variants] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the - options for a single run. Refer to the configure command to create a configuration - file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. This flag is - set to true, by default. - --content-types=... The UID of the content type(s) whose entries you want to publish in bulk. In case of - multiple content types, specify the IDs separated by spaces. - --delivery-token= The delivery token of the source environment. - --entry-uid= Entry Uid for publish all associated variant entries. - --include-variants Include Variants flag will publish all associated variant entries with base entry. - --publish-all-content-types (optional) Set it to true to bulk publish entries from all content types. If the - --content-types option is already used, then you cannot use this option. - --retry-failed= (optional) Use this option to retry publishing the failed entries/ assets from the - logfile. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags. - --source-env= Source environment - -DESCRIPTION - Publish entries from multiple contenttypes to multiple environments and locales - The publish command is used to publish entries from the specified content types, to the - specified environments and locales - - Note: Content Types, Environments and Locales are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:entries - -EXAMPLES - General Usage - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish --retry-failed [LOG FILE NAME] - - $ csdx cm:entries:publish -r [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --source-env - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --stack-api-key - - $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --include-variants - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants] - - - - Using --entry-uid and --include-variants - - $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants] -``` - -_See code: [src/commands/cm/entries/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js)_ - -## `csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` - -Publish edited entries from a specified content type to the given locales and environments - -``` -USAGE - $ csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] - [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don't mention the branch name, then by default the entries from main - branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment(s) on which the entries will be published. In case of - multiple environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type(s) whose edited entries you want to publish in bulk. In - case of multiple content types, specify the IDs separated by spaces. - --retry-failed= (optional) Use this option to retry publishing the failed entries/assets from the - logfile. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags - --source-env= The name of the source environment where the entries were initially published. - -DESCRIPTION - Publish edited entries from a specified content type to the given locales and environments - The publish-modified command is used to publish entries from the specified content types, to the - specified environments and locales - - Note: Content type(s), Source Environment, Destination Environment(s) and Locale(s) are required to execute the - command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:entry-edits - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:publish-modified --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-modified -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish-modified --retry-failed [LOG FILE NAME] - - $ csdx cm:entries:publish-modified -r [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --stack-api-key - - $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY] -``` - -_See code: [src/commands/cm/entries/publish-modified.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js)_ - -## `csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]` - -Publish non-localized fields for the given content types, from a particular source environment to the specified environments - -``` -USAGE - $ csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] - [--content-types ] [-e ] [-c ] [-y] [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --retry-failed= Use this option to retry publishing the failed entries from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - --source-env= The name of the source environment. - -DESCRIPTION - Publish non-localized fields for the given content types, from a particular source environment to the specified - environments - The non-localized field changes command is used to publish non-localized field changes from the given content types to - the specified environments - - Note: Content types, Environments and Source Environment are required to execute this command successfully. - But, if retryFailed flag is set, then only a logfile is required - -ALIASES - $ csdx cm:bulk-publish:nonlocalized-field-changes - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]` - - $ csdx cm:entries:publish-non-localized-fields --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-non-localized-fields -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:entries:publish-non-localized-fields --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV] -``` - -_See code: [src/commands/cm/entries/publish-non-localized-fields.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js)_ - -## `csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` - -Publish unpublished entries from the source environment, to other environments and locales - -``` -USAGE - $ csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] - [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don't mention the branch name, then by default the entries from main - branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -b, --bulk-publish= [default: true] Set this flag to use Contentstack's Bulk Publish APIs. It is true, by - default. - -c, --config= (optional) The path of the optional configuration JSON file containing all the - options for a single run. Refer to the configure command to create a configuration - file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].. - --content-types=... The UID of the content type(s) whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --locales= Locale in which entries will be published, e.g., en-us - --retry-failed= (optional) Use this option to retry publishing the failed entries from the logfile. It - is optional. Specify the name of the logfile that lists failed publish calls. If this - option is used, it will override all other flags. - --source-env= The name of the source environment where the entries were initially published. - -DESCRIPTION - Publish unpublished entries from the source environment, to other environments and locales - The publish-only-unpublished command is used to publish unpublished entries from the source environment, to other - environments and locales - - Note: Content type(s), Source Environment, Destination Environment(s) and Source Locale are required to execute the - command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:unpublished-entries - -EXAMPLES - General Usage - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] -source-env [SOURCE ENV] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]` - - $ csdx cm:entries:publish-only-unpublished --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:publish-only-unpublished -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:publish-only-unpublished --retry-failed [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV] - - - - Using --stack-api-key - - $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV] -``` - -_See code: [src/commands/cm/entries/publish-only-unpublished.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js)_ - -## `csdx cm:entries:unpublish` - -Unpublish entries from the given environment - -``` -USAGE - $ csdx cm:entries:unpublish [-a ] [-k ] [-e ] [-c ] [-y] [--locale ] [--branch - ] [--retry-failed ] [--bulk-unpublish ] [--api-version ] [--content-type ] - [--delivery-token ] [--include-variants] - -FLAGS - -a, --alias= Alias (name) for the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) Path to the configuration JSON file containing all options for a single run. - Refer to the configure command to create a configuration file. - -e, --environment= The name of the environment from where entries/assets need to be unpublished. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the --alias - flag. - -y, --yes Set to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --branch= [default: main] Specify the branch to fetch the content. If not mentioned, the main - branch will be used by default. - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that Contentstack's - Bulk Publish APIs will be used to unpublish the entries. - --content-type= The UID of the content type whose entries you want to unpublish in bulk. - --delivery-token= The delivery token of the source environment. - --include-variants Include Variants flag will unpublish all associated variant entries. - --locale= Locale from which entries/assets will be unpublished, e.g., en-us. - --retry-failed= (optional) Use this option to retry unpublishing the failed entries from the logfile. - Specify the name of the logfile that lists failed unpublish calls. If used, this option - will override all other flags. - -DESCRIPTION - Unpublish entries from the given environment - The unpublish command is used to unpublish entries from the given environment - - Note: Environment (Source Environment) and Locale are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - -EXAMPLES - General Usage - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]` - - $ csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE] - - $ csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] - - - - Using --include-variants flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] --include-variants -``` - -_See code: [src/commands/cm/entries/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js)_ - -## `csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]` - -Add fields from updated content types to their respective entries - -``` -USAGE - $ csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t - ] [-e ] [-c ] [-y] [--locales ] [--branch ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be published. - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which entries will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -t, --contentTypes=... The Contenttypes from which entries will be published. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --content-types=... The UID of the content type ID whose entries you want to publish in bulk. In case of - multiple content types, specify their IDs separated by spaces. - --force Update and publish all entries even if no fields have been added. - --retry-failed= Use this option to retry publishing the failed entries from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - -DESCRIPTION - Add fields from updated content types to their respective entries - The update-and-publish command is used to update existing entries with the updated schema of the respective content - type - - Note: Content types, Environments and Locales are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:add-fields - -EXAMPLES - General Usage - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:entries:update-and-publish --config [PATH TO CONFIG FILE] - - $ csdx cm:entries:update-and-publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed - - $ csdx cm:entries:update-and-publish --retry-failed [LOG FILE NAME] - - - - Using --branch - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --stack-api-key - - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] -``` - -_See code: [src/commands/cm/entries/update-and-publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js)_ - -## `csdx cm:stacks:publish` - -Publish entries and assets to multiple environments and locales - -``` -USAGE - $ csdx cm:stacks:publish - -DESCRIPTION - Publish entries and assets to multiple environments and locales - The publish command is used to publish entries and assets, to the specified environments and locales. - - Note: Content types, Environments and Locales are required to execute the publish entries command successfully. - Note: Environments and Locales are required to execute the publish assets command successfully. - But, if retry-failed flag is set, then only a logfile is required - -EXAMPLES - General Usage - - $ csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file in the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:stacks:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:stacks:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:stacks:publish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --api-version flag - - $ csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --api-version [API VERSION] -``` - -_See code: [src/commands/cm/stacks/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js)_ - -## `csdx cm:stacks:publish-clear-logs` - -Clear the log folder - -``` -USAGE - $ csdx cm:stacks:publish-clear-logs [--log-files-count] [-y] - -FLAGS - -y, --yes Delete all files without asking for confirmation - --log-files-count List number of log files - -DESCRIPTION - Clear the log folder - -ALIASES - $ csdx cm:bulk-publish:clear - -EXAMPLES - $ csdx cm:stacks:publish-clear-logs - - $ csdx cm:stacks:publish-clear-logs --log-files-count - - $ csdx cm:stacks:publish-clear-logs --yes - - $ csdx cm:stacks:publish-clear-logs -y -``` - -_See code: [src/commands/cm/stacks/publish-clear-logs.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-clear-logs.js)_ - -## `csdx cm:stacks:publish-configure` - -The configure command is used to generate a configuration file for publish scripts. - -``` -USAGE - $ csdx cm:stacks:publish-configure [-a ] [-k ] - -FLAGS - -a, --alias= Name (alias) of the management token you want to use. You must use either the --alias - flag or the --stack-api-key flag. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the --alias - flag. - -DESCRIPTION - The configure command is used to generate a configuration file for publish scripts. - -ALIASES - $ csdx cm:bulk-publish:configure - -EXAMPLES - $ csdx cm:stacks:publish-configure - - $ csdx cm:stacks:publish-configure -a - - $ csdx cm:stacks:publish-configure --alias - - $ csdx cm:stacks:publish-configure --stack-api-key -``` - -_See code: [src/commands/cm/stacks/publish-configure.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js)_ - -## `csdx cm:stacks:publish-revert` - -Revert publish operations by using a log file - -``` -USAGE - $ csdx cm:stacks:publish-revert [--retry-failed ] [--log-file ] - -FLAGS - --log-file= Path of the success logfile of a particular publish action. - --retry-failed= (optional) Use this option to retry publishing the failed entries from the logfile. Specify - the name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - -DESCRIPTION - Revert publish operations by using a log file - The revert command is used to revert all publish operations performed using bulk-publish script. - A log file name is required to execute revert command - - -ALIASES - $ csdx cm:bulk-publish:revert - -EXAMPLES - Using --log-file - - cm:bulk-publish:revert --log-file [LOG FILE NAME] - - - - Using --retry-failed - - cm:bulk-publish:revert --retry-failed [LOG FILE NAME] -``` - -_See code: [src/commands/cm/stacks/publish-revert.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-revert.js)_ - -## `csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]` - -Unpublish entries or assets of given content types from the specified environment - -``` -USAGE - $ csdx cm:stacks:unpublish csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] - [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token - ] [--only-assets] [--only-entries] - -FLAGS - -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -e, --environment= Source Environment - -k, --stack-api-key= Stack API key to be used - -l, --locale= Locale filter - -y, --yes Agree to process the command with the current configuration - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's - bulkpublish API will be used to unpublish the entries and assets - --content-type= Content type filter - --delivery-token= The delivery token of the source environment. - --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) - -DESCRIPTION - Unpublish entries or assets of given content types from the specified environment - The unpublish command is used to unpublish entries or assets from given environment - - Environment (Source Environment) and Locale are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - - A content type can be specified for unpublishing entries, but if no content-type(s) is/are specified and --only-assets - is not used, - then all entries from all content types will be unpublished from the source environment - - Note: --only-assets can be used to unpublish only assets and --only-entries can be used to unpublish only entries. - (--only-assets and --only-entries cannot be used together at the same time) - - -ALIASES - $ csdx cm:bulk-publish:unpublish - -EXAMPLES - General Usage - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] ----delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]` - - $ csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE] - - $ csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME] - - - - No content type - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] (Will unpublish all entries from all content types and assets from the source environment) - - - - Using --only-assets - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-assets (Will unpublish only assets from the source environment) - - - - Using --only-entries - - $ csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, all entries, from the source environment) - - $ csdx cm:stacks:unpublish --contentType [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, (from CONTENT TYPE) from the source environment) - - - - Using --branch flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] -``` - -_See code: [src/commands/cm/stacks/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js)_ - diff --git a/packages/contentstack-bulk-publish/bin/run.cmd b/packages/contentstack-bulk-publish/bin/run.cmd deleted file mode 100644 index 968fc30758..0000000000 --- a/packages/contentstack-bulk-publish/bin/run.cmd +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -node "%~dp0\run" %* diff --git a/packages/contentstack-bulk-publish/bin/run.js b/packages/contentstack-bulk-publish/bin/run.js deleted file mode 100755 index 8baf302391..0000000000 --- a/packages/contentstack-bulk-publish/bin/run.js +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env node - -// eslint-disable-next-line unicorn/prefer-top-level-await -(async () => { - const oclif = await import('@oclif/core'); - await oclif.execute({ development: false, dir: __dirname }); -})(); diff --git a/packages/contentstack-bulk-publish/copyLogs.js b/packages/contentstack-bulk-publish/copyLogs.js deleted file mode 100644 index 73d2585855..0000000000 --- a/packages/contentstack-bulk-publish/copyLogs.js +++ /dev/null @@ -1,36 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const logFileDir = 'logs'; -const dummyDir = 'test/dummy/'; - -import { sanitizePath } from '@contentstack/cli-utilities'; - -if (!fs.existsSync(path.join(__dirname, logFileDir))) { - fs.mkdirSync(path.join(__dirname, logFileDir)); -} - -const logs = [ - '1587758242717.bulk-publish-entries.success', - '1587758242717.publish-entries', - '1587758242717.publish-entries.success', - '1587758242717.publishentries.success', - '1587758242717.publish-entries.txt', - '1587758242718.bulk-publish-entries.success', - '1587758242718.publish-entries.success', - '1587758242719.publish-entries.success', - '1587956283100.publish-assets.success', - '1587758242717.bulk-add-fields.error', - '1587758242717.bulk-cross-publish.error', - '1587758242717.bulk-nonlocalized-field-changes.error', - '1587758242717.bulk-publish-assets.error', - '1587758242717.bulk-publish-draft.error', - '1587758242717.bulk-publish-edits.error', - '1587758242717.bulk-publish-entries.error', - '1587758242717.bulk-unpublish.error', - '1587758242717.revert.error', -]; - -logs.forEach((element) => { - fs.createReadStream(path.join(__dirname, dummyDir, sanitizePath(element))).pipe(fs.createWriteStream(path.join(__dirname, logFileDir, sanitizePath(element)))); -}); diff --git a/packages/contentstack-bulk-publish/package.json b/packages/contentstack-bulk-publish/package.json deleted file mode 100644 index 7ef08e0846..0000000000 --- a/packages/contentstack-bulk-publish/package.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "@contentstack/cli-cm-bulk-publish", - "description": "Contentstack CLI plugin for bulk publish actions", - "version": "1.10.3", - "author": "Contentstack", - "bugs": "https://github.com/contentstack/cli/issues", - "dependencies": { - "@contentstack/cli-command": "~1.7.0", - "@contentstack/cli-config": "~1.15.3", - "@contentstack/cli-utilities": "~1.15.0", - "@oclif/core": "^4.3.0", - "@oclif/plugin-help": "^6.2.28", - "chalk": "^4.1.2", - "dotenv": "^16.5.0", - "inquirer": "8.2.7", - "lodash": "^4.17.21", - "winston": "^3.17.0" - }, - "devDependencies": { - "@oclif/test": "^4.1.13", - "chai": "^4.5.0", - "eslint": "^8.57.1", - "eslint-config-oclif": "^6.0.62", - "mocha": "^10.8.2", - "nyc": "^15.1.0", - "oclif": "^4.17.46" - }, - "engines": { - "node": ">=14.0.0" - }, - "files": [ - "/npm-shrinkwrap.json", - "/oclif.manifest.json", - "/src", - "/yarn.lock" - ], - "homepage": "https://github.com/contentstack/cli", - "keywords": [ - "contentstack", - "cli", - "plugin" - ], - "license": "MIT", - "oclif": { - "commands": "./src/commands", - "bin": "csdx", - "hooks": { - "validateConfig": "./src/hooks/config.js" - }, - "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-bulk-publish/<%- commandPath %>" - }, - "csdxConfig": { - "expiredCommands": { - "cm:bulk-publish:configure": "csdx cm:stacks:publish-configure", - "cm:bulk-publish:clear": "csdx cm:stacks:publish-clear-logs", - "cm:bulk-publish:revert": "csdx cm:stacks:publish-revert", - "cm:bulk-publish:assets": "csdx cm:assets:publish", - "cm:bulk-publish:add-fields": "csdx cm:entries:update-and-publish", - "cm:bulk-publish:unpublished-entries": "csdx cm:entries:publish-only-unpublished", - "cm:bulk-publish:entries": "csdx cm:entries:publish", - "cm:bulk-publish:nonlocalized-field-changes": "csdx cm:entries:publish-non-localized-fields", - "cm:bulk-publish:unpublish": "csdx cm:stacks:unpublish or cm:entries:unpublish or cm:assets:unpublish", - "cm:bulk-publish:cross-publish": "csdx cm:entries:publish or csdx cm:assets:publish with source-env flag", - "cm:bulk-publish:entry-edits": "csdx cm:entries:publish-modified" - }, - "shortCommandName": { - "cm:assets:publish": "PB-A", - "cm:assets:unpublish": "UNPB-A", - "cm:entries:publish-modified": "PB-MF-E", - "cm:entries:publish-non-localized-fields": "PB-NLCF-E", - "cm:entries:publish-only-unpublished": "PB-UNPB-E", - "cm:entries:publish": "PB-E", - "cm:entries:unpublish": "UNPB-E", - "cm:entries:update-and-publish": "PB-UPD-E", - "cm:stacks:publish-clear-logs": "PB-CLRLG-S", - "cm:stacks:publish-configure": "PB-CNF-S", - "cm:stacks:publish-revert": "PB-RVT-S", - "cm:bulk-publish:unpublish": "O-BP-UNPB", - "cm:bulk-publish:entry-edits": "O-BP-EE", - "cm:bulk-publish:nonlocalized-field-changes": "O-BP-NLCF", - "cm:bulk-publish:clear": "O-BP-CLR", - "cm:bulk-publish:assets": "O-BP-A", - "cm:bulk-publish:cross-publish": "O-BP-CRS", - "cm:bulk-publish:entries": "O-BP-E", - "cm:bulk-publish:unpublished-entries": "O-BP-UNPB-E", - "cm:bulk-publish:add-fields": "O-BP-ADFLD", - "cm:bulk-publish:revert": "O-BP-RVT", - "cm:bulk-publish:configure": "O-BP-CNF" - } - }, - "repository": "https://github.com/contentstack/cli", - "scripts": { - "postpack": "rm -f oclif.manifest.json", - "prepack": "oclif manifest && oclif readme", - "test:unit": "mocha --reporter spec --forbid-only \"test/unit/**/*.test.js\"", - "posttest": "eslint .", - "version": "oclif readme && git add README.md", - "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo" - } -} diff --git a/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js deleted file mode 100644 index a032678c03..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js +++ /dev/null @@ -1,269 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities'); -const { start: startPublish } = require('../../../producer/publish-assets'); -const { start: startCrossPublish } = require('../../../producer/cross-publish'); -const store = require('../../../util/store.js'); -const { cliux } = require('@contentstack/cli-utilities'); -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class AssetsPublishCommand extends Command { - async run() { - const { flags: assetsFlags } = await this.parse(AssetsPublishCommand); - assetsFlags.retryFailed = assetsFlags['retry-failed'] || assetsFlags.retryFailed || false; - assetsFlags.folderUid = assetsFlags['folder-uid'] || assetsFlags.folderUid; - assetsFlags.bulkPublish = assetsFlags['bulk-publish'] || assetsFlags.bulkPublish; - assetsFlags.apiVersion = assetsFlags['api-version'] || '3'; // setting default value for apiVersion - delete assetsFlags['api-version']; - delete assetsFlags['retry-failed']; - delete assetsFlags['folder-uid']; - delete assetsFlags['bulk-publish']; - - let updatedFlags; - try { - const storeConfigKeyName = assetsFlags['source-env'] ? 'cross_env_publish' : 'publish_assets'; - updatedFlags = assetsFlags.config ? store.updateMissing(storeConfigKeyName, assetsFlags) : assetsFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - host: this.cmaHost, - cda: this.cdaHost, - branch: assetsFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - if (updatedFlags.folderUid === undefined) { - // set default value for folderUid - updatedFlags.folderUid = 'cs_root'; - } - stack = await getStack(config); - } - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - const publishFunction = async (func) => { - if (!updatedFlags.retryFailed) { - try { - await func(updatedFlags, stack, config); - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - try { - await func(updatedFlags); - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } - }; - - if (updatedFlags['source-env']) { - updatedFlags.deliveryToken = updatedFlags['delivery-token']; - updatedFlags.destEnv = updatedFlags.environments; - updatedFlags.environment = updatedFlags['source-env']; - updatedFlags.onlyAssets = true; - if (updatedFlags.locales instanceof Array) { - updatedFlags.locales.forEach((locale) => { - updatedFlags.locale = locale; - publishFunction(startCrossPublish); - }); - } else { - updatedFlags.locale = locales; - publishFunction(startCrossPublish); - } - } else { - publishFunction(startPublish); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.error('Confirmation failed.'); - } - } else { - this.error('Validation failed.'); - } - } - - validate({ environments, retryFailed, locales, 'source-env': sourceEnv, 'delivery-token': deliveryToken }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (sourceEnv && !deliveryToken) { - this.error('Specify the source environment delivery token. Run --help for more details.', { exit: 2 }); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (!locales || locales.length === 0) { - missing.push('Locales'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} are required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -AssetsPublishCommand.description = `Publish assets to the specified environments -The assets command is used to publish assets from the specified stack, to the specified environments - -Note: Environment(s) and Locale(s) are required to execute the command successfully -But, if retryFailed flag is set, then only a logfile is required -`; - -AssetsPublishCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) for the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - required: false, - }), - 'retry-failed': flags.string({ - description: - 'Use this option to retry publishing the failed assets from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - environments: flags.string({ - char: 'e', - description: - 'The name of the environment on which entries will be published. In case of multiple environments, specify their names separated by spaces.', - multiple: true, - }), - 'folder-uid': flags.string({ - description: - '(optional) The UID of the Assets’ folder from which the assets need to be published. The default value is cs_root.', - exclusive: ['source-env'], - }), - 'bulk-publish': flags.string({ - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - }), - config: flags.string({ - char: 'c', - description: - '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - locales: flags.string({ - char: 'l', - description: - 'Locales in which assets will be published, e.g., en-us. In the case of multiple locales, specify the codes separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: - 'The name of the branch where you want to perform the bulk publish operation. If you don’t mention the branch name, then by default the assets from the main branch will be published.', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), - - // To be deprecated - retryFailed: flags.string({ - char: 'r', - description: 'Retry publishing failed assets from the logfile (optional, will override all other flags).', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - folderUid: flags.string({ - char: 'u', - description: '(default: cs_root) Folder-uid from where the assets will be published.', - hidden: true, - parse: printFlagDeprecation(['-u', '--folderUid'], ['--folder-uid']), - exclusive: ['source-env'], - }), - bulkPublish: flags.string({ - char: 'b', - description: - "By default this flag is set as true. It indicates that Contentstack's bulk publish API will be used to publish the entries.", - default: 'true', - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']), - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - 'delivery-token': flags.string({ description: 'The delivery token of the source environment.' }), - 'source-env': flags.string({ description: 'Source environment' }), - 'content-types': flags.string({ description: 'Content types', hidden: true, multiple: true }), -}; - -AssetsPublishCommand.examples = [ - 'General Usage', - 'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', - 'csdx cm:assets:publish --config [PATH TO CONFIG FILE]', - 'csdx cm:assets:publish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:assets:publish --retry-failed [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', - '', - 'Using --source-env', - 'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --stack-api-key flag', - 'csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY]', -]; - -AssetsPublishCommand.aliases = ['cm:bulk-publish:assets']; - -AssetsPublishCommand.usage = - 'cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]'; - -module.exports = AssetsPublishCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js b/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js deleted file mode 100644 index 75aa85d142..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js +++ /dev/null @@ -1,202 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable node/no-extraneous-require */ -const { Command } = require('@contentstack/cli-command'); -const { cliux, flags, isAuthenticated } = require('@contentstack/cli-utilities'); -const { start } = require('../../../producer/unpublish'); -const store = require('../../../util/store.js'); -const configKey = 'Unpublish'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class UnpublishCommand extends Command { - async run() { - const { flags: unpublishFlags } = await this.parse(UnpublishCommand); - unpublishFlags.retryFailed = unpublishFlags['retry-failed'] || unpublishFlags.retryFailed || false; - unpublishFlags.bulkUnpublish = unpublishFlags['bulk-unpublish'] || unpublishFlags.bulkUnpublish; - unpublishFlags.deliveryToken = unpublishFlags['delivery-token'] || unpublishFlags.deliveryToken; - unpublishFlags.apiVersion = unpublishFlags['api-version'] || '3'; - unpublishFlags.onlyAssets = true; - unpublishFlags.onlyEntries = false; - delete unpublishFlags['api-version']; - delete unpublishFlags['retry-failed']; - delete unpublishFlags['bulk-unpublish']; - delete unpublishFlags['delivery-token']; - - let updatedFlags; - try { - updatedFlags = unpublishFlags.config ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - host: this.cmaHost, - cda: this.cdaHost, - branch: unpublishFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; - stack = await getStack(config); - } - if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { - this.error('A delivery token is required to execute this command.', { exit: 2 }); - } - - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ environment, retryFailed, locale }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!environment) { - missing.push('Environment'); - } - - // Adding !onlyAssets because if, onlyAssets is set to true, that means only assets are going to be unpublished. - // Then locale won't be necessary (turns out that this is not the case) - // if (!locale && !onlyAssets) { - // missing.push('Locale') - // } - - // Locales apply to assets as well - if (!locale) { - missing.push('Locale'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} is required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -UnpublishCommand.description = `Unpublish assets from given environment -The unpublish command is used for unpublishing assets from the given environment - -Note: Environment (Source Environment) and Locale are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required`; - -UnpublishCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - required: false, - }), - environment: flags.string({ - char: 'e', - description: 'The name of the environment from where entries/assets need to be unpublished.', - }), - config: flags.string({ - char: 'c', - description: - '(optional) Path of an optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - locale: flags.string({ - description: 'Locale from which entries/assets will be unpublished, e.g., en-us.', - }), - branch: flags.string({ - default: 'main', - description: - 'The name of the branch where you want to perform the bulk unpublish operation. If you don’t mention the branch name, then by default the content from the main branch will be unpublished.', - }), - 'retry-failed': flags.string({ - description: - '(optional) Use this option to retry unpublishing the failed entries from the logfile. Specify the name of the logfile that lists failed unpublish calls. If this option is used, it will override all other flags.', - }), - 'bulk-unpublish': flags.string({ - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - 'delivery-token': flags.string({ - description: 'The delivery token of the source environment.', - }), -}; - -UnpublishCommand.examples = [ - 'General Usage', - 'csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]`', - 'csdx cm:assets:unpublish --config [PATH TO CONFIG FILE]', - 'csdx cm:assets:unpublish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:assets:unpublish --retry-failed [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key flag', - 'csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', -]; - -module.exports = UnpublishCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js b/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js deleted file mode 100644 index 5ca4af0315..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js +++ /dev/null @@ -1,295 +0,0 @@ -/* eslint-disable node/no-extraneous-require */ -const { Command } = require('@contentstack/cli-command'); -const { cliux, printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities'); -const { start } = require('../../../producer/cross-publish'); -const store = require('../../../util/store.js'); -const configKey = 'cross_env_publish'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class CrossPublishCommand extends Command { - async run() { - const { flags: _flags } = await this.parse(CrossPublishCommand); - const crossPublishFlags = this.flagsAdapter(_flags || {}); - let updatedFlags; - try { - updatedFlags = crossPublishFlags.config ? store.updateMissing(configKey, crossPublishFlags) : crossPublishFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - host: this.cmaHost, - cda: this.cdaHost, - branch: crossPublishFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - updatedFlags.includeVariants = updatedFlags.includeVariants === false ? false : true; - stack = await getStack(config); - } - - if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { - this.error('A delivery token is required to execute this command.', { exit: 2 }); - } - - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ environment, retryFailed, destEnv, onlyAssets, contentType, onlyEntries, locale }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (onlyAssets && onlyEntries) { - this.error( - `The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default`, - ); - } - - if (onlyAssets && contentType) { - this.error( - `Specifying content-type and onlyAssets together will have unexpected results. Please do not use these 2 flags together. Thank you.`, - ); - } - - if (!environment) { - missing.push('Environment'); - } - - if (!destEnv) { - missing.push('Destination Environment'); - } - - if (!locale) { - missing.push('Locale'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} is required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } - - flagsAdapter(_flags) { - if ('content-type' in _flags) { - _flags.contentTypes = _flags['content-type']; - delete _flags['content-type']; - } - if ('locales' in _flags) { - _flags.locale = _flags.locales; - delete _flags['locales']; - } - if ('retry-failed' in _flags) { - _flags.retryFailed = _flags['retry-failed']; - delete _flags['retry-failed']; - } - if ('bulk-publish' in _flags) { - _flags.bulkPublish = _flags['bulk-publish']; - delete _flags['bulk-publish']; - } - if ('api-version' in _flags) { - _flags.apiVersion = _flags['api-version'] || '3'; - delete _flags['api-version']; - } - if ('source-env' in _flags) { - _flags.environment = _flags['source-env']; - delete _flags['source-env']; - } - if ('environments' in _flags) { - _flags.destEnv = _flags['environments']; - delete _flags['environments']; - } - if ('delivery-token' in _flags) { - _flags.deliveryToken = _flags['delivery-token']; - delete _flags['delivery-token']; - } - if ('include-variants' in _flags) { - _flags.includeVariants = _flags['include-variants']; - delete _flags['include-variants']; - } - return _flags; - } -} - -CrossPublishCommand.description = `Publish entries and assets from one environment to other environments -The cross-publish command is used to publish entries and assets from one environment to other environments - -Note: Content Type, Environment, Destination Environment(s) and Locale are required to execute the command successfully -But, if retryFailed flag is set, then only a logfile is required -`; - -CrossPublishCommand.flags = { - alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'Stack API key to be used', - required: false, - }), - retryFailed: flags.string({ - char: 'r', - description: '(optional) Retry publishing failed entries from the logfile (this flag overrides all other flags)', - hidden: true, - parse: printFlagDeprecation(['--retryFailed', '-r'], ['--retry-failed']), - }), - 'retry-failed': flags.string({ - description: '(optional) Retry publishing failed entries from the logfile (this flag overrides all other flags)', - }), - bulkPublish: flags.string({ - char: 'b', - hidden: true, - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - parse: printFlagDeprecation(['--bulkPublish', '-b'], ['--bulk-publish']), - }), - 'bulk-publish': flags.string({ - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - contentType: flags.string({ - char: 't', - description: 'The Content-Types from which entries need to be published', - multiple: true, - hidden: true, - parse: printFlagDeprecation(['--contentType', '-t'], ['--content-type']), - }), - 'content-type': flags.string({ - description: 'The Contenttypes from which entries will be published', - multiple: true, - }), - locale: flags.string({ - hidden: true, - char: 'l', - description: 'Source locale', - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - locales: flags.string({ - description: 'Source locale', - }), - environment: flags.string({ - char: 'e', - description: 'Source Environment', - hidden: true, - parse: printFlagDeprecation(['--environment', '-e'], ['--source-env']), - }), - 'source-env': flags.string({ - description: 'Source Env', - }), - destEnv: flags.string({ - char: 'd', - description: 'Destination Environments', - multiple: true, - hidden: true, - parse: printFlagDeprecation(['--destEnv'], ['--environments']), - }), - environments: flags.string({ - description: 'Destination Environments', - multiple: true, - }), - deliveryToken: flags.string({ - char: 'x', - description: 'The delivery token of the source environment.', - hidden: true, - parse: printFlagDeprecation(['--deliveryToken', '-x'], ['--delivery-token']), - }), - 'delivery-token': flags.string({ - description: 'The delivery token of the source environment.', - }), - config: flags.string({ char: 'c', description: 'Path to the config file' }), - yes: flags.boolean({ char: 'y', description: 'Agree to process the command with the current configuration' }), - branch: flags.string({ - char: 'B', - default: 'main', - description: 'Specify the branch to fetch the content (by default the main branch is selected)', - parse: printFlagDeprecation(['-B']), - }), - onlyAssets: flags.boolean({ description: 'Unpublish only assets', default: false }), - onlyEntries: flags.boolean({ description: 'Unpublish only entries', default: false }), - 'include-variants': flags.boolean({ - description: 'Include Variants flag will publish all associated variant entries.', - default: false, - }), -}; - -CrossPublishCommand.examples = [ - 'General Usage', - 'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`', - 'csdx cm:bulk-publish:cross-publish --config [PATH TO CONFIG FILE]', - 'csdx cm:bulk-publish:cross-publish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:bulk-publish:cross-publish --retry-failed [LOG FILE NAME]', - 'csdx cm:bulk-publish:cross-publish -r [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] -a [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key flag', - 'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --include-variants flag', - 'csdx cm:bulk-publish:cross-publish --content-type [CONTENT TYPE] --source-env [SOURCE ENV] --environments [DESTINATION ENVIRONMENT] --locales [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] [--include-variants]', - '', -]; - -CrossPublishCommand.usage = `cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries] [--include-variants]`; - -module.exports = CrossPublishCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/index.js b/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/index.js deleted file mode 100644 index dc188241e6..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/index.js +++ /dev/null @@ -1,14 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); - -class HelloCommand extends Command { - async run() { - this.log('Please run `csdx cm:bulk-publish --help` to view help section'); - } -} - -HelloCommand.description = `Bulk Publish script for managing entries and assets -`; - -HelloCommand.flags = {}; - -module.exports = HelloCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js deleted file mode 100644 index 7d93ffbd55..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js +++ /dev/null @@ -1,241 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); -const { start } = require('../../../producer/publish-edits'); -const store = require('../../../util/store.js'); -// eslint-disable-next-line node/no-extraneous-require -const { cliux } = require('@contentstack/cli-utilities'); -const configKey = 'publish_edits_on_env'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class PublishModifiedCommand extends Command { - async run() { - const { flags: entryEditsFlags } = await this.parse(PublishModifiedCommand); - entryEditsFlags.retryFailed = entryEditsFlags['retry-failed'] || entryEditsFlags.retryFailed || false; - entryEditsFlags.contentTypes = entryEditsFlags['content-types'] || entryEditsFlags.contentTypes; - entryEditsFlags.bulkPublish = entryEditsFlags['bulk-publish'] || entryEditsFlags.bulkPublish; - entryEditsFlags.sourceEnv = entryEditsFlags['source-env'] || entryEditsFlags.sourceEnv; - entryEditsFlags.apiVersion = entryEditsFlags['api-version'] || '3'; - delete entryEditsFlags['api-version']; - delete entryEditsFlags['retry-failed']; - delete entryEditsFlags['content-types']; - delete entryEditsFlags['bulk-publish']; - delete entryEditsFlags['source-env']; - - let updatedFlags; - try { - updatedFlags = entryEditsFlags.config ? store.updateMissing(configKey, entryEditsFlags) : entryEditsFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: entryEditsFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; - stack = await getStack(config); - } - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ contentTypes, environments, sourceEnv, locales, retryFailed }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!contentTypes || contentTypes.length === 0) { - missing.push('Content Types'); - } - - if (!sourceEnv || sourceEnv.length === 0) { - missing.push('SourceEnv'); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (!locales || locales.length === 0) { - missing.push('Locales'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} are required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -PublishModifiedCommand.description = `Publish edited entries from a specified content type to the given locales and environments -The publish-modified command is used to publish entries from the specified content types, to the -specified environments and locales - -Note: Content type(s), Source Environment, Destination Environment(s) and Locale(s) are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required -`; - -PublishModifiedCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - required: false, - }), - retryFailed: flags.string({ - char: 'r', - description: - '(optional) Use this option to retry publishing the failed entries/assets from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - 'retry-failed': flags.string({ - description: - '(optional) Use this option to retry publishing the failed entries/assets from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags', - }), - bulkPublish: flags.string({ - char: 'b', - description: "Set this flag to use Contentstack\'s Bulk Publish APIs. It is true, by default.", - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']), - }), - 'bulk-publish': flags.string({ - description: "Set this flag to use Contentstack\'s Bulk Publish APIs. It is true, by default.", - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - sourceEnv: flags.string({ - char: 's', - description: 'The name of the source environment where the entries were initially published.', - hidden: true, - parse: printFlagDeprecation(['-s', '--sourceEnv'], ['--source-env']), - }), - 'source-env': flags.string({ - description: 'The name of the source environment where the entries were initially published.', - }), - contentTypes: flags.string({ - char: 't', - description: - 'The UID of the content type(s) whose edited entries you want to publish in bulk. In case of multiple content types, specify the IDs separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']), - hidden: true, - }), - 'content-types': flags.string({ - description: - 'The UID of the content type(s) whose edited entries you want to publish in bulk. In case of multiple content types, specify the IDs separated by spaces.', - multiple: true, - }), - locales: flags.string({ - char: 'l', - description: - 'Locales in which entries will be published, e.g., en-us. In the case of multiple locales, specify the codes separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - environments: flags.string({ - char: 'e', - description: - 'The name of the environment(s) on which the entries will be published. In case of multiple environments, specify their names separated by spaces.', - multiple: true, - }), - config: flags.string({ - char: 'c', - description: - '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: - "The name of the branch where you want to perform the bulk publish operation. If you don't mention the branch name, then by default the entries from main branch will be published.", - parse: printFlagDeprecation(['-B'], ['--branch']), - }), -}; - -PublishModifiedCommand.examples = [ - 'General Usage', - 'csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', - 'csdx cm:entries:publish-modified --config [PATH TO CONFIG FILE]', - 'csdx cm:entries:publish-modified -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed', - 'csdx cm:entries:publish-modified --retry-failed [LOG FILE NAME]', - 'csdx cm:entries:publish-modified -r [LOG FILE NAME]', - '', - 'Using --branch', - 'csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key', - 'csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY]', -]; - -PublishModifiedCommand.aliases = ['cm:bulk-publish:entry-edits']; - -PublishModifiedCommand.usage = - 'cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]'; - -module.exports = PublishModifiedCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js deleted file mode 100644 index 2551f75514..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js +++ /dev/null @@ -1,237 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); -const { start } = require('../../../producer/nonlocalized-field-changes'); -const store = require('../../../util/store.js'); -const { cliux } = require('@contentstack/cli-utilities'); -const configKey = 'nonlocalized_field_changes'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -const { printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); -let config; - -class NonlocalizedFieldChangesCommand extends Command { - async run() { - const { flags: nonlocalizedFieldChangesFlags } = await this.parse(NonlocalizedFieldChangesCommand); - nonlocalizedFieldChangesFlags.retryFailed = - nonlocalizedFieldChangesFlags['retry-failed'] || nonlocalizedFieldChangesFlags.retryFailed || false; - nonlocalizedFieldChangesFlags.bulkPublish = - nonlocalizedFieldChangesFlags['bulk-publish'] || nonlocalizedFieldChangesFlags.bulkPublish; - nonlocalizedFieldChangesFlags.sourceEnv = - nonlocalizedFieldChangesFlags['source-env'] || nonlocalizedFieldChangesFlags.sourceEnv; - nonlocalizedFieldChangesFlags.contentTypes = - nonlocalizedFieldChangesFlags['content-types'] || nonlocalizedFieldChangesFlags.contentTypes; - nonlocalizedFieldChangesFlags.apiVersion = nonlocalizedFieldChangesFlags['api-version'] || '3'; - - delete nonlocalizedFieldChangesFlags['api-version']; - delete nonlocalizedFieldChangesFlags['retry-failed']; - delete nonlocalizedFieldChangesFlags['bulk-publish']; - delete nonlocalizedFieldChangesFlags['source-env']; - delete nonlocalizedFieldChangesFlags['content-types']; - - let updatedFlags; - try { - updatedFlags = nonlocalizedFieldChangesFlags.config - ? store.updateMissing(configKey, nonlocalizedFieldChangesFlags) - : nonlocalizedFieldChangesFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: nonlocalizedFieldChangesFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - stack = await getStack(config); - } - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ contentTypes, environments, sourceEnv, retryFailed }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!contentTypes || contentTypes.length === 0) { - missing.push('Content Types'); - } - - if (!sourceEnv) { - missing.push('SourceEnv'); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} are required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -NonlocalizedFieldChangesCommand.description = `Publish non-localized fields for the given content types, from a particular source environment to the specified environments -The non-localized field changes command is used to publish non-localized field changes from the given content types to the specified environments - -Note: Content types, Environments and Source Environment are required to execute this command successfully. -But, if retryFailed flag is set, then only a logfile is required`; - -NonlocalizedFieldChangesCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - required: false, - }), - 'retry-failed': flags.string({ - description: - 'Use this option to retry publishing the failed entries from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - 'bulk-publish': flags.string({ - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - }), - 'source-env': flags.string({ - description: 'The name of the source environment.', - }), - 'content-types': flags.string({ - description: - 'The UID of the content type whose entries you want to publish in bulk. In case of multiple content types, specify their IDs separated by spaces.', - multiple: true, - }), - environments: flags.string({ - char: 'e', - description: - 'The name of the environment on which entries will be published. In case of multiple environments, specify their names separated by spaces.', - multiple: true, - }), - config: flags.string({ - char: 'c', - description: - '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: - 'The name of the branch where you want to perform the bulk publish operation. If you don’t mention the branch name, then by default the content from the main branch will be published.', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), - - // To be deprecated - retryFailed: flags.string({ - char: 'r', - description: 'Retry publishing failed entries from the logfile.', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - bulkPublish: flags.string({ - char: 'b', - description: - "This flag is set to true by default. It indicates that Contentstack's bulk publish API will be used to publish the entries.", - default: 'true', - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']), - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - sourceEnv: flags.string({ - char: 's', - description: 'Source Environment', - hidden: true, - parse: printFlagDeprecation(['-s', '--sourceEnv'], ['--source-env']), - }), - contentTypes: flags.string({ - char: 't', - description: 'The content types from which entries will be published.', - multiple: true, - hidden: true, - parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']), - }), -}; - -NonlocalizedFieldChangesCommand.examples = [ - 'General Usage', - 'csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`', - 'csdx cm:entries:publish-non-localized-fields --config [PATH TO CONFIG FILE]', - 'csdx cm:entries:publish-non-localized-fields -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:entries:publish-non-localized-fields --retry-failed [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key flag', - 'csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV]', -]; - -NonlocalizedFieldChangesCommand.aliases = ['cm:bulk-publish:nonlocalized-field-changes']; - -NonlocalizedFieldChangesCommand.usage = - 'cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]'; - -module.exports = NonlocalizedFieldChangesCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js deleted file mode 100644 index 57577a68a2..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); -const { publishOnlyUnpublishedService } = require('../../../services/publish-only-unpublished'); - -class PublishOnlyUnpublished extends Command { - async run() { - try { - await publishOnlyUnpublishedService.apply(this, [PublishOnlyUnpublished]); - } catch (error) { - this.error(error?.message || error, { exit: 2 }); - } - } -} - -PublishOnlyUnpublished.description = `Publish unpublished entries from the source environment, to other environments and locales -The publish-only-unpublished command is used to publish unpublished entries from the source environment, to other environments and locales - -Note: Content type(s), Source Environment, Destination Environment(s) and Source Locale are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required -`; - -PublishOnlyUnpublished.flags = { - alias: flags.string({ char: 'a', description: 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.' }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - }), - retryFailed: flags.string({ - char: 'r', - hidden: true, - description: '(optional) Use this option to retry publishing the failed entries from the logfile. It is optional. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - parse: printFlagDeprecation(['--retryFailed', '-r'], ['--retry-failed']), - }), - 'retry-failed': flags.string({ - description: '(optional) Use this option to retry publishing the failed entries from the logfile. It is optional. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - bulkPublish: flags.string({ - char: 'b', - hidden: true, - description: - "Set this flag to use Contentstack\'s Bulk Publish APIs. It is true, by default.", - default: 'true', - parse: printFlagDeprecation(['--bulkPublish', '-b'], ['--bulk-publish']), - }), - 'bulk-publish': flags.string({ - char: 'b', - description: - "Set this flag to use Contentstack\'s Bulk Publish APIs. It is true, by default.", - default: 'true', - }), - 'api-version': flags.string({ - description : "API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]..", - }), - sourceEnv: flags.string({ - char: 's', - hidden: true, - description: 'The name of the source environment where the entries were initially published.', - parse: printFlagDeprecation(['--sourceEnv', '-s'], ['--source-env']), - }), - 'source-env': flags.string({ - description: 'The name of the source environment where the entries were initially published.', - }), - contentTypes: flags.string({ - char: 't', - description: 'The UID of the content type(s) whose entries you want to publish in bulk. In case of multiple content types, specify their IDs separated by spaces.', - multiple: true, - hidden: true, - parse: printFlagDeprecation(['--contentTypes', '-t'], ['--content-types']), - }), - 'content-types': flags.string({ - description: 'The UID of the content type(s) whose entries you want to publish in bulk. In case of multiple content types, specify their IDs separated by spaces.', - multiple: true, - }), - locale: flags.string({ - hidden: true, - char: 'l', - description: 'Locale in which entries will be published, e.g., en-us', - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - locales: flags.string({ - description: 'Locale in which entries will be published, e.g., en-us', - }), - environments: flags.string({ char: 'e', description: 'The name of the environment on which entries will be published. In case of multiple environments, specify their names separated by spaces.', multiple: true }), - config: flags.string({ char: 'c', description: '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.' }), - yes: flags.boolean({ char: 'y', description: 'Set it to true to process the command with the current configuration.' }), - branch: flags.string({ - char: 'B', - default: 'main', - description: 'The name of the branch where you want to perform the bulk publish operation. If you don\'t mention the branch name, then by default the entries from main branch will be published.', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), -}; - -PublishOnlyUnpublished.examples = [ - 'General Usage', - 'csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] -source-env [SOURCE ENV]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`', - 'csdx cm:entries:publish-only-unpublished --config [PATH TO CONFIG FILE]', - 'csdx cm:entries:publish-only-unpublished -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed', - 'csdx cm:entries:publish-only-unpublished --retry-failed [LOG FILE NAME]', - '', - 'Using --branch', - 'csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV]', - '', - 'Using --stack-api-key', - 'csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV]', -]; - -PublishOnlyUnpublished.aliases = ['cm:bulk-publish:unpublished-entries']; - -PublishOnlyUnpublished.usage = 'cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]'; - -module.exports = PublishOnlyUnpublished; \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js deleted file mode 100644 index fc32da49ce..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js +++ /dev/null @@ -1,315 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable node/no-extraneous-require */ -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); -const { start: startPublish } = require('../../../producer/publish-entries'); -const { start: startCrossPublish } = require('../../../producer/cross-publish'); -const store = require('../../../util/store.js'); -const { cliux } = require('@contentstack/cli-utilities'); -const configKey = 'publish_entries'; -const configKeyCrossEnv = 'cross_env_publish'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class PublishEntriesCommand extends Command { - async run() { - const { flags: entriesFlags } = await this.parse(PublishEntriesCommand); - entriesFlags.retryFailed = entriesFlags['retry-failed'] || entriesFlags.retryFailed || false; - entriesFlags.contentTypes = entriesFlags['content-types'] || entriesFlags.contentTypes; - entriesFlags.bulkPublish = entriesFlags['bulk-publish'] || entriesFlags.bulkPublish; - entriesFlags.publishAllContentTypes = - entriesFlags['publish-all-content-types'] || entriesFlags.publishAllContentTypes || false; - entriesFlags.apiVersion = entriesFlags['api-version'] || '3'; - entriesFlags.includeVariants = entriesFlags['include-variants'] || entriesFlags.includeVariants || false; - entriesFlags.entryUid = entriesFlags['entry-uid'] || entriesFlags.entryUid; - - if (entriesFlags.entryUid === undefined) { - delete entriesFlags['entryUid']; - } - delete entriesFlags['api-version']; - delete entriesFlags['retry-failed']; - delete entriesFlags['content-types']; - delete entriesFlags['bulk-publish']; - delete entriesFlags['publish-all-content-types']; - delete entriesFlags['include-variants']; - delete entriesFlags['entry-uid']; - - let updatedFlags; - try { - const storeConfigKey = entriesFlags['source-env'] ? configKeyCrossEnv : configKey; - updatedFlags = entriesFlags.config ? store.updateMissing(storeConfigKey, entriesFlags) : entriesFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: entriesFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; - stack = await getStack(config); - } - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - const publishFunction = async (func) => { - // eslint-disable-next-line no-negated-condition - if (!updatedFlags.retryFailed) { - await func(updatedFlags, stack, config); - } else { - await func(updatedFlags); - } - }; - - if (updatedFlags['source-env']) { - updatedFlags.deliveryToken = updatedFlags['delivery-token']; - updatedFlags.destEnv = updatedFlags.environments; - updatedFlags.environment = updatedFlags['source-env']; - updatedFlags.onlyEntries = true; - if(Array.isArray(updatedFlags.contentTypes) && updatedFlags.contentTypes.length > 0){ - for (const contentType of updatedFlags.contentTypes) { - updatedFlags.contentType = contentType; - if (Array.isArray(updatedFlags.locales)) { - for (const locale of updatedFlags.locales) { - updatedFlags.locale = locale; - console.log(`Bulk publish started for content type \x1b[36m${updatedFlags.contentType}\x1b[0m and locale is \x1b[36m${updatedFlags.locale}\x1b[0m`); - await publishFunction(startCrossPublish); - } - } else { - updatedFlags.locale = updatedFlags.locales; - publishFunction(startCrossPublish); - } - } - } - } else { - publishFunction(startPublish); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ - contentTypes, - locales, - environments, - retryFailed, - publishAllContentTypes, - 'source-env': sourceEnv, - 'delivery-token': deliveryToken, - }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (sourceEnv && !deliveryToken) { - this.error('Specify the source environment delivery token. Run --help for more details.', { exit: 2 }); - } - - if (publishAllContentTypes && contentTypes && contentTypes.length > 0) { - this.error( - 'Do not specify contentTypes when publishAllContentTypes flag is set. Please check --help for more details', - { exit: 2 }, - ); - } - - if ((!contentTypes || contentTypes.length === 0) && !publishAllContentTypes) { - missing.push('Content Types'); - } - - if (!locales || locales.length === 0) { - missing.push('Locales'); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} are required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - - if (data.yes) { - return true; - } - - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -PublishEntriesCommand.description = `Publish entries from multiple contenttypes to multiple environments and locales -The publish command is used to publish entries from the specified content types, to the -specified environments and locales - -Note: Content Types, Environments and Locales are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required -`; - -PublishEntriesCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - }), - retryFailed: flags.string({ - char: 'r', - description: - '(optional) Use this option to retry publishing the failed entries/ assets from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - 'retry-failed': flags.string({ - description: - '(optional) Use this option to retry publishing the failed entries/ assets from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - bulkPublish: flags.string({ - char: 'b', - description: `Set this flag to use Contentstack\'s Bulk Publish APIs. This flag is set to true, by default.`, - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']), - }), - 'bulk-publish': flags.string({ - description: `Set this flag to use Contentstack\'s Bulk Publish APIs. This flag is set to true, by default.`, - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - 'publish-all-content-types': flags.boolean({ - description: - '(optional) Set it to true to bulk publish entries from all content types. If the --content-types option is already used, then you cannot use this option.', - }), - publishAllContentTypes: flags.boolean({ - char: 'o', - description: - '(optional) Set it to true to bulk publish entries from all content types. If the --content-types option is already used, then you cannot use this option.', - hidden: true, - parse: printFlagDeprecation(['-o', '--publishAllContentTypes'], ['--publish-all-content-types']), - }), - 'content-types': flags.string({ - description: - 'The UID of the content type(s) whose entries you want to publish in bulk. In case of multiple content types, specify the IDs separated by spaces.', - multiple: true, - }), - contentTypes: flags.string({ - char: 't', - description: - 'The UID of the content type(s) whose entries you want to publish in bulk. In case of multiple content types, specify the IDs separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']), - hidden: true, - }), - locales: flags.string({ - char: 'l', - description: - ' Locales in which entries will be published, e.g., en-us. In the case of multiple locales, specify the codes separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - environments: flags.string({ - char: 'e', - description: - 'The name of the environment on which entries will be published. In case of multiple environments, specify their names separated by spaces.', - multiple: true, - }), - config: flags.string({ - char: 'c', - description: - '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: - 'The name of the branch where you want to perform the bulk publish operation. If you don’t mention the branch name, then by default the content from main branch will be published.', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), - 'delivery-token': flags.string({ description: 'The delivery token of the source environment.' }), - 'source-env': flags.string({ description: 'Source environment' }), - 'entry-uid': flags.string({ description: 'Entry Uid for publish all associated variant entries.' }), - 'include-variants': flags.boolean({ - default: false, // set the default value to false - description: 'Include Variants flag will publish all associated variant entries with base entry.', - }), -}; - -PublishEntriesCommand.examples = [ - 'General Usage', - 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', - 'csdx cm:entries:publish --config [PATH TO CONFIG FILE]', - 'csdx cm:entries:publish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed', - 'csdx cm:entries:publish --retry-failed [LOG FILE NAME]', - 'csdx cm:entries:publish -r [LOG FILE NAME]', - '', - 'Using --branch', - 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', - '', - 'Using --source-env', - 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --stack-api-key', - 'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --include-variants', - 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]', - '', - 'Using --entry-uid and --include-variants', - 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]', -]; - -PublishEntriesCommand.aliases = ['cm:bulk-publish:entries']; - -PublishEntriesCommand.usage = - 'cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]'; - -module.exports = PublishEntriesCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js deleted file mode 100644 index 2402a4c193..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js +++ /dev/null @@ -1,213 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable node/no-extraneous-require */ -const { Command } = require('@contentstack/cli-command'); -const { cliux, flags } = require('@contentstack/cli-utilities'); -const { start } = require('../../../producer/unpublish'); -const store = require('../../../util/store.js'); -const configKey = 'Unpublish'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class UnpublishCommand extends Command { - async run() { - const { flags: unpublishFlags } = await this.parse(UnpublishCommand); - unpublishFlags.retryFailed = unpublishFlags['retry-failed'] || unpublishFlags.retryFailed || false; - unpublishFlags.bulkUnpublish = unpublishFlags['bulk-unpublish'] || unpublishFlags.bulkUnpublish; - unpublishFlags.contentType = unpublishFlags['content-type'] || unpublishFlags.contentType || ''; - unpublishFlags.deliveryToken = unpublishFlags['delivery-token'] || unpublishFlags.deliveryToken; - unpublishFlags.onlyAssets = false; - unpublishFlags.onlyEntries = true; - unpublishFlags.apiVersion = unpublishFlags['api-version'] || '3'; - unpublishFlags.includeVariants = unpublishFlags['include-variants'] || false; - delete unpublishFlags['api-version']; - delete unpublishFlags['retry-failed']; - delete unpublishFlags['bulk-unpublish']; - delete unpublishFlags['content-type']; - delete unpublishFlags['delivery-token']; - delete unpublishFlags['include-variants']; - - let updatedFlags; - try { - updatedFlags = unpublishFlags.config ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: unpublishFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; - stack = await getStack(config); - } - if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { - this.error('A delivery token is required to execute this command.', { exit: 2 }); - } - - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ environment, retryFailed, locale }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!environment) { - missing.push('Environment'); - } - - // Locales apply to assets as well - if (!locale) { - missing.push('Locale'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} is required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - if (!data.contentType) { - return await cliux.confirm( - 'Do you want to continue with this configuration. This will unpublish all the entries from all content types? [yes or no]', - ); - } else { - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } - } -} - -UnpublishCommand.description = `Unpublish entries from the given environment -The unpublish command is used to unpublish entries from the given environment - -Note: Environment (Source Environment) and Locale are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required`; - -UnpublishCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) for the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - }), - environment: flags.string({ - char: 'e', - description: 'The name of the environment from where entries/assets need to be unpublished.', - }), - config: flags.string({ - char: 'c', - description: - '(optional) Path to the configuration JSON file containing all options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set to true to process the command with the current configuration.', - }), - locale: flags.string({ - description: 'Locale from which entries/assets will be unpublished, e.g., en-us.', - }), - branch: flags.string({ - default: 'main', - description: 'Specify the branch to fetch the content. If not mentioned, the main branch will be used by default.', - }), - 'retry-failed': flags.string({ - description: - '(optional) Use this option to retry unpublishing the failed entries from the logfile. Specify the name of the logfile that lists failed unpublish calls. If used, this option will override all other flags.', - }), - 'bulk-unpublish': flags.string({ - description: - "This flag is set to true by default. It indicates that Contentstack's Bulk Publish APIs will be used to unpublish the entries.", - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - 'content-type': flags.string({ - description: 'The UID of the content type whose entries you want to unpublish in bulk.', - }), - 'delivery-token': flags.string({ - description: 'The delivery token of the source environment.', - }), - 'include-variants': flags.boolean({ - default: false, // set the default value to false - description: 'Include Variants flag will unpublish all associated variant entries.', - }), -}; - -UnpublishCommand.examples = [ - 'General Usage', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]`', - 'csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE]', - 'csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key flag', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', - '', - 'Using --include-variants flag', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] --include-variants', -]; - -module.exports = UnpublishCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js deleted file mode 100644 index ec36a1768b..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js +++ /dev/null @@ -1,226 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, cliux, flags } = require('@contentstack/cli-utilities'); - -const store = require('../../../util/store.js'); -const { getStack } = require('../../../util/client.js'); -const { start } = require('../../../producer/add-fields'); -const { prettyPrint, formatError } = require('../../../util'); - -let config; -const configKey = 'addFields'; - -class UpdateAndPublishCommand extends Command { - async run() { - const { flags: addFieldsFlags } = await this.parse(UpdateAndPublishCommand); - addFieldsFlags.retryFailed = addFieldsFlags['retry-failed'] || addFieldsFlags.retryFailed || false; - addFieldsFlags.contentTypes = addFieldsFlags['content-types'] || addFieldsFlags.contentTypes; - addFieldsFlags.bulkPublish = addFieldsFlags['bulk-publish'] || addFieldsFlags.bulkPublish; - addFieldsFlags.apiVersion = addFieldsFlags['api-version'] || '3'; - delete addFieldsFlags['api-version']; - delete addFieldsFlags['retry-failed']; - delete addFieldsFlags['content-types']; - delete addFieldsFlags['bulk-publish']; - - let updatedFlags; - try { - updatedFlags = addFieldsFlags.config ? store.updateMissing(configKey, addFieldsFlags) : addFieldsFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: addFieldsFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - - stack = await getStack(config); - } - if (await this.confirmFlags(updatedFlags)) { - try { - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ contentTypes, locales, environments, retryFailed }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!contentTypes || contentTypes.length === 0) { - missing.push('Content Types'); - } - - if (!locales || locales.length === 0) { - missing.push('Locales'); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} are required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -UpdateAndPublishCommand.description = `Add fields from updated content types to their respective entries -The update-and-publish command is used to update existing entries with the updated schema of the respective content type - -Note: Content types, Environments and Locales are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required -`; - -UpdateAndPublishCommand.flags = { - alias: flags.string({ - char: 'a', - description: - 'Alias (name) of the management token. You must use either the --alias flag or the --stack-api-key flag.', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.', - }), - 'retry-failed': flags.string({ - description: - 'Use this option to retry publishing the failed entries from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - 'bulk-publish': flags.string({ - description: 'Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by default.', - default: 'true', - }), - 'api-version': flags.string({ - description: 'API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].', - }), - 'content-types': flags.string({ - description: - 'The UID of the content type ID whose entries you want to publish in bulk. In case of multiple content types, specify their IDs separated by spaces.', - multiple: true, - }), - environments: flags.string({ - char: 'e', - description: - 'The name of the environment on which entries will be published. In case of multiple environments, specify their names separated by spaces.', - multiple: true, - }), - config: flags.string({ - char: 'c', - description: - '(optional) The path of the optional configuration JSON file containing all the options for a single run. Refer to the configure command to create a configuration file.', - }), - yes: flags.boolean({ - char: 'y', - description: 'Set it to true to process the command with the current configuration.', - }), - locales: flags.string({ - char: 'l', - description: - 'Locales in which entries will be published, e.g., en-us. In the case of multiple locales, specify the codes separated by spaces.', - multiple: true, - parse: printFlagDeprecation(['-l'], ['--locales']), - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: - 'The name of the branch where you want to perform the bulk publish operation. If you don’t mention the branch name, then by default the content from the main branch will be published.', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), - force: flags.boolean({ - default: false, - description: 'Update and publish all entries even if no fields have been added.', - }), - - // To be deprecated - retryFailed: flags.string({ - char: 'r', - description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags).', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - bulkPublish: flags.string({ - char: 'b', - description: - "This flag is set to true by default. It indicates that contentstack's bulk publish API will be used to publish the entries.", - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']), - }), - contentTypes: flags.string({ - char: 't', - description: 'The Contenttypes from which entries will be published.', - multiple: true, - parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']), - }), -}; - -UpdateAndPublishCommand.examples = [ - 'General Usage', - 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', - 'csdx cm:entries:update-and-publish --config [PATH TO CONFIG FILE]', - 'csdx cm:entries:update-and-publish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed', - 'csdx cm:entries:update-and-publish --retry-failed [LOG FILE NAME]', - '', - 'Using --branch', - 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key', - 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY]', -]; - -UpdateAndPublishCommand.aliases = ['cm:bulk-publish:add-fields']; - -UpdateAndPublishCommand.usage = - 'cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]'; - -module.exports = UpdateAndPublishCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-clear-logs.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-clear-logs.js deleted file mode 100644 index 7f36ef17ee..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-clear-logs.js +++ /dev/null @@ -1,82 +0,0 @@ -const fs = require('fs'); -const { Command } = require('@contentstack/cli-command'); -const { cliux, printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); - -const { getLogsDirPath } = require('../../../util/logger.js'); - -class ClearCommand extends Command { - async run() { - const { flags: clearFlags } = await this.parse(ClearCommand); - let dirPath = getLogsDirPath(); - if (clearFlags['log-files-count'] || clearFlags.list) { - this.listFiles(dirPath); - } else if (clearFlags.yes) { - this.rmDir(dirPath, false); - } else { - const confirmation = await cliux.confirm('Proceed to delete all log files (y/n)?'); - if (confirmation) { - this.rmDir(dirPath, false); - } else { - this.log('No action performed'); - } - } - } - - rmDir(dirPath, removeSelf = true) { - try { - if (fs.existsSync(dirPath)) { - const files = fs.readdirSync(dirPath); - if (files.length > 0) - for (const element of files) { - const filePath = dirPath + '/' + element; - if (fs.statSync(filePath).isFile()) fs.unlinkSync(filePath); - else rmDir(filePath); - } - if (removeSelf) { - fs.rmdirSync(dirPath); - } - this.log('Log files have been cleared'); - } else { - this.error(`The log directory does not exist.`); - } - } catch (e) { - return; - } - } - - listFiles(dirPath) { - if (fs.existsSync(dirPath)) { - fs.readdir(dirPath, (_err, files) => { - this.log('Total number of log files - ', files.length); - }); - } else { - this.error(`The log directory does not exist.`); - } - } -} - -ClearCommand.description = `Clear the log folder`; - -ClearCommand.flags = { - 'log-files-count': flags.boolean({ description: 'List number of log files' }), - yes: flags.boolean({ char: 'y', description: 'Delete all files without asking for confirmation' }), - - //To be depreacted - list: flags.boolean({ - description: 'List number of log files', - char: 'l', - hidden: true, - parse: printFlagDeprecation(['-l', '--list'], ['--log-files-count']), - }), -}; - -ClearCommand.examples = [ - 'csdx cm:stacks:publish-clear-logs', - 'csdx cm:stacks:publish-clear-logs --log-files-count', - 'csdx cm:stacks:publish-clear-logs --yes', - 'csdx cm:stacks:publish-clear-logs -y', -]; - -ClearCommand.aliases = ['cm:bulk-publish:clear']; - -module.exports = ClearCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js deleted file mode 100644 index e403e3d7e1..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js +++ /dev/null @@ -1,51 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const { Command } = require('@contentstack/cli-command'); -const { flags } = require('@contentstack/cli-utilities'); - -let config = require('../../../config/index.js'); - -class ConfigureCommand extends Command { - async run() { - const { flags: configureFlags } = await this.parse(ConfigureCommand); - - if (configureFlags.alias) { - try { - this.getToken(configureFlags.alias); - } catch (error) { - this.error(`The configured management token alias '${configureFlags.alias}' has not been added yet. Add it using 'csdx auth:tokens:add -a ${configureFlags.alias}'.`, { exit: 2 }) - } - } else if (configureFlags['stack-api-key']) { - configureFlags.stackApiKey = configureFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - - this.setConfig(configureFlags); - this.log('The configuration has been saved successfully.'); - } - - setConfig({ alias, stackApiKey }) { - if (alias) config.alias = alias; - else if (stackApiKey) config.stackApiKey = stackApiKey; - fs.writeFileSync(path.join(process.cwd(), 'config.js'), `module.exports = ${JSON.stringify(config, null, 2)}`); - } -} - -ConfigureCommand.description = `The configure command is used to generate a configuration file for publish scripts.`; - -ConfigureCommand.flags = { - alias: flags.string({ char: 'a', description: 'Name (alias) of the management token you want to use. You must use either the --alias flag or the --stack-api-key flag.' }), - 'stack-api-key': flags.string({ char: 'k', description: 'API key of the source stack. You must use either the --stack-api-key flag or the --alias flag.' }), -}; - -ConfigureCommand.examples = [ - 'csdx cm:stacks:publish-configure', - 'csdx cm:stacks:publish-configure -a ', - 'csdx cm:stacks:publish-configure --alias ', - 'csdx cm:stacks:publish-configure --stack-api-key ', -]; - -ConfigureCommand.aliases = ['cm:bulk-publish:configure']; - -module.exports = ConfigureCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-revert.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-revert.js deleted file mode 100644 index eb0a922b36..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-revert.js +++ /dev/null @@ -1,106 +0,0 @@ -const { Command } = require('@contentstack/cli-command'); -const { cliux, printFlagDeprecation, flags } = require('@contentstack/cli-utilities'); - -const store = require('../../../util/store.js'); -const { start } = require('../../../producer/revert'); -const { prettyPrint, formatError } = require('../../../util'); - -let config; -const configKey = 'revert'; - -class RevertCommand extends Command { - async run() { - const { flags: revertFlags } = await this.parse(RevertCommand); - revertFlags.retryFailed = revertFlags['retry-failed'] || revertFlags.retryFailed; - revertFlags.logFile = revertFlags['log-file'] || revertFlags.logFile; - delete revertFlags['retry-failed']; - delete revertFlags['log-file']; - - let updatedFlags; - try { - updatedFlags = revertFlags.config ? store.updateMissing(configKey, revertFlags) : revertFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (this.validate(updatedFlags)) { - if (await this.confirmFlags(updatedFlags)) { - try { - await start(updatedFlags, config); - } catch (error) { - const message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ retryFailed, logFile }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!logFile) { - missing.push('log-file'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} is required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } -} - -RevertCommand.description = `Revert publish operations by using a log file -The revert command is used to revert all publish operations performed using bulk-publish script. -A log file name is required to execute revert command -`; - -RevertCommand.flags = { - 'retry-failed': flags.string({ - description: - '(optional) Use this option to retry publishing the failed entries from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - }), - 'log-file': flags.string({ description: 'Path of the success logfile of a particular publish action.' }), - - //To be deprecated - retryFailed: flags.string({ - char: 'r', - description: - '(optional) Use this option to retry publishing the failed entries from the logfile. Specify the name of the logfile that lists failed publish calls. If this option is used, it will override all other flags.', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - logFile: flags.string({ - char: 'l', - description: 'Path of the success logfile of a particular publish action.', - hidden: true, - parse: printFlagDeprecation(['-l', '--logFile'], ['--log-file']), - }), -}; - -RevertCommand.examples = [ - 'Using --log-file', - 'cm:bulk-publish:revert --log-file [LOG FILE NAME]', - '', - 'Using --retry-failed', - 'cm:bulk-publish:revert --retry-failed [LOG FILE NAME]', -]; - -RevertCommand.aliases = ['cm:bulk-publish:revert']; - -module.exports = RevertCommand; diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js deleted file mode 100644 index e1cae290e0..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js +++ /dev/null @@ -1,112 +0,0 @@ -'use strict'; - -const { Command } = require('@contentstack/cli-command'); -const { getSelectedCommand } = require('../../../util/command-helper'); -const AssetsPublishReceiverCommand = require('../assets/publish'); -const EntriesPublishReceiverCommand = require('../entries/publish'); - -class StackPublishCommand extends Command { - async run() { - try { - this.optionController = new OptionController(); - this.entriesPublishReceiver = new EntriesPublishReceiverCommand(this.argv, this.config); - this.assetsPublishReceiver = new AssetsPublishReceiverCommand(this.argv, this.config); - this.entriesAndAssetsPublishReceiver = new PublishEntriesAndAssetsCommand(); - - this.publishEntriesCommand = new PublishEntriesCommand(this.entriesPublishReceiver); - this.publishAssetsCommand = new PublishAssetsCommand(this.assetsPublishReceiver); - this.publishEntriesAndAssetsCommand = new PublishEntriesAndAssetsCommand(this.entriesPublishReceiver, this.assetsPublishReceiver); - - this.optionController.setCommand(0, this.publishEntriesCommand); - this.optionController.setCommand(1, this.publishAssetsCommand); - this.optionController.setCommand(2, this.publishEntriesAndAssetsCommand); - - const selectedCommand = await getSelectedCommand(); - await this.optionController.execute(selectedCommand); - } catch (error) { - this.error(error.message, { exit: 2 }); - } - } -} - -StackPublishCommand.description = `Publish entries and assets to multiple environments and locales -The publish command is used to publish entries and assets, to the specified environments and locales. - -Note: Content types, Environments and Locales are required to execute the publish entries command successfully. -Note: Environments and Locales are required to execute the publish assets command successfully. -But, if retry-failed flag is set, then only a logfile is required`; - -StackPublishCommand.examples = [ - 'General Usage', - 'csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS]', - '', - 'Using --config or -c flag', - 'Generate a config file in the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', - 'csdx cm:stacks:publish --config [PATH TO CONFIG FILE]', - 'csdx cm:stacks:publish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:stacks:publish --retry-failed [LOG FILE NAME]', - '', - 'Using --branch flag', - 'csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', - '', - 'Using --api-version flag', - 'csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --api-version [API VERSION]', -]; - -StackPublishCommand.flags = []; // Same as entries and assets. - -module.exports = StackPublishCommand; - -// Invoker -class OptionController { - constructor() { - this.runCommands = []; - const noCommand = new NoCommand(); - for (let i = 0; i < 3; i++) { - this.runCommands[i] = noCommand; - } - } - - setCommand(slot, command) { - this.runCommands[slot] = command; - } - - async execute(slot) { - await this.runCommands[slot].execute(); - } -} - -class NoCommand { - execute() { } -} - -class PublishEntriesCommand { - constructor(publishEntryReceiver) { - this.publishEntry = publishEntryReceiver; - } - async execute() { - await this.publishEntry.run(); - } -} - -class PublishAssetsCommand { - constructor(publishAssetReceiver) { - this.publishAsset = publishAssetReceiver; - } - async execute() { - await this.publishAsset.run(); - } -} - -class PublishEntriesAndAssetsCommand { - constructor(publishEntryReceiver, publishAssetReceiver) { - this.publishEntry = publishEntryReceiver; - this.publishAsset = publishAssetReceiver; - } - async execute() { - await this.publishAsset.run(); - await this.publishEntry.run(); - } -} diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js deleted file mode 100644 index 2b24cea396..0000000000 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js +++ /dev/null @@ -1,301 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable node/no-extraneous-require */ -const { Command } = require('@contentstack/cli-command'); -const { printFlagDeprecation, cliux, flags } = require('@contentstack/cli-utilities'); -const { start } = require('../../../producer/unpublish'); -const store = require('../../../util/store.js'); -const configKey = 'Unpublish'; -const { prettyPrint, formatError } = require('../../../util'); -const { getStack } = require('../../../util/client.js'); -let config; - -class UnpublishCommand extends Command { - async run() { - const { flags: unpublishFlags } = await this.parse(UnpublishCommand); - unpublishFlags.retryFailed = unpublishFlags['retry-failed'] || unpublishFlags.retryFailed; - unpublishFlags.bulkUnpublish = unpublishFlags['bulk-unpublish'] || unpublishFlags.bulkUnpublish; - unpublishFlags.contentType = unpublishFlags['content-type'] || unpublishFlags.contentType; - unpublishFlags.deliveryToken = unpublishFlags['delivery-token'] || unpublishFlags.deliveryToken; - unpublishFlags.onlyAssets = unpublishFlags['only-assets'] || unpublishFlags.onlyAssets; - unpublishFlags.onlyEntries = unpublishFlags['only-entries'] || unpublishFlags.onlyEntries; - unpublishFlags.apiVersion = unpublishFlags['api-version'] || '3'; - delete unpublishFlags['api-version']; - delete unpublishFlags['retry-failed']; - delete unpublishFlags['bulk-unpublish']; - delete unpublishFlags['content-type']; - delete unpublishFlags['delivery-token']; - delete unpublishFlags['only-assets']; - delete unpublishFlags['only-entries']; - - let updatedFlags; - try { - updatedFlags = unpublishFlags.config ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - - if (this.validate(updatedFlags)) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: unpublishFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - config.alias = updatedFlags.alias; - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Use the `--alias` or `--stack-api-key` flag to proceed.', { exit: 2 }); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; - stack = await getStack(config); - } - if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { - this.error('A delivery token is required to execute this command.', { exit: 2 }); - } - - if (await this.confirmFlags(updatedFlags)) { - try { - if (process.env.NODE_ENV === 'test') { - return; - } - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } - } - - validate({ environment, retryFailed, locale, contentType, onlyAssets, onlyEntries }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (onlyAssets && onlyEntries) { - this.error( - `The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default`, - ); - } - - if (onlyAssets && contentType) { - this.error( - `Specifying content-type and onlyAssets together will have unexpected results. Please do not use these 2 flags together. Thank you.`, - ); - } - - if (!environment) { - missing.push('Environment'); - } - - // Adding !onlyAssets because if, onlyAssets is set to true, that means only assets are going to be unpublished. - // Then locale won't be necessary (turns out that this is not the case) - // if (!locale && !onlyAssets) { - // missing.push('Locale') - // } - - // Locales apply to assets as well - if (!locale) { - missing.push('Locale'); - } - - if (missing.length > 0) { - this.error( - `${missing.join(', ')} is required for processing this command. Please check --help for more details`, - { exit: 2 }, - ); - } else { - return true; - } - } - - async confirmFlags(data) { - let confirmation; - prettyPrint(data); - if (data.yes) { - return true; - } - - if (!data.contentType && !data.onlyAssets) { - confirmation = await cliux.confirm( - 'Do you want to continue with this configuration. This will unpublish all the entries from all content types? [yes or no]', - ); - } else { - confirmation = await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); - } - return confirmation; - } -} - -UnpublishCommand.description = `Unpublish entries or assets of given content types from the specified environment -The unpublish command is used to unpublish entries or assets from given environment - -Environment (Source Environment) and Locale are required to execute the command successfully -But, if retry-failed flag is set, then only a logfile is required - -A content type can be specified for unpublishing entries, but if no content-type(s) is/are specified and --only-assets is not used, -then all entries from all content types will be unpublished from the source environment - -Note: --only-assets can be used to unpublish only assets and --only-entries can be used to unpublish only entries. -(--only-assets and --only-entries cannot be used together at the same time) -`; - -UnpublishCommand.flags = { - alias: flags.string({ - char: 'a', - description: 'Alias(name) for the management token', - }), - 'stack-api-key': flags.string({ - char: 'k', - description: 'Stack API key to be used', - }), - environment: flags.string({ - char: 'e', - description: 'Source Environment', - }), - config: flags.string({ - char: 'c', - description: 'Path to the config file', - }), - yes: flags.boolean({ - char: 'y', - description: 'Agree to process the command with the current configuration', - }), - locale: flags.string({ - char: 'l', - description: 'Locale filter', - parse: printFlagDeprecation(['-l'], ['--locale']), - }), - branch: flags.string({ - char: 'B', - default: 'main', - description: 'Specify the branch to fetch the content from (default is main branch)', - parse: printFlagDeprecation(['-B'], ['--branch']), - }), - 'retry-failed': flags.string({ - description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)', - }), - 'bulk-unpublish': flags.string({ - description: - "This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to unpublish the entries and assets", - default: 'true', - }), - 'api-version': flags.string({ - description : "API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2].", - }), - 'content-type': flags.string({ - description: 'Content type filter', - }), - 'delivery-token': flags.string({ - description: 'The delivery token of the source environment.', - }), - 'only-assets': flags.boolean({ - description: 'Unpublish only assets', - default: false, - hidden: true, - }), - 'only-entries': flags.boolean({ - description: 'Unpublish only entries', - default: false, - hidden: true, - }), - - // To be deprecated - retryFailed: flags.string({ - char: 'r', - description: 'Retry publishing failed entries from the logfile', - hidden: true, - parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']), - }), - bulkUnpublish: flags.string({ - char: 'b', - description: - "This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used for publishing the entries", - default: 'true', - hidden: true, - parse: printFlagDeprecation(['-b', '--bulkUnpublish'], ['--bulk-unpublish']), - }), - contentType: flags.string({ - char: 't', - description: 'Content Type filter', - hidden: true, - parse: printFlagDeprecation(['-t', '--contentType'], ['--content-type']), - }), - deliveryToken: flags.string({ - char: 'x', - description: 'Delivery Token for source environment', - hidden: true, - parse: printFlagDeprecation(['-x', '--deliveryToken'], ['--delivery-token']), - }), - onlyAssets: flags.boolean({ - description: 'Unpublish only assets', - default: false, - hidden: true, - parse: printFlagDeprecation(['--onlyAssets'], ['--only-assets']), - }), - onlyEntries: flags.boolean({ - description: 'Unpublish only entries', - default: false, - hidden: true, - parse: printFlagDeprecation(['--onlyEntries'], ['--only-entries']), - }), -}; - -UnpublishCommand.examples = [ - 'General Usage', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] ----delivery-token [DELIVERY TOKEN]', - '', - 'Using --config or -c flag', - 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]`', - 'csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE]', - 'csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE]', - '', - 'Using --retry-failed flag', - 'csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME]', - '', - 'No content type', - 'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] (Will unpublish all entries from all content types and assets from the source environment)', - '', - 'Using --only-assets', - 'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-assets (Will unpublish only assets from the source environment)', - '', - 'Using --only-entries', - 'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, all entries, from the source environment)', - 'csdx cm:stacks:unpublish --contentType [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, (from CONTENT TYPE) from the source environment)', - '', - 'Using --branch flag', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', - '', - 'Using --stack-api-key flag', - 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', -]; - -UnpublishCommand.aliases = ['cm:bulk-publish:unpublish']; - -UnpublishCommand.usage = - 'csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]'; - -module.exports = UnpublishCommand; diff --git a/packages/contentstack-bulk-publish/src/config/defaults.json b/packages/contentstack-bulk-publish/src/config/defaults.json deleted file mode 100644 index a7e060ead6..0000000000 --- a/packages/contentstack-bulk-publish/src/config/defaults.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "apiEndpoint": "https://api.contentstack.io", - "cdnEndpoint": "https://cdn.contentstack.io", - "apiVersion": 3 -} \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/config/dummy.json b/packages/contentstack-bulk-publish/src/config/dummy.json deleted file mode 100644 index b059b0583e..0000000000 --- a/packages/contentstack-bulk-publish/src/config/dummy.json +++ /dev/null @@ -1,115 +0,0 @@ -{ - "apikey": "tt", - "contentTypes": [ - "test" - ], - "apiEndPoint": "https://api.localhost.com", - "manageToken": "dummyManageToken", - "cdnEndPoint": "https://cdn.localhost.com", - "deliveryToken": "dummydeliveryToken", - "apiVersion": 3, - "publish_unpublished_env": { - "contentTypes": [ - "dummyContentType" - ], - "sourceEnv": "dummyEnvironment", - "locale": "en-us", - "environments": [ - "dummyEnvironment" - ], - "bulkPublish": true - }, - "publish_assets": { - "environments": [ - "dummyEnvironment" - ], - "folderUid": "cs_root", - "bulkPublish": false - }, - "publish_entries": { - "contentTypes": [ - "dummyContentType" - ], - "locales": [ - "en-us" - ], - "environments": [ - "dummyEnvironment" - ], - "publishAllContentTypes": true, - "bulkPublish": false - }, - "cross_env_publish": { - "filter": { - "environment": "dummyEnvironment", - "content_type_uid": "dummyContentType", - "locale": "en-us", - "type": "asset_published,entry_published" - }, - "deliveryToken": "dummyDeliveryToken", - "destEnv": [ - "dummyEnvironment1" - ], - "bulkPublish": true - }, - "publish_edits_on_env": { - "contentTypes": [ - "dummyContentType" - ], - "sourceEnv": "dummyEnvironment", - "environments": [ - "dummyEnvironment" - ], - "locales": [ - "en-us" - ], - "bulkPublish": false - }, - "nonlocalized_field_changes": { - "sourceEnv": "dummyEnvironment", - "contentTypes": [ - "helloworld" - ], - "environments": [ - "dummyEnvironment" - ], - "bulkPublish": false - }, - "addFields": { - "deleteFields": [ - "updated_by", - "created_by", - "created_at", - "updated_at", - "_version", - "ACL" - ], - "locales": [ - "en-us" - ], - "contentTypes": [ - "helloworld" - ], - "environments": [ - "dummyEnvironment" - ], - "defaults": { - "number": null, - "boolean": false, - "isodate": [], - "file": null, - "reference": [] - }, - "bulkPublish": true - }, - "Unpublish": { - "filter": { - "environment": "dummyEnvironment", - "content_type_uid": "dummyContentType", - "locale": "en-us", - "type": "asset_published,entry_published" - }, - "deliveryToken": "dummyDeliveryToken", - "bulkUnpublish": true - } -} \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/config/index.js b/packages/contentstack-bulk-publish/src/config/index.js deleted file mode 100644 index f7868b19cb..0000000000 --- a/packages/contentstack-bulk-publish/src/config/index.js +++ /dev/null @@ -1,71 +0,0 @@ -module.exports = { - alias: 'Placeholder Management Token Alias', - publish_unpublished_env: { - contentTypes: ['placeholder content type'], - sourceEnv: 'placeholder source env', - locale: 'placeholder locale', - environments: ['placeholder env'], - bulkPublish: true, - }, - publish_assets: { - environments: ['placeholder env'], - folderUid: 'placeholder folder uid', - bulkPublish: true, - locales: ['placeholder locale'], - }, - publish_entries: { - contentTypes: ['placeholder content type'], - locales: ['placeholder locale'], - bulkPublish: true, - environments: ['placeholder env'], - publishAllContentTypes: false, - }, - Unpublish: { - filter: { - environment: 'placeholder env', - content_type_uid: 'placeholder content type', - locale: 'placeholder locale', - type: 'placeholder types', - }, - deliveryToken: 'placeholder delivery token', - bulkUnpublish: true, - }, - cross_env_publish: { - filter: { - environment: 'placeholder env', - content_type_uid: 'placeholder content type', - locale: 'placeholder locale', - type: 'placeholder types', - }, - deliveryToken: 'placeholder delivery token', - destEnv: ['placeholder env'], - bulkPublish: true, - }, - publish_edits_on_env: { - contentTypes: ['placeholder content type'], - sourceEnv: 'placeholder source env', - environments: ['placeholder env'], - locales: ['placeholder locale'], - bulkPublish: true, - }, - nonlocalized_field_changes: { - sourceEnv: 'placeholder env', - contentTypes: ['placeholder content type'], - environments: ['placeholder env'], - bulkPublish: true, - }, - addFields: { - deleteFields: ['updated_by', 'created_by', 'created_at', 'updated_at', '_version', 'ACL'], - locales: ['placeholder locale'], - contentTypes: ['placeholder content type'], - environments: ['placeholder env'], - defaults: { - number: null, - boolean: false, - isodate: [], - file: null, - reference: [], - }, - bulkPublish: true, - }, -}; diff --git a/packages/contentstack-bulk-publish/src/consumer/publish.js b/packages/contentstack-bulk-publish/src/consumer/publish.js deleted file mode 100644 index 2138c48bab..0000000000 --- a/packages/contentstack-bulk-publish/src/consumer/publish.js +++ /dev/null @@ -1,779 +0,0 @@ -/* eslint-disable node/no-extraneous-require */ -/* eslint-disable node/no-unsupported-features/es-syntax */ -/* eslint-disable no-negated-condition */ -/* eslint-disable no-console */ -const chalk = require('chalk'); -const path = require('path'); -const { formatError } = require('../util'); -const apiVersionForNRP = '3.2'; -const nrpApiVersionWarning = `Provided apiVersion is invalid. ${apiVersionForNRP} is only supported value. Continuing with regular bulk-publish for now.`; - -const { getLoggerInstance, addLogs, getLogsDirPath } = require('../util/logger'); -const { sanitizePath } = require('@contentstack/cli-utilities'); -const logsDir = getLogsDirPath(); - -let logger; -let fileNme; - -function initializeLogger(fileName) { - fileNme = fileName; - fileNme = `${Date.now()}.${fileNme}`; - logger = getLoggerInstance(fileNme); - return path.join(logsDir, sanitizePath(fileNme)); -} - -/* eslint-disable camelcase */ -function removePublishDetails(elements) { - if (elements && elements.length > 0) { - return elements.map(({ publish_details, ...rest }) => rest); - } else { - delete elements.publish_details; - } - return elements; -} - -function displayEntriesDetails(sanitizedData, action, mapping = []) { - if (action === 'bulk_publish') { - sanitizedData.forEach((entry) => { - if (Array.isArray(entry?.publish_details) && entry.publish_details.length > 0) { - const matchingPublishDetails = entry.publish_details.filter((pd) => - Object.keys(mapping).includes(pd.environment) - ); - if (matchingPublishDetails.length > 0) { - const pd = matchingPublishDetails[0]; - console.log( - chalk.green( - `Entry UID: '${entry.uid}', Content Type: '${entry.content_type}', Locale: '${entry.locale}', Version: '${pd.version}', Environment: '${pd.environment}'`, - ), - ); - } - } else if (!Array.isArray(entry.publish_details)) { - console.log(chalk.green(`Entry UID: '${entry.uid}', Content Type: '${entry.content_type}', Locale: '${entry.locale}'`)); - } - }); - } else if (action === 'bulk_unpublish') { - sanitizedData.forEach((entry) => { - console.log(chalk.green(`Entry UID: '${entry.uid}', Content Type: '${entry.content_type}', Locale: '${entry.locale}'`)); - }); - } -} - -function displayAssetsDetails(sanitizedData, action, mapping) { - if (action === 'bulk_publish') { - sanitizedData.forEach((asset) => { - asset?.publish_details.forEach((pd) => { - if (Object.keys(mapping).includes(pd.environment)) { - console.log( - chalk.green( - `Asset UID: '${asset.uid}'${pd.version ? `, Version: '${pd.version}'` : ''}${ - asset.locale ? `, Locale: '${asset.locale}'` : '' - }, Environment: ${pd.environment}`, - ), - ); - } - }); - }); - } else if (action === 'bulk_unpublish') { - sanitizedData.forEach((asset) => { - console.log( - chalk.green( - `Asset UID: '${asset.uid}'${asset.version ? `, Version: '${asset.version}'` : ''}${ - asset.locale ? `, Locale: '${asset.locale}'` : '' - }`, - ), - ); - }); - } -} -async function publishEntry(data, _config, queue) { - const lang = []; - const entryObj = data.obj; - const stack = entryObj.stack; - lang.push(entryObj.locale); - stack - .contentType(entryObj.content_type) - .entry(entryObj.entryUid) - .publish({ - publishDetails: { environments: entryObj.environments, locales: lang }, - locale: entryObj.locale || 'en-us', - }) - .then((publishEntryResponse) => { - if (!publishEntryResponse.error_message) { - console.log( - chalk.green( - `Entry published. Content Type UID: ${entryObj.content_type}, Entry UID: ${entryObj.entryUid}, Locale: ${entryObj.locale}`, - ), - ); - delete entryObj.stack; - addLogs( - logger, - { options: entryObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw publishEntryResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete entryObj.stack; - console.log( - chalk.red( - `Entry could not be published. Content Type UID: ${entryObj.content_type}, Entry UID: ${ - entryObj.entryUid - }, Locale: ${entryObj.locale}, Error: ${formatError(error)}`, - ), - ); - addLogs( - logger, - { - options: removePublishDetails(entryObj), - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - }); -} - -async function publishAsset(data, _config, queue) { - const assetobj = data.obj; - const stack = assetobj.stack; - - stack - .asset(assetobj.assetUid) - .publish({ publishDetails: { environments: assetobj.environments, locales: [assetobj.locale || 'en-us'] } }) - .then((publishAssetResponse) => { - if (!publishAssetResponse.error_message) { - console.log(chalk.green(`Asset published. Asset UID: ${assetobj.assetUid}, Locale: ${assetobj.locale}`)); - delete assetobj.stack; - addLogs( - logger, - { options: assetobj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw publishAssetResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete assetobj.stack; - console.log(chalk.red(`Could not publish. Error: ${formatError(error)}`)); - addLogs( - logger, - { - options: removePublishDetails(assetobj), - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - }); -} - -async function UnpublishEntry(data, _config, queue) { - const lang = []; - const entryObj = data.obj; - const stack = entryObj.stack; - lang.push(entryObj.locale); - stack - .contentType(entryObj.content_type) - .entry(entryObj.entryUid) - .unpublish({ publishDetails: { environments: entryObj.environments, locales: lang }, locale: entryObj.locale }) - .then((unpublishEntryResponse) => { - if (!unpublishEntryResponse.error_message) { - delete entryObj.stack; - console.log( - chalk.green( - `Entry unpublished. Content Type UID: ${entryObj.content_type}, Entry UID: ${entryObj.entryUid}, Locale: ${entryObj.locale}`, - ), - ); - addLogs( - logger, - { options: entryObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw unpublishEntryResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete entryObj.stack; - console.log( - chalk.red( - `Entry could not be unpublished. Content Type UID: ${entryObj.content_type}, Entry UID: ${ - entryObj.entryUid - }, Locale: ${entryObj.locale}, Error: ${formatError(error)}`, - ), - ); - addLogs( - logger, - { options: entryObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); -} - -async function UnpublishAsset(data, _config, queue) { - const assetobj = data.obj; - const stack = assetobj.stack; - - stack - .asset(assetobj.assetUid) - .unpublish({ publishDetails: { environments: assetobj.environments, locales: [assetobj.locale || 'en-us'] } }) - .then((unpublishAssetResponse) => { - if (!unpublishAssetResponse.error_message) { - delete assetobj.stack; - console.log(`The asset with UID '${assetobj.assetUid}' has been unpublished.`); - addLogs( - logger, - { options: assetobj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw unpublishAssetResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete assetobj.stack; - console.log(chalk.red(`Could not unpublish. Error: ${formatError(error)}`)); - addLogs( - logger, - { options: assetobj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); -} - -async function getEnvironment(stack, environment) { - const mapping = {}; - if (Array.isArray(environment) && environment.length) { - for (let i = 0; i < environment.length; i++) { - const key = await stack.environment(environment[i]).fetch(); - mapping[key.uid] = environment[i]; - } - } else { - const key = await stack.environment(environment[i]).fetch(); - mapping[key.uid] = environment[i]; - } - return mapping; -} - -async function performBulkPublish(data, _config, queue) { - // add validation for user uid - // if user not logged in, then user uid won't be available and NRP too won't work - let conf; - const bulkPublishObj = data.obj; - const stack = bulkPublishObj.stack; - let payload = {}; - const mapping = await getEnvironment(stack, bulkPublishObj.environments); - switch (bulkPublishObj.Type) { - case 'entry': - conf = { - entries: removePublishDetails(bulkPublishObj.entries), - locales: [bulkPublishObj.locale], - environments: bulkPublishObj.environments, - }; - payload['details'] = conf; - if (bulkPublishObj.apiVersion) { - if (!isNaN(bulkPublishObj.apiVersion) && bulkPublishObj.apiVersion === apiVersionForNRP) { - payload['api_version'] = bulkPublishObj.apiVersion; - payload.details.publish_with_reference = true; - } else { - if (bulkPublishObj.apiVersion !== '3') { - // because 3 is the default value for api-version, and it exists for the purpose of display only - console.log(chalk.yellow(nrpApiVersionWarning)); - } - } - } - stack - .bulkOperation() - .publish(payload) - .then((bulkPublishEntriesResponse) => { - if (!bulkPublishEntriesResponse.error_message) { - console.log( - chalk.green(`Bulk entries sent for publish`), - bulkPublishEntriesResponse.job_id ? chalk.yellow(`job_id: ${bulkPublishEntriesResponse.job_id}`) : '', - ); - displayEntriesDetails(bulkPublishObj.entries, 'bulk_publish', mapping); - delete bulkPublishObj.stack; - addLogs( - logger, - { options: bulkPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw bulkPublishEntriesResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete bulkPublishObj.stack; - console.log(chalk.red(`Bulk entries failed to publish. Error: ${formatError(error)}`)); - displayEntriesDetails(bulkPublishObj.entries, 'bulk_publish', mapping); - addLogs( - logger, - { options: bulkPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); - break; - case 'asset': - conf = { - assets: removePublishDetails(bulkPublishObj.assets), - locales: [bulkPublishObj.locale], - environments: bulkPublishObj.environments, - }; - payload['details'] = conf; - if (bulkPublishObj.apiVersion) { - if (!isNaN(bulkPublishObj.apiVersion) && bulkPublishObj.apiVersion === apiVersionForNRP) { - payload['api_version'] = bulkPublishObj.apiVersion; - } else { - if (bulkPublishObj.apiVersion !== '3') { - // because 3 is the default value for api-version, and it exists for the purpose of display only - console.log(chalk.yellow(nrpApiVersionWarning)); - } - } - } - stack - .bulkOperation() - .publish(payload) - .then((bulkPublishAssetsResponse) => { - if (!bulkPublishAssetsResponse.error_message) { - console.log( - chalk.green( - `Bulk assets sent for publish`, - bulkPublishAssetsResponse.job_id ? chalk.yellow(`job_id: ${bulkPublishAssetsResponse.job_id}`) : '', - ), - ); - displayAssetsDetails(bulkPublishObj.assets, 'bulk_publish', mapping); - delete bulkPublishObj.stack; - addLogs( - logger, - { options: bulkPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw bulkPublishAssetsResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete bulkPublishObj.stack; - console.log(chalk.red(`Bulk assets failed to publish. Error: ${formatError(error)}`)); - - displayAssetsDetails(sanitizedData, 'bulk_publish', mapping); - addLogs( - logger, - { options: bulkPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); - break; - default: - console.log('No such type found. If it is for a content type, use "No such content type found."'); - } -} - -async function performBulkUnPublish(data, _config, queue) { - let conf; - const bulkUnPublishObj = data.obj; - const stack = bulkUnPublishObj.stack; - let payload = {}; - switch (bulkUnPublishObj.Type) { - case 'entry': - conf = { - entries: removePublishDetails(bulkUnPublishObj.entries), - locales: [bulkUnPublishObj.locale], - environments: bulkUnPublishObj.environments, - }; - payload['details'] = conf; - if (bulkUnPublishObj.apiVersion) { - if (!isNaN(bulkUnPublishObj.apiVersion) && bulkUnPublishObj.apiVersion === apiVersionForNRP) { - payload['api_version'] = bulkUnPublishObj.apiVersion; - } else { - if (bulkUnPublishObj.apiVersion !== '3') { - // because 3 is the default value for api-version, and it exists for the purpose of display only - console.log(chalk.yellow(nrpApiVersionWarning)); - } - } - } - stack - .bulkOperation() - .unpublish(payload) - .then((bulkUnPublishEntriesResponse) => { - if (!bulkUnPublishEntriesResponse.error_message) { - delete bulkUnPublishObj.stack; - - console.log( - chalk.green( - `Bulk entries sent for Unpublish`, - bulkUnPublishEntriesResponse.job_id - ? chalk.yellow(`job_id: ${bulkUnPublishEntriesResponse.job_id}`) - : '', - ), - ); - displayEntriesDetails(bulkUnPublishObj.entries, 'bulk_unpublish'); - addLogs( - logger, - { options: bulkUnPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw bulkUnPublishEntriesResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete bulkUnPublishObj.stack; - console.log(chalk.red(`Bulk entries failed to unpublish. Error: ${formatError(error)}`)); - displayEntriesDetails(bulkUnPublishObj.entries, 'bulk_unpublish'); - addLogs( - logger, - { options: bulkUnPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); - break; - case 'asset': - conf = { - assets: removePublishDetails(bulkUnPublishObj.assets), - locales: [bulkUnPublishObj.locale || 'en-us'], - environments: bulkUnPublishObj.environments, - }; - payload['details'] = conf; - if (bulkUnPublishObj.apiVersion) { - if (!isNaN(bulkUnPublishObj.apiVersion) && bulkUnPublishObj.apiVersion === apiVersionForNRP) { - payload['api_version'] = bulkUnPublishObj.apiVersion; - } else { - if (bulkUnPublishObj.apiVersion !== '3') { - // because 3 is the default value for api-version, and it exists for the purpose of display only - console.log(chalk.yellow(nrpApiVersionWarning)); - } - } - } - stack - .bulkOperation() - .unpublish(payload) - .then((bulkUnPublishAssetsResponse) => { - if (!bulkUnPublishAssetsResponse.error_message) { - delete bulkUnPublishObj.stack; - console.log( - chalk.green( - `Bulk assets sent for Unpublish`, - bulkUnPublishAssetsResponse.job_id ? chalk.yellow(`job_id: ${bulkUnPublishAssetsResponse.job_id}`) : '', - ), - ); - displayAssetsDetails(bulkUnPublishObj.assets, 'bulk_unpublish'); - addLogs( - logger, - { options: bulkUnPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'info', - ); - } else { - throw bulkUnPublishAssetsResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - delete bulkUnPublishObj.stack; - console.log(chalk.red(`Bulk assets failed to unpublish. Error: ${formatError(error)}`)); - displayAssetsDetails(bulkUnPublishObj.assets, 'bulk_unpublish'); - addLogs( - logger, - { options: bulkUnPublishObj, api_key: stack.stackHeaders.api_key, alias: stack.alias, host: stack.host }, - 'error', - ); - } - }); - break; - default: - console.log('No such type'); - } -} - -// short-term fix for reverting to previous versions -/* eslint-disable no-case-declarations */ -async function publishUsingVersion(data, _config, queue) { - let conf; - let successfullyPublished = []; - let failedToPublish = []; - let counter = 0; - const bulkPublishObj = data.obj; - const stack = bulkPublishObj.stack; - switch (bulkPublishObj.Type) { - case 'entry': - successfullyPublished = []; - failedToPublish = []; - counter = 0; - const aggregatedEntries = { - ...bulkPublishObj, - }; - bulkPublishObj.entries.forEach(async (entry) => { - conf = { - publishDetails: { - environments: bulkPublishObj.environments, - locales: [bulkPublishObj.locale], - }, - locale: bulkPublishObj.locale, - version: entry.version, - }; - stack - .contentType(entry.content_type) - .entry(entry.uid) - .publish(conf) - .then((publishEntriesResponse) => { - if (!publishEntriesResponse.error_message) { - console.log(chalk.green(`Entry=${entry.uid} sent for publish`)); - - counter += 1; - - successfullyPublished.push({ - ...entry, - }); - - if (counter === bulkPublishObj.entries.length) { - if (successfullyPublished.length > 0) { - aggregatedEntries.entries = successfullyPublished; - addLogs( - logger, - { - options: aggregatedEntries, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'info', - ); - } - - if (failedToPublish.length > 0) { - aggregatedEntries.entries = failedToPublish; - addLogs( - logger, - { - options: bulkPublishObj, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - } - } else { - failedToPublish.push({ - ...entry, - }); - - // throw bulkPublishEntriesResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - counter += 1; - - failedToPublish.push({ - ...entry, - }); - - if (counter === bulkPublishObj.entries.length) { - if (successfullyPublished.length > 0) { - aggregatedEntries.entries = successfullyPublished; - addLogs( - logger, - { - options: aggregatedEntries, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'info', - ); - } - - if (failedToPublish.length > 0) { - aggregatedEntries.entries = failedToPublish; - addLogs( - logger, - { - options: bulkPublishObj, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - } - - console.log(chalk.red(`Entry '${entry.uid}' failed to publish. Error: ${formatError(error)}`)); - } - }); - }); - break; - case 'asset': - successfullyPublished = []; - failedToPublish = []; - counter = 0; - const aggregatedAssets = { - ...bulkPublishObj, - }; - bulkPublishObj.assets.forEach(async (asset) => { - conf = { - publishDetails: { - environments: bulkPublishObj.environments, - locales: [bulkPublishObj.locale], - }, - version: asset.version, - }; - stack - .asset(asset.uid) - .publish(conf) - .then((publishAssetsResponse) => { - if (!publishAssetsResponse.error_message) { - console.log(chalk.green(`Asset=${asset.uid} sent for publish`)); - - counter += 1; - - successfullyPublished.push({ - ...asset, - }); - - if (counter === bulkPublishObj.assets.length) { - if (successfullyPublished.length > 0) { - aggregatedAssets.assets = successfullyPublished; - addLogs( - logger, - { - options: aggregatedAssets, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'info', - ); - } - - if (failedToPublish.length > 0) { - aggregatedAssets.assets = failedToPublish; - addLogs( - logger, - { - options: bulkPublishObj, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - } - } else { - failedToPublish.push({ - ...asset, - }); - - // throw bulkPublishAssetsResponse; - } - }) - .catch((error) => { - if (error.errorCode === 429 && data.retry < 2) { - data.retry++; - queue.Enqueue(data); - } else { - counter += 1; - - failedToPublish.push({ - ...asset, - }); - - if (counter === bulkPublishObj.assets.length) { - if (successfullyPublished.length > 0) { - aggregatedAssets.assets = successfullyPublished; - addLogs( - logger, - { - options: aggregatedAssets, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'info', - ); - } - - if (failedToPublish.length > 0) { - aggregatedAssets.assets = failedToPublish; - addLogs( - logger, - { - options: bulkPublishObj, - api_key: stack.stackHeaders.api_key, - alias: stack.alias, - host: stack.host, - }, - 'error', - ); - } - } - - console.log(chalk.red(`Asset=${asset.uid} failed to publish with error ${formatError(error)}`)); - } - }); - }); - break; - default: - console.log('No such type'); - } -} - -module.exports = { - performBulkPublish, - performBulkUnPublish, - initializeLogger, - publishEntry, - publishAsset, - UnpublishEntry, - UnpublishAsset, - publishUsingVersion, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/add-fields.js b/packages/contentstack-bulk-publish/src/producer/add-fields.js deleted file mode 100644 index 2f83d46768..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/add-fields.js +++ /dev/null @@ -1,510 +0,0 @@ -/* eslint-disable max-depth */ -/* eslint-disable complexity */ -/* eslint-disable node/no-unsupported-features/es-syntax */ -/* eslint-disable camelcase */ -/* eslint-disable new-cap */ -/* eslint-disable no-console */ -/* eslint-disable max-params */ -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); - -const queue = getQueue(); -queue.consumer = performBulkPublish; -let logFileName; -let bulkPublishSet = []; -let filePath; - -let changedFlag = false; - -const defaults = { - number: null, - boolean: false, - isodate: [], - file: null, - reference: [], -}; - -const deleteFields = ['updated_by', 'created_by', 'created_at', 'updated_at', '_version', 'ACL']; - -function setConfig(conf, bp) { - if (bp) { - logFileName = 'bulk-add-fields'; - queue.consumer = performBulkPublish; - } else { - logFileName = 'add-fields'; - queue.consumer = publishEntry; - } - config = conf; - queue.config = conf; - filePath = initializeLogger(logFileName); -} - -async function getContentTypeSchema(stack, contentType) { - return new Promise((resolve, reject) => { - stack - .contentType(contentType) - .fetch({ include_global_field_schema: true }) - .then((content) => { - resolve(content.schema); - }) - .catch((error) => reject(error)); - }); -} - -function removeUnwanted(entry, unwantedkeys) { - unwantedkeys.forEach((key) => { - delete entry[key]; - }); - return entry; -} - -function isLinkObject(obj, keyName) { - if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) { - return false; - } - - const linkKeyNames = ['link', 'card_link']; - if (linkKeyNames.includes(keyName)) { - return true; - } - - const hasTitle = 'title' in obj && obj.title !== undefined; - const hasUrl = 'url' in obj && obj.url !== undefined; - const hasHref = 'href' in obj && obj.href !== undefined; - - return hasTitle && (hasUrl || hasHref); -} - -function ensureHrefIsString(linkObj) { - if (linkObj.href === undefined || linkObj.href === null) { - linkObj.href = ''; - } else if (typeof linkObj.href !== 'string') { - linkObj.href = String(linkObj.href); - } -} - -function isValidJsonRte(obj) { - return obj !== null && - typeof obj === 'object' && - !Array.isArray(obj) && - typeof obj.type === 'string' && - obj.type !== ''; -} - -function cleanJsonFields(obj) { - if (obj === null || obj === undefined || typeof obj !== 'object') { - return obj; - } - - if (Array.isArray(obj)) { - return obj.map((item) => cleanJsonFields(item)); - } - - const cleaned = {}; - for (const key in obj) { - if (!obj.hasOwnProperty(key)) { - continue; - } - let value = obj[key]; - const isJsonField = key.endsWith('_rte') || key === 'json_rte'; - const isAccessibilityField = key.endsWith('_accessibility') || key === 'image_preset_accessibility'; - - if (isJsonField) { - if (value === '' || value === null || value === undefined) { - continue; - } - if (typeof value === 'object' && !Array.isArray(value)) { - const keyCount = Object.keys(value).length; - if (keyCount === 0) { - continue; - } - if (!isValidJsonRte(value)) { - continue; - } - cleaned[key] = value; - } else { - continue; - } - } else if (isAccessibilityField && value === '') { - cleaned[key] = {}; - } else if (typeof value === 'object' && value !== null && !Array.isArray(value)) { - value = cleanJsonFields(value); - if (value !== null && typeof value === 'object') { - cleaned[key] = value; - } - } else { - cleaned[key] = value; - } - } - return cleaned; -} - -function convertUrlToHref(obj) { - if (obj === null || obj === undefined) { - return obj; - } - - if (Array.isArray(obj)) { - return obj.map((item) => convertUrlToHref(item)); - } - - if (typeof obj === 'object') { - const converted = {}; - for (const key in obj) { - const value = obj[key]; - - if (isLinkObject(value, key)) { - converted[key] = { ...value }; - if (converted[key].url !== undefined && converted[key].href === undefined) { - if (typeof converted[key].url === 'string') { - converted[key].href = converted[key].url; - } else if (converted[key].url === null || converted[key].url === undefined) { - converted[key].href = ''; - } else { - converted[key].href = String(converted[key].url); - } - delete converted[key].url; - } - ensureHrefIsString(converted[key]); - } else { - converted[key] = convertUrlToHref(value); - } - } - return converted; - } - - return obj; -} - -function fileFields(entry, uid, multiple) { - if (entry[uid]) { - if (typeof entry[uid] === 'object' || Array.isArray(entry[uid])) { - if (multiple) { - const temp = []; - entry[uid].forEach((file) => { - temp.push(file.uid); - }); - entry[uid] = temp; - } else { - entry[uid] = entry[uid].uid; - } - } - } -} - -function addFields(contentType, entry) { - contentType.forEach((schema) => { - if (schema.uid && !schema.schema) { - if (Object.prototype.hasOwnProperty.call(entry, schema.uid) && schema.data_type === 'file') { - changedFlag = true; - fileFields(entry, schema.uid, schema.multiple); - } - - if (!Object.prototype.hasOwnProperty.call(entry, schema.uid)) { - changedFlag = true; - if (schema.multiple) { - if (schema.field_metadata && schema.field_metadata.default_value) { - if (schema.data_type === 'isodate') { - entry[schema.uid] = [schema.field_metadata.default_value.date]; - } else { - entry[schema.uid] = [schema.field_metadata.default_value]; - } - } else { - entry[schema.uid] = []; - } - } else if (schema.field_metadata && schema.field_metadata.default_value) { - if (schema.data_type === 'isodate') { - entry[schema.uid] = schema.field_metadata.default_value.date; - } else { - entry[schema.uid] = schema.field_metadata.default_value; - } - } else if (schema.enum) { - entry[schema.uid] = null; - } else if (schema.data_type === 'json') { - const isJsonRteField = schema.uid && (schema.uid.endsWith('_rte') || schema.uid === 'json_rte'); - if (!isJsonRteField) { - entry[schema.uid] = {}; - } - } else if (Object.prototype.hasOwnProperty.call(defaults, schema.data_type)) { - entry[schema.uid] = defaults[schema.data_type]; - } else { - entry[schema.uid] = ''; - } - } - } - - if (schema.uid && schema.schema) { - if (!entry[schema.uid]) { - if (schema.multiple) { - entry[schema.uid] = []; - } else { - entry[schema.uid] = {}; - } - } - } - - if (schema.data_type === 'group' && !schema.multiple) { - addFields(schema.schema, entry[schema.uid]); - if (entry[schema.uid]) { - entry[schema.uid] = convertUrlToHref(entry[schema.uid]); - } - } - if (schema.data_type === 'group' && schema.multiple) { - entry[schema.uid].forEach((field) => { - addFields(schema.schema, field); - }); - if (entry[schema.uid]) { - entry[schema.uid] = convertUrlToHref(entry[schema.uid]); - } - } - if (schema.data_type === 'global_field' && !schema.multiple) { - addFields(schema.schema, entry[schema.uid]); - if (entry[schema.uid]) { - entry[schema.uid] = convertUrlToHref(entry[schema.uid]); - } - } - if (schema.data_type === 'global_field' && schema.multiple) { - entry[schema.uid].forEach((field) => { - addFields(schema.schema, field); - }); - if (entry[schema.uid]) { - entry[schema.uid] = convertUrlToHref(entry[schema.uid]); - } - } - if (schema.data_type === 'blocks') { - if (!entry[schema.uid] && !Array.isArray(entry[schema.uid])) { - entry[schema.uid] = []; - } - - schema.blocks.forEach((block) => { - let filterBlockFields = entry[schema.uid].filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - if (filterBlockFields.length > 0) { - filterBlockFields.forEach((bfield) => { - addFields(block.schema, bfield[block.uid]); - if (bfield[block.uid]) { - bfield[block.uid] = convertUrlToHref(bfield[block.uid]); - } - }); - } else { - entry[schema.uid].push({ [block.uid]: {} }); - filterBlockFields = entry[schema.uid].filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - if (filterBlockFields.length > 0) { - filterBlockFields.forEach((bfield) => { - addFields(block.schema, bfield[block.uid]); - if (bfield[block.uid]) { - bfield[block.uid] = convertUrlToHref(bfield[block.uid]); - } - }); - } - } - }); - } - }); - return { entry, changedFlag }; -} - -async function updateEntry(updatedEntry, locale) { - return updatedEntry - .update({ locale: locale || 'en-us' }) - .then(() => { - return Promise.resolve(true); - }) - .catch((error) => { - console.error(error); - return Promise.resolve(false); - }); -} - -/* eslint-disable no-param-reassign */ -async function getEntries( - stack, - config, - schema, - contentType, - locale, - bulkPublish, - environments, - forceUpdate, - apiVersion, - bulkPublishLimit, - skip = 0, -) { - let queryParams = { - locale: locale || 'en-us', - include_count: true, - skip: skip, - include_publish_details: true, - }; - stack - .contentType(contentType) - .entry() - .query(queryParams) - .find() - .then(async (entriesResponse) => { - skip += entriesResponse.items.length; - let entries = entriesResponse.items; - for (let index = 0; index < entriesResponse.items.length; index++) { - let updatedEntry = addFields(schema, entries[index]); - if (updatedEntry.changedFlag || forceUpdate) { - let entryData = JSON.parse(JSON.stringify(updatedEntry.entry)); - entryData = removeUnwanted(entryData, deleteFields); - entryData = cleanJsonFields(entryData); - entryData = convertUrlToHref(entryData); - entryData = cleanJsonFields(entryData); - const entry = stack.contentType(contentType).entry(entries[index].uid); - Object.assign(entry, entryData); - const flag = await updateEntry(entry, locale); - if (flag) { - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid: entries[index].uid, - content_type: contentType, - locale, - publish_details: entries[index].publish_details, - }); - } - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } else { - await queue.Enqueue({ - content_type: contentType, - publish_details: entries[index].publish_details || [], - environments: environments, - entryUid: entries[index].uid, - locale, - Type: 'entry', - stack: stack, - }); - } - } else { - console.log(`Update failed for entry UID '${entries[index].uid}' of content type '${contentType}'.`); - } - } else { - console.log(`No changes detected for content type '${contentType}' and entry UID '${entries[index].uid}'.`); - } - - if (index === entriesResponse.items.length - 1 && bulkPublishSet.length > 0 && bulkPublishSet.length < bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } - if (skip === entriesResponse.count) { - return Promise.resolve(); - } - return setTimeout( - async () => - getEntries(stack, config, schema, contentType, locale, bulkPublish, environments, forceUpdate, apiVersion, bulkPublishLimit, skip), - 2000, - ); - }) - .catch((error) => console.log(error)); - return true; -} - -/* eslint-disable no-await-in-loop */ -/* eslint-disable no-loop-func */ - -async function start( - { contentTypes, locales, environments, retryFailed, bulkPublish, force: forceUpdate, apiVersion }, - stack, - config, -) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - process.exit(0); - }); - - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['bulk-add-fields', 'add-fields'])) { - return false; - } - - bulkPublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkPublish); - - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue: queue }, 'publish'); - } - } - } else { - setConfig(config, bulkPublish); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - for (let i = 0; i < contentTypes.length; i += 1) { - getContentTypeSchema(stack, contentTypes[i]) - .then(async (schema) => { - for (let j = 0; j < locales.length; j += 1) { - try { - await getEntries( - stack, - config, - schema, - contentTypes[i], - locales[j], - bulkPublish, - environments, - forceUpdate, - apiVersion, - bulkPublishLimit - ); - } catch (err) { - console.log(`Failed to retrieve entries for content type '${contentTypes[i]}' and locale '${locales[j]}'.`); - } - } - }) - .catch((err) => { - console.log(`Failed to fetch schema: ${JSON.stringify(err)}`); - }); - } - } -} - -module.exports = { - start, - getContentTypeSchema, - getEntries, - setConfig, - removeUnwanted, - addFields, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/cross-publish.js b/packages/contentstack-bulk-publish/src/producer/cross-publish.js deleted file mode 100644 index f77f34b7f9..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/cross-publish.js +++ /dev/null @@ -1,411 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable new-cap */ -/* eslint-disable camelcase */ -/* eslint-disable complexity */ -/* eslint-disable max-params */ -const { configHandler, cliux } = require('@contentstack/cli-utilities'); -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, publishAsset, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const queue = getQueue(); -const entryQueue = getQueue(); -const assetQueue = getQueue(); -const { Command } = require('@contentstack/cli-command'); -const command = new Command(); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); -const { generateBulkPublishStatusUrl } = require('../util/generate-bulk-publish-url'); -const VARIANTS_PUBLISH_API_VERSION = '3.2'; - -let bulkPublishSet = []; -let bulkPublishAssetSet = []; -let changedFlag = false; -let logFileName; -let filePath; - -function getQueryParams(filter) { - let queryString = ''; - Object.keys(filter).forEach((key) => { - if (filter[key]) { - queryString = `${queryString}&${key}=${filter[key]}`; - } - }); - - return queryString; -} - -async function bulkAction(stack, items, bulkPublish, filter, destEnv, apiVersion, bulkPublishLimit, variantsFlag = false) { - return new Promise(async (resolve) => { - for (let index = 0; index < items.length; index++) { - changedFlag = true; - - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit && items[index].type === 'entry_published') { - const entry = { - uid: items[index].data.uid, - content_type: items[index].content_type_uid, - locale: items[index].data.locale || 'en-us', - version: items[index].data._version, - publish_details: [items[index].data.publish_details] || [], - }; - - if (variantsFlag && Array.isArray(items[index].data.variants) && items[index].data.variants.length > 0) { - entry.variants = items[index].data.variants || []; - entry.variant_rules = { - publish_latest_base: false, - publish_latest_base_conditionally: true - }; - } - - bulkPublishSet.push(JSON.parse(JSON.stringify(entry))); - } - - if (bulkPublishAssetSet.length < bulkPublishLimit && items[index].type === 'asset_published') { - bulkPublishAssetSet.push({ - uid: items[index].data.uid, - version: items[index].data._version, - publish_details: [items[index].data.publish_details] || [], - }); - } - - if (bulkPublishAssetSet.length === bulkPublishLimit) { - await queue.Enqueue({ - assets: bulkPublishAssetSet, - Type: 'asset', - locale: filter.locale, - environments: destEnv, - stack: stack, - apiVersion, - }); - bulkPublishAssetSet = []; - } - - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale: filter.locale, - Type: 'entry', - environments: destEnv, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - - if (index === items.length - 1 && bulkPublishAssetSet.length <= bulkPublishLimit && bulkPublishAssetSet.length > 0) { - await queue.Enqueue({ - assets: bulkPublishAssetSet, - Type: 'asset', - locale: filter.locale, - environments: destEnv, - stack: stack, - apiVersion, - }); - bulkPublishAssetSet = []; - } - - if (index === items.length - 1 && bulkPublishSet.length <= bulkPublishLimit && bulkPublishSet.length > 0) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale: filter.locale, - Type: 'entry', - environments: destEnv, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - } else { - if (items[index].type === 'entry_published') { - await entryQueue.Enqueue({ - content_type: items[index].content_type_uid, - publish_details: [items[index].data.publish_details], - environments: destEnv, - entryUid: items[index].data.uid, - version: items[index].data._version, - locale: items[index].data.locale || 'en-us', - version: items[index].data._version, - Type: 'entry', - stack: stack, - }); - } - if (items[index].type === 'asset_published') { - await assetQueue.Enqueue({ - assetUid: items[index].data.uid, - publish_details: [items[index].data.publish_details], - locale: filter.locale, - environments: destEnv, - Type: 'asset', - stack: stack, - }); - } - } - } - return resolve(); - }); -} - -async function getSyncEntries( - stack, - config, - queryParams, - bulkPublish, - filter, - deliveryToken, - destEnv, - apiVersion, - bulkPublishLimit, - variantsFlag = false, - paginationToken = null, -) { - return new Promise(async (resolve, reject) => { - try { - let tokenDetails; - if (config.stackApiKey) { - tokenDetails = { apiKey: config.stackApiKey }; - } else { - tokenDetails = command.getToken(config.alias); - } - const queryParamsObj = {}; - const pairs = queryParams.split('&').filter((e) => e !== null && e !== '' && e !== undefined); - for (let i in pairs) { - const split = pairs[i].split('='); - queryParamsObj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]); - } - - const deliveryAPIOptions = { - api_key: tokenDetails.apiKey, - delivery_token: deliveryToken, - environment: queryParamsObj.environment, - branch: config.branch, - }; - - const earlyAccessHeaders = configHandler.get(`earlyAccessHeaders`); - if (earlyAccessHeaders && Object.keys(earlyAccessHeaders).length > 0) { - deliveryAPIOptions.early_access = Object.values(earlyAccessHeaders); - } - - const Stack = new command.deliveryAPIClient.Stack(deliveryAPIOptions); - - Stack.setHost(config.cda); - - const syncData = {}; - - if (paginationToken) { - syncData['pagination_token'] = paginationToken; - } else { - syncData['init'] = true; - } - if (queryParamsObj.locale) { - syncData['locale'] = queryParamsObj.locale; - } - if (filter?.content_type_uid) { - syncData['content_type_uid'] = filter.content_type_uid; - } - if (queryParamsObj.type) { - syncData['type'] = queryParamsObj.type; - } - let entriesResponse; - entriesResponse = await Stack.sync(syncData); - - - if (variantsFlag) { - for (let index = 0; index < entriesResponse?.items?.length; index++) { - let variants = []; - const entries = entriesResponse.items[index]; - variants = await getVariantEntries(stack, entries.content_type_uid, entriesResponse, index, queryParamsObj); - if (variants.length > 0) { - entriesResponse.items[index].data.variants = variants; - } - } - } - - if (entriesResponse.items.length > 0) { - await bulkAction(stack, entriesResponse.items, bulkPublish, filter, destEnv, apiVersion, bulkPublishLimit, variantsFlag); - } - if (!entriesResponse.pagination_token) { - if (!changedFlag) console.log('No entries or assets found published in the specified environment.'); - return resolve(); - } - setTimeout(async () => { - await getSyncEntries( - stack, - config, - queryParams, - bulkPublish, - filter, - deliveryToken, - destEnv, - apiVersion, - bulkPublishLimit, - variantsFlag, - entriesResponse.pagination_token, - ); - }, 3000); - return resolve(); - } catch (error) { - reject(error); - } - }); -} - -function setConfig(conf, bp) { - if (bp) { - logFileName = 'bulk-cross-publish'; - queue.consumer = performBulkPublish; - } else { - logFileName = 'cross-publish'; - entryQueue.consumer = publishEntry; - assetQueue.consumer = publishAsset; - } - - queue.config = conf; - entryQueue.config = conf; - assetQueue.config = conf; - filePath = initializeLogger(logFileName); -} - -async function getVariantEntries(stack, contentType, entries, index, queryParams, skip = 0) { - try { - let variantQueryParams = { - locale: queryParams.locale || 'en-us', - include_count: true, - skip: skip, // Adding skip parameter for pagination - limit: 100, // Set a limit to fetch up to 100 entries per request - }; - const entryUid = entries.items[index].data.uid - const variantsEntriesResponse = await stack - .contentType(contentType) - .entry(entryUid) - .variants() - .query(variantQueryParams) - .find(); - - const variants = variantsEntriesResponse.items.map((entry) => ({ - uid: entry.variants._variant._uid, - })); - - if (variantsEntriesResponse.items.length === variantQueryParams.limit) { - const nextVariants = await getVariantEntries( - stack, - contentType, - entries, - index, - queryParams, - skip + variantQueryParams.limit, - ); - return Array.isArray(nextVariants) ? variants.concat(nextVariants) : variants; - } - return variants; - } catch (error) { - const errorMessage = - error?.errorMessage || - error?.message || - error?.errors || - 'Falied to fetch the variant entries, Please contact the admin for support.'; - throw new Error(`Error fetching variants: ${errorMessage}`); - } -} - -async function start( - { - retryFailed, - bulkPublish, - deliveryToken, - contentType, - environment, - locale, - onlyAssets, - onlyEntries, - destEnv, - f_types, - apiVersion, - includeVariants, - }, - stack, - config, -) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - - // Generate and display the bulk publish status link - if (bulkPublish && stack && config) { - const statusUrl = generateBulkPublishStatusUrl(stack, config); - if (statusUrl) { - process.stdout.write('\n'); - process.stdout.write('\x1b[37mHere is the link to check the bulk publish status: \x1b[0m'); - process.stdout.write('\x1b[34m' + statusUrl + '\x1b[0m'); - process.stdout.write('\n'); - } - } - - process.exit(0); - }); - - if (retryFailed) { - if (typeof retryFailed === 'string' && retryFailed.length > 0) { - if (!validateFile(retryFailed, ['cross-publish', 'bulk-cross-publish'])) { - return false; - } - - const bulkPublishFlag = retryFailed.match(/bulk/) ? true : false; - setConfig(config, bulkPublishFlag); - - if (bulkPublishFlag) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue, assetQueue }, 'publish'); - } - } - } else { - let filter = { - environment, - locale, - }; - if (f_types) filter.type = f_types; - // filter.type = (f_types) ? f_types : types // types mentioned in the config file (f_types) are given preference - if (contentType) { - filter.content_type_uid = contentType; - filter.type = 'entry_published'; - } - if (onlyAssets) { - filter.type = 'asset_published'; - delete filter.content_type_uid; - } - if (onlyEntries) { - filter.type = 'entry_published'; - } - setConfig(config, bulkPublish); - // filter.type = (f_types) ? f_types : types // types mentioned in the config file (f_types) are given preference - const queryParams = getQueryParams(filter); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - if (includeVariants) { - apiVersion = VARIANTS_PUBLISH_API_VERSION; - } - await getSyncEntries( - stack, - config, - queryParams, - bulkPublish, - filter, - deliveryToken, - destEnv, - apiVersion, bulkPublishLimit, - includeVariants, - ); - } -} - -module.exports = { - getSyncEntries, - setConfig, - getQueryParams, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/nonlocalized-field-changes.js b/packages/contentstack-bulk-publish/src/producer/nonlocalized-field-changes.js deleted file mode 100644 index cfc0f0292c..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/nonlocalized-field-changes.js +++ /dev/null @@ -1,386 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable new-cap */ -/* eslint-disable max-params */ -/* eslint-disable unicorn/explicit-length-check */ -/* eslint-disable camelcase */ -/* eslint-disable max-depth */ -/* eslint-disable complexity */ -/* eslint-disable node/no-extraneous-require */ -const _ = require('lodash'); -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); - -let changedFlag = false; -const queue = getQueue(); -let skipCount; -let logFileName; -let bulkPublishSet = []; -let filePath; - -function setConfig(conf, bp) { - if (bp) { - logFileName = 'bulk-nonlocalized-field-changes'; - queue.consumer = performBulkPublish; - } else { - logFileName = 'nonlocalized-field-changes'; - queue.consumer = publishEntry; - } - config = conf; - queue.config = conf; - filePath = initializeLogger(logFileName); -} - -async function getContentTypeSchema(stack, contentType) { - return new Promise((resolve, reject) => { - stack - .contentType(contentType) - .fetch({ include_global_field_schema: true }) - .then((content) => { - resolve(content.schema); - }) - .catch((error) => reject(error)); - }); -} - -/* eslint-disable consistent-return */ - -async function getLocalizedEntry(stack, entry, contentType, locale, sourceEnv) { - return new Promise((resolve, _reject) => { - let queryParams = { - locale: locale, - environment: sourceEnv, - include_publish_details: true, - }; - stack - .contentType(contentType) - .entry(entry.uid) - .fetch(queryParams) - .then((entryResponse) => { - if (entryResponse) { - resolve(entryResponse); - } - resolve({}); - }) - .catch((error) => { - if (error.errorCode === 141) { - resolve({}); - } - if (typeof error === 'string') { - if (JSON.parse(error).errorCode !== 141) console.log(error); - } - }); - }); -} - -function checkReferenceFieldChanges(ref1, ref2) { - for (let i = 0; i < (ref1.length || ref2.length); i += 1) { - if (typeof ref1[i] === 'object' && typeof ref2[i] === 'object') { - if (ref1[i].uid !== ref2[i].uid || ref1[i]._content_type_uid !== ref2[i]._content_type_uid) { - changedFlag = true; - } - } else { - changedFlag = true; - } - } -} - -function checkNonLocalizedFieldChanges(contentType, entry, localizedEntry, isNonLocalized = false) { - contentType.forEach((field) => { - if ((field.non_localizable || isNonLocalized) && !field.schema && !field.blocks) { - if ((entry[field.uid] && !localizedEntry[field.uid]) || (!entry[field.uid] && localizedEntry[field.uid])) { - changedFlag = true; - return; - } - if (entry[field.uid] && localizedEntry[field.uid]) { - if (field.multiple) { - if (JSON.stringify(entry[field.uid]) !== JSON.stringify(localizedEntry[field.uid])) { - changedFlag = true; - } - return; - } - if (field.data_type === 'reference') { - checkReferenceFieldChanges(entry[field.uid], localizedEntry[field.uid]); - return; - } - if (entry[field.uid] !== localizedEntry[field.uid]) { - changedFlag = true; - } - } - } - if (field.data_type === 'group' || field.data_type === 'global_field') { - if (field.multiple) { - let tempEntry = _.cloneDeep(entry[field.uid]); - let tempLocalizedEntry = _.cloneDeep(localizedEntry[field.uid]); - if (!tempEntry) { - tempEntry = []; - } - if (!tempLocalizedEntry) { - tempLocalizedEntry = []; - } - for (const element of tempEntry) { - if (field.non_localizable || isNonLocalized) { - checkNonLocalizedFieldChanges(field.schema, element, tempLocalizedEntry || {}, true); - } else { - checkNonLocalizedFieldChanges(field.schema, element, tempLocalizedEntry || {}, false); - } - } - } else { - let tempEntry = _.cloneDeep(entry[field.uid]); - let tempLocalizedEntry = _.cloneDeep(localizedEntry[field.uid]); - if (!tempEntry) { - tempEntry = {}; - } - if (!tempLocalizedEntry) { - tempLocalizedEntry = {}; - } - if (field.non_localizable || isNonLocalized) { - checkNonLocalizedFieldChanges(field.schema, tempEntry, tempLocalizedEntry, true); - } else { - checkNonLocalizedFieldChanges(field.schema, tempEntry, tempLocalizedEntry, false); - } - } - } - if (field.data_type === 'blocks') { - let tempEntry = _.cloneDeep(entry[field.uid]); - let tempLocalizedEntry = _.cloneDeep(localizedEntry[field.uid]); - if (!tempEntry) tempEntry = []; - if (!tempLocalizedEntry) tempLocalizedEntry = []; - - if (field.non_localizable || isNonLocalized) { - field.blocks.forEach((block) => { - let filterTempEntryBlocks = []; - let filterLocalizedEntryBlocks = []; - filterTempEntryBlocks = tempEntry.filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - filterLocalizedEntryBlocks = tempLocalizedEntry.filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - if (filterTempEntryBlocks.length) { - for (let iterator = 0; iterator < filterTempEntryBlocks.length; iterator += 1) { - checkNonLocalizedFieldChanges( - block.schema, - filterTempEntryBlocks[iterator][block.uid], - filterLocalizedEntryBlocks[iterator] ? filterLocalizedEntryBlocks[iterator][block.uid] : {}, - true, - ); - } - } - }); - } else { - field.blocks.forEach((block) => { - let filterTempEntryBlocks = []; - let filterLocalizedEntryBlocks = []; - filterTempEntryBlocks = tempEntry.filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - filterLocalizedEntryBlocks = tempLocalizedEntry.filter((blockField) => { - if (Object.prototype.hasOwnProperty.call(blockField, block.uid)) { - return blockField; - } - return false; - }); - - if (filterTempEntryBlocks.length) { - for (let iterator = 0; iterator < filterTempEntryBlocks.length; iterator += 1) { - checkNonLocalizedFieldChanges( - block.schema, - filterTempEntryBlocks[iterator][block.uid], - filterLocalizedEntryBlocks[iterator] ? filterLocalizedEntryBlocks[iterator][block.uid] : {}, - false, - ); - } - } - }); - } - } - }); - return changedFlag; -} - -/* eslint-disable consistent-return */ -/* eslint-disable no-await-in-loop */ - -async function getEntries( - stack, - schema, - contentType, - languages, - masterLocale, - bulkPublish, - environments, - sourceEnv, - apiVersion, - bulkPublishLimit, - skip = 0, -) { - return new Promise((resolve, reject) => { - skipCount = skip; - let queryParams = { - locale: masterLocale || 'en-us', - environment: sourceEnv, - include_count: true, - skip: skipCount, - }; - stack - .contentType(contentType) - .entry() - .query(queryParams) - .find() - .then(async (entriesResponse) => { - skipCount += entriesResponse.items.length; - if (entriesResponse && entriesResponse.items.length > 0) { - for (const language of languages) { - const locale = language; - for (const element of entriesResponse.items) { - const entry = element; - try { - let localizedEntry = await getLocalizedEntry(stack, entry, contentType, locale.code, sourceEnv); - localizedEntry = localizedEntry || {}; - if (checkNonLocalizedFieldChanges(schema, entry, localizedEntry)) { - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid: entry.uid, - content_type: contentType, - locale: locale.code, - publish_details: localizedEntry.publish_details || [], - }); - } - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale: locale.code, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } else { - await queue.Enqueue({ - content_type: contentType, - publish_details: entry.publish_details || [], - environments: environments, - entryUid: entry.uid, - locale: locale.code, - Type: 'entry', - stack: stack, - }); - } - } else { - console.log( - `No Change in NonLocalized field for contentType ${contentType} entryUid ${entry.uid} with locale ${locale.code}`, - ); - } - changedFlag = false; - } catch (error) { - reject(error); - } - } - if (bulkPublishSet.length > 0 && bulkPublishSet.length < bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale: locale.code, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } - } - if (skipCount === entriesResponse.count) { - changedFlag = false; - bulkPublishSet = []; - return resolve(); - } - await getEntries(stack, schema, contentType, languages, masterLocale, bulkPublish, environments, sourceEnv, apiVersion, bulkPublishLimit, skipCount); - return resolve(); - }) - .catch((error) => reject(error)); - return resolve(); - }); -} - -async function getLanguages(stack) { - return new Promise((resolve, reject) => { - stack - .locale() - .query() - .find() - .then((languages) => { - resolve(languages.items); - }) - .catch((error) => reject(error)); - }); -} - -async function start({ retryFailed, bulkPublish, sourceEnv, contentTypes, environments, apiVersion }, stack, config) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - process.exit(0); - }); - - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['nonlocalized-field-changes', 'bulk-nonlocalized-field-changes'])) { - return false; - } - - bulkPublish = retryFailed.match(/bulk/) ? true : false; - setConfig(config, bulkPublish); - - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue: queue }, 'publish'); - } - } - } else { - setConfig(config, bulkPublish); - const masterLocale = 'en-us'; - const languages = await getLanguages(stack); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - for (const element of contentTypes) { - /* eslint-disable no-await-in-loop */ - const schema = await getContentTypeSchema(stack, element); - await getEntries(stack, schema, element, languages, masterLocale, bulkPublish, environments, sourceEnv, apiVersion, bulkPublishLimit); - /* eslint-enable no-await-in-loop */ - } - } -} - -module.exports = { - start, - setConfig, - getLanguages, - getEntries, - getLocalizedEntry, - getContentTypeSchema, - checkNonLocalizedFieldChanges, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/publish-assets.js b/packages/contentstack-bulk-publish/src/producer/publish-assets.js deleted file mode 100644 index a9afbdd7c9..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/publish-assets.js +++ /dev/null @@ -1,175 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable new-cap */ -/* eslint-disable camelcase */ -const { cliux } = require('@contentstack/cli-utilities'); -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishAsset, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); -const { generateBulkPublishStatusUrl } = require('../util/generate-bulk-publish-url'); - -const queue = getQueue(); -let logFileName; -let bulkPublishSet = []; -let filePath; - -/* eslint-disable no-param-reassign */ - -async function getAssets(stack, folder, bulkPublish, environments, locale, apiVersion, bulkPublishLimit, skip = 0) { - return new Promise((resolve, reject) => { - let queryParams = { - folder: folder, - skip: skip, - include_count: true, - include_folders: true, - include_publish_details: true, - }; - stack - .asset() - .query(queryParams) - .find() - .then(async (assetResponse) => { - if (assetResponse && assetResponse.items.length > 0) { - skip += assetResponse.items.length; - let assets = assetResponse.items; - for (let index = 0; index < assetResponse.items.length; index++) { - if (assets[index].is_dir === true) { - await getAssets( - stack, - assets[index].uid, - bulkPublish, - environments, - locale, - apiVersion, - bulkPublishLimit, - 0, - ); - continue; - } - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid: assets[index].uid, - locale, - publish_details: assets[index].publish_details || [], - }); - } - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - assets: bulkPublishSet, - Type: 'asset', - environments: environments, - locale, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - - if ( - assetResponse.items.length - 1 === index && - bulkPublishSet.length > 0 && - bulkPublishSet.length < bulkPublishLimit - ) { - await queue.Enqueue({ - assets: bulkPublishSet, - Type: 'asset', - environments: environments, - locale, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - } else { - await queue.Enqueue({ - assetUid: assets[index].uid, - publish_details: assets[index].publish_details || [], - environments: environments, - Type: 'asset', - locale, - stack: stack, - }); - } - } - if (skip === assetResponse.count) { - return resolve(true); - } - await getAssets(stack, folder, bulkPublish, environments, locale, apiVersion, bulkPublishLimit, skip); - return resolve(); - } else { - resolve(); - } - }) - .catch((error) => { - reject(error); - }); - }); -} - -function setConfig(conf, bp) { - if (bp) { - queue.consumer = performBulkPublish; - logFileName = 'bulk-publish-assets'; - } else { - queue.consumer = publishAsset; - logFileName = 'publish-assets'; - } - config = conf; - queue.config = conf; - filePath = initializeLogger(logFileName); -} - -async function start({ retryFailed, bulkPublish, environments, folderUid, locales, apiVersion }, stack, config) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - - // Generate and display the bulk publish status link - if (bulkPublish && stack && config) { - const statusUrl = generateBulkPublishStatusUrl(stack, config); - if (statusUrl) { - process.stdout.write('\n'); - process.stdout.write('\x1b[37mHere is the link to check the bulk publish status: \x1b[0m'); - process.stdout.write('\x1b[34m' + statusUrl + '\x1b[0m'); - process.stdout.write('\n'); - } - } - - process.exit(0); - }); - - if (retryFailed) { - if (!validateFile(retryFailed, ['publish-assets', 'bulk-publish-assets'])) { - return false; - } - - bulkPublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkPublish); - - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { assetQueue: queue }, 'publish'); - } - } else if (folderUid) { - setConfig(config, bulkPublish); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - for (const locale of locales) { - await getAssets(stack, folderUid, bulkPublish, environments, locale, apiVersion, bulkPublishLimit); - } - } -} - -module.exports = { - getAssets, - setConfig, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/publish-edits.js b/packages/contentstack-bulk-publish/src/producer/publish-edits.js deleted file mode 100644 index dfc57a15d5..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/publish-edits.js +++ /dev/null @@ -1,182 +0,0 @@ -/* eslint-disable new-cap */ -/* eslint-disable max-depth */ -/* eslint-disable unicorn/catch-error-name */ -/* eslint-disable no-console */ -/* eslint-disable max-params */ -/* eslint-disable camelcase */ -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); - -let skipCount; -const queue = getQueue(); -let changedFlag = false; -let bulkPublishSet = []; -let logFileName; -let filePath; - -async function getEnvironment(stack, environmentName) { - return new Promise((resolve, reject) => { - stack - .environment(environmentName) - .fetch() - .then((env) => { - resolve(env); - }) - .catch((error) => reject(error)); - }); -} - -async function getEntries(stack, contentType, environmentUid, locale, bulkPublish, environments, apiVersion, bulkPublishLimit, skip = 0) { - return new Promise((resolve, reject) => { - skipCount = skip; - - let queryParams = { - include_count: true, - skip: skipCount, - include_publish_details: true, - locale, - }; - - stack - .contentType(contentType) - .entry() - .query(queryParams) - .find() - .then(async (responseEntries) => { - skipCount += responseEntries.items.length; - if (responseEntries.items.length > 0) { - let entries = responseEntries.items; - for (let index = 0; index < responseEntries.items.length; index++) { - const publishedEntry = entries[index].publish_details.find( - (publishEnv) => publishEnv.environment === environmentUid && publishEnv.locale === locale, - ); - if (publishedEntry && publishedEntry.version < entries[index]._version) { - changedFlag = true; - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid: entries[index].uid, - content_type: contentType, - locale, - publish_details: entries[index].publish_details || [], - }); - } - } else { - await queue.Enqueue({ - content_type: contentType, - publish_details: entries[index].publish_details || [], - environments: environments, - entryUid: entries[index].uid, - locale, - Type: 'entry', - stack: stack, - }); - } - } - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - if ( - index === responseEntries.items.length - 1 && - bulkPublishSet.length > 0 && - bulkPublishSet.length <= bulkPublishLimit - ) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } - } - if (responseEntries.count === skipCount) { - if (!changedFlag) - console.log(`No edits were detected in the specified environment for content type ${contentType}`); - bulkPublishSet = []; - return resolve(); - } - await getEntries(stack, contentType, environmentUid, locale, bulkPublish, environments, apiVersion, skipCount); - return resolve(); - }) - .catch((error) => { - reject(error); - }); - }); -} - -function setConfig(conf, bp) { - if (bp) { - logFileName = 'bulk-publish-edits'; - queue.consumer = performBulkPublish; - } else { - logFileName = 'publish-edits'; - queue.consumer = publishEntry; - } - config = conf; - queue.config = config; - filePath = initializeLogger(logFileName); -} - -async function start({ retryFailed, bulkPublish, sourceEnv, contentTypes, locales, environments, apiVersion }, stack, config) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - process.exit(0); - }); - - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['publish-edits', 'bulk-publish-edits'])) { - return false; - } - - bulkPublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkPublish); - - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue: queue }, 'publish'); - } - } - } else if (sourceEnv) { - setConfig(config, bulkPublish); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid) - const environmentDetails = await getEnvironment(stack, sourceEnv); - for (let i = 0; i < contentTypes.length; i += 1) { - for (let j = 0; j < locales.length; j += 1) { - /* eslint-disable no-await-in-loop */ - await getEntries(stack, contentTypes[i], environmentDetails.uid, locales[j], bulkPublish, environments, apiVersion,bulkPublishLimit ); - /* eslint-enable no-await-in-loop */ - } - } - } -} - -module.exports = { - getEntries, - getEnvironment, - setConfig, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/publish-entries.js b/packages/contentstack-bulk-publish/src/producer/publish-entries.js deleted file mode 100644 index df5f76c401..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/publish-entries.js +++ /dev/null @@ -1,323 +0,0 @@ -/* eslint-disable max-params */ -/* eslint-disable new-cap */ -/* eslint-disable camelcase */ -/* eslint-disable max-depth */ -/* eslint-disable no-console */ -const { cliux } = require('@contentstack/cli-utilities'); -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); -const { generateBulkPublishStatusUrl } = require('../util/generate-bulk-publish-url'); -const VARIANTS_PUBLISH_API_VERSION = '3.2'; - -const queue = getQueue(); - -let skipCount; -let logFileName; -let contentTypesList = []; -let allContentTypes = []; -let bulkPublishSet = []; -let filePath; - -async function getEntries( - stack, - contentType, - locale, - bulkPublish, - environments, - apiVersion, - bulkPublishLimit, - variantsFlag = false, - entry_uid = undefined, - skip = 0, -) { - return new Promise((resolve, reject) => { - skipCount = skip; - - let queryParams = { - locale: locale || 'en-us', - include_count: true, - skip: skipCount, - include_publish_details: true, - }; - - if (variantsFlag) { - queryParams.apiVersion = VARIANTS_PUBLISH_API_VERSION; - } - if (entry_uid) { - queryParams.uid = entry_uid; - } - - stack - .contentType(contentType) - .entry() - .query(queryParams) - .find() - .then(async (entriesResponse) => { - skipCount += entriesResponse.items.length; - let entries = entriesResponse.items; - - for (let index = 0; index < entries.length; index++) { - let variants = []; - if (bulkPublish) { - let entry; - if (bulkPublishSet.length < bulkPublishLimit) { - entry = { - uid: entries[index].uid, - content_type: contentType, - locale, - publish_details: entries[index].publish_details || [], - }; - - if (variantsFlag) { - variants = await getVariantEntries(stack, contentType, entries, index, queryParams); - if (variants.length > 0) { - entry.variant_rules = { - publish_latest_base: false, - publish_latest_base_conditionally: true, - }; - entry.variants = variants; - } - } - } - bulkPublishSet.push(entry); - - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - - if ( - index === entries.length - 1 && - bulkPublishSet.length <= bulkPublishLimit && - bulkPublishSet.length > 0 - ) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion, - }); - bulkPublishSet = []; - } - } else { - await queue.Enqueue({ - content_type: contentType, - publish_details: entries[index].publish_details || [], - environments: environments, - entryUid: entries[index].uid, - locale, - Type: 'entry', - stack: stack, - }); - } - } - - if (entriesResponse.count === skipCount) { - bulkPublishSet = []; - return resolve(); - } - await getEntries( - stack, - contentType, - locale, - bulkPublish, - environments, - apiVersion, - bulkPublishLimit, - variantsFlag, - entry_uid, - skipCount, - ); - return resolve(); - }) - .catch((error) => reject(error)); - }); -} - -async function getVariantEntries(stack, contentType, entries, index, queryParams, skip = 0) { - try { - let variantQueryParams = { - locale: queryParams.locale || 'en-us', - include_count: true, - skip: skip, // Adding skip parameter for pagination - limit: 100, // Set a limit to fetch up to 100 entries per request - include_publish_details: true, - }; - - const variantsEntriesResponse = await stack - .contentType(contentType) - .entry(entries[index].uid) - .variants() - .query(variantQueryParams) - .find(); - - // Map the response items to extract variant UIDs - const variants = variantsEntriesResponse.items.map((entry) => ({ - uid: entry.variants._variant._uid, - })); - - // Check if there are more entries to fetch - if (variantsEntriesResponse.items.length === variantQueryParams.limit) { - // Recursively fetch the next set of variants with updated skip value - const nextVariants = await getVariantEntries( - stack, - contentType, - entries, - index, - queryParams, - skip + variantQueryParams.limit, - ); - - // Ensure nextVariants is an array before concatenation - return Array.isArray(nextVariants) ? variants.concat(nextVariants) : variants; - } - - return variants; - } catch (error) { - // Handle error message retrieval from different properties - const errorMessage = - error?.errorMessage || - error?.message || - error?.errors || - 'Falied to fetch the variant entries, Please contact the admin for support.'; - throw new Error(`Error fetching variants: ${errorMessage}`); - } -} - -async function getContentTypes(stack, skip = 0, contentTypes = []) { - return new Promise((resolve, reject) => { - skipCount = skip; - contentTypesList = contentTypes; - stack - .contentType() - .query({ include_count: true, skip: skipCount }) - .find() - .then((contentTypeResponse) => { - if (contentTypeResponse.items.length > 0) { - contentTypesList = [...contentTypesList, ...contentTypeResponse.items]; - skipCount += contentTypeResponse.items.length; - if (skipCount < contentTypeResponse.count) { - getContentTypes(stack, skipCount, contentTypesList); - } - resolve(contentTypesList); - } - }) - .catch((error) => reject(error)); - }); -} - -function setConfig(conf, bp) { - if (bp) { - queue.consumer = performBulkPublish; - logFileName = 'bulk-publish-entries'; - } else { - queue.consumer = publishEntry; - logFileName = 'publish-entries'; - } - config = conf; - queue.config = conf; - filePath = initializeLogger(logFileName); -} - -async function start( - { - retryFailed, - bulkPublish, - publishAllContentTypes, - contentTypes, - locales, - environments, - apiVersion, - includeVariants, - entryUid, - }, - stack, - config, -) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - - // Generate and display the bulk publish status link - if (bulkPublish && stack && config) { - const statusUrl = generateBulkPublishStatusUrl(stack, config); - if (statusUrl) { - process.stdout.write('\n'); - process.stdout.write('\x1b[37mHere is the link to check the bulk publish status: \x1b[0m'); - process.stdout.write('\x1b[34m' + statusUrl + '\x1b[0m'); - process.stdout.write('\n'); - } - } - - process.exit(0); - }); - - if (includeVariants) { - apiVersion = VARIANTS_PUBLISH_API_VERSION; - } - - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['publish-entries', 'bulk-publish-entries'])) { - return false; - } - bulkPublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkPublish); - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue: queue }, 'publish'); - } - } - } else { - setConfig(config, bulkPublish); - if (publishAllContentTypes) { - allContentTypes = await getContentTypes(stack); - } else { - allContentTypes = contentTypes; - } - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - for (let loc = 0; loc < locales.length; loc += 1) { - for (let i = 0; i < allContentTypes.length; i += 1) { - /* eslint-disable no-await-in-loop */ - await getEntries( - stack, - allContentTypes[i].uid || allContentTypes[i], - locales[loc], - bulkPublish, - environments, - apiVersion, - bulkPublishLimit, - includeVariants, - entryUid, - ); - /* eslint-enable no-await-in-loop */ - } - } - } -} - -module.exports = { - getEntries, - setConfig, - getContentTypes, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js b/packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js deleted file mode 100644 index 7e2c4c0b62..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/publish-unpublished-env.js +++ /dev/null @@ -1,199 +0,0 @@ -/* eslint-disable max-params */ -/* eslint-disable max-depth */ -/* eslint-disable unicorn/catch-error-name */ -/* eslint-disable no-console */ -/* eslint-disable new-cap */ -/* eslint-disable camelcase */ -const { cliux } = require('@contentstack/cli-utilities'); -const { getQueue } = require('../util/queue'); -const { performBulkPublish, publishEntry, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); -const { generateBulkPublishStatusUrl } = require('../util/generate-bulk-publish-url'); - -const queue = getQueue(); -let skipCount; -let changedFlag = false; -let logFileName = 'publish-unpublished-env'; -let bulkPublishSet = []; -let filePath; - -function setConfig(conf, bp) { - if (bp) { - logFileName = 'bulk-publish-draft'; - queue.consumer = performBulkPublish; - } else { - logFileName = 'publish-draft'; - queue.consumer = publishEntry; - } - config = conf; - queue.config = config; - filePath = initializeLogger(logFileName); -} - -async function getEnvironment(stack, environmentName) { - return new Promise((resolve, reject) => { - stack - .environment(environmentName) - .fetch() - .then((env) => { - resolve(env); - }) - .catch((error) => reject(error)); - }); -} - -async function getEntries(stack, contentType, environmentUid, locale, bulkPublish, environments, apiVersion, bulkPublishLimit, skip = 0) { - return new Promise((resolve, reject) => { - skipCount = skip; - - let queryParams = { - include_count: true, - skip: skipCount, - include_publish_details: true, - }; - - stack - .contentType(contentType) - .entry() - .query(queryParams) - .find() - .then(async (responseEntries) => { - skipCount += responseEntries.items.length; - if (responseEntries.items.length > 0) { - let entries = responseEntries.items; - for (let index = 0; index < responseEntries.items.length; index++) { - const publishedEntry = entries[index].publish_details.find( - (publishEnv) => publishEnv.environment === environmentUid && publishEnv.locale === locale, - ); - if (!publishedEntry) { - changedFlag = true; - if (bulkPublish) { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid: entries[index].uid, - content_type: contentType, - locale, - publish_details: entries[index].publish_details || [], - }); - } - } else { - await queue.Enqueue({ - content_type: contentType, - publish_details: entries[index].publish_details, - environments: environments, - entryUid: entries[index].uid, - locale, - Type: 'entry', - stack: stack, - }); - } - } - if (bulkPublish) { - if (bulkPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - if ( - index === responseEntries.items.length - 1 && - bulkPublishSet.length < bulkPublishLimit && - bulkPublishSet.length > 0 - ) { - await queue.Enqueue({ - entries: bulkPublishSet, - locale, - Type: 'entry', - environments: environments, - stack: stack, - apiVersion - }); - bulkPublishSet = []; - } - } - } - } - if (responseEntries.count === skipCount) { - if (!changedFlag) console.log(`No draft entries found for content type ${contentType}`); - bulkPublishSet = []; - return resolve(); - } - await getEntries(stack, contentType, environmentUid, locale, bulkPublish, environments, apiVersion, skipCount); - return resolve(); - }) - .catch((error) => { - reject(error); - }); - }); -} - -async function start({ sourceEnv, environments, locale, contentTypes, bulkPublish, retryFailed, apiVersion }, stack, config) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - - // Generate and display the bulk publish status link - if (bulkPublish && stack && config) { - const statusUrl = generateBulkPublishStatusUrl(stack, config); - if (statusUrl) { - process.stdout.write('\n'); - process.stdout.write('\x1b[37mHere is the link to check the bulk unpublish status: \x1b[0m'); - process.stdout.write('\x1b[34m' + statusUrl + '\x1b[0m'); - process.stdout.write('\n'); - } - } - - process.exit(0); - }); - - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['publish-draft', 'bulk-publish-draft'])) { - return false; - } - - bulkPublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkPublish); - - if (bulkPublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue: queue }, 'publish'); - } - } - } else { - setConfig(config, bulkPublish); - if (sourceEnv) { - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - const environmentDetails = await getEnvironment(stack, sourceEnv); - for (let i = 0; i < contentTypes.length; i += 1) { - /* eslint-disable no-await-in-loop */ - await getEntries(stack, contentTypes[i], environmentDetails.uid, locale, bulkPublish, environments, apiVersion, bulkPublishLimit); - /* eslint-enable no-await-in-loop */ - changedFlag = false; - } - } - } -} - -// start() - -module.exports = { - getEntries, - getEnvironment, - setConfig, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/revert.js b/packages/contentstack-bulk-publish/src/producer/revert.js deleted file mode 100644 index 943438ba7e..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/revert.js +++ /dev/null @@ -1,391 +0,0 @@ -/* eslint-disable node/no-extraneous-require */ -/* eslint-disable no-await-in-loop */ -/* eslint-disable require-atomic-updates */ -/* eslint-disable no-console */ -/* eslint-disable new-cap */ -/* eslint-disable camelcase */ -const chalk = require('chalk'); -const { getAllLogs } = require('../util/logger'); -const { getQueue } = require('../util/queue'); -const { validateFile } = require('../util/fs'); -const { configHandler } = require('@contentstack/cli-utilities'); -let config = configHandler -const { initializeLogger, performBulkUnPublish, publishUsingVersion } = require('../consumer/publish'); -const getStack = require('../util/client.js').getStack; -const { fetchBulkPublishLimit } = require('../util/common-utility'); - -const intervalBetweenPublishRequests = 3; // interval in seconds - -const unpublishQueue = getQueue(); -const publishQueue = getQueue(); - -const revertLogFileName = 'revert'; - -function setConfig(conf) { - config = conf; - unpublishQueue.config = conf; - publishQueue.config = conf; - unpublishQueue.consumer = performBulkUnPublish; - publishQueue.consumer = publishUsingVersion; -} - -function getLogFileDataType(data) { - const element = data[0]; - if (element.message.options.Type) { - return element.message.options.Type; - } - if (element.message.options.entryUid) { - return 'entry'; - } - return 'asset'; -} - -async function getEnvironmentUids(stack, environments) { - return new Promise((resolve, reject) => { - stack - .environment() - .query() - .find() - .then((allEnvironments) => { - const filteredEnvironments = allEnvironments.items - .filter((environment) => environments.indexOf(environment.name) !== -1) - .map(({ name, uid }) => ({ name, uid })); - resolve(filteredEnvironments); - }) - .catch((error) => reject(error)); - }); -} - -function filterPublishDetails(elements, environments, locale) { - if (locale && locale.length > 0) { - locale.forEach((loc) => { - elements[loc].forEach((entry) => { - if (entry.publish_details.length > 0) { - entry.publish_details = entry.publish_details.filter( - (element) => environments.indexOf(element.environment) !== -1 && element.locale === loc, - ); - } - }); - }); - } else { - for (let i = 0; i < elements.length; i += 1) { - if (elements[i].publish_details.length > 0) { - elements[i].publish_details = elements[i].publish_details.filter( - (element) => environments.indexOf(element.environment) !== -1, - ); - } - } - } - return elements; -} - -async function formatLogData(stack, data) { - const formattedLogs = {}; - const type = getLogFileDataType(data); - - switch (type) { - case 'entry': - formattedLogs.entries = {}; - formattedLogs.locale = []; - for (let i = 0; i < data.length; i += 1) { - if (formattedLogs.locale.indexOf(data[i].message.options.locale) === -1) { - formattedLogs.locale.push(data[i].message.options.locale); - } - if (!formattedLogs.entries[data[i].message.options.locale]) - formattedLogs.entries[data[i].message.options.locale] = []; - if (data[i].message.options.entries) { - // for handling bulk-publish-entries logs - formattedLogs.entries[data[i].message.options.locale] = formattedLogs.entries[ - data[i].message.options.locale - ].concat(data[i].message.options.entries); - } else { - // for handling logs created by publishing in a regular way - formattedLogs.entries[data[i].message.options.locale].push({ - uid: data[i].message.options.entryUid, - content_type: data[i].message.options.content_type, - locale: data[i].message.options.locale, - publish_details: data[i].message.options.publish_details, - }); - } - if (!formattedLogs.environments) formattedLogs.environments = data[i].message.options.environments; - if (!formattedLogs.api_key) formattedLogs.api_key = data[i].message.api_key; - } - break; - case 'asset': - formattedLogs.assets = []; - for (let i = 0; i < data.length; i += 1) { - if (data[i].message.options.assets) { - // for handling bulk-publish-assets logs - formattedLogs.assets = formattedLogs.assets.concat(data[i].message.options.assets); - } else { - // for handling logs created by publishing assets in a regular way - formattedLogs.assets.push({ - uid: data[i].message.options.assetUid, - publish_details: data[i].message.options.publish_details, - }); - } - if (!formattedLogs.environments) formattedLogs.environments = data[i].message.options.environments; - if (!formattedLogs.api_key) formattedLogs.api_key = data[i].message.api_key; - } - break; - default: - break; - } - - formattedLogs.environments = await getEnvironmentUids(stack, formattedLogs.environments); - formattedLogs.type = type; - if (type === 'entry') { - formattedLogs.entries = filterPublishDetails( - formattedLogs.entries, - formattedLogs.environments.map(({ uid }) => uid), - formattedLogs.locale, - ); - } else { - formattedLogs.assets = filterPublishDetails( - formattedLogs.assets, - formattedLogs.environments.map(({ uid }) => uid), - ); - } - - return formattedLogs; -} - -async function mapSeries(iterable, action) { - for (let x of iterable) { - await action(x); - } -} - -function sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); -} - -function processPublishRequests(data) { - return sleep(intervalBetweenPublishRequests * 1000).then(() => { - publishQueue.Enqueue(data); - }); -} - -async function revertUsingLogs(logFileName) { - let bulkUnpublishSet = []; - const setOfBulkPublishRequestPayloads = []; - let bulkPublishSet = []; - - if (validateFile(logFileName)) { - const response = await getAllLogs(logFileName); - let logs; - - if (response.file.length > 0) { - initializeLogger(revertLogFileName); - const stack = await getStack({ - apikey: response.file[0].message.api_key, - alias: response.file[0].message.alias, - host: response.file[0].message.host, - branch: response.file[0].message.branch || 'main', - delayMs: response.file[0].message.delayMs - }); - logs = await formatLogData(stack, response.file); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - - logs.environments.forEach((environment, envIndex) => { - switch (logs.type) { - case 'entry': - logs.locale.forEach((loc, locIndex) => { - logs.entries[loc].forEach(({ publish_details, uid, locale, content_type }, entryIndex) => { - const publishDetailsForThisEnvironment = publish_details.filter( - (publishDetail) => publishDetail.environment === environment.uid, - ); - - if (publishDetailsForThisEnvironment.length > 0) { - // handle revert case - - publishDetailsForThisEnvironment.forEach((publishDetail) => { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid, - version: publishDetail.version, - locale, - content_type, - publish_details: [publishDetail], - }); - } - - if (bulkPublishSet.length === bulkPublishLimit) { - const data = { - entries: bulkPublishSet, - environments: [environment.name], - locale: loc, - Type: 'entry', - stack: stack, - }; - setOfBulkPublishRequestPayloads.push(data); - bulkPublishSet = []; - } - }); - } else { - if (bulkUnpublishSet.length < bulkPublishLimit) { - bulkUnpublishSet.push({ - uid, - locale, - content_type, - publish_details: [], - }); - } - - if (bulkUnpublishSet.length === bulkPublishLimit) { - unpublishQueue.Enqueue({ - entries: bulkUnpublishSet, - environments: [environment.name], - locale: loc, - Type: 'entry', - stack: stack, - }); - bulkUnpublishSet = []; - } - } - - if (entryIndex === logs.entries[loc].length - 1) { - if (bulkUnpublishSet.length <= bulkPublishLimit && bulkUnpublishSet.length !== 0) { - unpublishQueue.Enqueue({ - entries: bulkUnpublishSet, - environments: [environment.name], - locale: loc, - Type: 'entry', - stack: stack, - }); - bulkUnpublishSet = []; - } - - if (bulkPublishSet.length <= bulkPublishLimit && bulkPublishSet.length !== 0) { - const data = { - entries: bulkPublishSet, - environments: [environment.name], - locale: loc, - Type: 'entry', - stack: stack, - }; - setOfBulkPublishRequestPayloads.push(data); - bulkPublishSet = []; - } - } - - if ( - envIndex === logs.environments.length - 1 && - locIndex === logs.locale.length - 1 && - entryIndex === logs.entries[loc].length - 1 - ) { - mapSeries(setOfBulkPublishRequestPayloads, processPublishRequests); - } - }); - }); - break; - case 'asset': - logs.assets.forEach(({ publish_details, uid }, assetIndex) => { - const publishDetailsForThisEnvironment = publish_details.filter( - (publishDetail) => publishDetail.environment === environment.uid, - ); - - if (publishDetailsForThisEnvironment.length > 0) { - // handle revert case - - publishDetailsForThisEnvironment.forEach((publishDetail) => { - if (bulkPublishSet.length < bulkPublishLimit) { - bulkPublishSet.push({ - uid, - version: publishDetail.version, - publish_details: [publishDetail], - }); - } - - if (bulkPublishSet.length === bulkPublishLimit) { - const data = { - assets: bulkPublishSet, - environments: [environment.name], - locale: 'en-us', - Type: 'asset', - stack: stack, - }; - setOfBulkPublishRequestPayloads.push(data); - bulkPublishSet = []; - } - }); - } else { - if (bulkUnpublishSet.length < bulkPublishLimit) { - bulkUnpublishSet.push({ - uid, - publish_details: [], - }); - } - - if (bulkUnpublishSet.length === bulkPublishLimit) { - unpublishQueue.Enqueue({ - assets: bulkUnpublishSet, - environments: [environment.name], - Type: 'asset', - stack: stack, - }); - bulkUnpublishSet = []; - } - } - - if (assetIndex === logs.assets.length - 1) { - if (bulkUnpublishSet.length <= bulkPublishLimit && bulkUnpublishSet.length !== 0) { - unpublishQueue.Enqueue({ - assets: bulkUnpublishSet, - environments: [environment.name], - Type: 'asset', - stack: stack, - }); - bulkUnpublishSet = []; - } - - if (bulkPublishSet.length <= bulkPublishLimit && bulkPublishSet.length !== 0) { - const data = { - assets: bulkPublishSet, - environments: [environment.name], - locale: 'en-us', - Type: 'asset', - stack: stack, - }; - setOfBulkPublishRequestPayloads.push(data); - bulkPublishSet = []; - } - } - - if (envIndex === logs.environments.length - 1 && assetIndex === logs.assets.length - 1) { - mapSeries(setOfBulkPublishRequestPayloads, processPublishRequests); - } - }); - break; - default: - break; - } - }); - } else { - console.log(chalk.red('Error: This log file is empty. Please check error logs if any')); - } - } -} - -async function start({ retryFailed, logFile }, cfg) { - setConfig(cfg); - if (retryFailed) { - if (typeof retryFailed === 'string') { - if (!validateFile(retryFailed, ['revert'])) { - return false; - } - - revertUsingLogs(retryFailed); - } - } else { - revertUsingLogs(logFile); - } -} - -module.exports = { - setConfig, - revertUsingLogs, - start, -}; diff --git a/packages/contentstack-bulk-publish/src/producer/unpublish.js b/packages/contentstack-bulk-publish/src/producer/unpublish.js deleted file mode 100644 index 95b45b9786..0000000000 --- a/packages/contentstack-bulk-publish/src/producer/unpublish.js +++ /dev/null @@ -1,395 +0,0 @@ -/* eslint-disable max-params */ -/* eslint-disable new-cap */ -/* eslint-disable complexity */ -/* eslint-disable no-console */ -/* eslint-disable camelcase */ -const { configHandler, cliux } = require('@contentstack/cli-utilities'); -const { getQueue } = require('../util/queue'); -const { performBulkUnPublish, UnpublishEntry, UnpublishAsset, initializeLogger } = require('../consumer/publish'); -const retryFailedLogs = require('../util/retryfailed'); -const { validateFile } = require('../util/fs'); -const queue = getQueue(); -const entryQueue = getQueue(); -const assetQueue = getQueue(); -const { Command } = require('@contentstack/cli-command'); -const command = new Command(); -const { isEmpty } = require('../util'); -const { fetchBulkPublishLimit } = require('../util/common-utility'); -const { generateBulkPublishStatusUrl } = require('../util/generate-bulk-publish-url'); -const VARIANTS_UNPUBLISH_API_VERSION = '3.2'; -const delay = (ms) => new Promise((res) => setTimeout(res, ms)); - -let bulkUnPublishSet = []; -let bulkUnPulishAssetSet = []; -let logFileName; -let filePath; - -function setConfig(conf, bup) { - if (bup) { - logFileName = 'bulk-unpublish'; - queue.consumer = performBulkUnPublish; - } else { - logFileName = 'unpublish'; - entryQueue.consumer = UnpublishEntry; - assetQueue.consumer = UnpublishAsset; - } - config = conf; - queue.config = conf; - entryQueue.config = conf; - assetQueue.config = conf; - filePath = initializeLogger(logFileName); -} - -let changedFlag = false; - -function getQueryParams(filter) { - let queryString = ''; - Object.keys(filter).forEach((key) => { - if (filter[key]) { - queryString = `${queryString}&${key}=${filter[key]}`; - } - }); - - return queryString; -} - -function bulkAction(stack, items, bulkUnpublish, environment, locale, apiVersion, bulkPublishLimit, variantsFlag = false) { - return new Promise(async (resolve) => { - for (let index = 0; index < items.length; index++) { - changedFlag = true; - - if (bulkUnpublish) { - if (bulkUnPublishSet.length < bulkPublishLimit && items[index].type === 'entry_published') { - const entryData = { - uid: items[index].data.uid, - content_type: items[index].content_type_uid, - locale: items[index].data.locale || 'en-us', - publish_details: items[index].data.publish_details || [], - }; - - if (variantsFlag && Array.isArray(items[index].data.variants) && items[index].data.variants.length > 0) { - const entryWithVariants = { ...entryData, variants: items[index].data.variants }; - bulkUnPublishSet.push(entryWithVariants); - } else { - bulkUnPublishSet.push(entryData); - } - } - - if (bulkUnPulishAssetSet.length < bulkPublishLimit && items[index].type === 'asset_published') { - bulkUnPulishAssetSet.push({ - uid: items[index].data.uid, - version: items[index].data._version, - publish_details: [items[index].data.publish_details] || [], - }); - } - - if (bulkUnPulishAssetSet.length === bulkPublishLimit) { - await queue.Enqueue({ - assets: bulkUnPulishAssetSet, - Type: 'asset', - locale: locale, - environments: [environment], - stack: stack, - apiVersion, - }); - bulkUnPulishAssetSet = []; - } - - if (bulkUnPublishSet.length === bulkPublishLimit) { - await queue.Enqueue({ - entries: bulkUnPublishSet, - locale: locale, - Type: 'entry', - environments: [environment], - stack: stack, - apiVersion, - }); - bulkUnPublishSet = []; - } - if (index === items.length - 1 && bulkUnPulishAssetSet.length <= bulkPublishLimit && bulkUnPulishAssetSet.length > 0) { - await queue.Enqueue({ - assets: bulkUnPulishAssetSet, - Type: 'asset', - locale: locale, - environments: [environment], - stack: stack, - apiVersion, - }); - bulkUnPulishAssetSet = []; - } - - if (index === items.length - 1 && bulkUnPublishSet.length <= bulkPublishLimit && bulkUnPublishSet.length > 0) { - await queue.Enqueue({ - entries: bulkUnPublishSet, - locale: locale, - Type: 'entry', - environments: [environment], - stack: stack, - apiVersion, - }); - bulkUnPublishSet = []; - } - } else { - if (items[index].type === 'entry_published') { - await entryQueue.Enqueue({ - content_type: items[index].content_type_uid, - publish_details: [items[index].data.publish_details], - environments: [environment], - entryUid: items[index].data.uid, - locale: items[index].data.locale || 'en-us', - Type: 'entry', - stack: stack, - apiVersion, - }); - } - if (items[index].type === 'asset_published') { - await assetQueue.Enqueue({ - assetUid: items[index].data.uid, - publish_details: [items[index].data.publish_details], - environments: [environment], - Type: 'entry', - stack: stack, - }); - } - } - } - return resolve(); - }); -} - -async function getSyncEntries( - stack, - config, - locale, - queryParams, - bulkUnpublish, - environment, - deliveryToken, - apiVersion, - bulkPublishLimit, - variantsFlag, - paginationToken = null, -) { - return new Promise(async (resolve, reject) => { - try { - let tokenDetails; - if (config.stackApiKey) { - tokenDetails = { apiKey: config.stackApiKey }; - } else { - tokenDetails = command.getToken(config.alias); - } - const queryParamsObj = {}; - const pairs = queryParams.split('&'); - for (let i in pairs) { - const split = pairs[i].split('='); - queryParamsObj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]); - } - - const deliveryAPIOptions = { - api_key: tokenDetails.apiKey, - delivery_token: deliveryToken, - environment: queryParamsObj.environment, - branch: config.branch, - }; - - const earlyAccessHeaders = configHandler.get(`earlyAccessHeaders`); - if (earlyAccessHeaders && Object.keys(earlyAccessHeaders).length > 0) { - deliveryAPIOptions.early_access = Object.values(earlyAccessHeaders); - } - - const Stack = new command.deliveryAPIClient.Stack(deliveryAPIOptions); - Stack.setHost(config.cda); - - const syncData = {}; - - if (paginationToken) { - syncData['pagination_token'] = paginationToken; - } else { - syncData['init'] = true; - } - if (queryParamsObj.locale) { - syncData['locale'] = queryParamsObj.locale; - } - if (queryParamsObj.type) { - syncData['type'] = queryParamsObj.type; - } - if(queryParamsObj.content_type_uid) { - syncData['content_type_uid'] = queryParamsObj.content_type_uid; - } - - const entriesResponse = await Stack.sync(syncData); - if (entriesResponse.items.length > 0) { - if (variantsFlag) { - queryParamsObj.apiVersion = VARIANTS_UNPUBLISH_API_VERSION; - const itemsWithVariants = await attachVariantsToItems(stack, entriesResponse.items, queryParamsObj); - // Call bulkAction for entries with variants - await bulkAction(stack, itemsWithVariants, bulkUnpublish, environment, locale, apiVersion, bulkPublishLimit, variantsFlag); - } - // Call bulkAction for entries without variants - await bulkAction(stack, entriesResponse.items, bulkUnpublish, environment, locale, apiVersion, bulkPublishLimit, false); - } - if (entriesResponse.items.length === 0 && !entriesResponse.pagination_token) { - if (!changedFlag) console.log('No entries or assets found published in the specified environment.'); - return resolve(); - } - - await delay(3000); - await getSyncEntries( - stack, - config, - locale, - queryParams, - bulkUnpublish, - environment, - deliveryToken, - apiVersion, - bulkPublishLimit, - variantsFlag, - entriesResponse.pagination_token, - ); - - return resolve(); - } catch (error) { - return reject(error); - } - }); -} -async function attachVariantsToItems(stack, items, queryParams) { - for (const item of items) { - const { content_type_uid, data } = item; - const variantEntries = await getVariantEntries(stack, content_type_uid, item, queryParams); // Fetch the variants using fetchVariants method - item.data.variants = variantEntries; // Attach the fetched variants to the data object in the item - } - return items; -} - -async function getVariantEntries(stack, contentType, entries, queryParams, skip = 0) { - try { - let variantQueryParams = { - locale: queryParams.locale || 'en-us', - include_count: true, - skip: skip, // Adding skip parameter for pagination - limit: 100, // Set a limit to fetch up to 100 entries per request - }; - - const variantsEntriesResponse = await stack - .contentType(contentType) - .entry(entries.data.uid) - .variants() - .query(variantQueryParams) - .find(); - - // Map the response items to extract variant UIDs - const variants = variantsEntriesResponse.items.map(entry => ({ - uid: entry.variants._variant._uid, - })); - - // Check if there are more entries to fetch - if (variantsEntriesResponse.items.length === variantQueryParams.limit) { - // Recursively fetch the next set of variants with updated skip value - const nextVariants = await getVariantEntries(stack, contentType, entries, queryParams, skip + variantQueryParams.limit); - - // Ensure nextVariants is an array before concatenation - return Array.isArray(nextVariants) ? variants.concat(nextVariants) : variants; - } - - return variants; - } catch (error) { - // Handle error message retrieval from different properties - const errorMessage = error?.errorMessage || error?.message || error?.errors || 'Falied to fetch the variant entries, Please contact the admin for support.'; - throw new Error(`Error fetching variants: ${errorMessage}`); - } -} - -async function start( - { - retryFailed, - bulkUnpublish, - contentType, - locale, - environment, - deliveryToken, - onlyAssets, - onlyEntries, - f_types, - apiVersion, - includeVariants, - }, - stack, - config, -) { - process.on('beforeExit', async () => { - const isErrorLogEmpty = await isEmpty(`${filePath}.error`); - const isSuccessLogEmpty = await isEmpty(`${filePath}.success`); - if (!isErrorLogEmpty) { - console.log(`The error log for this session is stored at ${filePath}.error`); - } else if (!isSuccessLogEmpty) { - console.log(`The success log for this session is stored at ${filePath}.success`); - } - - // Generate and display the bulk publish status link - if (bulkUnpublish && stack && config) { - const statusUrl = generateBulkPublishStatusUrl(stack, config); - if (statusUrl) { - process.stdout.write('\n'); - process.stdout.write('\x1b[37mHere is the link to check the bulk unpublish status: \x1b[0m'); - process.stdout.write('\x1b[34m' + statusUrl + '\x1b[0m'); - process.stdout.write('\n'); - } - } - - process.exit(0); - }); - if (includeVariants) { - apiVersion = VARIANTS_UNPUBLISH_API_VERSION; - } - if (retryFailed) { - if (typeof retryFailed === 'string' && retryFailed.length > 0) { - if (!validateFile(retryFailed, ['unpublish', 'bulk-unpublish'])) { - return false; - } - - bulkUnpublish = retryFailed.match(new RegExp('bulk')) ? true : false; - setConfig(config, bulkUnpublish); - - if (bulkUnpublish) { - await retryFailedLogs(retryFailed, queue, 'bulk'); - } else { - await retryFailedLogs(retryFailed, { entryQueue, assetQueue }, 'publish'); - } - } - } else { - let filter = { - environment, - locale, - }; - if (f_types) { - filter.type = f_types; - } - // filter.type = (f_types) ? f_types : types // types mentioned in the config file (f_types) are given preference - if (contentType) { - filter.content_type_uid = contentType; - filter.type = 'entry_published'; - } - if (onlyAssets) { - filter.type = 'asset_published'; - delete filter.content_type_uid; - } - if (onlyEntries) { - filter.type = 'entry_published'; - } - setConfig(config, bulkUnpublish); - const queryParams = getQueryParams(filter); - const bulkPublishLimit = fetchBulkPublishLimit(stack?.org_uid); - await getSyncEntries(stack, config, locale, queryParams, bulkUnpublish, environment, deliveryToken, apiVersion, bulkPublishLimit, includeVariants); - } -} - -// start() - -module.exports = { - getSyncEntries, - setConfig, - getQueryParams, - start, -}; \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js b/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js deleted file mode 100644 index 57a8e9f761..0000000000 --- a/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -const { cliux } = require('@contentstack/cli-utilities'); - -const { start } = require('../producer/publish-unpublished-env'); -const { prettyPrint, formatError } = require('../util'); -const { getStack } = require('../util/client'); -const store = require('../util/store'); - -const configKey = 'publish_unpublished_env'; - -async function publishOnlyUnpublishedService(UnpublishedEntriesCommand) { - let config; - const _flags = await this.parse(UnpublishedEntriesCommand); - const unpublishedEntriesFlags = flagsAdapter(_flags.flags); - let updatedFlags; - try { - updatedFlags = unpublishedEntriesFlags.config - ? store.updateMissing(configKey, unpublishedEntriesFlags) - : unpublishedEntriesFlags; - } catch (error) { - this.error(error.message, { exit: 2 }); - } - if (validate.apply(this, [updatedFlags])) { - let stack; - if (!updatedFlags.retryFailed) { - config = { - alias: updatedFlags.alias, - host: this.cmaHost, - cda: this.cdaHost, - branch: unpublishedEntriesFlags.branch, - delayMs: updatedFlags.delayMs, - }; - if (updatedFlags.alias) { - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } - } else if (updatedFlags['stack-api-key']) { - config.stackApiKey = updatedFlags['stack-api-key']; - } else { - this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); - } - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - stack = await getStack(config); - if (await confirmFlags(updatedFlags)) { - try { - if (!updatedFlags.retryFailed) { - await start(updatedFlags, stack, config); - } else { - await start(updatedFlags); - } - } catch (error) { - let message = formatError(error); - this.error(message, { exit: 2 }); - } - } else { - this.exit(0); - } - } -} - -function validate({ contentTypes, environments, sourceEnv, locale, retryFailed }) { - let missing = []; - if (retryFailed) { - return true; - } - - if (!contentTypes || contentTypes.length === 0) { - missing.push('Content Types'); - } - - if (!sourceEnv) { - missing.push('SourceEnv'); - } - - if (!environments || environments.length === 0) { - missing.push('Environments'); - } - - if (!locale) { - missing.push('Source Locale'); - } - - if (missing.length > 0) { - this.error(`${missing.join(', ')} are required for processing this command. Please check --help for more details`, { - exit: 2, - }); - } else { - return true; - } -} - -async function confirmFlags(data) { - prettyPrint(data); - if (data.yes) { - return true; - } - return await cliux.confirm('Do you want to continue with this configuration ? [yes or no]'); -} - -function flagsAdapter(flags) { - if ('content-types' in flags) { - flags.contentTypes = flags['content-types']; - delete flags['content-types']; - } - if ('locales' in flags) { - flags.locale = flags.locales; - delete flags['locales']; - } - if ('source-env' in flags) { - flags.sourceEnv = flags['source-env']; - delete flags['source-env']; - } - if ('retry-failed' in flags) { - flags.retryFailed = flags['retry-failed']; - delete flags['retry-failed']; - } - if ('bulk-publish' in flags) { - flags.bulkPublish = flags['bulk-publish']; - delete flags['bulk-publish']; - } - if ('api-version' in flags) { - flags.apiVersion = flags['api-version'] || '3'; - delete flags['api-version']; - } - return flags; -} - -module.exports = { - publishOnlyUnpublishedService, - validate, - confirmFlags, -}; diff --git a/packages/contentstack-bulk-publish/src/util/client.js b/packages/contentstack-bulk-publish/src/util/client.js deleted file mode 100644 index cbcf534f9b..0000000000 --- a/packages/contentstack-bulk-publish/src/util/client.js +++ /dev/null @@ -1,38 +0,0 @@ -const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities'); -const { Command } = require('@contentstack/cli-command'); -const command = new Command(); - -async function getStack(data) { - const options = { - host: data.host, - branchName: data.branch, - delayMs: data.delayMs, - }; - const stackOptions = {}; - if (data.alias) { - const tokenDetails = command.getToken(data.alias); - options.management_token = tokenDetails.token; - stackOptions.management_token = tokenDetails.token; - stackOptions.api_key = tokenDetails.apiKey; - } else if (data.stackApiKey) { - if (!isAuthenticated()) { - throw new Error( - 'Please login to proceed further. Or use `--alias` instead of `--stack-api-key` to proceed without logging in.', - ); - } - stackOptions.api_key = data.stackApiKey; - } - const managementClient = await managementSDKClient(options); - const stack = managementClient.stack(stackOptions); - if (data.stackApiKey && isAuthenticated()) { - const stackDetails = await stack.fetch(); - stack.org_uid = stackDetails.org_uid; - } - stack.alias = data.alias; - stack.host = data.host; - return stack; -} - -module.exports = { - getStack, -}; diff --git a/packages/contentstack-bulk-publish/src/util/command-helper.js b/packages/contentstack-bulk-publish/src/util/command-helper.js deleted file mode 100644 index a405461782..0000000000 --- a/packages/contentstack-bulk-publish/src/util/command-helper.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const inquirer = require('inquirer'); - -const COMMAND_CODE_MAP = { - 'Publish Entries': 0, - 'Publish Assets': 1, - 'Publish Entries and Assets': 2, -}; - -const getSelectedCommand = async () => { - const inquirerOptions = [{ - type: 'list', - message: 'Choose one of the following task to execute.', - choices: Object.keys(COMMAND_CODE_MAP), - name: 'selectedOption', - loop: false, - }]; - const selectedOption = await inquirer.prompt(inquirerOptions); - return COMMAND_CODE_MAP[selectedOption]; -}; - -module.exports = { - getSelectedCommand, -}; \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/util/common-utility.js b/packages/contentstack-bulk-publish/src/util/common-utility.js deleted file mode 100644 index c51c0a40de..0000000000 --- a/packages/contentstack-bulk-publish/src/util/common-utility.js +++ /dev/null @@ -1,30 +0,0 @@ -const { configHandler, cliux } = require('@contentstack/cli-utilities'); - -function fetchBulkPublishLimit(orgUid) { - const plan = configHandler.get('rateLimit'); - let bulkPublishLimit = 1; // Default limit according to the default plan - - if (plan) { - const orgPlan = plan[orgUid]?.bulkLimit; - const defaultPlan = plan['default']?.bulkLimit; - - if (orgPlan?.value && orgPlan?.utilize) { - bulkPublishLimit = Math.ceil((orgPlan.value * orgPlan.utilize) / 100); - } else if (defaultPlan?.value && defaultPlan?.utilize) { - bulkPublishLimit = Math.ceil((defaultPlan.value * defaultPlan.utilize) / 100); - } - } else { - cliux.print( - 'Bulk publish limit not found in config. Using default limit. Please set the limit using $csdx config:set:rate-limit', - { color: 'yellow' }, - ); - // TODO: Update the link once the rate-limit documentation is ready - cliux.print( - 'Suggestions: To set the rate limit, visit https://www.contentstack.com/docs/developers/cli#get-started-with-contentstack-command-line-interface-cli', - { color: 'blue' }, - ); - } - return bulkPublishLimit; -} - -module.exports = { fetchBulkPublishLimit }; diff --git a/packages/contentstack-bulk-publish/src/util/fs.js b/packages/contentstack-bulk-publish/src/util/fs.js deleted file mode 100644 index 30204c1657..0000000000 --- a/packages/contentstack-bulk-publish/src/util/fs.js +++ /dev/null @@ -1,68 +0,0 @@ -const fs = require('fs'); -const { getLogsDirPath } = require('../util/logger.js'); - -const logsDir = getLogsDirPath(); - -/* eslint-disable consistent-return */ - -function doesFileExistInLogsDirectory(filename) { - const files = fs.readdirSync(logsDir); - if (files.indexOf(filename) !== -1) { - return true; - } - throw new Error(`${filename} doesn't exist in logs directory at ${logsDir}`); -} - -function validateFile(filename, types) { - if (doesFileExistInLogsDirectory(filename)) { - const [timestamp, logType, status] = filename.split('.'); - - if (!timestamp || !logType || !status) { - throw new Error(`${filename} is not a valid log file or the log name has been changed`); - } - - if (status !== 'success' && status !== 'error') { - throw new Error(`${filename} is not a valid log file or the log name has been changed`); - } - - if (logType) { - switch (logType) { - case 'bulk-add-fields': - case 'add-fields': - case 'bulk-cross-publish': - case 'cross-publish': - case 'bulk-nonlocalized-field-changes': - case 'nonlocalized-field-changes': - case 'bulk-publish-assets': - case 'publish-assets': - case 'bulk-publish-edits': - case 'publish-edits': - case 'bulk-publish-entries': - case 'publish-entries': - case 'publish-unpublished-env': - case 'bulk-publish-draft': - case 'publish-draft': - case 'bulk-unpublish': - case 'unpublish': - case 'revert': - if (types && types.length > 0) { - if (status !== 'error') { - throw new Error('Error: The given log file is not an error log file.'); - } - - if (types.indexOf(logType) === -1) { - let validTypes = '' + types.join(', '); - throw new Error(`For this operation, the log file should be of the following types: ${validTypes}`); - } - } - return true; - default: - throw new Error(`${filename} is not a valid log file or the log name has been changed`); - } - } - } -} - -module.exports = { - validateFile, -}; diff --git a/packages/contentstack-bulk-publish/src/util/generate-bulk-publish-url.js b/packages/contentstack-bulk-publish/src/util/generate-bulk-publish-url.js deleted file mode 100644 index b98f0d84af..0000000000 --- a/packages/contentstack-bulk-publish/src/util/generate-bulk-publish-url.js +++ /dev/null @@ -1,42 +0,0 @@ -const { regions } = require('@contentstack/cli-config/lib/utils/region-handler'); -const { configHandler } = require('@contentstack/cli-utilities'); - -/** - * Get the appropriate app URL based on the host - * Uses the configured region from configHandler to get the uiHost - * @param {string} host - The host URL - * @returns {string} The app URL - */ -function getAppUrlFromHost(host) { - // Get the current region from configHandler - const currentRegion = configHandler.get('region'); - if (currentRegion && currentRegion.uiHost) { - return currentRegion.uiHost; - } - // Default to NA region if no region is configured - return regions['AWS-NA'].uiHost; -} - -/** - * Generate the bulk publish status URL based on stack configuration - * @param {Object} stack - Stack object containing api_key and host - * @param {Object} config - Config object containing stackApiKey, branch, and host - * @returns {string|null} The status URL or null if apiKey is not available - */ -function generateBulkPublishStatusUrl(stack, config) { - const apiKey = stack?.api_key || config?.stackApiKey; - if (!apiKey) { - return null; - } - const branch = config?.branch; - const host = stack?.host || config?.host || 'app.contentstack.com'; - const appUrl = getAppUrlFromHost(host); - - // Only include branch parameter if branch is not empty - const branchParam = branch ? `?branch=${branch}` : ''; - return `${appUrl}/#!/stack/${apiKey}/publish-queue${branchParam}`; -} - -module.exports = { - generateBulkPublishStatusUrl, -}; \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/src/util/index.js b/packages/contentstack-bulk-publish/src/util/index.js deleted file mode 100644 index ad067baaaf..0000000000 --- a/packages/contentstack-bulk-publish/src/util/index.js +++ /dev/null @@ -1,64 +0,0 @@ -const chalk = require('chalk'); -const fs = require('fs'); - -function prettyPrint(data) { - console.log(chalk.yellow('Configuration to use for executing this command:')); - Object.keys(data).forEach((key, _index) => { - console.log(chalk.grey(`${key}: ${data[key]}`)); - }); - console.log('\n'); -} - -function formatError(error) { - try { - if (typeof error === 'string') { - error = JSON.parse(error); - } else { - error = JSON.parse(error.message); - } - } catch (e) {} - let message = error.errorMessage || error.error_message || error.statusText || error; - if (error.errors && Object.keys(error.errors).length > 0) { - Object.keys(error.errors).forEach((e) => { - let entity = e; - if (e === 'authorization') entity = 'Management Token'; - if (e === 'api_key') entity = 'Stack API key'; - if (e === 'uid') entity = 'Content Type'; - if (e === 'access_token') entity = 'Delivery Token'; - message += ' ' + [entity, error.errors[e]].join(' '); - }); - } - return message; -} - -function setDelayForBulkPublish(_queue) { - // empty block - // queue.requestBatchSize = 1 - // queue.delay = 1 -} - -function getNumberOfBulkPublishRequests(count) { - // for example, if the total count of elements is 738 - // then the number of requets that'll be required are (if there are 10 elements per request) - // (738 - 8)/10 + 1 = 74 requests - return (count - (count % 10)) / 10 + 1; -} - -function isEmpty(file) { - return new Promise((resolve) => { - fs.readFile(file, (_err, data) => { - if (data.length === 0) { - return resolve(true); - } - return resolve(false); - }); - }); -} - -module.exports = { - prettyPrint, - formatError, - setDelayForBulkPublish, - getNumberOfBulkPublishRequests, - isEmpty, -}; diff --git a/packages/contentstack-bulk-publish/src/util/logger.js b/packages/contentstack-bulk-publish/src/util/logger.js deleted file mode 100644 index 400f5ed1ae..0000000000 --- a/packages/contentstack-bulk-publish/src/util/logger.js +++ /dev/null @@ -1,56 +0,0 @@ -const { sanitizePath } = require('@contentstack/cli-utilities'); -const path = require('path'); -const winston = require('winston'); -const cwd = process.cwd(); -const logsDir = path.join(cwd, 'contentstack-cli-logs', 'bulk-publish'); - -let filename; - -module.exports.getLoggerInstance = (fileName) => { - filename = path.join(logsDir, sanitizePath(fileName)); - return winston.createLogger({ - transports: [ - new winston.transports.File({ filename: `${filename}.error`, level: 'error' }), - new winston.transports.File({ filename: `${filename}.success`, level: 'info' }), - ], - }); -}; - -/* eslint-disable no-multi-assign */ -const getFileLoggerInstance = (module.exports.getFileLoggerInstance = (fileName) => { - filename = path.join(logsDir, sanitizePath(fileName)); - return winston.createLogger({ - transports: [new winston.transports.File({ filename })], - }); -}); - -module.exports.getAllLogs = (fname) => - new Promise((resolve, reject) => { - const options = { - limit: 1000000000000, - start: 0, - order: 'desc', - }; - const logger = getFileLoggerInstance(fname); - logger.query(options, async (err, result) => { - if (err) return reject(err); - return resolve(result); - }); - }); - -module.exports.addLogs = (logger, data, Type) => { - switch (Type) { - case 'error': - logger.error(data); - break; - case 'info': - logger.info(data); - break; - default: - console.log('Unknown log level.'); - } -}; - -module.exports.getLogsDirPath = () => { - return logsDir; -}; diff --git a/packages/contentstack-bulk-publish/src/util/queue.js b/packages/contentstack-bulk-publish/src/util/queue.js deleted file mode 100644 index f4cd030ddc..0000000000 --- a/packages/contentstack-bulk-publish/src/util/queue.js +++ /dev/null @@ -1,57 +0,0 @@ -const { EventEmitter } = require('events'); - -class Queue extends EventEmitter { - constructor() { - super(); - this.consumer = null; - this.count = 0; - this.store = []; - this.config = {}; - this.delay = 1; - this.requestBatchSize = 1; - this.on('dequeue', this.check); - } - - check() { - if (this.store.length > 0) { - this.Dequeue(); - } - } - - Enqueue(obj) { - if (!obj.retry) { - obj = { obj, retry: 0 }; - } - if (this.count === this.requestBatchSize) { - return this.sleep(this.delay).then(() => { - this.count = 1; // reset the count to 1. Because the current object will be processed too, and that counts as one request - this.store.push(obj); - this.check(); - }); - } else { - this.count++; - this.store.push(obj); - this.check(); - } - } - - Dequeue() { - const deq = this.store.shift(); - this.emit('dequeue'); - if (deq) { - this.consumer(deq, this.config, this); - } - } - - sleep(seconds) { - return new Promise((resolve) => { - setTimeout(resolve, seconds * 1000); - }); - } -} - -module.exports = { - getQueue: function () { - return new Queue(); - }, -}; diff --git a/packages/contentstack-bulk-publish/src/util/retryfailed.js b/packages/contentstack-bulk-publish/src/util/retryfailed.js deleted file mode 100644 index 42adb8b968..0000000000 --- a/packages/contentstack-bulk-publish/src/util/retryfailed.js +++ /dev/null @@ -1,43 +0,0 @@ -const { getAllLogs } = require('./logger'); -const { getStack } = require('./client.js'); - -module.exports = async (filename, queue, Type) => { - const logs = await getAllLogs(filename); - if (logs.file.length > 0) { - logs.file.forEach(async (log) => { - const stackOptions = {host: log.message.host, delayMs: log.message.delayMs }; - if(log.message.alias) { - stackOptions["alias"] = log.message.alias - } else { - stackOptions["stackApiKey"] = log.message.api_key - } - if (Type === 'bulk') { - log.message.options.stack = await getStack(stackOptions); - queue.Enqueue(log.message.options); - } - if (Type === 'publish') { - if (log.message.options.Type === 'entry') { - queue.entryQueue.Enqueue({ - content_type: log.message.options.content_type, - publish_details: log.message.options.publish_details, - environments: log.message.options.environments, - entryUid: log.message.options.entryUid, - locale: log.message.options.locale, - Type: 'entry', - stack: await getStack(stackOptions), - }); - } else { - queue.assetQueue.Enqueue({ - assetUid: log.message.options.assetUid, - publish_details: log.message.options.publish_assets, - environments: log.message.options.environments, - Type: 'asset', - stack: await getStack(stackOptions), - }); - } - } - }); - } else { - throw new Error('NO FAILURE LOGS WERE FOUND'); - } -}; diff --git a/packages/contentstack-bulk-publish/src/util/store.js b/packages/contentstack-bulk-publish/src/util/store.js deleted file mode 100644 index ad98bfc8f4..0000000000 --- a/packages/contentstack-bulk-publish/src/util/store.js +++ /dev/null @@ -1,83 +0,0 @@ -const fs = require('fs'); -const config = require('../config/index.js'); -const chalk = require('chalk'); -const {pathValidator} = require('@contentstack/cli-utilities') - -function save(key, data) { - let bulkPublish = config ? config : {}; - let filePath = pathValidator(config.json); - bulkPublish[key] = data; - fs.writeFile(filePath, JSON.stringify(bulkPublish), (error) => { - if (error) { - console.log(chalk.red(error)); - return; - } - console.log(chalk.green(`Configuration file successfully created at '${filePath}'.`)); - }); -} - -function get(key, filePath) { - try { - const missing = []; - const bulkPublish = require(filePath); - if (!bulkPublish) { - throw new Error('Unable to read config file'); - } - if (!bulkPublish.alias) { - missing.push('alias'); - } - if (missing.length > 0) { - throw new Error(`Please update the following values in the config file: ${missing.join(', ')}`); - } - if (key === 'revert') bulkPublish[key] = {}; - if (key === 'Unpublish' || key === 'cross_env_publish') bulkPublish[key] = handleFilterObj(bulkPublish[key]); - if (!bulkPublish[key] || Object.keys(bulkPublish[key]).length === 0) { - if (key !== 'revert') { - throw new Error(`Config is empty for ${key} case`); - } - } - return { - alias: bulkPublish.alias, - delayMs: bulkPublish.delayMs, - ...bulkPublish[key], - }; - } catch (error) { - if (error.code === 'ENOENT' || error.code === 'MODULE_NOT_FOUND') - throw new Error('The given config file was not found'); - throw error; - } -} - -function updateMissing(key, flags) { - let savedConfig; - savedConfig = get(key, pathValidator(flags.config)); - Object.keys(savedConfig).forEach((element) => { - if (flags[element] === undefined) { - console.log(`Using '${element}' from the configuration file.`); - flags[element] = savedConfig[element]; - } - }); - if (flags.publishAllContentTypes) delete savedConfig.contentTypes; - console.log('\n'); - return flags; -} - -// a fix for handling filter object in Unpublish and cross publish cases -// in the config file -// because both unpublish and cross-publish commands build the filter object -// internally, and in the original bulk-publish script the filter object was -// mentioned in the config file itself -function handleFilterObj(config1) { - config1.environment = config1.filter.environment; - config1.contentType = config1.filter.content_type_uid; - config1.locale = config1.filter.locale; - config1.f_types = config1.filter.type; // adding f_types to differentiate the types specified in the config.js, and the types defined internally in Unpublish and Cross Publish - delete config1.filter; - return config1; -} - -module.exports = { - save: save, - get: get, - updateMissing: updateMissing, -}; diff --git a/packages/contentstack-bulk-publish/test/helpers/helper.js b/packages/contentstack-bulk-publish/test/helpers/helper.js deleted file mode 100644 index cba76fc299..0000000000 --- a/packages/contentstack-bulk-publish/test/helpers/helper.js +++ /dev/null @@ -1,15 +0,0 @@ -const managementSDKClient = require('@contentstack/cli-utilities'); -let config = { - source_stack: process.env.STACK_API_KEY || 'asdf', - management_token: process.env.MANAGEMENT_TOKEN || 'asdf', -} - -const getStack = async (data = {}) => { - const client = await managementSDKClient(config); - return client.stack({ - source_stack: data.STACK_API_KEY || config.source_stack, - management_token: data.MANAGEMENT_TOKEN || config.management_token, - }); -}; - -module.exports = { getStack }; diff --git a/packages/contentstack-bulk-publish/test/helpers/init.js b/packages/contentstack-bulk-publish/test/helpers/init.js deleted file mode 100644 index d6fb5cb82c..0000000000 --- a/packages/contentstack-bulk-publish/test/helpers/init.js +++ /dev/null @@ -1,4 +0,0 @@ -process.env.NODE_ENV = 'development'; - -global.oclif = global.oclif || {}; -global.oclif.columns = 80; \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/test/unit/commands/assets/publish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/assets/publish.test.js deleted file mode 100644 index ef2a35f039..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/assets/publish.test.js +++ /dev/null @@ -1,116 +0,0 @@ -const { describe, it } = require('mocha'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); - -const AssetsPublish = require('../../../../src/commands/cm/assets/publish'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; - -describe('AssetsPublish', () => { - let assetPublishSpy; - let configHandlerGetStub; - - beforeEach(() => { - assetPublishSpy = sinon.spy(AssetsPublish.prototype, 'run'); - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - - afterEach(() => { - assetPublishSpy.restore(); - if (configHandlerGetStub) { - configHandlerGetStub.restore(); - } - }); - it('should throw error when management token alias is not configured', async () => { - const args = ['--environments', environments[0], '--locales', locales[0], '--alias', 'm_alias', '--yes']; - const expectedError = - "The configured management token alias m_alias has not been added yet. Add it using 'csdx auth:tokens:add -a m_alias'"; - - try { - await AssetsPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(assetPublishSpy.calledOnce).to.be.true; - } - }); - - it('should fail when invalid environment is specified', async () => { - const args = ['--environments', 'invalid_env', '--locales', locales[0], '--alias', 'm_alias', '--yes']; - try { - await AssetsPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(assetPublishSpy.calledOnce).to.be.true; - } - }); - - it('should fail when invalid locale is specified', async () => { - const args = ['--environments', environments[0], '--locales', 'invalid_locale', '--alias', 'm_alias', '--yes']; - - try { - await AssetsPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(assetPublishSpy.calledOnce).to.be.true; - } - }); - - it('Should fail when alias and stack api key flags are not passed', async () => { - const args = ['--environments', environments[0], '--locales', locales[0], '--yes']; - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - try { - await AssetsPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(assetPublishSpy.calledOnce).to.be.true; - } - assetPublishSpy.restore(); - }); - - it('Should run successfully when user is logged in and stack api key is passed', async () => { - const prompts = { - environments: environments[0], - locales: locales[0], - // @ts-ignore-next-line secret-detection - key: 'asdf', - }; - const args = [ - '--environments', - prompts.environments, - '--locales', - prompts.locales, - '--stack-api-key', - prompts.key, - '--yes', - ]; - - try { - await AssetsPublish.run(args); - expect(assetPublishSpy.calledOnce).to.be.true; - assetPublishSpy.restore(); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - } - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/assets/unpublish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/assets/unpublish.test.js deleted file mode 100644 index ccb700ed1f..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/assets/unpublish.test.js +++ /dev/null @@ -1,114 +0,0 @@ -const { expect } = require('chai'); -const sinon = require('sinon'); -const { describe, it, beforeEach, afterEach } = require('mocha'); -const UnpublishCommand = require('../../../../src/commands/cm/assets/unpublish'); -const AddTokenCommand = require('@contentstack/cli-auth/lib/commands/auth/tokens/add').default; -const helper = require('../../../helpers/helper'); -const { cliux, configHandler } = require('@contentstack/cli-utilities'); - -describe('AssetsUnpublish Command', () => { - let sandbox; - let stackDetails; - let configHandlerGetStub; - - beforeEach(async () => { - sandbox = sinon.createSandbox(); - - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sandbox.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - - stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('executes successfully with required parameters', async () => { - const runStub = sandbox.stub(UnpublishCommand.prototype, 'run').resolves(); - - const result = await UnpublishCommand.run([ - '--alias', - 'm_alias', - '--environment', - 'env', - '--locale', - 'en-us', - '--delivery-token', - 'test-delivery-token', - '--yes', - ]); - - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('executes successfully with stack identifier', async () => { - const runStub = sandbox.stub(UnpublishCommand.prototype, 'run').resolves(); - - const result = await UnpublishCommand.run([ - '--stack-api-key', - stackDetails.api_key, - '--environment', - 'env', - '--locale', - 'en-us', - '--delivery-token', - 'test-delivery-token', - '--yes', - ]); - - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('prompts for missing delivery token', async () => { - sandbox.stub(helper, 'getStack').resolves({ ...stackDetails, delivery_token: undefined }); - sandbox.stub(cliux, 'prompt').resolves('prompted-token'); - sandbox.stub(AddTokenCommand.prototype, 'run').resolves(); - const runStub = sandbox.stub(UnpublishCommand.prototype, 'run').resolves('Success'); - - const result = await UnpublishCommand.run([ - '--alias', - 'm_alias', - '--environment', - 'env', - '--locale', - 'en-us', - '--yes', - ]); - - expect(result).to.equal('Success'); - sinon.assert.calledOnce(runStub); - }); - - it('throws error for missing authentication parameters', async () => { - const runStub = sandbox.stub(UnpublishCommand.prototype, 'run'); - - try { - await UnpublishCommand.run(['--environment', 'env', '--locale', 'en-us', '--yes']); - } catch (error) { - expect(error.message).to.equal('Use the `--alias` or `--stack-api-key` flag to proceed.'); - expect(runStub.called).to.be.false; - } - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/bulk-publish/cross-publish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/bulk-publish/cross-publish.test.js deleted file mode 100644 index 039f98d865..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/bulk-publish/cross-publish.test.js +++ /dev/null @@ -1,171 +0,0 @@ -const { expect } = require('chai'); -const sinon = require('sinon'); -const { cliux, configHandler } = require('@contentstack/cli-utilities'); -const CrossPublish = require('../../../../src/commands/cm/bulk-publish/cross-publish'); -const AddTokenCommand = require('@contentstack/cli-auth/lib/commands/auth/tokens/add').default; -const helper = require('../../../helpers/helper'); - -describe('CrossPublish', () => { - let sandbox; - let stackDetails; - let configHandlerGetStub; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sandbox.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - - stackDetails = { - api_key: 'asdf', - environment: 'sourceEnv', - alias: 'dummy_alias', - delivery_token: undefined, - management_token: 'mgmt-token', - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('executes successfully with all required parameters', async () => { - const runStub = sandbox.stub(CrossPublish.prototype, 'run').resolves('Success'); - - const result = await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - '--locale', - 'en-us', - '--alias', - 'dummy_alias', - '--delivery-token', - 'token123', - '--onlyAssets', - '--yes', - ]); - - expect(result).to.equal('Success'); - sinon.assert.calledOnce(runStub); - }); - - it('prompts for delivery token if not provided', async () => { - sandbox.stub(helper, 'getStack').resolves({ ...stackDetails, delivery_token: undefined }); - sandbox.stub(cliux, 'prompt').resolves('prompted-token'); - sandbox.stub(AddTokenCommand.prototype, 'run').resolves(); - const runStub = sandbox.stub(CrossPublish.prototype, 'run').resolves('Success'); - - const result = await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - '--locale', - 'en-us', - '--alias', - 'dummy_alias', - '--onlyAssets', - '--yes', - ]); - - expect(result).to.equal('Success'); - sinon.assert.calledOnce(runStub); - }); - - it('throws error when required flags are missing', async () => { - try { - await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - // Missing --locale - '--alias', - 'dummy_alias', - '--delivery-token', - 'token123', - ]); - } catch (error) { - expect(error.message).to.include('Locale is required'); - } - }); - - it('validates authentication requirement', async () => { - try { - await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - '--locale', - 'en-us', - // Missing alias and stack-api-key - '--delivery-token', - 'token123', - ]); - } catch (error) { - expect(error.message).to.include('Use the `--alias` or `--stack-api-key` flag to proceed.'); - } - }); - - it('runs with stack a p i instead of alias', async () => { - const runStub = sandbox.stub(CrossPublish.prototype, 'run').resolves('Success'); - - const result = await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - '--locale', - 'en-us', - '--stack-api-key', - 'asdf', - '--delivery-token', - 'token123', - '--onlyAssets', - '--yes', - ]); - - expect(result).to.equal('Success'); - sinon.assert.calledOnce(runStub); - }); - - it('validates flag combinations only assets and only entries', async () => { - try { - await CrossPublish.run([ - '--source-env', - 'sourceEnv', - '--environments', - 'targetEnv', - '--locale', - 'en-us', - '--stack-api-key', - 'asdf', - '--delivery-token', - 'token123', - '--onlyAssets', - '--onlyEntries', - '--yes', - ]); - } catch (error) { - expect(error.message).to.include( - 'The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default', - ); - } - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-modified.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-modified.test.js deleted file mode 100644 index 6b632cedb5..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-modified.test.js +++ /dev/null @@ -1,95 +0,0 @@ -const { describe, it } = require('mocha'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); - -const EntriesPublishModified = require('../../../../src/commands/cm/entries/publish-modified'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; -const contentTypes = ['ct1', 'ct2']; - -describe('EntriesPublishModified Command', () => { - let sandbox; - let configHandlerGetStub; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sandbox.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should run the command all the required parameters', async () => { - const runStub = sandbox.stub(EntriesPublishModified.prototype, 'run').resolves(); - - const args = [ - '--content-types', contentTypes[0], - '--source-env', environments[0], - '-e', environments[1], - '--locales', locales[0], - '--alias', 'm_alias', - '--yes', - ]; - - const result = await EntriesPublishModified.run(args); - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('throws error for missing authentication parameters', async () => { - const runStub = sandbox.stub(EntriesPublishModified.prototype, 'run').callThrough(); - const args = [ - '--content-types', contentTypes[0], - '--source-env', environments[0], - '-e', environments[1], - '--locales', locales[0], - '--yes', - ]; - - try { - await EntriesPublishModified.run(args); - } catch (error) { - expect(error).to.be.an('error'); - expect(error.message).to.equal('Use the `--alias` or `--stack-api-key` flag to proceed.'); - expect(runStub.calledOnce).to.be.true; - } - }); - - it('executes with required parameters and user is logged in', async () => { - const runStub = sandbox.stub(EntriesPublishModified.prototype, 'run').resolves(); - - const args = [ - '--content-types', contentTypes[0], - '--source-env', environments[0], - '-e', environments[1], - '--locales', locales[0], - '--stack-api-key', 'asdf', - '--yes', - ]; - - const result = await EntriesPublishModified.run(args); - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); -}); \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-non-localized-fields.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-non-localized-fields.test.js deleted file mode 100644 index 390bdab6b6..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-non-localized-fields.test.js +++ /dev/null @@ -1,101 +0,0 @@ -const { describe, it, beforeEach, afterEach } = require('mocha'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); - -const EntriesPublishNonLocalizedFields = require('../../../../src/commands/cm/entries/publish-non-localized-fields'); - -config(); - -const environments = ['env1', 'env2']; -const contentTypes = ['ct1', 'ct2']; - -describe('EntriesPublishNonLocalizedFields', () => { - let runStub; - let configHandlerGetStub; - let stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - - beforeEach(() => { - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - - afterEach(() => { - if (runStub && runStub.restore) runStub.restore(); - if (configHandlerGetStub && configHandlerGetStub.restore) configHandlerGetStub.restore(); - }); - - it('Should run the command when all the flags are passed', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--source-env', - environments[0], - '--environments', - environments[1], - '--alias', - 'm_alias', - '--yes', - ]; - runStub = sinon.stub(EntriesPublishNonLocalizedFields.prototype, 'run').resolves(); - await EntriesPublishNonLocalizedFields.run(args); - expect(runStub.calledOnce).to.be.true; - }); - - it('Should fail when alias and stack api key flags are not passed', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--source-env', - environments[0], - '--environments', - environments[1], - '--yes', - ]; - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - - try { - await EntriesPublishNonLocalizedFields.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - } - }); - - it('Should run successfully when user is logged in and stack api key is passed', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--source-env', - environments[0], - '--environments', - environments[1], - '--stack-api-key', - stackDetails.api_key, - '--yes', - ]; - runStub = sinon.stub(EntriesPublishNonLocalizedFields.prototype, 'run').resolves(); - await EntriesPublishNonLocalizedFields.run(args); - expect(runStub.calledOnce).to.be.true; - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-only-unpublished.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-only-unpublished.test.js deleted file mode 100644 index 84dc5839b7..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish-only-unpublished.test.js +++ /dev/null @@ -1,109 +0,0 @@ -const { describe, it, afterEach, beforeEach } = require('mocha'); -const EntriesPublishOnlyUnpublished = require('../../../../src/commands/cm/entries/publish-only-unpublished'); -const sinon = require('sinon'); -const { config } = require('dotenv'); -const { expect } = require('chai'); -const { configHandler } = require('@contentstack/cli-utilities'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; -const contentTypes = ['ct1', 'ct2']; - -describe('EntriesPublishOnlyUnpublished', () => { - let runStub; - let configHandlerGetStub; - - beforeEach(() => { - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - - afterEach(() => { - if (runStub && runStub.restore) runStub.restore(); - if (configHandlerGetStub && configHandlerGetStub.restore) configHandlerGetStub.restore(); - }); - - it('should run the command all the required parameters', async () => { - const args = [ - '-b', - '--content-types', - contentTypes[0], - '--locales', - locales[0], - '--source-env', - environments[0], - '-a', - 'm_alias', - '--yes', - ]; - - runStub = sinon.stub(EntriesPublishOnlyUnpublished.prototype, 'run').resolves('Command executed'); - - const result = await EntriesPublishOnlyUnpublished.run(args); - expect(result).to.equal('Command executed'); - expect(runStub.calledOnce).to.be.true; - }); - - it('throws error for missing authentication parameters', async () => { - const args = [ - '-b', - '--content-types', - contentTypes[0], - '--locales', - locales[0], - '--environments', - environments[0], - '--yes', - ]; - - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - - runStub = sinon.stub(EntriesPublishOnlyUnpublished.prototype, 'run').callsFake(function () { - throw new Error(expectedError); - }); - - try { - await EntriesPublishOnlyUnpublished.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(runStub.calledOnce).to.be.true; - } - }); - - it('executes with stack parameter configuration and should run successfully when user is logged', async () => { - const args = [ - '-b', - '--content-types', - contentTypes[0], - '--locales', - locales[0], - '--environments', - environments[0], - '--stack-api-key', - 'asdf', - '--yes', - ]; - - runStub = sinon.stub(EntriesPublishOnlyUnpublished.prototype, 'run').resolves('Executed with stack API key'); - - const result = await EntriesPublishOnlyUnpublished.run(args); - expect(result).to.equal('Executed with stack API key'); - expect(runStub.calledOnce).to.be.true; - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/publish.test.js deleted file mode 100644 index 9e7b6ae459..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/publish.test.js +++ /dev/null @@ -1,107 +0,0 @@ -const { describe, it } = require('mocha'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); - -const EntriesPublish = require('../../../../src/commands/cm/entries/publish'); - -config(); - -const environments = ['env1', 'env2']; -const contentTypes = ['ct1', 'ct2']; -const locales = ['en-us', 'fr-fr']; - -describe('EntriesPublish Command', () => { - let runStub; - let stackDetails; - let configHandlerGetStub; - - beforeEach(() => { - runStub = sinon.stub(EntriesPublish.prototype, 'run').resolves(); - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - }); - afterEach(() => { - if (runStub && runStub.restore) runStub.restore(); - if (configHandlerGetStub && configHandlerGetStub.restore) configHandlerGetStub.restore(); - }); - - // @ts-ignore-next-line secret-detection - it('should run the command all the required parameters', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--alias', - stackDetails.alias, - '--yes', - ]; - - await EntriesPublish.run(args); - expect(runStub.calledOnce).to.be.true; - }); - - // @ts-ignore-next-line secret-detection - it('throws error for missing authentication parameters', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--yes', - ]; - - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - - try { - await EntriesPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - } - }); - - // @ts-ignore-next-line secret-detection - it('executes with stack parameter configuration', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--stack-api-key', - stackDetails.api_key, - '--yes', - ]; - - await EntriesPublish.run(args); - expect(runStub.calledOnce).to.be.true; - }); -}); \ No newline at end of file diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/unpublish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/unpublish.test.js deleted file mode 100644 index 3e5205c0c4..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/unpublish.test.js +++ /dev/null @@ -1,114 +0,0 @@ -const { expect } = require('chai'); -const sinon = require('sinon'); -const { describe, it, beforeEach, afterEach } = require('mocha'); -const EntriesUnpublish = require('../../../../src/commands/cm/entries/unpublish'); -const AddTokenCommand = require('@contentstack/cli-auth/lib/commands/auth/tokens/add').default; -const helper = require('../../../helpers/helper'); -const { cliux, configHandler } = require('@contentstack/cli-utilities'); - -describe('EntriesUnpublish Command', () => { - let sandbox; - let stackDetails; - let configHandlerGetStub; - - beforeEach(async () => { - sandbox = sinon.createSandbox(); - - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sandbox.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - - stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('executes successfully with required parameters', async () => { - const runStub = sandbox.stub(EntriesUnpublish.prototype, 'run').resolves(); - - const result = await EntriesUnpublish.run([ - '--alias', - 'm_alias', - '--environment', - 'env', - '--locale', - 'en-us', - '--delivery-token', - 'test-delivery-token', - '--yes', - ]); - - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('executes successfully with stack identifier', async () => { - const runStub = sandbox.stub(EntriesUnpublish.prototype, 'run').resolves(); - - const result = await EntriesUnpublish.run([ - '--stack-api-key', - stackDetails.api_key, - '--environment', - 'env', - '--locale', - 'en-us', - '--delivery-token', - 'test-delivery-token', - '--yes', - ]); - - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('prompts for missing delivery token', async () => { - sandbox.stub(helper, 'getStack').resolves({ ...stackDetails, delivery_token: undefined }); - sandbox.stub(cliux, 'prompt').resolves('prompted-token'); - sandbox.stub(AddTokenCommand.prototype, 'run').resolves(); - const runStub = sandbox.stub(EntriesUnpublish.prototype, 'run').resolves('Success'); - - const result = await EntriesUnpublish.run([ - '--alias', - 'm_alias', - '--environment', - 'env', - '--locale', - 'en-us', - '--yes', - ]); - - expect(result).to.equal('Success'); - sinon.assert.calledOnce(runStub); - }); - - it('throws error for missing authentication parameters', async () => { - const runStub = sandbox.stub(EntriesUnpublish.prototype, 'run'); - - try { - await EntriesUnpublish.run(['--environment', 'env', '--locale', 'en-us', '--yes']); - } catch (error) { - expect(error.message).to.equal('Use the `--alias` or `--stack-api-key` flag to proceed.'); - expect(runStub.called).to.be.false; - } - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/entries/update-and-publish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/entries/update-and-publish.test.js deleted file mode 100644 index 06962a6501..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/entries/update-and-publish.test.js +++ /dev/null @@ -1,101 +0,0 @@ -const { describe, it } = require('mocha'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); - -const EntriesUpdateAndPublish = require('../../../../src/commands/cm/entries/update-and-publish'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; -const contentTypes = ['ct1', 'ct2']; - -describe('EntriesUpdateAndPublish', () => { - let sandbox; - let stackDetails; - let configHandlerGetStub; - - beforeEach(async () => { - sandbox = sinon.createSandbox(); - - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sandbox.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - - stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - it('Should run the command when all the flags are passed', async () => { - const runStub = sandbox.stub(EntriesUpdateAndPublish.prototype, 'run').resolves(); - const args = [ - '--content-types', - contentTypes[0], - '-e', - environments[0], - '--locales', - locales[0], - '-a', - 'm_alias', - '--yes', - ]; - const result = await EntriesUpdateAndPublish.run(args); - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); - - it('Should fail when alias and stack api key flags are not passed', async () => { - const args = ['--content-types', contentTypes[0], '-e', environments[0], '--locales', locales[0], '--yes']; - const entriesUpdateAndPublishSpy = sinon.spy(EntriesUpdateAndPublish.prototype, 'run'); - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - try { - await EntriesUpdateAndPublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(entriesUpdateAndPublishSpy.calledOnce).to.be.true; - } - entriesUpdateAndPublishSpy.restore(); - }); - - it('Should run successfully when user is logged in and stack api key is passed', async () => { - const runStub = sandbox.stub(EntriesUpdateAndPublish.prototype, 'run').resolves(); - - const args = [ - '--content-types', - contentTypes[0], - '-e', - environments[0], - '--locales', - locales[0], - '--stack-api-key', - stackDetails.api_key, - '--yes', - ]; - const result = await EntriesUpdateAndPublish.run(args); - expect(runStub.calledOnce).to.be.true; - expect(result).to.be.undefined; - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/stacks/publish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/stacks/publish.test.js deleted file mode 100644 index 84bed64ae0..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/stacks/publish.test.js +++ /dev/null @@ -1,115 +0,0 @@ -const { describe, it, afterEach, beforeEach } = require('mocha'); -const inquirer = require('inquirer'); -const sinon = require('sinon'); -const { expect } = require('chai'); -const { config } = require('dotenv'); -const { configHandler } = require('@contentstack/cli-utilities'); -const StackPublish = require('../../../../src/commands/cm/stacks/publish'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; -const contentTypes = ['ct1', 'ct2']; - -describe('StackPublish', () => { - let runStub, stackDetails, promptStub, configHandlerGetStub; - - beforeEach(() => { - stackDetails = { - api_key: 'asdf', - environment: 'env', - delivery_token: 'asdf', - management_token: 'asdf', - alias: 'm_alias', - }; - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - afterEach(() => { - sinon.restore(); // Restores all stubs - }); - - it('should run the command all the required parameters', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--alias', - stackDetails.alias, - '--yes', - ]; - - runStub = sinon.stub(StackPublish.prototype, 'run').resolves('Executed successfully'); - promptStub = sinon.stub(inquirer, 'prompt').resolves({ publishType: 'Publish Entries and Assets' }); - - const result = await StackPublish.run(args); - expect(result).to.equal('Executed successfully'); - expect(runStub.calledOnce).to.be.true; - }); - - it('throws error for missing authentication parameters', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--yes', - ]; - - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - - runStub = sinon.stub(StackPublish.prototype, 'run').callsFake(function () { - throw new Error(expectedError); - }); - - promptStub = sinon.stub(inquirer, 'prompt').resolves({ publishType: 'Publish Entries and Assets' }); - - try { - await StackPublish.run(args); - } catch (error) { - expect(error).to.be.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(runStub.calledOnce).to.be.true; - } - }); - - it('Should run successfully when user is logged in and stack api key is passed', async () => { - const args = [ - '--content-types', - contentTypes[0], - '--environments', - environments[0], - '--locales', - locales[0], - '--stack-api-key', - 'asdf', - '--yes', - ]; - - runStub = sinon.stub(StackPublish.prototype, 'run').resolves('Executed with stack API key'); - promptStub = sinon.stub(inquirer, 'prompt').resolves({ publishType: 'Publish Entries and Assets' }); - - const result = await StackPublish.run(args); - expect(result).to.equal('Executed with stack API key'); - expect(runStub.calledOnce).to.be.true; - }); -}); diff --git a/packages/contentstack-bulk-publish/test/unit/commands/stacks/unpublish.test.js b/packages/contentstack-bulk-publish/test/unit/commands/stacks/unpublish.test.js deleted file mode 100644 index 9bb3a29ae5..0000000000 --- a/packages/contentstack-bulk-publish/test/unit/commands/stacks/unpublish.test.js +++ /dev/null @@ -1,139 +0,0 @@ -const { describe, it, afterEach, beforeEach } = require('mocha'); -const StackUnpublish = require('../../../../src/commands/cm/stacks/unpublish'); -const { cliux, configHandler } = require('@contentstack/cli-utilities'); -const sinon = require('sinon'); -const { config } = require('dotenv'); -const { expect } = require('chai'); - -config(); - -const environments = ['env1', 'env2']; -const locales = ['en-us', 'fr-fr']; -const contentTypes = ['ct1', 'ct2']; - -describe('StackUnpublish', () => { - let promptStub; - let runStub; - let configHandlerGetStub; - - beforeEach(() => { - // Stub configHandler.get to configure region - // Region is required for cmaHost property in Command base class - configHandlerGetStub = sinon.stub(configHandler, 'get').callsFake((key) => { - if (key === 'region') { - return { - cma: 'api.contentstack.io', - cda: 'cdn.contentstack.io', - uiHost: 'app.contentstack.com', - developerHubUrl: 'developer.contentstack.com', - launchHubUrl: 'launch.contentstack.com', - personalizeUrl: 'personalize.contentstack.com', - }; - } - return undefined; - }); - }); - - afterEach(() => { - sinon.restore(); // clean up all stubs - }); - - it('Should run the command when all the flags are passed', async function () { - const args = [ - '--content-type', - contentTypes[0], - '--environment', - environments[0], - '--locale', - locales[0], - '--alias', - 'asdf', - '--delivery-token', - 'd_token', - '--yes', - ]; - - promptStub = sinon.stub(cliux, 'prompt'); // shouldn't be called - runStub = sinon.stub(StackUnpublish.prototype, 'run').resolves('Unpublish success'); - - const result = await StackUnpublish.run(args); - expect(result).to.equal('Unpublish success'); - sinon.assert.notCalled(promptStub); - }); - - it('Should ask for delivery token when the flag is not passed', async () => { - const args = [ - '--content-type', - contentTypes[0], - '--environment', - environments[0], - '--locale', - locales[0], - '--alias', - 'asdf', - '--yes', - ]; - - promptStub = sinon.stub(cliux, 'prompt').resolves({ deliveryToken: 'd_token' }); - runStub = sinon.stub(StackUnpublish.prototype, 'run').resolves('Unpublish with prompt'); - - const result = await StackUnpublish.run(args); - expect(result).to.equal('Unpublish with prompt'); - sinon.assert.calledOnce(runStub); - }); - - it('Should fail when alias and stack api key flags are not passed', async () => { - const args = [ - '--content-type', - contentTypes[0], - '--environment', - environments[0], - '--locale', - locales[0], - '--delivery-token', - 'd_token', - '--yes', - ]; - - const expectedError = 'Use the `--alias` or `--stack-api-key` flag to proceed.'; - - runStub = sinon.stub(StackUnpublish.prototype, 'run').callsFake(function () { - throw new Error(expectedError); - }); - - promptStub = sinon.stub(cliux, 'prompt'); - - try { - await StackUnpublish.run(args); - } catch (error) { - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal(expectedError); - expect(runStub.calledOnce).to.be.true; - } - - sinon.assert.notCalled(promptStub); - }); - - it('Should run successfully when user is logged in and stack api key is passed', async () => { - const args = [ - '--content-type', - contentTypes[0], - '--environment', - environments[0], - '--locale', - locales[0], - '--stack-api-key', - 'asdf', - '--delivery-token', - 'd_token', - '--yes', - ]; - - promptStub = sinon.stub(cliux, 'prompt'); - runStub = sinon.stub(StackUnpublish.prototype, 'run').resolves('Unpublish with stack API key'); - - const result = await StackUnpublish.run(args); - expect(result).to.equal('Unpublish with stack API key'); - sinon.assert.notCalled(promptStub); - }); -}); \ No newline at end of file diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 013494b125..45cacb4513 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -35,32 +35,12 @@ USAGE * [`csdx auth:tokens:add [-a ] [--delivery] [--management] [-e ] [-k ] [-y] [--token ]`](#csdx-authtokensadd--a-value---delivery---management--e-value--k-value--y---token-value) * [`csdx auth:tokens:remove`](#csdx-authtokensremove) * [`csdx auth:whoami`](#csdx-authwhoami) -* [`csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmassetspublish--a-value---retry-failed-value--e-value---folder-uid-value---bulk-publish-value--c-value--y---locales-value---branch-value---delivery-token-value---source-env-value) -* [`csdx cm:assets:unpublish`](#csdx-cmassetsunpublish) * [`csdx cm:bootstrap`](#csdx-cmbootstrap) * [`csdx cm:branches`](#csdx-cmbranches) * [`csdx cm:branches:create`](#csdx-cmbranchescreate) * [`csdx cm:branches:delete [-uid ] [-k ]`](#csdx-cmbranchesdelete--uid-value--k-value) * [`csdx cm:branches:diff [--base-branch ] [--compare-branch ] [-k ][--module ] [--format ] [--csv-path ]`](#csdx-cmbranchesdiff---base-branch-value---compare-branch-value--k-value--module-value---format-value---csv-path-value) * [`csdx cm:branches:merge [-k ][--compare-branch ] [--no-revert] [--export-summary-path ] [--use-merge-summary ] [--comment ] [--base-branch ]`](#csdx-cmbranchesmerge--k-value--compare-branch-value---no-revert---export-summary-path-value---use-merge-summary-value---comment-value---base-branch-value) -* [`csdx cm:bulk-publish`](#csdx-cmbulk-publish) -* [`csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]`](#csdx-cmentriesupdate-and-publish--a-value---retry-failed-value---bulk-publish-value---content-types-value--t-value--e-value--c-value--y---locales-value---branch-value) -* [`csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmassetspublish--a-value---retry-failed-value--e-value---folder-uid-value---bulk-publish-value--c-value--y---locales-value---branch-value---delivery-token-value---source-env-value) -* [`csdx cm:bulk-publish:clear`](#csdx-cmbulk-publishclear) -* [`csdx cm:bulk-publish:configure`](#csdx-cmbulk-publishconfigure) -* [`csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries] [--include-variants]`](#csdx-cmbulk-publishcross-publish--a-value---retry-failed-value---bulk-publish-value---content-type-value---locales-value---source-env-value---environments-value---delivery-token-value--c-value--y---branch-value---onlyassets---onlyentries---include-variants) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants) -* [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value) -* [`csdx cm:bulk-publish:revert`](#csdx-cmbulk-publishrevert) -* [`csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]`](#csdx-csdx-cmstacksunpublish--a-value--e-value--c-value--y---locale-value---branch-value---retry-failed-value---bulk-unpublish-value---content-type-value---delivery-token-value---only-assets---only-entries) -* [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants) -* [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:unpublish`](#csdx-cmentriesunpublish) -* [`csdx cm:entries:update-and-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-types ] [-t ] [-e ] [-c ] [-y] [--locales ] [--branch ]`](#csdx-cmentriesupdate-and-publish--a-value---retry-failed-value---bulk-publish-value---content-types-value--t-value--e-value--c-value--y---locales-value---branch-value) * [`csdx cm:export-to-csv`](#csdx-cmexport-to-csv) * [`csdx cm:stacks:audit`](#csdx-cmstacksaudit) * [`csdx cm:stacks:audit:fix`](#csdx-cmstacksauditfix) @@ -69,12 +49,7 @@ USAGE * [`csdx cm:stacks:import [--config ] [--stack-api-key ] [--data-dir ] [--alias ] [--module ] [--backup-dir ] [--branch ] [--import-webhook-status disable|current]`](#csdx-cmstacksimport---config-value---stack-api-key-value---data-dir-value---alias-value---module-value---backup-dir-value---branch-value---import-webhook-status-disablecurrent) * [`csdx cm:stacks:import-setup [-k ] [-d ] [-a ] [--modules ]`](#csdx-cmstacksimport-setup--k-value--d-value--a-value---modules-valuevalue) * [`csdx cm:stacks:migration [-k ] [-a ] [--file-path ] [--branch ] [--config-file ] [--config ] [--multiple]`](#csdx-cmstacksmigration--k-value--a-value---file-path-value---branch-value---config-file-value---config-value---multiple) -* [`csdx cm:stacks:publish`](#csdx-cmstackspublish) -* [`csdx cm:stacks:publish-clear-logs`](#csdx-cmstackspublish-clear-logs) -* [`csdx cm:stacks:publish-configure`](#csdx-cmstackspublish-configure) -* [`csdx cm:stacks:publish-revert`](#csdx-cmstackspublish-revert) * [`csdx cm:stacks:seed [--repo ] [--org ] [--stack-api-key ] [--stack-name ] [--yes ] [--alias ] [--locale ]`](#csdx-cmstacksseed---repo-value---org-value---stack-api-key-value---stack-name-value---yes-value---alias-value---locale-value) -* [`csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]`](#csdx-csdx-cmstacksunpublish--a-value--e-value--c-value--y---locale-value---branch-value---retry-failed-value---bulk-unpublish-value---content-type-value---delivery-token-value---only-assets---only-entries) * [`csdx config:get:base-branch`](#csdx-configgetbase-branch) * [`csdx config:get:ea-header`](#csdx-configgetea-header) * [`csdx config:get:early-access-header`](#csdx-configgetearly-access-header) @@ -293,167 +268,6 @@ EXAMPLES _See code: [@contentstack/cli-auth](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/auth/whoami.ts)_ -## `csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]` - -Publish assets to the specified environments - -``` -USAGE - $ csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish - ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ] - -FLAGS - -B, --branch= [default: main] The name of the branch where you want to perform the bulk publish - operation. If you don’t mention the branch name, then by default the assets from the - main branch will be published. - -a, --alias= Alias (name) for the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) The path of the optional configuration JSON file containing all the options - for a single run. Refer to the configure command to create a configuration file. - -e, --environments=... The name of the environment on which entries will be published. In case of multiple - environments, specify their names separated by spaces. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the - --alias flag. - -l, --locales=... Locales in which assets will be published, e.g., en-us. In the case of multiple - locales, specify the codes separated by spaces. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-publish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --delivery-token= The delivery token of the source environment. - --folder-uid= (optional) The UID of the Assets’ folder from which the assets need to be published. - The default value is cs_root. - --retry-failed= Use this option to retry publishing the failed assets from the logfile. Specify the - name of the logfile that lists failed publish calls. If this option is used, it will - override all other flags. - --source-env= Source environment - -DESCRIPTION - Publish assets to the specified environments - The assets command is used to publish assets from the specified stack, to the specified environments - - Note: Environment(s) and Locale(s) are required to execute the command successfully - But, if retryFailed flag is set, then only a logfile is required - - -ALIASES - $ csdx cm:bulk-publish:assets - -EXAMPLES - General Usage - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]` - - $ csdx cm:assets:publish --config [PATH TO CONFIG FILE] - - $ csdx cm:assets:publish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:assets:publish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] - - - - Using --source-env - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] - - - - Using --stack-api-key flag - - $ csdx cm:assets:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --stack-api-key [STACK API KEY] -``` - -_See code: [@contentstack/cli-cm-bulk-publish](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/publish.js)_ - -## `csdx cm:assets:unpublish` - -Unpublish assets from given environment - -``` -USAGE - $ csdx cm:assets:unpublish [-a ] [-k ] [-e ] [-c ] [-y] [--locale ] [--branch - ] [--retry-failed ] [--bulk-unpublish ] [--api-version ] [--delivery-token ] - -FLAGS - -a, --alias= Alias (name) of the management token. You must use either the --alias flag or the - --stack-api-key flag. - -c, --config= (optional) Path of an optional configuration JSON file containing all the options for a - single run. Refer to the configure command to create a configuration file. - -e, --environment= The name of the environment from where entries/assets need to be unpublished. - -k, --stack-api-key= API key of the source stack. You must use either the --stack-api-key flag or the --alias - flag. - -y, --yes Set it to true to process the command with the current configuration. - --api-version= API version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --branch= [default: main] The name of the branch where you want to perform the bulk unpublish - operation. If you don’t mention the branch name, then by default the content from the - main branch will be unpublished. - --bulk-unpublish= [default: true] Set this flag to use Contentstack’s Bulk Publish APIs. It is true, by - default. - --delivery-token= The delivery token of the source environment. - --locale= Locale from which entries/assets will be unpublished, e.g., en-us. - --retry-failed= (optional) Use this option to retry unpublishing the failed entries from the logfile. - Specify the name of the logfile that lists failed unpublish calls. If this option is - used, it will override all other flags. - -DESCRIPTION - Unpublish assets from given environment - The unpublish command is used for unpublishing assets from the given environment - - Note: Environment (Source Environment) and Locale are required to execute the command successfully - But, if retry-failed flag is set, then only a logfile is required - -EXAMPLES - General Usage - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] - - - - Using --config or -c flag - - Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]` - - $ csdx cm:assets:unpublish --config [PATH TO CONFIG FILE] - - $ csdx cm:assets:unpublish -c [PATH TO CONFIG FILE] - - - - Using --retry-failed flag - - $ csdx cm:assets:unpublish --retry-failed [LOG FILE NAME] - - - - Using --branch flag - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] - - - - Using --stack-api-key flag - - $ csdx cm:assets:unpublish --bulk-unpublish --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] -``` - -_See code: [@contentstack/cli-cm-bulk-publish](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/assets/unpublish.js)_ - ## `csdx cm:bootstrap` Bootstrap contentstack apps @@ -487,1518 +301,189 @@ EXAMPLES $ csdx cm:bootstrap --app-name "kickstart-next" --project-dir --stack-api-key "stack-api-key" - $ csdx cm:bootstrap --app-name "kickstart-next" --project-dir --org "your-org-uid" --stack-name "stack-name" - - $ csdx cm:bootstrap --app-name "kickstart-next" --project-dir --run-dev-server -``` - -_See code: [@contentstack/cli-cm-bootstrap](https://github.com/contentstack/cli/blob/main/packages/contentstack-bootstrap/src/commands/cm/bootstrap.ts)_ - -## `csdx cm:branches` - -List the branches - -``` -USAGE - $ csdx cm:branches - -FLAGS - -k, --stack-api-key= Stack API key - --verbose Verbose, display information in detailed format. - -DESCRIPTION - List the branches - -EXAMPLES - $ csdx cm:branches - - $ csdx cm:branches --verbose - - $ csdx cm:branches -k -``` - -_See code: [@contentstack/cli-cm-branches](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/index.ts)_ - -## `csdx cm:branches:create` - -Create a new branch - -``` -USAGE - $ csdx cm:branches:create - $ csdx cm:branches:create [--source ] [--uid ] [-k ] - $ csdx cm:branches:create [--source ] [--uid ] [--stack-api-key ] - -FLAGS - -k, --stack-api-key= Stack API key - --source= Source branch from which a new branch is to be created. - --uid= Branch UID (unique name) to be created. - -DESCRIPTION - Create a new branch - -EXAMPLES - $ csdx cm:branches:create - - $ csdx cm:branches:create --source main -uid new_branch -k bltxxxxxxxx - - $ csdx cm:branches:create --source main --uid new_branch --stack-api-key bltxxxxxxxx -``` - -_See code: [@contentstack/cli-cm-branches](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/create.ts)_ - -## `csdx cm:branches:delete [-uid ] [-k ]` - -Delete a branch - -``` -USAGE - $ csdx cm:branches:delete [-uid ] [-k ] - $ csdx cm:branches:delete [--uid ] [--stack-api-key ] - -FLAGS - -k, --stack-api-key= Stack API key - -y, --yes Force the deletion of the branch by skipping the confirmation - --uid= Branch UID to be deleted - -DESCRIPTION - Delete a branch - -EXAMPLES - $ csdx cm:branches:delete - - $ csdx cm:branches:delete --uid main -k bltxxxxxxxx - - $ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx - - $ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx --yes -``` - -_See code: [@contentstack/cli-cm-branches](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/delete.ts)_ - -## `csdx cm:branches:diff [--base-branch ] [--compare-branch ] [-k ][--module ] [--format ] [--csv-path ]` - -Differences between two branches - -``` -USAGE - $ csdx cm:branches:diff [--base-branch ] [--compare-branch ] [-k ][--module ] [--format - ] [--csv-path ] - -FLAGS - -k, --stack-api-key= [optional] Provide the stack API key to show the difference between branches. - --base-branch= [optional] Base branch (Target branch). - --compare-branch= [optional] Compare branch (Source branch). - --csv-path= [optional] Custom path for CSV output file. If not provided, will use the current - working directory. - --format=