Skip to content

Commit

Permalink
Merge pull request #1556 from contentstack/fix/dev
Browse files Browse the repository at this point in the history
Fix stage
  • Loading branch information
cs-raj authored Sep 10, 2024
2 parents 9ebc90d + 9f57892 commit 9db63ce
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { Import, ImportHelperMethodsConfig, LogType, ProjectStruct } from '@contentstack/cli-variants';
import { sanitizePath } from '@contentstack/cli-utilities';
import { ImportConfig, ModuleClassParams } from '../../types';
import {
log,
Expand All @@ -20,9 +21,9 @@ export default class ImportVarientEntries {
this.config = importConfig;
this.personalization = importConfig.modules.personalization;
this.projectMapperFilePath = path.resolve(
this.config.data,
sanitizePath(this.config.data),
'mapper',
this.personalization.dirName,
sanitizePath(this.personalization.dirName),
'projects',
'projects.json',
);
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-variants/src/export/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import omit from 'lodash/omit';
import { resolve as pResolve } from 'node:path';

import { sanitizePath } from '@contentstack/cli-utilities';
import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils';
import { PersonalizationConfig, ExportConfig, AttributesConfig, AttributeStruct } from '../types';

Expand All @@ -19,10 +19,10 @@ export default class ExportAttributes extends PersonalizationAdapter<ExportConfi
this.personalizationConfig = exportConfig.modules.personalization;
this.attributesConfig = exportConfig.modules.attributes;
this.attributesFolderPath = pResolve(
exportConfig.data,
exportConfig.branchName || '',
this.personalizationConfig.dirName,
this.attributesConfig.dirName,
sanitizePath(exportConfig.data),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(this.personalizationConfig.dirName),
sanitizePath(this.attributesConfig.dirName),
);
this.attributes = [];
}
Expand All @@ -37,7 +37,7 @@ export default class ExportAttributes extends PersonalizationAdapter<ExportConfi
log(this.exportConfig, 'No Attributes found with the given project!', 'info');
} else {
this.sanitizeAttribs();
fsUtil.writeFile(pResolve(this.attributesFolderPath, this.attributesConfig.fileName), this.attributes);
fsUtil.writeFile(pResolve(sanitizePath(this.attributesFolderPath), sanitizePath(this.attributesConfig.fileName)), this.attributes);
log(this.exportConfig, 'All the attributes have been exported successfully!', 'success');
}
} catch (error) {
Expand Down
13 changes: 7 additions & 6 deletions packages/contentstack-variants/src/export/experiences.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { sanitizePath } from '@contentstack/cli-utilities';
import { PersonalizationConfig, ExportConfig, ExperienceStruct } from '../types';
import { formatError, fsUtil, log, PersonalizationAdapter } from '../utils';

Expand All @@ -19,9 +20,9 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
this.exportConfig = exportConfig;
this.personalizationConfig = exportConfig.modules.personalization;
this.experiencesFolderPath = path.resolve(
exportConfig.data,
exportConfig.branchName || '',
this.personalizationConfig.dirName,
sanitizePath(exportConfig.data),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(this.personalizationConfig.dirName),
'experiences',
);
}
Expand All @@ -38,7 +39,7 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
log(this.exportConfig, 'No Experiences found with the give project', 'info');
return;
}
fsUtil.writeFile(path.resolve(this.experiencesFolderPath, 'experiences.json'), experiences);
fsUtil.writeFile(path.resolve(sanitizePath(this.experiencesFolderPath), 'experiences.json'), experiences);

const experienceToVariantsStrList: Array<string> = [];
const experienceToContentTypesMap: Record<string, string[]> = {};
Expand All @@ -62,12 +63,12 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
}
}
fsUtil.writeFile(
path.resolve(this.experiencesFolderPath, 'experiences-variants-ids.json'),
path.resolve(sanitizePath(this.experiencesFolderPath), 'experiences-variants-ids.json'),
experienceToVariantsStrList,
);

fsUtil.writeFile(
path.resolve(this.experiencesFolderPath, 'experiences-content-types.json'),
path.resolve(sanitizePath(this.experiencesFolderPath), 'experiences-content-types.json'),
experienceToContentTypesMap,
);
log(this.exportConfig, 'All the experiences have been exported successfully!', 'success');
Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-variants/src/export/projects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';

import { sanitizePath } from '@contentstack/cli-utilities';
import { ExportConfig, PersonalizationConfig } from '../types';
import { PersonalizationAdapter, log, fsUtil, formatError } from '../utils';

Expand All @@ -16,9 +16,9 @@ export default class ExportProjects extends PersonalizationAdapter<ExportConfig>
this.exportConfig = exportConfig;
this.personalizationConfig = exportConfig.modules.personalization;
this.projectFolderPath = path.resolve(
exportConfig.data,
exportConfig.branchName || '',
this.personalizationConfig.dirName,
sanitizePath(exportConfig.data),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(this.personalizationConfig.dirName),
'projects',
);
}
Expand All @@ -35,7 +35,7 @@ export default class ExportProjects extends PersonalizationAdapter<ExportConfig>
}
this.exportConfig.personalizationEnabled = true;
this.exportConfig.project_id = project[0]?.uid;
fsUtil.writeFile(path.resolve(this.projectFolderPath, 'projects.json'), project);
fsUtil.writeFile(path.resolve(sanitizePath(this.projectFolderPath), 'projects.json'), project);
log(this.exportConfig, 'Project exported successfully!', 'success');
} catch (error) {
log(this.exportConfig, `Failed to export projects!`, 'error');
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-variants/src/export/variant-entries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, mkdirSync } from 'fs';
import { join, resolve } from 'path';
import { FsUtility } from '@contentstack/cli-utilities';
import { FsUtility, sanitizePath } from '@contentstack/cli-utilities';

import { APIConfig, AdapterType, ExportConfig, LogType } from '../types';
import VariantAdapter, { VariantHttpClient } from '../utils/variant-api-adapter';
Expand All @@ -25,7 +25,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Exp
},
};
super(Object.assign(config, conf));
this.entriesDirPath = resolve(config.data, config.branchName || '', config.modules.entries.dirName);
this.entriesDirPath = resolve(sanitizePath(config.data), sanitizePath(config.branchName || ''), sanitizePath(config.modules.entries.dirName));
}

/**
Expand All @@ -39,7 +39,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Exp

for (let index = 0; index < entries.length; index++) {
const entry = entries[index];
const variantEntryBasePath = join(this.entriesDirPath, content_type_uid, locale, variantEntry.dirName, entry.uid);
const variantEntryBasePath = join(sanitizePath(this.entriesDirPath), sanitizePath(content_type_uid), sanitizePath(locale), sanitizePath(variantEntry.dirName), sanitizePath(entry.uid));
const variantEntriesFs = new FsUtility({
isArray: true,
keepMetadata: false,
Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-variants/src/import/attribute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path';
import { existsSync } from 'fs';

import { sanitizePath } from '@contentstack/cli-utilities';
import { PersonalizationAdapter, fsUtil } from '../utils';
import { APIConfig, AttributeStruct, ImportConfig, LogType } from '../types';

Expand All @@ -21,9 +21,9 @@ export default class Attribute extends PersonalizationAdapter<ImportConfig> {
super(Object.assign(config, conf));
this.personalizationConfig = this.config.modules.personalization;
this.attributeConfig = this.personalizationConfig.attributes;
this.mapperDirPath = resolve(this.config.backupDir, 'mapper', this.personalizationConfig.dirName);
this.attrMapperDirPath = resolve(this.mapperDirPath, this.attributeConfig.dirName);
this.attributesUidMapperPath = resolve(this.attrMapperDirPath, 'uid-mapping.json');
this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName));
this.attrMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName));
this.attributesUidMapperPath = resolve(sanitizePath(this.attrMapperDirPath), 'uid-mapping.json');
this.attributesUidMapper = {};
}

Expand All @@ -35,7 +35,7 @@ export default class Attribute extends PersonalizationAdapter<ImportConfig> {

await fsUtil.makeDirectory(this.attrMapperDirPath);
const { dirName, fileName } = this.attributeConfig;
const attributesPath = resolve(this.config.data, this.personalizationConfig.dirName, dirName, fileName);
const attributesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName));

if (existsSync(attributesPath)) {
try {
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-variants/src/import/audiences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path';
import { existsSync } from 'fs';

import { sanitizePath } from '@contentstack/cli-utilities';
import { APIConfig, AudienceStruct, ImportConfig, LogType } from '../types';
import { PersonalizationAdapter, fsUtil, lookUpAttributes } from '../utils';

Expand All @@ -24,10 +24,10 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {
this.personalizationConfig = this.config.modules.personalization;
this.audienceConfig = this.personalizationConfig.audiences;
this.attributeConfig = this.personalizationConfig.attributes;
this.mapperDirPath = resolve(this.config.backupDir, 'mapper', this.personalizationConfig.dirName);
this.audienceMapperDirPath = resolve(this.mapperDirPath, this.audienceConfig.dirName);
this.audiencesUidMapperPath = resolve(this.audienceMapperDirPath, 'uid-mapping.json');
this.attributesMapperPath = resolve(this.mapperDirPath, this.attributeConfig.dirName, 'uid-mapping.json');
this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName));
this.audienceMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.audienceConfig.dirName));
this.audiencesUidMapperPath = resolve(sanitizePath(this.audienceMapperDirPath), 'uid-mapping.json');
this.attributesMapperPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName), 'uid-mapping.json');
this.audiencesUidMapper = {};
}

Expand All @@ -39,7 +39,7 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {

await fsUtil.makeDirectory(this.audienceMapperDirPath);
const { dirName, fileName } = this.audienceConfig;
const audiencesPath = resolve(this.config.data, this.personalizationConfig.dirName, dirName, fileName);
const audiencesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName));

if (existsSync(audiencesPath)) {
try {
Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-variants/src/import/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path';
import { existsSync } from 'fs';

import { sanitizePath } from '@contentstack/cli-utilities';
import { PersonalizationAdapter, fsUtil } from '../utils';
import { APIConfig, EventStruct, ImportConfig, LogType } from '../types';

Expand All @@ -21,9 +21,9 @@ export default class Events extends PersonalizationAdapter<ImportConfig> {
super(Object.assign(config, conf));
this.personalizationConfig = this.config.modules.personalization;
this.eventsConfig = this.personalizationConfig.events;
this.mapperDirPath = resolve(this.config.backupDir, 'mapper', this.personalizationConfig.dirName);
this.eventMapperDirPath = resolve(this.mapperDirPath, this.eventsConfig.dirName);
this.eventsUidMapperPath = resolve(this.eventMapperDirPath, 'uid-mapping.json');
this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName));
this.eventMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.eventsConfig.dirName));
this.eventsUidMapperPath = resolve(sanitizePath(this.eventMapperDirPath), 'uid-mapping.json');
this.eventsUidMapper = {};
}

Expand All @@ -35,7 +35,7 @@ export default class Events extends PersonalizationAdapter<ImportConfig> {

await fsUtil.makeDirectory(this.eventMapperDirPath);
const { dirName, fileName } = this.eventsConfig;
const eventsPath = resolve(this.config.data, this.personalizationConfig.dirName, dirName, fileName);
const eventsPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName));

if (existsSync(eventsPath)) {
try {
Expand Down
40 changes: 20 additions & 20 deletions packages/contentstack-variants/src/import/experiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join, resolve } from 'path';
import { existsSync } from 'fs';
import values from 'lodash/values';
import cloneDeep from 'lodash/cloneDeep';

import { sanitizePath } from '@contentstack/cli-utilities';
import { PersonalizationAdapter, fsUtil, lookUpAudiences, lookUpEvents } from '../utils';
import { APIConfig, ImportConfig, ExperienceStruct, CreateExperienceInput, LogType } from '../types';

Expand Down Expand Up @@ -46,38 +46,38 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
super(Object.assign(config, conf));
this.personalizationConfig = this.config.modules.personalization;
this.experiencesDirPath = resolve(
this.config.data,
this.personalizationConfig.dirName,
this.personalizationConfig.experiences.dirName,
sanitizePath(this.config.data),
sanitizePath(this.personalizationConfig.dirName),
sanitizePath(this.personalizationConfig.experiences.dirName),
);
this.experiencesPath = join(this.experiencesDirPath, this.personalizationConfig.experiences.fileName);
this.experiencesPath = join(sanitizePath(this.experiencesDirPath), sanitizePath(this.personalizationConfig.experiences.fileName));
this.experienceConfig = this.personalizationConfig.experiences;
this.audienceConfig = this.personalizationConfig.audiences;
this.mapperDirPath = resolve(this.config.backupDir, 'mapper', this.personalizationConfig.dirName);
this.expMapperDirPath = resolve(this.mapperDirPath, this.experienceConfig.dirName);
this.experiencesUidMapperPath = resolve(this.expMapperDirPath, 'uid-mapping.json');
this.cmsVariantGroupPath = resolve(this.expMapperDirPath, 'cms-variant-groups.json');
this.cmsVariantPath = resolve(this.expMapperDirPath, 'cms-variants.json');
this.audiencesMapperPath = resolve(this.mapperDirPath, this.audienceConfig.dirName, 'uid-mapping.json');
this.eventsMapperPath = resolve(this.mapperDirPath, 'events', 'uid-mapping.json');
this.failedCmsExpPath = resolve(this.expMapperDirPath, 'failed-cms-experience.json');
this.failedCmsExpPath = resolve(this.expMapperDirPath, 'failed-cms-experience.json');
this.experienceCTsPath = resolve(this.experiencesDirPath, 'experiences-content-types.json');
this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName));
this.expMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.experienceConfig.dirName));
this.experiencesUidMapperPath = resolve(sanitizePath(this.expMapperDirPath), 'uid-mapping.json');
this.cmsVariantGroupPath = resolve(sanitizePath(this.expMapperDirPath), 'cms-variant-groups.json');
this.cmsVariantPath = resolve(sanitizePath(this.expMapperDirPath), 'cms-variants.json');
this.audiencesMapperPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.audienceConfig.dirName), 'uid-mapping.json');
this.eventsMapperPath = resolve(sanitizePath(this.mapperDirPath), 'events', 'uid-mapping.json');
this.failedCmsExpPath = resolve(sanitizePath(this.expMapperDirPath), 'failed-cms-experience.json');
this.failedCmsExpPath = resolve(sanitizePath(this.expMapperDirPath), 'failed-cms-experience.json');
this.experienceCTsPath = resolve(sanitizePath(this.experiencesDirPath), 'experiences-content-types.json');
this.experienceVariantsIdsPath = resolve(
this.config.data,
this.personalizationConfig.dirName,
this.experienceConfig.dirName,
sanitizePath(this.config.data),
sanitizePath(this.personalizationConfig.dirName),
sanitizePath(this.experienceConfig.dirName),
'experiences-variants-ids.json',
);
this.variantUidMapperFilePath = resolve(this.expMapperDirPath, 'variants-uid-mapping.json');
this.variantUidMapperFilePath = resolve(sanitizePath(this.expMapperDirPath), 'variants-uid-mapping.json');
this.experiencesUidMapper = {};
this.cmsVariantGroups = {};
this.cmsVariants = {};
this.expThresholdTimer = this.experienceConfig?.thresholdTimer ?? 30000;
this.expCheckIntervalDuration = this.experienceConfig?.checkIntervalDuration ?? 5000;
this.maxValidateRetry = Math.round(this.expThresholdTimer / this.expCheckIntervalDuration);
this.pendingVariantAndVariantGrpForExperience = [];
this.cTsSuccessPath = resolve(this.config.backupDir, 'mapper', 'content_types', 'success.json');
this.cTsSuccessPath = resolve(sanitizePath(this.config.backupDir), 'mapper', 'content_types', 'success.json');
this.createdCTs = [];
}

Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-variants/src/import/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join, resolve as pResolve } from 'path';
import { existsSync, readFileSync } from 'fs';

import { sanitizePath } from '@contentstack/cli-utilities';
import { PersonalizationAdapter, askProjectName, fsUtil } from '../utils';
import { APIConfig, CreateProjectInput, ImportConfig, LogType, ProjectStruct } from '../types';

Expand All @@ -14,9 +14,9 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
};
super(Object.assign(config, conf));
this.projectMapperFolderPath = pResolve(
this.config.backupDir,
sanitizePath(this.config.backupDir),
'mapper',
this.config.modules.personalization.dirName,
sanitizePath(this.config.modules.personalization.dirName),
'projects',
);
}
Expand All @@ -28,7 +28,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
async import() {
const personalization = this.config.modules.personalization;
const { dirName, fileName } = personalization.projects;
const projectPath = join(this.config.data, personalization.dirName, dirName, fileName);
const projectPath = join(sanitizePath(this.config.data), sanitizePath(personalization.dirName), sanitizePath(dirName), sanitizePath(fileName));

if (existsSync(projectPath)) {
const projects = JSON.parse(readFileSync(projectPath, 'utf8')) as CreateProjectInput[];
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
this.config.modules.personalization.importData = true;

await fsUtil.makeDirectory(this.projectMapperFolderPath);
fsUtil.writeFile(pResolve(this.projectMapperFolderPath, 'projects.json'), projectRes);
fsUtil.writeFile(pResolve(sanitizePath(this.projectMapperFolderPath), 'projects.json'), projectRes);
this.log(this.config, `Project Created Successfully: ${projectRes.uid}`, 'info');
}
} else {
Expand Down
Loading

0 comments on commit 9db63ce

Please sign in to comment.