@contentstack/cli-cm-import 1.8.2 → 1.8.4

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.8.2 linux-x64 node-v18.17.1
50
+ @contentstack/cli-cm-import/1.8.4 linux-x64 node-v18.17.1
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -11,6 +11,7 @@ const path = tslib_1.__importStar(require("path"));
11
11
  const lodash_1 = require("lodash");
12
12
  const utils_1 = require("../../utils");
13
13
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
14
+ const content_type_helper_1 = require("../../utils/content-type-helper");
14
15
  class ContentTypesImport extends base_class_1.default {
15
16
  constructor({ importConfig, stackAPIClient }) {
16
17
  super({ importConfig, stackAPIClient });
@@ -134,8 +135,11 @@ class ContentTypesImport extends base_class_1.default {
134
135
  serializeUpdateCTs(apiOptions) {
135
136
  const { apiData: contentType } = apiOptions;
136
137
  if (contentType.field_rules) {
138
+ contentType.field_rules = (0, content_type_helper_1.updateFieldRules)(contentType);
139
+ if (!contentType.field_rules.length) {
140
+ delete contentType.field_rules;
141
+ }
137
142
  this.fieldRules.push(contentType.uid);
138
- delete contentType.field_rules;
139
143
  }
140
144
  (0, utils_1.lookupExtension)(this.importConfig, contentType.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
141
145
  const contentTypePayload = this.stack.contentType(contentType.uid);
@@ -415,13 +415,19 @@ class EntriesImport extends base_class_1.default {
415
415
  return;
416
416
  }
417
417
  for (let cTUid of cTsWithFieldRules) {
418
- const contentType = (0, lodash_1.find)(this.cTs, { uid: cTUid });
418
+ const cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
419
+ const contentType = (0, lodash_1.find)(cTs, { uid: cTUid });
419
420
  if (contentType.field_rules) {
420
421
  let fieldRuleLength = contentType.field_rules.length;
422
+ const fieldDatatypeMap = {};
423
+ for (let i = 0; i < contentType.schema.length; i++) {
424
+ const field = contentType.schema[i].uid;
425
+ fieldDatatypeMap[field] = contentType.schema[i].data_type;
426
+ }
421
427
  for (let k = 0; k < fieldRuleLength; k++) {
422
428
  let fieldRuleConditionLength = contentType.field_rules[k].conditions.length;
423
429
  for (let i = 0; i < fieldRuleConditionLength; i++) {
424
- if (contentType.field_rules[k].conditions[i].operand_field === 'reference') {
430
+ if (fieldDatatypeMap[contentType.field_rules[k].conditions[i].operand_field] === 'reference') {
425
431
  let fieldRulesValue = contentType.field_rules[k].conditions[i].value;
426
432
  let fieldRulesArray = fieldRulesValue.split('.');
427
433
  let updatedValue = [];
@@ -142,9 +142,12 @@ class ImportWorkflows extends base_class_1.default {
142
142
  }
143
143
  return newStage;
144
144
  });
145
- workflow.workflow_stages = newWorkflowStages;
146
145
  const updateWorkflow = this.stack.workflow(workflow.uid);
147
- Object.assign(updateWorkflow, workflow);
146
+ Object.assign(updateWorkflow, {
147
+ name: workflow.name,
148
+ branches: workflow.branches,
149
+ workflow_stages: newWorkflowStages,
150
+ });
148
151
  return updateWorkflow.update();
149
152
  }
150
153
  /**
@@ -30,4 +30,5 @@ declare class ContentTypesImport {
30
30
  updateContentType(contentType: any): Promise<void>;
31
31
  updateGlobalFields(uid: any): Promise<boolean>;
32
32
  mapUidToTitle(): Promise<void>;
33
+ updateFieldRules(contentType: any): any[];
33
34
  }
@@ -130,8 +130,11 @@ class ContentTypesImport {
130
130
  return;
131
131
  const requestObject = cloneDeep(this.requestOptions);
132
132
  if (contentType.field_rules) {
133
+ contentType.field_rules = this.updateFieldRules(contentType);
134
+ if (!contentType.field_rules.length) {
135
+ delete contentType.field_rules;
136
+ }
133
137
  this.fieldRules.push(contentType.uid);
134
- delete contentType.field_rules;
135
138
  }
136
139
  lookupExtension(this.importConfig, contentType.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
137
140
  requestObject.json.content_type = contentType;
@@ -172,5 +175,29 @@ class ContentTypesImport {
172
175
  this.titleToUIdMap.set(ct.uid, ct.title);
173
176
  });
174
177
  }
178
+ updateFieldRules(contentType) {
179
+ const fieldDataTypeMap = {};
180
+ for (let i = 0; i < contentType.schema.length; i++) {
181
+ const field = contentType.schema[i];
182
+ fieldDataTypeMap[field.uid] = field.data_type;
183
+ }
184
+ const fieldRules = [...contentType.field_rules];
185
+ let len = fieldRules.length;
186
+ // Looping backwards as we need to delete elements as we move.
187
+ for (let i = len - 1; i >= 0; i--) {
188
+ const conditions = fieldRules[i].conditions;
189
+ let isReference = false;
190
+ for (let j = 0; j < conditions.length; j++) {
191
+ const field = conditions[j].operand_field;
192
+ if (fieldDataTypeMap[field] === 'reference') {
193
+ isReference = true;
194
+ }
195
+ }
196
+ if (isReference) {
197
+ fieldRules.splice(i, 1);
198
+ }
199
+ }
200
+ return fieldRules;
201
+ }
175
202
  }
176
203
  module.exports = ContentTypesImport;
@@ -14,7 +14,7 @@ const { default: config } = require('../../config');
14
14
  const addlogs = log;
15
15
  module.exports = class ImportEntries {
16
16
  constructor(importConfig, stackAPIClient) {
17
- this.skipFiles = ['__master.json', '__priority.json', 'schema.json'];
17
+ this.skipFiles = ['__master.json', '__priority.json', 'schema.json', '.DS_Store'];
18
18
  this.config = _.merge(config, importConfig);
19
19
  this.stackAPIClient = stackAPIClient;
20
20
  this.mappedAssetUidPath = path.resolve(this.config.data, 'mapper', 'assets', 'uid-mapping.json');
@@ -1029,7 +1029,7 @@ module.exports = class ImportEntries {
1029
1029
  // only checking one level deep, not recursive
1030
1030
  if (element.length) {
1031
1031
  for (const item of element) {
1032
- if ((item.type === 'p' || item.type === 'a') && item.children && item.children.length > 0) {
1032
+ if ((item.type === 'p' || item.type === 'a' || item.type === 'span') && item.children && item.children.length > 0) {
1033
1033
  return this.doEntryReferencesExist(item.children);
1034
1034
  }
1035
1035
  else if (this.isEntryRef(item)) {
@@ -1041,7 +1041,7 @@ module.exports = class ImportEntries {
1041
1041
  if (this.isEntryRef(element)) {
1042
1042
  return true;
1043
1043
  }
1044
- if ((element.type === 'p' || element.type === 'a') && element.children && element.children.length > 0) {
1044
+ if ((element.type === 'p' || element.type === 'a' || element.type === 'span') && element.children && element.children.length > 0) {
1045
1045
  return this.doEntryReferencesExist(element.children);
1046
1046
  }
1047
1047
  }
@@ -158,9 +158,12 @@ module.exports = class importWorkflows {
158
158
  }
159
159
  return newStage;
160
160
  });
161
- workflow.workflow_stages = newWorkflowStages;
162
161
  const updateWorkflow = this.stackAPIClient.workflow(workflow.uid);
163
- Object.assign(updateWorkflow, workflow);
162
+ Object.assign(updateWorkflow, {
163
+ name: workflow.name,
164
+ branches: workflow.branches,
165
+ workflow_stages: newWorkflowStages,
166
+ });
164
167
  return updateWorkflow.update();
165
168
  }
166
169
  };
@@ -191,8 +191,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
191
191
  jsonRteData.children.forEach((element) => {
192
192
  if (element.type) {
193
193
  switch (element.type) {
194
- case 'a':
195
- case 'p': {
194
+ default: {
196
195
  if (element.children && element.children.length > 0) {
197
196
  gatherJsonRteAssetIds(element);
198
197
  }
@@ -49,3 +49,4 @@ export declare const suppressSchemaReference: (schema: any, flag: any) => void;
49
49
  export declare const removeReferenceFields: (schema: any, flag: {
50
50
  supressed: boolean;
51
51
  }, stackAPIClient: any) => Promise<boolean | void>;
52
+ export declare const updateFieldRules: (contentType: any) => any[];
@@ -6,7 +6,7 @@
6
6
  * suppress mandatory fields
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = void 0;
9
+ exports.updateFieldRules = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = void 0;
10
10
  exports.schemaTemplate = {
11
11
  content_type: {
12
12
  title: 'Seed',
@@ -150,3 +150,28 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
150
150
  }
151
151
  };
152
152
  exports.removeReferenceFields = removeReferenceFields;
153
+ const updateFieldRules = function (contentType) {
154
+ const fieldDataTypeMap = {};
155
+ for (let i = 0; i < contentType.schema.length; i++) {
156
+ const field = contentType.schema[i];
157
+ fieldDataTypeMap[field.uid] = field.data_type;
158
+ }
159
+ const fieldRules = [...contentType.field_rules];
160
+ let len = fieldRules.length;
161
+ // Looping backwards as we need to delete elements as we move.
162
+ for (let i = len - 1; i >= 0; i--) {
163
+ const conditions = fieldRules[i].conditions;
164
+ let isReference = false;
165
+ for (let j = 0; j < conditions.length; j++) {
166
+ const field = conditions[j].operand_field;
167
+ if (fieldDataTypeMap[field] === 'reference') {
168
+ isReference = true;
169
+ }
170
+ }
171
+ if (isReference) {
172
+ fieldRules.splice(i, 1);
173
+ }
174
+ }
175
+ return fieldRules;
176
+ };
177
+ exports.updateFieldRules = updateFieldRules;
@@ -21,8 +21,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
21
21
  jsonRteData.children.forEach((element) => {
22
22
  if (element.type) {
23
23
  switch (element.type) {
24
- case 'a':
25
- case 'p': {
24
+ default: {
26
25
  if (element.children && element.children.length > 0) {
27
26
  gatherJsonRteEntryIds(element);
28
27
  }
@@ -412,7 +411,7 @@ function doEntryReferencesExist(element) {
412
411
  // only checking one level deep, not recursive
413
412
  if (element.length) {
414
413
  for (const item of element) {
415
- if ((item.type === 'p' || item.type === 'a') && item.children && item.children.length > 0) {
414
+ if ((item.type === 'p' || item.type === 'a' || item.type === 'span') && item.children && item.children.length > 0) {
416
415
  return doEntryReferencesExist(item.children);
417
416
  }
418
417
  else if (isEntryRef(item)) {
@@ -424,7 +423,7 @@ function doEntryReferencesExist(element) {
424
423
  if (isEntryRef(element)) {
425
424
  return true;
426
425
  }
427
- if ((element.type === 'p' || element.type === 'a') && element.children && element.children.length > 0) {
426
+ if ((element.type === 'p' || element.type === 'a' || element.type === 'span') && element.children && element.children.length > 0) {
428
427
  return doEntryReferencesExist(element.children);
429
428
  }
430
429
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.2",
2
+ "version": "1.8.4",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.8.2",
4
+ "version": "1.8.4",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "~1.2.11",
9
- "@contentstack/cli-utilities": "~1.5.1",
8
+ "@contentstack/cli-command": "~1.2.12",
9
+ "@contentstack/cli-utilities": "~1.5.2",
10
10
  "@contentstack/management": "~1.10.0",
11
- "@oclif/config": "^1.18.3",
12
11
  "@oclif/core": "^2.9.3",
13
12
  "big-json": "^3.2.0",
14
13
  "bluebird": "^3.7.2",
@@ -96,4 +95,4 @@
96
95
  }
97
96
  },
98
97
  "repository": "https://github.com/contentstack/cli"
99
- }
98
+ }