@contentstack/cli-variants 1.1.0 → 1.1.2

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.
@@ -62,9 +62,9 @@ class VariantEntries extends variant_api_adapter_1.default {
62
62
  };
63
63
  super(Object.assign((0, omit_1.default)(config, ['helpers']), conf));
64
64
  this.config = config;
65
- this.entriesMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.branchName || ''), 'mapper', 'entries');
65
+ this.entriesMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), 'mapper', 'entries');
66
66
  this.personalizeConfig = this.config.modules.personalize;
67
- this.entriesDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.branchName || ''), (0, cli_utilities_1.sanitizePath)(config.modules.entries.dirName));
67
+ this.entriesDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.modules.entries.dirName));
68
68
  this.failedVariantPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'failed-entry-variants.json');
69
69
  this.failedVariantEntries = new Map();
70
70
  }
@@ -81,7 +81,7 @@ class VariantEntries extends variant_api_adapter_1.default {
81
81
  const filePath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'data-for-variant-entry.json');
82
82
  const variantIdPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.experiences.dirName), 'variants-uid-mapping.json');
83
83
  if (!(0, fs_1.existsSync)(filePath)) {
84
- (0, utils_1.log)(this.config, this.messages.IMPORT_ENTRY_NOT_FOUND, 'info');
84
+ (0, utils_1.log)(this.config, this.messages.VARIANT_ENTRY_FILE_NOT_FOUND, 'info');
85
85
  return;
86
86
  }
87
87
  if (!(0, fs_1.existsSync)(variantIdPath)) {
@@ -133,7 +133,7 @@ class VariantEntries extends variant_api_adapter_1.default {
133
133
  const ctConfig = this.config.modules['content-types'];
134
134
  const contentType = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), (0, cli_utilities_1.sanitizePath)(ctConfig.dirName), `${(0, cli_utilities_1.sanitizePath)(content_type)}.json`), 'utf8'));
135
135
  const variantEntryBasePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesDirPath), (0, cli_utilities_1.sanitizePath)(content_type), (0, cli_utilities_1.sanitizePath)(locale), (0, cli_utilities_1.sanitizePath)(variantEntry.dirName), (0, cli_utilities_1.sanitizePath)(entry_uid));
136
- const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath });
136
+ const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
137
137
  for (const _ in fs.indexFileContent) {
138
138
  try {
139
139
  const variantEntries = (yield fs.readChunkFiles.next());
@@ -176,12 +176,12 @@ class VariantEntries extends variant_api_adapter_1.default {
176
176
  const start = Date.now();
177
177
  for (let [, variantEntry] of (0, entries_1.default)(batch)) {
178
178
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
179
- log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid}`, 'info');
179
+ log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, 'info');
180
180
  };
181
181
  const onReject = ({ error, apiData, log }) => {
182
182
  const { entryUid, variantUid } = apiData;
183
183
  this.failedVariantEntries.set(variantUid, apiData);
184
- log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
184
+ log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`, 'error');
185
185
  log(this.config, error, 'error');
186
186
  };
187
187
  // NOTE Find new variant Id by old Id
@@ -352,10 +352,10 @@ class VariantEntries extends variant_api_adapter_1.default {
352
352
  return;
353
353
  }
354
354
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
355
- log(this.config, `Entry variant: '${variantUid}' of entry uid ${entryUid} published successfully!`, 'info');
355
+ log(this.config, `Entry variant: '${variantUid}' of entry '${entryUid}' published on locales '${locales.join(',')}'`, 'info');
356
356
  };
357
357
  const onReject = ({ error, apiData: { entryUid, variantUid }, log }) => {
358
- log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
358
+ log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid} on locales '${locales.join(',')}'`, 'error');
359
359
  log(this.config, (0, utils_1.formatError)(error), 'error');
360
360
  };
361
361
  const { environments, locales } = this.serializePublishEntries(variantEntry);
@@ -8,6 +8,7 @@ declare const migrationMsg: {
8
8
  IMPORT_MSG: string;
9
9
  };
10
10
  declare const variantEntry: {
11
+ VARIANT_ENTRY_FILE_NOT_FOUND: string;
11
12
  IMPORT_ENTRY_NOT_FOUND: string;
12
13
  EMPTY_VARIANT_UID_DATA: string;
13
14
  VARIANT_ID_NOT_FOUND: string;
@@ -18,6 +18,7 @@ const migrationMsg = {
18
18
  IMPORT_MSG: 'Migrating {module}...',
19
19
  };
20
20
  const variantEntry = {
21
+ VARIANT_ENTRY_FILE_NOT_FOUND: 'Variant entry file not found!',
21
22
  IMPORT_ENTRY_NOT_FOUND: 'Entries data not found to import variant entries',
22
23
  EMPTY_VARIANT_UID_DATA: 'Empty variants entry mapper found!',
23
24
  VARIANT_ID_NOT_FOUND: 'Variant ID not found',
@@ -188,10 +188,10 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
188
188
  const { reject, resolve, log, variantUid } = apiParams;
189
189
  const { entry_uid, content_type_uid } = options;
190
190
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
191
- const onSuccess = (response) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
191
+ const onSuccess = (response) => resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
192
192
  const onReject = (error) => reject({
193
193
  error,
194
- apiData: { entryUid: entry_uid, variantUid },
194
+ apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
195
195
  log,
196
196
  });
197
197
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-variants",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Variants plugin",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -54,18 +54,9 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
54
54
  },
55
55
  };
56
56
  super(Object.assign(omit(config, ['helpers']), conf));
57
- this.entriesMapperPath = resolve(
58
- sanitizePath(config.backupDir),
59
- sanitizePath(config.branchName || ''),
60
- 'mapper',
61
- 'entries',
62
- );
57
+ this.entriesMapperPath = resolve(sanitizePath(config.backupDir), 'mapper', 'entries');
63
58
  this.personalizeConfig = this.config.modules.personalize;
64
- this.entriesDirPath = resolve(
65
- sanitizePath(config.backupDir),
66
- sanitizePath(config.branchName || ''),
67
- sanitizePath(config.modules.entries.dirName),
68
- );
59
+ this.entriesDirPath = resolve(sanitizePath(config.backupDir), sanitizePath(config.modules.entries.dirName));
69
60
  this.failedVariantPath = resolve(sanitizePath(this.entriesMapperPath), 'failed-entry-variants.json');
70
61
  this.failedVariantEntries = new Map();
71
62
  }
@@ -89,7 +80,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
89
80
  );
90
81
 
91
82
  if (!existsSync(filePath)) {
92
- log(this.config, this.messages.IMPORT_ENTRY_NOT_FOUND, 'info');
83
+ log(this.config, this.messages.VARIANT_ENTRY_FILE_NOT_FOUND, 'info');
93
84
  return;
94
85
  }
95
86
 
@@ -171,7 +162,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
171
162
  sanitizePath(variantEntry.dirName),
172
163
  sanitizePath(entry_uid),
173
164
  );
174
- const fs = new FsUtility({ basePath: variantEntryBasePath });
165
+ const fs = new FsUtility({ basePath: variantEntryBasePath, createDirIfNotExist: false });
175
166
 
176
167
  for (const _ in fs.indexFileContent) {
177
168
  try {
@@ -219,13 +210,21 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
219
210
 
220
211
  for (let [, variantEntry] of entries(batch)) {
221
212
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }: any) => {
222
- log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid}`, 'info');
213
+ log(
214
+ this.config,
215
+ `Created entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`,
216
+ 'info',
217
+ );
223
218
  };
224
219
 
225
220
  const onReject = ({ error, apiData, log }: any) => {
226
221
  const { entryUid, variantUid } = apiData;
227
222
  this.failedVariantEntries.set(variantUid, apiData);
228
- log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
223
+ log(
224
+ this.config,
225
+ `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid} locale '${locale}'`,
226
+ 'error',
227
+ );
229
228
  log(this.config, error, 'error');
230
229
  };
231
230
  // NOTE Find new variant Id by old Id
@@ -442,10 +441,18 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
442
441
  }
443
442
 
444
443
  const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }: any) => {
445
- log(this.config, `Entry variant: '${variantUid}' of entry uid ${entryUid} published successfully!`, 'info');
444
+ log(
445
+ this.config,
446
+ `Entry variant: '${variantUid}' of entry '${entryUid}' published on locales '${locales.join(',')}'`,
447
+ 'info',
448
+ );
446
449
  };
447
450
  const onReject = ({ error, apiData: { entryUid, variantUid }, log }: any) => {
448
- log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
451
+ log(
452
+ this.config,
453
+ `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid} on locales '${locales.join(',')}'`,
454
+ 'error',
455
+ );
449
456
  log(this.config, formatError(error), 'error');
450
457
  };
451
458
 
@@ -13,6 +13,7 @@ const migrationMsg = {
13
13
  };
14
14
 
15
15
  const variantEntry = {
16
+ VARIANT_ENTRY_FILE_NOT_FOUND: 'Variant entry file not found!',
16
17
  IMPORT_ENTRY_NOT_FOUND: 'Entries data not found to import variant entries',
17
18
  EMPTY_VARIANT_UID_DATA: 'Empty variants entry mapper found!',
18
19
  VARIANT_ID_NOT_FOUND: 'Variant ID not found',
@@ -54,7 +54,7 @@ export type PublishVariantEntryDto = {
54
54
  uid: string;
55
55
  version?: number;
56
56
  }[];
57
- }
57
+ };
58
58
  locale: string;
59
59
  version?: number;
60
- } & AnyProperty;
60
+ } & AnyProperty;
@@ -226,11 +226,12 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
226
226
  const { entry_uid, content_type_uid } = options;
227
227
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
228
228
 
229
- const onSuccess = (response: any) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
229
+ const onSuccess = (response: any) =>
230
+ resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
230
231
  const onReject = (error: any) =>
231
232
  reject({
232
233
  error,
233
- apiData: { entryUid: entry_uid, variantUid },
234
+ apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
234
235
  log,
235
236
  });
236
237