@contentstack/cli-cm-import-setup 1.0.0-beta.1

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +6 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +7 -0
  7. package/lib/commands/cm/stacks/import-setup.d.ts +10 -0
  8. package/lib/commands/cm/stacks/import-setup.js +53 -0
  9. package/lib/config/index.d.ts +3 -0
  10. package/lib/config/index.js +77 -0
  11. package/lib/import/import-setup.d.ts +32 -0
  12. package/lib/import/import-setup.js +112 -0
  13. package/lib/import/index.d.ts +1 -0
  14. package/lib/import/index.js +8 -0
  15. package/lib/import/modules/assets.d.ts +27 -0
  16. package/lib/import/modules/assets.js +102 -0
  17. package/lib/import/modules/base-setup.d.ts +37 -0
  18. package/lib/import/modules/base-setup.js +183 -0
  19. package/lib/import/modules/content-types.d.ts +6 -0
  20. package/lib/import/modules/content-types.js +20 -0
  21. package/lib/import/modules/custom-roles.d.ts +0 -0
  22. package/lib/import/modules/custom-roles.js +0 -0
  23. package/lib/import/modules/entries.d.ts +6 -0
  24. package/lib/import/modules/entries.js +20 -0
  25. package/lib/import/modules/extensions.d.ts +20 -0
  26. package/lib/import/modules/extensions.js +61 -0
  27. package/lib/import/modules/global-fields.d.ts +0 -0
  28. package/lib/import/modules/global-fields.js +0 -0
  29. package/lib/import/modules/index.d.ts +0 -0
  30. package/lib/import/modules/index.js +0 -0
  31. package/lib/import/modules/marketplace-apps.d.ts +26 -0
  32. package/lib/import/modules/marketplace-apps.js +81 -0
  33. package/lib/import/modules/taxonomies.d.ts +53 -0
  34. package/lib/import/modules/taxonomies.js +141 -0
  35. package/lib/types/default-config.d.ts +55 -0
  36. package/lib/types/default-config.js +2 -0
  37. package/lib/types/import-config.d.ts +55 -0
  38. package/lib/types/import-config.js +2 -0
  39. package/lib/types/index.d.ts +115 -0
  40. package/lib/types/index.js +2 -0
  41. package/lib/utils/backup-handler.d.ts +2 -0
  42. package/lib/utils/backup-handler.js +61 -0
  43. package/lib/utils/common-helper.d.ts +0 -0
  44. package/lib/utils/common-helper.js +0 -0
  45. package/lib/utils/file-helper.d.ts +15 -0
  46. package/lib/utils/file-helper.js +144 -0
  47. package/lib/utils/import-config-handler.d.ts +3 -0
  48. package/lib/utils/import-config-handler.js +91 -0
  49. package/lib/utils/index.d.ts +7 -0
  50. package/lib/utils/index.js +16 -0
  51. package/lib/utils/interactive.d.ts +3 -0
  52. package/lib/utils/interactive.js +38 -0
  53. package/lib/utils/log.d.ts +12 -0
  54. package/lib/utils/log.js +31 -0
  55. package/lib/utils/logger.d.ts +8 -0
  56. package/lib/utils/logger.js +157 -0
  57. package/lib/utils/login-handler.d.ts +8 -0
  58. package/lib/utils/login-handler.js +53 -0
  59. package/messages/index.json +1 -0
  60. package/oclif.manifest.json +56 -0
  61. package/package.json +96 -0
@@ -0,0 +1,55 @@
1
+ import { Modules } from '.';
2
+ export default interface DefaultConfig {
3
+ host: string;
4
+ developerHubBaseUrl: string;
5
+ modules: {
6
+ 'custom-roles': {
7
+ dirName: string;
8
+ fileName: string;
9
+ dependencies: Modules[];
10
+ };
11
+ environments: {
12
+ dirName: string;
13
+ fileName: string;
14
+ dependencies?: Modules[];
15
+ };
16
+ extensions: {
17
+ dirName: string;
18
+ fileName: string;
19
+ dependencies?: Modules[];
20
+ };
21
+ assets: {
22
+ dirName: string;
23
+ fileName: string;
24
+ dependencies?: Modules[];
25
+ fetchConcurrency: number;
26
+ };
27
+ 'content-types': {
28
+ dirName: string;
29
+ fileName: string;
30
+ dependencies: Modules[];
31
+ };
32
+ entries: {
33
+ dirName: string;
34
+ fileName: string;
35
+ dependencies: Modules[];
36
+ };
37
+ 'global-fields': {
38
+ dirName: string;
39
+ fileName: string;
40
+ dependencies: Modules[];
41
+ };
42
+ 'marketplace-apps': {
43
+ dirName: string;
44
+ fileName: string;
45
+ dependencies?: Modules[];
46
+ };
47
+ taxonomies: {
48
+ dirName: string;
49
+ fileName: string;
50
+ dependencies?: Modules[];
51
+ invalidKeys: string[];
52
+ };
53
+ };
54
+ fetchConcurrency: number;
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,55 @@
1
+ import { Modules } from '.';
2
+ import DefaultConfig from './default-config';
3
+ export interface ExternalConfig {
4
+ source_stack?: string;
5
+ data: string;
6
+ fetchConcurrency: number;
7
+ writeConcurrency: number;
8
+ email?: string;
9
+ password?: string;
10
+ }
11
+ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
12
+ cliLogsPath?: string;
13
+ contentDir: string;
14
+ data: string;
15
+ management_token?: string;
16
+ apiKey: string;
17
+ forceStopMarketplaceAppsPrompt: boolean;
18
+ auth_token?: string;
19
+ contentTypes?: string[];
20
+ branches?: branch[];
21
+ branchEnabled?: boolean;
22
+ branchDir?: string;
23
+ moduleName?: Modules;
24
+ master_locale: masterLocale;
25
+ headers?: {
26
+ api_key: string;
27
+ access_token?: string;
28
+ authtoken?: string;
29
+ 'X-User-Agent': string;
30
+ };
31
+ access_token?: string;
32
+ isAuthenticated?: boolean;
33
+ target_stack?: string;
34
+ masterLocale: masterLocale;
35
+ backupConcurrency?: number;
36
+ authtoken?: string;
37
+ destinationStackName?: string;
38
+ org_uid?: string;
39
+ contentVersion: number;
40
+ stackName?: string;
41
+ branchName: string;
42
+ selectedModules: Modules[];
43
+ useBackedupDir?: string;
44
+ backupDir: string;
45
+ createBackupDir?: string;
46
+ region: any;
47
+ }
48
+ type branch = {
49
+ uid: string;
50
+ source: string;
51
+ };
52
+ type masterLocale = {
53
+ code: string;
54
+ };
55
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,115 @@
1
+ import { ContentstackClient } from '@contentstack/cli-utilities';
2
+ import ImportConfig from './import-config';
3
+ export type ModuleClassParams = {
4
+ stackAPIClient: ReturnType<ContentstackClient['stack']>;
5
+ config: ImportConfig;
6
+ dependencies: Modules;
7
+ };
8
+ export interface AuthOptions {
9
+ contentstackClient: ContentstackClient;
10
+ }
11
+ export interface ContentStackManagementClient {
12
+ contentstackClient: object;
13
+ }
14
+ export interface PrintOptions {
15
+ color?: string;
16
+ }
17
+ export type AdditionalKeys = {
18
+ backupDir: string;
19
+ };
20
+ export type ApiModuleType = 'fetch-assets';
21
+ export type ApiOptions = {
22
+ uid?: string;
23
+ url?: string;
24
+ entity: ApiModuleType;
25
+ apiData?: Record<any, any> | any;
26
+ resolve: (value: any) => Promise<void> | void;
27
+ reject: (error: any) => Promise<void> | void;
28
+ additionalInfo?: Record<any, any>;
29
+ includeParamOnCompletion?: boolean;
30
+ serializeData?: (input: ApiOptions) => any;
31
+ };
32
+ export type EnvType = {
33
+ processName: string;
34
+ totalCount?: number;
35
+ indexerCount?: number;
36
+ currentIndexer?: number;
37
+ apiParams?: ApiOptions;
38
+ concurrencyLimit?: number;
39
+ apiContent: Record<string, any>[];
40
+ };
41
+ export type CustomPromiseHandlerInput = {
42
+ index: number;
43
+ batchIndex: number;
44
+ element?: Record<string, unknown>;
45
+ apiParams?: ApiOptions;
46
+ isLastRequest: boolean;
47
+ };
48
+ export type CustomPromiseHandler = (input: CustomPromiseHandlerInput) => Promise<any>;
49
+ export interface InquirePayload {
50
+ type: string;
51
+ name: string;
52
+ message: string;
53
+ choices?: Array<any>;
54
+ transformer?: Function;
55
+ }
56
+ export interface User {
57
+ email: string;
58
+ authtoken: string;
59
+ }
60
+ export type Modules = 'stack' | 'assets' | 'locales' | 'environments' | 'extensions' | 'webhooks' | 'global-fields' | 'entries' | 'content-types' | 'custom-roles' | 'workflows' | 'labels' | 'marketplace-apps' | 'taxonomies';
61
+ export interface ExtensionsRecord {
62
+ title: string;
63
+ uid: string;
64
+ }
65
+ export interface MarketplaceAppsConfig {
66
+ dirName: string;
67
+ fileName: string;
68
+ dependencies?: Modules[];
69
+ }
70
+ export interface EnvironmentConfig {
71
+ dirName: string;
72
+ fileName: string;
73
+ dependencies?: Modules[];
74
+ }
75
+ export interface LabelConfig {
76
+ dirName: string;
77
+ fileName: string;
78
+ }
79
+ export interface WebhookConfig {
80
+ dirName: string;
81
+ fileName: string;
82
+ }
83
+ export interface WorkflowConfig {
84
+ dirName: string;
85
+ fileName: string;
86
+ invalidKeys: string[];
87
+ }
88
+ export interface CustomRoleConfig {
89
+ dirName: string;
90
+ fileName: string;
91
+ customRolesLocalesFileName: string;
92
+ }
93
+ export type AssetRecord = {
94
+ uid: string;
95
+ url: string;
96
+ title: string;
97
+ };
98
+ export interface TaxonomiesConfig {
99
+ dirName: string;
100
+ fileName: string;
101
+ dependencies?: Modules[];
102
+ }
103
+ export { default as DefaultConfig } from './default-config';
104
+ export { default as ImportConfig } from './import-config';
105
+ export type ExtensionType = {
106
+ uid: string;
107
+ scope: Record<string, unknown>;
108
+ title: string;
109
+ };
110
+ export type TaxonomyQueryParams = {
111
+ include_count: boolean;
112
+ limit: number;
113
+ skip: number;
114
+ depth?: number;
115
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { ImportConfig } from '../types';
2
+ export default function backupHandler(importConfig: ImportConfig): Promise<string>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = tslib_1.__importStar(require("path"));
5
+ const fs_extra_1 = require("fs-extra");
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const index_1 = require("./index");
8
+ async function backupHandler(importConfig) {
9
+ if (importConfig.hasOwnProperty('useBackedupDir')) {
10
+ return importConfig.useBackedupDir;
11
+ }
12
+ let backupDirPath;
13
+ const subDir = isSubDirectory(importConfig);
14
+ if (subDir) {
15
+ backupDirPath = path.resolve((0, cli_utilities_1.sanitizePath)(importConfig.contentDir), '..', '_backup_' + Math.floor(Math.random() * 1000));
16
+ if (importConfig.createBackupDir) {
17
+ cli_utilities_1.cliux.print(`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, {
18
+ color: 'yellow',
19
+ });
20
+ }
21
+ }
22
+ else {
23
+ // NOTE: If the backup folder's directory is provided, create it at that location; otherwise, the default path (working directory).
24
+ backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
25
+ if (importConfig.createBackupDir) {
26
+ if (index_1.fileHelper.fileExistsSync(importConfig.createBackupDir)) {
27
+ index_1.fileHelper.removeDirSync(importConfig.createBackupDir);
28
+ }
29
+ index_1.fileHelper.makeDirectory(importConfig.createBackupDir);
30
+ backupDirPath = importConfig.createBackupDir;
31
+ }
32
+ }
33
+ if (backupDirPath) {
34
+ cli_utilities_1.cliux.print('Copying content to the backup directory...');
35
+ return new Promise((resolve, reject) => {
36
+ return (0, fs_extra_1.copy)(importConfig.contentDir, backupDirPath, (error) => {
37
+ if (error) {
38
+ (0, index_1.trace)(error, 'error', true);
39
+ return reject(error);
40
+ }
41
+ resolve(backupDirPath);
42
+ });
43
+ });
44
+ }
45
+ }
46
+ exports.default = backupHandler;
47
+ /**
48
+ * Check whether provided backup directory path is sub directory or not
49
+ * @param importConfig
50
+ * @returns
51
+ */
52
+ function isSubDirectory(importConfig) {
53
+ const parent = importConfig.contentDir;
54
+ const child = importConfig.createBackupDir ? importConfig.createBackupDir : process.cwd();
55
+ const relative = path.relative(parent, child);
56
+ if (relative) {
57
+ return !relative.startsWith('..') && !path.isAbsolute(relative);
58
+ }
59
+ // true if both parent and child have same path
60
+ return true;
61
+ }
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ import { FsUtility } from '@contentstack/cli-utilities';
2
+ export declare const readFileSync: (filePath: string, parse?: boolean) => any;
3
+ export declare const readFile: (filePath: string, options?: {
4
+ type: string;
5
+ }) => Promise<any>;
6
+ export declare const readLargeFile: (filePath: string, opts?: any) => Promise<any>;
7
+ export declare const writeFileSync: (filePath: string, data: any) => void;
8
+ export declare const writeFile: (filePath: string, data: any) => Promise<any>;
9
+ export declare const writeLargeFile: (filePath: string, data: any) => Promise<any>;
10
+ export declare const makeDirectory: (dir: string) => void;
11
+ export declare const readdirSync: (dirPath: string) => any;
12
+ export declare const isFolderExist: (folderPath: string) => Promise<any>;
13
+ export declare const fileExistsSync: (path: string) => boolean;
14
+ export declare const removeDirSync: (path: string) => void;
15
+ export declare const fsUtil: FsUtility;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fsUtil = exports.removeDirSync = exports.fileExistsSync = exports.isFolderExist = exports.readdirSync = exports.makeDirectory = exports.writeLargeFile = exports.writeFile = exports.writeFileSync = exports.readLargeFile = exports.readFile = exports.readFileSync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
8
+ const bigJSON = tslib_1.__importStar(require("big-json"));
9
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
10
+ const readFileSync = function (filePath, parse = true) {
11
+ let data;
12
+ filePath = path.resolve((0, cli_utilities_1.sanitizePath)(filePath));
13
+ if (fs.existsSync(filePath)) {
14
+ try {
15
+ data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : data;
16
+ }
17
+ catch (error) {
18
+ return data;
19
+ }
20
+ }
21
+ return data;
22
+ };
23
+ exports.readFileSync = readFileSync;
24
+ // by default file type is json
25
+ const readFile = async (filePath, options = { type: 'json' }) => {
26
+ return new Promise((resolve, reject) => {
27
+ filePath = path.resolve((0, cli_utilities_1.sanitizePath)(filePath));
28
+ fs.readFile(filePath, 'utf-8', (error, data) => {
29
+ if (error) {
30
+ if (error.code === 'ENOENT') {
31
+ return resolve('');
32
+ }
33
+ reject(error);
34
+ }
35
+ else {
36
+ if (options.type !== 'json') {
37
+ return resolve(data);
38
+ }
39
+ resolve(JSON.parse(data));
40
+ }
41
+ });
42
+ });
43
+ };
44
+ exports.readFile = readFile;
45
+ const readLargeFile = function (filePath, opts) {
46
+ if (typeof filePath !== 'string') {
47
+ return;
48
+ }
49
+ filePath = path.resolve((0, cli_utilities_1.sanitizePath)(filePath));
50
+ if (fs.existsSync(filePath)) {
51
+ return new Promise((resolve, reject) => {
52
+ const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
53
+ const parseStream = bigJSON.createParseStream();
54
+ parseStream.on('data', function (data) {
55
+ if ((opts === null || opts === void 0 ? void 0 : opts.type) === 'array') {
56
+ return resolve(Object.values(data));
57
+ }
58
+ resolve(data);
59
+ });
60
+ parseStream.on('error', function (error) {
61
+ console.log('error', error);
62
+ reject(error);
63
+ });
64
+ readStream.pipe(parseStream);
65
+ });
66
+ }
67
+ };
68
+ exports.readLargeFile = readLargeFile;
69
+ const writeFileSync = function (filePath, data) {
70
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
71
+ fs.writeFileSync(filePath, data);
72
+ };
73
+ exports.writeFileSync = writeFileSync;
74
+ const writeFile = function (filePath, data) {
75
+ return new Promise((resolve, reject) => {
76
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
77
+ fs.writeFile(filePath, data, (error) => {
78
+ if (error) {
79
+ return reject(error);
80
+ }
81
+ resolve('done');
82
+ });
83
+ });
84
+ };
85
+ exports.writeFile = writeFile;
86
+ const writeLargeFile = function (filePath, data) {
87
+ if (typeof filePath !== 'string' || typeof data !== 'object') {
88
+ return;
89
+ }
90
+ filePath = path.resolve((0, cli_utilities_1.sanitizePath)(filePath));
91
+ return new Promise((resolve, reject) => {
92
+ const stringifyStream = bigJSON.createStringifyStream({
93
+ body: data,
94
+ });
95
+ var writeStream = fs.createWriteStream(filePath, 'utf-8');
96
+ stringifyStream.pipe(writeStream);
97
+ writeStream.on('finish', () => {
98
+ resolve('');
99
+ });
100
+ writeStream.on('error', (error) => {
101
+ reject(error);
102
+ });
103
+ });
104
+ };
105
+ exports.writeLargeFile = writeLargeFile;
106
+ const makeDirectory = function (dir) {
107
+ for (let key in arguments) {
108
+ const dirname = path.resolve(arguments[key]);
109
+ if (!fs.existsSync(dirname)) {
110
+ mkdirp_1.default.sync(dirname);
111
+ }
112
+ }
113
+ };
114
+ exports.makeDirectory = makeDirectory;
115
+ const readdirSync = function (dirPath) {
116
+ if (fs.existsSync(dirPath)) {
117
+ return fs.readdirSync(dirPath);
118
+ }
119
+ else {
120
+ return [];
121
+ }
122
+ };
123
+ exports.readdirSync = readdirSync;
124
+ const isFolderExist = async (folderPath) => {
125
+ return new Promise((resolve, reject) => {
126
+ folderPath = path.resolve((0, cli_utilities_1.sanitizePath)(folderPath));
127
+ fs.access(folderPath, (error) => {
128
+ if (error) {
129
+ return resolve(false);
130
+ }
131
+ resolve(true);
132
+ });
133
+ });
134
+ };
135
+ exports.isFolderExist = isFolderExist;
136
+ const fileExistsSync = function (path) {
137
+ return fs.existsSync(path);
138
+ };
139
+ exports.fileExistsSync = fileExistsSync;
140
+ const removeDirSync = function (path) {
141
+ fs.rmdirSync(path, { recursive: true });
142
+ };
143
+ exports.removeDirSync = removeDirSync;
144
+ exports.fsUtil = new cli_utilities_1.FsUtility();
@@ -0,0 +1,3 @@
1
+ import { ImportConfig } from '../types';
2
+ declare const setupConfig: (importCmdFlags: any) => Promise<ImportConfig>;
3
+ export default setupConfig;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const merge_1 = tslib_1.__importDefault(require("merge"));
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const config_1 = tslib_1.__importDefault(require("../config"));
8
+ const file_helper_1 = require("./file-helper");
9
+ const interactive_1 = require("./interactive");
10
+ const login_handler_1 = tslib_1.__importDefault(require("./login-handler"));
11
+ const setupConfig = async (importCmdFlags) => {
12
+ var _a;
13
+ let config = (0, merge_1.default)({}, config_1.default);
14
+ // setup the config
15
+ // if (importCmdFlags['config']) {
16
+ // let externalConfig = await readFile(importCmdFlags['config']);
17
+ // if (isArray(externalConfig['modules'])) {
18
+ // config.modules = filter(config.modules, (module) => includes(externalConfig['modules'], module));
19
+ // externalConfig = omit(externalConfig, ['modules']);
20
+ // }
21
+ // config = merge.recursive(config, externalConfig);
22
+ // }
23
+ config.contentDir = importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)());
24
+ const pattern = /[*$%#<>{}!&?]/g;
25
+ if (pattern.test(config.contentDir)) {
26
+ cli_utilities_1.cliux.print(`\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, {
27
+ color: 'yellow',
28
+ });
29
+ config.contentDir = await (0, interactive_1.askContentDir)();
30
+ }
31
+ config.contentDir = config.contentDir.replace(/['"]/g, '');
32
+ config.contentDir = path.resolve(config.contentDir);
33
+ //Note to support the old key
34
+ config.data = config.contentDir;
35
+ if ((0, file_helper_1.fileExistsSync)(path.join(config.contentDir, 'export-info.json'))) {
36
+ config.contentVersion =
37
+ ((await (0, file_helper_1.readFile)(path.join(config.contentDir, 'export-info.json'))) || {}).contentVersion || 2;
38
+ }
39
+ else {
40
+ config.contentVersion = 1;
41
+ }
42
+ const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];
43
+ if (managementTokenAlias) {
44
+ const { token, apiKey } = (_a = cli_utilities_1.configHandler.get(`tokens.${managementTokenAlias}`)) !== null && _a !== void 0 ? _a : {};
45
+ config.management_token = token;
46
+ config.apiKey = apiKey;
47
+ if (!config.management_token) {
48
+ throw new Error(`No management token found on given alias ${managementTokenAlias}`);
49
+ }
50
+ }
51
+ if (!config.management_token) {
52
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
53
+ if (config.email && config.password) {
54
+ await (0, login_handler_1.default)(config);
55
+ }
56
+ else {
57
+ throw new Error('Please login or provide an alias for the management token');
58
+ }
59
+ }
60
+ else {
61
+ config.apiKey =
62
+ importCmdFlags['stack-uid'] || importCmdFlags['stack-api-key'] || config.target_stack || (await (0, interactive_1.askAPIKey)());
63
+ if (typeof config.apiKey !== 'string') {
64
+ throw new Error('Invalid API key received');
65
+ }
66
+ }
67
+ }
68
+ config.isAuthenticated = (0, cli_utilities_1.isAuthenticated)();
69
+ //Note to support the old key
70
+ config.source_stack = config.apiKey;
71
+ // config.skipAudit = importCmdFlags['skip-audit'];
72
+ // config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes;
73
+ // config.importWebhookStatus = importCmdFlags['import-webhook-status'];
74
+ // config.skipPrivateAppRecreationIfExist = importCmdFlags['skip-app-recreation'];
75
+ if (importCmdFlags['branch']) {
76
+ config.branchName = importCmdFlags['branch'];
77
+ config.branchDir = path.join((0, cli_utilities_1.sanitizePath)(config.contentDir), (0, cli_utilities_1.sanitizePath)(config.branchName));
78
+ }
79
+ const selectedModule = importCmdFlags['modules'] || (await (0, interactive_1.askSelectedModules)());
80
+ if (selectedModule === 'both') {
81
+ config.selectedModules = ['content-types', 'entries'];
82
+ }
83
+ else {
84
+ config.selectedModules = [selectedModule];
85
+ }
86
+ if (importCmdFlags['backup-dir']) {
87
+ config.useBackedupDir = importCmdFlags['backup-dir'];
88
+ }
89
+ return config;
90
+ };
91
+ exports.default = setupConfig;
@@ -0,0 +1,7 @@
1
+ export * as interactive from './interactive';
2
+ export { default as setupImportConfig } from './import-config-handler';
3
+ export * as fileHelper from './file-helper';
4
+ export { fsUtil } from './file-helper';
5
+ export { default as backupHandler } from './backup-handler';
6
+ export { log, unlinkFileLogger } from './logger';
7
+ export * from './log';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.interactive = tslib_1.__importStar(require("./interactive"));
6
+ var import_config_handler_1 = require("./import-config-handler");
7
+ Object.defineProperty(exports, "setupImportConfig", { enumerable: true, get: function () { return tslib_1.__importDefault(import_config_handler_1).default; } });
8
+ exports.fileHelper = tslib_1.__importStar(require("./file-helper"));
9
+ var file_helper_1 = require("./file-helper");
10
+ Object.defineProperty(exports, "fsUtil", { enumerable: true, get: function () { return file_helper_1.fsUtil; } });
11
+ var backup_handler_1 = require("./backup-handler");
12
+ Object.defineProperty(exports, "backupHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(backup_handler_1).default; } });
13
+ var logger_1 = require("./logger");
14
+ Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logger_1.log; } });
15
+ Object.defineProperty(exports, "unlinkFileLogger", { enumerable: true, get: function () { return logger_1.unlinkFileLogger; } });
16
+ tslib_1.__exportStar(require("./log"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const askContentDir: () => Promise<string>;
2
+ export declare const askSelectedModules: () => Promise<string>;
3
+ export declare const askAPIKey: () => Promise<string>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askAPIKey = exports.askSelectedModules = exports.askContentDir = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const askContentDir = async () => {
8
+ let result = await cli_utilities_1.cliux.inquire({
9
+ type: 'input',
10
+ message: 'Enter the path for the content',
11
+ name: 'dir',
12
+ validate: cli_utilities_1.validatePath,
13
+ });
14
+ result = result.replace(/["']/g, '');
15
+ return path.resolve(result);
16
+ };
17
+ exports.askContentDir = askContentDir;
18
+ const askSelectedModules = async () => {
19
+ return cli_utilities_1.cliux.inquire({
20
+ type: 'list',
21
+ name: 'selectedModule',
22
+ message: 'Please select a module to generate the mapper files',
23
+ choices: [
24
+ { name: 'Content types', value: 'content-types' },
25
+ { name: 'Entries', value: 'entries' },
26
+ { name: 'Both', value: 'both' },
27
+ ],
28
+ });
29
+ };
30
+ exports.askSelectedModules = askSelectedModules;
31
+ const askAPIKey = async () => {
32
+ return cli_utilities_1.cliux.inquire({
33
+ type: 'input',
34
+ message: 'Enter the stack api key',
35
+ name: 'apiKey',
36
+ });
37
+ };
38
+ exports.askAPIKey = askAPIKey;
@@ -0,0 +1,12 @@
1
+ import { LogEntry } from 'winston/index';
2
+ import { Logger } from '@contentstack/cli-utilities';
3
+ import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger';
4
+ import { ImportConfig } from '../types';
5
+ declare let logger: Logger;
6
+ export declare function isImportConfig(config: ImportConfig | MessageType): config is ImportConfig;
7
+ export declare function log(entry: LogEntry): void;
8
+ export declare function log(error: MessageType, logType: LogsType): void;
9
+ export declare function log(error: MessageType, logType: 'error', hidden: boolean): void;
10
+ export declare function initLogger(config?: ImportConfig | undefined): Logger;
11
+ export { logger };
12
+ export declare const trace: typeof log;