Skip to content

Commit

Permalink
Merge pull request #15 from contentstack/feat/CS-44635
Browse files Browse the repository at this point in the history
Feat: Implementation of Variant Entry Import [CS-44635[
  • Loading branch information
antonyagustine authored Apr 10, 2024
2 parents af47c3b + 8eed1e8 commit 9c66e57
Show file tree
Hide file tree
Showing 15 changed files with 361 additions and 64 deletions.
90 changes: 45 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion packages/contentstack-import/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const config: DefaultConfig = {
personalization: {
importData: true,
dirName: 'personalization',
importOrder: ['projects','attributes', 'audiences'],
importOrder: ['projects', 'attributes', 'audiences'],
projects: {
dirName: 'projects',
fileName: 'projects.json',
Expand All @@ -168,6 +168,14 @@ const config: DefaultConfig = {
fileName: 'audiences.json',
},
},
variantEntry: {
dirName: 'variants',
fileName: 'index.json',
apiConcurrency: 5,
query: {
locale: 'en-us',
},
},
},
languagesCode: [
'af-za',
Expand Down
8 changes: 8 additions & 0 deletions packages/contentstack-import/src/types/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ export default interface DefaultConfig {
fileName: string;
};
};
variantEntry: {
dirName: string;
fileName: string;
apiConcurrency: number;
query: {
locale: string;
} & AnyProperty;
} & AnyProperty;
};
languagesCode: string[];
apis: {
Expand Down
12 changes: 6 additions & 6 deletions packages/contentstack-utilities/src/fs-utility/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class FsUtility {
const indexPath = `${this.basePath}/${this.indexFileName}`;

if (existsSync(indexPath)) {
indexData = JSON.parse(readFileSync(indexPath, 'utf-8'));
indexData = JSON.parse(readFileSync(indexPath, 'utf8'));
}

return indexData;
Expand Down Expand Up @@ -139,7 +139,7 @@ export default class FsUtility {
parse = typeof parse === 'undefined' ? true : parse;

if (existsSync(filePath)) {
data = parse ? JSON.parse(readFileSync(filePath, 'utf-8')) : data;
data = parse ? JSON.parse(readFileSync(filePath, 'utf8')) : data;
}

return data;
Expand Down Expand Up @@ -329,7 +329,7 @@ export default class FsUtility {
const path = basePath || pResolve(this.basePath, 'metadata.json');
if (!existsSync(path)) return {};

return JSON.parse(readFileSync(path, { encoding: 'utf-8' }));
return JSON.parse(readFileSync(path, { encoding: 'utf8' }));
}

/**
Expand All @@ -353,7 +353,7 @@ export default class FsUtility {
}

const fileContent = readFileSync(pResolve(this.basePath, this.readIndexer[index]), {
encoding: 'utf-8',
encoding: 'utf8',
});

resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
Expand All @@ -374,7 +374,7 @@ export default class FsUtility {
}

const fileContent = readFileSync(pResolve(this.basePath, this.readIndexer[this.pageInfo.after]), {
encoding: 'utf-8',
encoding: 'utf8',
});

resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
Expand All @@ -396,7 +396,7 @@ export default class FsUtility {
}

const fileContent = readFileSync(pResolve(this.basePath, this.readIndexer[this.pageInfo.before]), {
encoding: 'utf-8',
encoding: 'utf8',
});

resolve(this.fileExt === 'json' ? JSON.parse(fileContent) : fileContent);
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-variants/src/import/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Project from './project';
import Attribute from './attribute';
import Audiences from './audiences';
import VariantEntries from './variant-entries';

// NOTE Acting as namespace to avoid the same class name conflicts in other modules
export const Import = {
Project,
Attribute,
Audiences
Audiences,
VariantEntries,
};
2 changes: 1 addition & 1 deletion packages/contentstack-variants/src/import/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { existsSync, readFileSync } from 'fs';

import { PersonalizationAdapter } from '../utils';
import { APIConfig, AnyProperty, CreateProjectInput, ImportConfig, LogType } from '../types';
import { APIConfig, CreateProjectInput, ImportConfig, LogType } from '../types';

export default class Project extends PersonalizationAdapter<ImportConfig> {
constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) {
Expand Down
Loading

0 comments on commit 9c66e57

Please sign in to comment.