@contentstack/cli-variants 1.1.3 → 1.1.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/lib/import/experiences.js +10 -5
- package/lib/import/project.js +2 -1
- package/package.json +3 -3
- package/src/import/experiences.ts +12 -4
- package/src/import/project.ts +11 -3
|
@@ -110,8 +110,12 @@ class Experiences extends utils_1.PersonalizationAdapter {
|
|
|
110
110
|
const jobRes = yield this.validateVariantGroupAndVariantsCreated();
|
|
111
111
|
utils_1.fsUtil.writeFile(this.cmsVariantPath, this.cmsVariants);
|
|
112
112
|
utils_1.fsUtil.writeFile(this.cmsVariantGroupPath, this.cmsVariantGroups);
|
|
113
|
-
if (jobRes)
|
|
113
|
+
if (jobRes) {
|
|
114
114
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Variant & Variant groups' }), 'info');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.personalizeConfig.importData = false;
|
|
118
|
+
}
|
|
115
119
|
if (this.personalizeConfig.importData) {
|
|
116
120
|
this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info');
|
|
117
121
|
yield this.attachCTsInExperience();
|
|
@@ -193,11 +197,12 @@ class Experiences extends utils_1.PersonalizationAdapter {
|
|
|
193
197
|
var _a;
|
|
194
198
|
try {
|
|
195
199
|
const promises = this.pendingVariantAndVariantGrpForExperience.map((expUid) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
var _a, _b, _c, _d;
|
|
200
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
197
201
|
const expRes = yield this.getExperience(expUid);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this.
|
|
202
|
+
const variants = (_b = (_a = expRes === null || expRes === void 0 ? void 0 : expRes._cms) === null || _a === void 0 ? void 0 : _a.variants) !== null && _b !== void 0 ? _b : {};
|
|
203
|
+
if ((expRes === null || expRes === void 0 ? void 0 : expRes._cms) && ((_c = expRes === null || expRes === void 0 ? void 0 : expRes._cms) === null || _c === void 0 ? void 0 : _c.variantGroup) && Object.keys(variants).length > 0) {
|
|
204
|
+
this.cmsVariants[expUid] = (_e = (_d = expRes._cms) === null || _d === void 0 ? void 0 : _d.variants) !== null && _e !== void 0 ? _e : {};
|
|
205
|
+
this.cmsVariantGroups[expUid] = (_g = (_f = expRes._cms) === null || _f === void 0 ? void 0 : _f.variantGroup) !== null && _g !== void 0 ? _g : {};
|
|
201
206
|
return expUid; // Return the expUid for filtering later
|
|
202
207
|
}
|
|
203
208
|
}));
|
package/lib/import/project.js
CHANGED
|
@@ -49,7 +49,8 @@ class Project extends utils_1.PersonalizationAdapter {
|
|
|
49
49
|
description: project.description,
|
|
50
50
|
connectedStackApiKey: this.config.apiKey,
|
|
51
51
|
}).catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
52
|
+
if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
53
|
+
error.includes('personalize.PROJECTS.DUPLICATE_NAME')) {
|
|
53
54
|
const projectName = yield (0, utils_1.askProjectName)('Copy Of ' + (newName || project.name));
|
|
54
55
|
return yield createProject(projectName);
|
|
55
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-variants",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Variants plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@contentstack/cli-dev-dependencies": "^1.2.4",
|
|
21
|
-
"@oclif/test": "^4.1.
|
|
21
|
+
"@oclif/test": "^4.1.3",
|
|
22
22
|
"@types/chai": "^4.3.20",
|
|
23
|
-
"@types/node": "^20.17.
|
|
23
|
+
"@types/node": "^20.17.9",
|
|
24
24
|
"chai": "^4.5.0",
|
|
25
25
|
"mocha": "^10.8.2",
|
|
26
26
|
"nyc": "^15.1.0",
|
|
@@ -45,7 +45,7 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
45
45
|
const conf: APIConfig = {
|
|
46
46
|
config,
|
|
47
47
|
baseURL: config.modules.personalize.baseURL[config.region.name],
|
|
48
|
-
headers: { 'X-Project-Uid': config.modules.personalize.project_id},
|
|
48
|
+
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
|
|
49
49
|
cmaConfig: {
|
|
50
50
|
baseURL: config.region.cma + `/v3`,
|
|
51
51
|
headers: { api_key: config.apiKey },
|
|
@@ -141,8 +141,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
141
141
|
const jobRes = await this.validateVariantGroupAndVariantsCreated();
|
|
142
142
|
fsUtil.writeFile(this.cmsVariantPath, this.cmsVariants);
|
|
143
143
|
fsUtil.writeFile(this.cmsVariantGroupPath, this.cmsVariantGroups);
|
|
144
|
-
if (jobRes)
|
|
144
|
+
if (jobRes) {
|
|
145
145
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Variant & Variant groups' }), 'info');
|
|
146
|
+
} else {
|
|
147
|
+
this.personalizeConfig.importData = false;
|
|
148
|
+
}
|
|
146
149
|
|
|
147
150
|
if (this.personalizeConfig.importData) {
|
|
148
151
|
this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info');
|
|
@@ -162,7 +165,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
162
165
|
* function import experience versions from a JSON file and creates them in the project.
|
|
163
166
|
*/
|
|
164
167
|
async importExperienceVersions(experience: ExperienceStruct, oldExperienceUid: string) {
|
|
165
|
-
const versionsPath = resolve(
|
|
168
|
+
const versionsPath = resolve(
|
|
169
|
+
sanitizePath(this.experiencesDirPath),
|
|
170
|
+
'versions',
|
|
171
|
+
`${sanitizePath(oldExperienceUid)}.json`,
|
|
172
|
+
);
|
|
166
173
|
|
|
167
174
|
if (!existsSync(versionsPath)) {
|
|
168
175
|
return;
|
|
@@ -231,7 +238,8 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
231
238
|
try {
|
|
232
239
|
const promises = this.pendingVariantAndVariantGrpForExperience.map(async (expUid) => {
|
|
233
240
|
const expRes = await this.getExperience(expUid);
|
|
234
|
-
|
|
241
|
+
const variants = expRes?._cms?.variants ?? {};
|
|
242
|
+
if (expRes?._cms && expRes?._cms?.variantGroup && Object.keys(variants).length > 0) {
|
|
235
243
|
this.cmsVariants[expUid] = expRes._cms?.variants ?? {};
|
|
236
244
|
this.cmsVariantGroups[expUid] = expRes._cms?.variantGroup ?? {};
|
|
237
245
|
return expUid; // Return the expUid for filtering later
|
package/src/import/project.ts
CHANGED
|
@@ -28,8 +28,13 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
|
|
|
28
28
|
async import() {
|
|
29
29
|
const personalize = this.config.modules.personalize;
|
|
30
30
|
const { dirName, fileName } = personalize.projects;
|
|
31
|
-
const projectPath = join(
|
|
32
|
-
|
|
31
|
+
const projectPath = join(
|
|
32
|
+
sanitizePath(this.config.data),
|
|
33
|
+
sanitizePath(personalize.dirName),
|
|
34
|
+
sanitizePath(dirName),
|
|
35
|
+
sanitizePath(fileName),
|
|
36
|
+
);
|
|
37
|
+
|
|
33
38
|
if (existsSync(projectPath)) {
|
|
34
39
|
const projects = JSON.parse(readFileSync(projectPath, 'utf8')) as CreateProjectInput[];
|
|
35
40
|
|
|
@@ -46,7 +51,10 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
|
|
|
46
51
|
description: project.description,
|
|
47
52
|
connectedStackApiKey: this.config.apiKey,
|
|
48
53
|
}).catch(async (error) => {
|
|
49
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
56
|
+
error.includes('personalize.PROJECTS.DUPLICATE_NAME')
|
|
57
|
+
) {
|
|
50
58
|
const projectName = await askProjectName('Copy Of ' + (newName || project.name));
|
|
51
59
|
return await createProject(projectName);
|
|
52
60
|
}
|