@contentstack/cli-cm-import 1.16.2 → 1.16.3

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.16.2 linux-x64 node-v18.20.4
50
+ @contentstack/cli-cm-import/1.16.3 linux-x64 node-v18.20.4
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -15,6 +15,7 @@ export default class ImportMarketplaceApps {
15
15
  developerHubBaseUrl: string;
16
16
  nodeCrypto: NodeCrypto;
17
17
  appSdk: ContentstackMarketplaceClient;
18
+ existingNames: Set<string>;
18
19
  constructor({ importConfig }: ModuleClassParams);
19
20
  /**
20
21
  * This function starts the process of importing marketplace apps.
@@ -28,6 +28,7 @@ class ImportMarketplaceApps {
28
28
  this.appOriginalName = undefined;
29
29
  this.installedApps = [];
30
30
  this.installationUidMapping = {};
31
+ this.existingNames = new Set();
31
32
  }
32
33
  /**
33
34
  * This function starts the process of importing marketplace apps.
@@ -269,14 +270,14 @@ class ImportMarketplaceApps {
269
270
  if (location.meta) {
270
271
  location.meta = (0, map_1.default)(location.meta, (meta) => {
271
272
  if (meta.name && this.appOriginalName == meta.name) {
272
- const name = (0, interactive_1.getAppName)((0, first_1.default)((0, split_1.default)(meta.name, '◈')), appSuffix);
273
+ const name = (0, interactive_1.getLocationName)((0, first_1.default)((0, split_1.default)(meta.name, '◈')), appSuffix, this.existingNames);
273
274
  if (!this.appNameMapping[this.appOriginalName]) {
274
275
  this.appNameMapping[this.appOriginalName] = name;
275
276
  }
276
277
  meta.name = name;
277
278
  }
278
279
  else if (meta.name) {
279
- meta.name = (0, interactive_1.getAppName)((0, first_1.default)((0, split_1.default)(meta.name, '◈')), appSuffix + (+index + 1));
280
+ meta.name = (0, interactive_1.getLocationName)((0, first_1.default)((0, split_1.default)(meta.name, '◈')), appSuffix + (+index + 1), this.existingNames);
280
281
  }
281
282
  return meta;
282
283
  });
@@ -3,4 +3,5 @@ export declare const askAPIKey: () => Promise<string>;
3
3
  export declare const askEncryptionKey: (defaultValue: unknown) => Promise<string>;
4
4
  export declare const askAppName: (app: any, appSuffix: number) => Promise<string>;
5
5
  export declare const getAppName: (name: string, appSuffix?: number) => string;
6
+ export declare const getLocationName: (name: string, appSuffix: number, existingNames: Set<string>) => string;
6
7
  export declare const selectConfiguration: () => Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectConfiguration = exports.getAppName = exports.askAppName = exports.askEncryptionKey = exports.askAPIKey = exports.askContentDir = void 0;
3
+ exports.selectConfiguration = exports.getLocationName = exports.getAppName = exports.askAppName = exports.askEncryptionKey = exports.askAPIKey = exports.askContentDir = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cli_utilities_1 = require("@contentstack/cli-utilities");
6
6
  const path = tslib_1.__importStar(require("path"));
@@ -56,6 +56,24 @@ const getAppName = (name, appSuffix = 1) => {
56
56
  return name;
57
57
  };
58
58
  exports.getAppName = getAppName;
59
+ const getLocationName = (name, appSuffix = 1, existingNames) => {
60
+ const maxLength = 50;
61
+ const suffixLength = appSuffix.toString().length + 1; // +1 for the '◈' character
62
+ let truncatedName = name;
63
+ if (name.length + suffixLength > maxLength) {
64
+ truncatedName = name.slice(0, maxLength - suffixLength);
65
+ }
66
+ let newName = `${(0, first_1.default)((0, split_1.default)(truncatedName, '◈'))}◈${appSuffix}`;
67
+ // Ensure uniqueness
68
+ while (existingNames.has(newName)) {
69
+ appSuffix++;
70
+ newName = `${(0, first_1.default)((0, split_1.default)(truncatedName, '◈'))}◈${appSuffix}`;
71
+ }
72
+ // Add the new name to the set of existing names
73
+ existingNames.add(newName);
74
+ return newName;
75
+ };
76
+ exports.getLocationName = getLocationName;
59
77
  const validateAppName = (name) => {
60
78
  if (name.length < 3 || name.length > 20) {
61
79
  return 'The app name should be within 3-20 characters long.';
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.16.2",
2
+ "version": "1.16.3",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.16.2",
4
+ "version": "1.16.3",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {