@contentstack/cli-cm-import 1.26.2 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import/1.26.2 linux-x64 node-v22.18.0
50
+ @contentstack/cli-cm-import/1.27.0 linux-x64 node-v22.18.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -91,6 +91,9 @@ FLAGS
91
91
  extensions, marketplace-apps, global-fields, labels, locales, webhooks,
92
92
  workflows, custom-roles, personalize projects, and taxonomies.
93
93
  -y, --yes [optional] Force override all Marketplace prompts.
94
+ --branch-alias=<value> The alias of the branch where you want to import your content. If you don't
95
+ mention the branch alias, then by default the content will be imported to the
96
+ main branch.
94
97
  --exclude-global-modules Excludes the branch-independent module from the import operation.
95
98
  --import-webhook-status=<option> [default: disable] [default: disable] (optional) This webhook state keeps the
96
99
  same state of webhooks as the source stack. <options: disable|current>
@@ -157,6 +160,9 @@ FLAGS
157
160
  extensions, marketplace-apps, global-fields, labels, locales, webhooks,
158
161
  workflows, custom-roles, personalize projects, and taxonomies.
159
162
  -y, --yes [optional] Force override all Marketplace prompts.
163
+ --branch-alias=<value> The alias of the branch where you want to import your content. If you don't
164
+ mention the branch alias, then by default the content will be imported to the
165
+ main branch.
160
166
  --exclude-global-modules Excludes the branch-independent module from the import operation.
161
167
  --import-webhook-status=<option> [default: disable] [default: disable] (optional) This webhook state keeps the
162
168
  same state of webhooks as the source stack. <options: disable|current>
@@ -26,26 +26,6 @@ class ImportCommand extends cli_command_1.Command {
26
26
  if (this.personalizeUrl)
27
27
  importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl;
28
28
  const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importConfig);
29
- if (!flags.branch) {
30
- try {
31
- // Use stack configuration to check for branch availability
32
- // false positive - no hardcoded secret here
33
- // @ts-ignore-next-line secret-detection
34
- const keyProp = 'api_key';
35
- const branches = await managementAPIClient
36
- .stack({ [keyProp]: importConfig.apiKey })
37
- .branch()
38
- .query()
39
- .find()
40
- .then(({ items }) => items);
41
- if (branches.length) {
42
- flags.branch = 'main';
43
- }
44
- }
45
- catch (error) {
46
- // Branch not enabled, just the let flow continue
47
- }
48
- }
49
29
  const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
50
30
  const result = await moduleImporter.start();
51
31
  backupDir = importConfig.backupDir;
@@ -150,6 +130,11 @@ ImportCommand.flags = {
150
130
  char: 'B',
151
131
  description: "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
152
132
  parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
133
+ exclusive: ['branch-alias'],
134
+ }),
135
+ 'branch-alias': cli_utilities_1.flags.string({
136
+ description: "The alias of the branch where you want to import your content. If you don't mention the branch alias, then by default the content will be imported to the main branch.",
137
+ exclusive: ['branch'],
153
138
  }),
154
139
  'import-webhook-status': cli_utilities_1.flags.string({
155
140
  description: '[default: disable] (optional) This webhook state keeps the same state of webhooks as the source stack. <options: disable|current>',
@@ -436,7 +436,7 @@ const config = {
436
436
  getEncryptionKeyMaxRetry: 3,
437
437
  // useBackedupDir: '',
438
438
  // backupConcurrency: 10,
439
- onlyTSModules: ['taxonomies', 'personalize', 'variant-entries'],
439
+ onlyTSModules: ['taxonomies', 'personalize', 'variant-entries', 'stack'],
440
440
  auditConfig: {
441
441
  noLog: false,
442
442
  skipConfirm: true,
@@ -23,8 +23,13 @@ class ModuleImporter {
23
23
  this.importConfig.stackName = stackDetails.name;
24
24
  this.importConfig.org_uid = stackDetails.org_uid;
25
25
  }
26
- if (this.importConfig.branchName) {
27
- await (0, utils_1.validateBranch)(this.stackAPIClient, this.importConfig, this.importConfig.branchName);
26
+ await (0, utils_1.setupBranchConfig)(this.importConfig, this.stackAPIClient);
27
+ if (this.importConfig.branchAlias && this.importConfig.branchName) {
28
+ this.stackAPIClient = this.managementAPIClient.stack({
29
+ api_key: this.importConfig.apiKey,
30
+ management_token: this.importConfig.management_token,
31
+ branch_uid: this.importConfig.branchName,
32
+ });
28
33
  }
29
34
  if (this.importConfig.management_token) {
30
35
  await (0, cli_utilities_1.addLocale)(this.importConfig.apiKey, this.importConfig.management_token, this.importConfig.host);
@@ -40,15 +45,7 @@ class ModuleImporter {
40
45
  // NOTE audit and fix the import content.
41
46
  if (!this.importConfig.skipAudit &&
42
47
  (!this.importConfig.moduleName ||
43
- [
44
- 'content-types',
45
- 'global-fields',
46
- 'entries',
47
- 'extensions',
48
- 'workflows',
49
- 'custom-roles',
50
- 'assets'
51
- ].includes(this.importConfig.moduleName))) {
48
+ ['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles', 'assets'].includes(this.importConfig.moduleName))) {
52
49
  if (!(await this.auditImportData(logger))) {
53
50
  return { noSuccessMsg: true };
54
51
  }
@@ -127,15 +124,7 @@ class ModuleImporter {
127
124
  }
128
125
  else if (this.importConfig.modules.types.length) {
129
126
  this.importConfig.modules.types
130
- .filter((val) => [
131
- 'content-types',
132
- 'global-fields',
133
- 'entries',
134
- 'extensions',
135
- 'workflows',
136
- 'custom-roles',
137
- 'assets'
138
- ].includes(val))
127
+ .filter((val) => ['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles', 'assets'].includes(val))
139
128
  .forEach((val) => {
140
129
  args.push('--modules', val);
141
130
  });
@@ -61,7 +61,7 @@ class ContentTypesImport extends base_class_1.default {
61
61
  cli_utilities_1.log.debug(`Found ${this.cTs.length} content types to import`, this.importConfig.context);
62
62
  await utils_1.fsUtil.makeDirectory(this.cTsMapperPath);
63
63
  cli_utilities_1.log.debug('Created content types mapper directory', this.importConfig.context);
64
- this.installedExtensions = ((await utils_1.fsUtil.readFile(this.marketplaceAppMapperPath)) || { extension_uid: {} }).extension_uid;
64
+ this.installedExtensions = (utils_1.fsUtil.readFile(this.marketplaceAppMapperPath) || { extension_uid: {} }).extension_uid;
65
65
  cli_utilities_1.log.debug(`Loaded ${(_a = Object.keys(this.installedExtensions)) === null || _a === void 0 ? void 0 : _a.length} installed extensions`, this.importConfig.context);
66
66
  this.taxonomies = utils_1.fsUtil.readFile(this.taxonomiesPath);
67
67
  const taxonomyCount = Object.keys(this.taxonomies || {}).length;
@@ -46,24 +46,24 @@ class EntriesImport extends base_class_1.default {
46
46
  async start() {
47
47
  var _a;
48
48
  try {
49
- this.cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
49
+ this.cTs = (utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json')) || []);
50
50
  if (!this.cTs || (0, lodash_1.isEmpty)(this.cTs)) {
51
- cli_utilities_1.log.info('No content type found', this.importConfig.context);
51
+ cli_utilities_1.log.warn(`No content types file found at ${path.join(this.cTsPath, 'schema.json')}. Skipping entries import.`, this.importConfig.context);
52
52
  return;
53
53
  }
54
54
  cli_utilities_1.log.debug(`Found ${this.cTs.length} content types for entry import`, this.importConfig.context);
55
- this.installedExtensions = ((await utils_1.fsUtil.readFile(this.marketplaceAppMapperPath)) || { extension_uid: {} }).extension_uid;
55
+ this.installedExtensions = (utils_1.fsUtil.readFile(this.marketplaceAppMapperPath) || { extension_uid: {} }).extension_uid;
56
56
  cli_utilities_1.log.debug('Loaded installed extensions for entry processing', this.importConfig.context);
57
57
  this.assetUidMapper = utils_1.fsUtil.readFile(this.assetUidMapperPath) || {};
58
58
  this.assetUrlMapper = utils_1.fsUtil.readFile(this.assetUrlMapperPath) || {};
59
59
  cli_utilities_1.log.debug(`Loaded asset mappings - UIDs: ${Object.keys(this.assetUidMapper).length}, URLs: ${Object.keys(this.assetUrlMapper).length}`, this.importConfig.context);
60
- this.taxonomies = utils_1.fsUtil.readFile(this.taxonomiesPath);
60
+ this.taxonomies = (utils_1.fsUtil.readFile(this.taxonomiesPath) || {});
61
61
  cli_utilities_1.log.debug('Loaded taxonomy data for entry processing', this.importConfig.context);
62
62
  utils_1.fsUtil.makeDirectory(this.entriesMapperPath);
63
63
  cli_utilities_1.log.debug('Created entries mapper directory', this.importConfig.context);
64
64
  cli_utilities_1.log.info('Preparing content types for entry import', this.importConfig.context);
65
65
  await this.disableMandatoryCTReferences();
66
- this.locales = (0, lodash_1.values)(utils_1.fsUtil.readFile(this.localesPath));
66
+ this.locales = (0, lodash_1.values)((utils_1.fsUtil.readFile(this.localesPath) || []));
67
67
  this.locales.unshift(this.importConfig.master_locale); // adds master locale to the list
68
68
  cli_utilities_1.log.debug(`Processing entries for ${(0, lodash_1.values)(this.locales).length} locales`, this.importConfig.context);
69
69
  //Create Entries
@@ -119,8 +119,14 @@ class EntriesImport extends base_class_1.default {
119
119
  // Publishing entries
120
120
  if (!this.importConfig.skipEntriesPublish) {
121
121
  cli_utilities_1.log.info('Starting entry publishing process', this.importConfig.context);
122
- this.envs = utils_1.fileHelper.readFileSync(this.envPath);
123
- cli_utilities_1.log.debug(`Loaded ${Object.keys(this.envs).length} environments for publishing`, this.importConfig.context);
122
+ this.envs = utils_1.fileHelper.readFileSync(this.envPath) || {};
123
+ if (Object.keys(this.envs).length === 0) {
124
+ cli_utilities_1.log.warn(`No environments file found at ${this.envPath}. Entries will not be published.`, this.importConfig.context);
125
+ return;
126
+ }
127
+ else {
128
+ cli_utilities_1.log.debug(`Loaded ${Object.keys(this.envs).length} environments for publishing`, this.importConfig.context);
129
+ }
124
130
  for (let entryRequestOption of entryRequestOptions) {
125
131
  await this.publishEntries(entryRequestOption).catch((error) => {
126
132
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid: entryRequestOption.cTUid, locale: entryRequestOption.locale }), `Error in publishing entries of ${entryRequestOption.cTUid} in locale ${entryRequestOption.locale}`);
@@ -137,7 +143,6 @@ class EntriesImport extends base_class_1.default {
137
143
  catch (error) {
138
144
  this.createEntryDataForVariantEntry();
139
145
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
140
- throw new Error('Error while importing entries');
141
146
  }
142
147
  }
143
148
  /**
@@ -157,8 +162,7 @@ class EntriesImport extends base_class_1.default {
157
162
  cli_utilities_1.log.debug(`Successfully processed content type: ${uid}`, this.importConfig.context);
158
163
  };
159
164
  const onReject = ({ error, apiData: { uid } }) => {
160
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }));
161
- throw new Error(`${uid} content type references removal failed`);
165
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), `${uid} content type references removal failed`);
162
166
  };
163
167
  return await this.makeConcurrentCall({
164
168
  processName: 'Update content types (removing mandatory references temporarily)',
@@ -587,7 +591,7 @@ class EntriesImport extends base_class_1.default {
587
591
  for (const index in indexer) {
588
592
  cli_utilities_1.log.debug(`Processing reference update chunk ${index} of ${indexerCount} for ${cTUid} in ${locale}`, this.importConfig.context);
589
593
  const chunk = await fs.readChunkFiles.next().catch((error) => {
590
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid, locale }), 'Error');
594
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid, locale }), 'Failed to load data chunks due to a read error. Ensure the files are accessible and not corrupted.');
591
595
  });
592
596
  if (chunk) {
593
597
  let apiContent = (0, lodash_1.values)(chunk);
@@ -664,7 +668,7 @@ class EntriesImport extends base_class_1.default {
664
668
  cli_utilities_1.log.success(`${uid} content type references updated`, this.importConfig.context);
665
669
  };
666
670
  const onReject = ({ error, apiData: { uid } }) => {
667
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), 'Error');
671
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), `Failed to update references of content type '${uid}'`);
668
672
  throw new Error(`Failed to update references of content type ${uid}`);
669
673
  };
670
674
  return await this.makeConcurrentCall({
@@ -724,7 +728,7 @@ class EntriesImport extends base_class_1.default {
724
728
  }
725
729
  async updateFieldRules() {
726
730
  var _a, _b, _c;
727
- let cTsWithFieldRules = utils_1.fsUtil.readFile(path.join(this.cTsPath + '/field_rules_uid.json'));
731
+ let cTsWithFieldRules = (utils_1.fsUtil.readFile(path.join(this.cTsPath + '/field_rules_uid.json')) || []);
728
732
  if (!cTsWithFieldRules || (cTsWithFieldRules === null || cTsWithFieldRules === void 0 ? void 0 : cTsWithFieldRules.length) === 0) {
729
733
  cli_utilities_1.log.debug('No content types with field rules found to update', this.importConfig.context);
730
734
  return;
@@ -732,7 +736,7 @@ class EntriesImport extends base_class_1.default {
732
736
  cli_utilities_1.log.debug(`Found ${cTsWithFieldRules.length} content types with field rules to update`, this.importConfig.context);
733
737
  for (let cTUid of cTsWithFieldRules) {
734
738
  cli_utilities_1.log.debug(`Processing field rules for content type: ${cTUid}`, this.importConfig.context);
735
- const cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
739
+ const cTs = (utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json')) || []);
736
740
  const contentType = (0, lodash_1.find)(cTs, { uid: cTUid });
737
741
  if (contentType.field_rules) {
738
742
  cli_utilities_1.log.debug(`Found ${contentType.field_rules.length} field rules for content type: ${cTUid}`, this.importConfig.context);
@@ -27,6 +27,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
27
27
  branches?: branch[];
28
28
  branchEnabled?: boolean;
29
29
  branchDir?: string;
30
+ branchAlias?: string;
30
31
  moduleName?: Modules;
31
32
  master_locale: masterLocale;
32
33
  headers?: {
@@ -290,7 +290,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
290
290
  }
291
291
  }
292
292
  if (unmatchedUids.length) {
293
- cli_utilities_1.log.warn(`Found ${unmatchedUids.length} unmatched asset UIDs`);
293
+ cli_utilities_1.log.debug(`Found ${unmatchedUids.length} unmatched asset UIDs`);
294
294
  let unmatchedAssetUids = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
295
295
  unmatchedAssetUids = unmatchedAssetUids || {};
296
296
  if (unmatchedAssetUids.hasOwnProperty(data.content_type.uid)) {
@@ -304,7 +304,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
304
304
  helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
305
305
  }
306
306
  if (unmatchedUrls.length) {
307
- cli_utilities_1.log.warn(`Found ${unmatchedUrls.length} unmatched asset URLs`);
307
+ cli_utilities_1.log.debug(`Found ${unmatchedUrls.length} unmatched asset URLs`);
308
308
  let unmatchedAssetUrls = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
309
309
  unmatchedAssetUrls = unmatchedAssetUrls || {};
310
310
  if (unmatchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
@@ -128,8 +128,7 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
128
128
  catch (error) {
129
129
  // Else warn and modify the schema object.
130
130
  isContentTypeError = true;
131
- cli_utilities_1.log.warn(`Content type does not exist: ${schema[i].reference_to[j]}`);
132
- console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
131
+ cli_utilities_1.log.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
133
132
  }
134
133
  }
135
134
  if (isContentTypeError) {
@@ -238,7 +238,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
238
238
  }
239
239
  });
240
240
  if (unmapped.length > 0) {
241
- cli_utilities_1.log.warn(`Found ${unmapped.length} unmapped entry references`);
241
+ cli_utilities_1.log.debug(`Found ${unmapped.length} unmapped entry references`);
242
242
  let unmappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'unmapped-uids.json'));
243
243
  unmappedUids = unmappedUids || {};
244
244
  if (unmappedUids.hasOwnProperty(data.content_type.uid)) {
@@ -69,7 +69,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
69
69
  schema[i].reference_to = global_fields_data[global_fields_key_value];
70
70
  }
71
71
  else {
72
- cli_utilities_1.log.warn(`No mapping found for global field: ${global_fields_key_value}`);
72
+ cli_utilities_1.log.debug(`No mapping found for global field: ${global_fields_key_value}`);
73
73
  }
74
74
  }
75
75
  else if (schema[i].hasOwnProperty('extension_uid')) {
@@ -88,7 +88,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
88
88
  schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
89
89
  }
90
90
  else {
91
- cli_utilities_1.log.warn(`No mapping found for extension: ${extension_key_value}`);
91
+ cli_utilities_1.log.debug(`No mapping found for extension: ${extension_key_value}`);
92
92
  }
93
93
  }
94
94
  }
@@ -111,7 +111,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
111
111
  newPluginUidsArray.push(marketPlaceAppsData.extension_uid[extension_key_value]);
112
112
  }
113
113
  else {
114
- cli_utilities_1.log.warn(`No mapping found for plugin extension: ${extension_key_value}`);
114
+ cli_utilities_1.log.debug(`No mapping found for plugin extension: ${extension_key_value}`);
115
115
  }
116
116
  });
117
117
  cli_utilities_1.log.debug(`Updated plugins array with ${newPluginUidsArray.length} mapped extensions`);
@@ -92,6 +92,9 @@ const setupConfig = async (importCmdFlags) => {
92
92
  config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes;
93
93
  config.importWebhookStatus = importCmdFlags['import-webhook-status'];
94
94
  config.skipPrivateAppRecreationIfExist = !importCmdFlags['skip-app-recreation'];
95
+ if (importCmdFlags['branch-alias']) {
96
+ config.branchAlias = importCmdFlags['branch-alias'];
97
+ }
95
98
  if (importCmdFlags['branch']) {
96
99
  config.branchName = importCmdFlags['branch'];
97
100
  config.branchDir = config.contentDir;
@@ -1,3 +1,4 @@
1
+ export { setupBranchConfig } from './setup-branch';
1
2
  export * as interactive from './interactive';
2
3
  export { default as setupImportConfig } from './import-config-handler';
3
4
  export * as fileHelper from './file-helper';
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
3
+ exports.lookUpTerms = exports.lookUpTaxonomy = exports.restoreJsonRteEntryRefs = exports.removeEntryRefsFromJSONRTE = exports.removeUidsFromJsonRteFields = exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = exports.setupBranchConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ var setup_branch_1 = require("./setup-branch");
6
+ Object.defineProperty(exports, "setupBranchConfig", { enumerable: true, get: function () { return setup_branch_1.setupBranchConfig; } });
5
7
  exports.interactive = tslib_1.__importStar(require("./interactive"));
6
8
  var import_config_handler_1 = require("./import-config-handler");
7
9
  Object.defineProperty(exports, "setupImportConfig", { enumerable: true, get: function () { return tslib_1.__importDefault(import_config_handler_1).default; } });
@@ -0,0 +1,3 @@
1
+ import { ContentstackClient } from '@contentstack/cli-utilities';
2
+ import { ImportConfig } from 'src/types';
3
+ export declare const setupBranchConfig: (config: ImportConfig, stackAPIClient: ReturnType<ContentstackClient['stack']>) => Promise<void>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupBranchConfig = void 0;
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const common_helper_1 = require("./common-helper");
6
+ const setupBranchConfig = async (config, stackAPIClient) => {
7
+ if (config.branchName) {
8
+ await (0, common_helper_1.validateBranch)(stackAPIClient, config, config.branchName);
9
+ return;
10
+ }
11
+ if (config.branchAlias) {
12
+ config.branchName = await (0, cli_utilities_1.getBranchFromAlias)(stackAPIClient, config.branchAlias);
13
+ return;
14
+ }
15
+ try {
16
+ const branches = await stackAPIClient
17
+ .branch()
18
+ .query()
19
+ .find()
20
+ .then(({ items }) => items);
21
+ if (branches.length) {
22
+ cli_utilities_1.log.info(`Stack is branch Enabled and Branch is not passed by default import will be done in main branch`);
23
+ }
24
+ }
25
+ catch (error) {
26
+ // Here the stack is not branch enabled or any network issue
27
+ cli_utilities_1.log.debug('Failed to fetch branches', { error });
28
+ }
29
+ };
30
+ exports.setupBranchConfig = setupBranchConfig;
@@ -102,11 +102,24 @@
102
102
  "branch": {
103
103
  "char": "B",
104
104
  "description": "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
105
+ "exclusive": [
106
+ "branch-alias"
107
+ ],
105
108
  "name": "branch",
106
109
  "hasDynamicHelp": false,
107
110
  "multiple": false,
108
111
  "type": "option"
109
112
  },
113
+ "branch-alias": {
114
+ "description": "The alias of the branch where you want to import your content. If you don't mention the branch alias, then by default the content will be imported to the main branch.",
115
+ "exclusive": [
116
+ "branch"
117
+ ],
118
+ "name": "branch-alias",
119
+ "hasDynamicHelp": false,
120
+ "multiple": false,
121
+ "type": "option"
122
+ },
110
123
  "import-webhook-status": {
111
124
  "description": "[default: disable] (optional) This webhook state keeps the same state of webhooks as the source stack. <options: disable|current>",
112
125
  "name": "import-webhook-status",
@@ -199,5 +212,5 @@
199
212
  ]
200
213
  }
201
214
  },
202
- "version": "1.26.2"
215
+ "version": "1.27.0"
203
216
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.26.2",
4
+ "version": "1.27.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-audit": "~1.14.0",
9
- "@contentstack/cli-command": "~1.6.0",
10
- "@contentstack/cli-utilities": "~1.13.1",
8
+ "@contentstack/cli-audit": "~1.14.1",
9
+ "@contentstack/cli-command": "~1.6.1",
10
+ "@contentstack/cli-utilities": "~1.14.0",
11
11
  "@contentstack/management": "~1.22.0",
12
- "@contentstack/cli-variants": "~1.3.0",
12
+ "@contentstack/cli-variants": "~1.3.1",
13
13
  "@oclif/core": "^4.3.0",
14
14
  "big-json": "^3.2.0",
15
15
  "bluebird": "^3.7.2",