@contentstack/cli-cm-export 1.5.9 → 1.7.0

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 (113) hide show
  1. package/README.md +2 -2
  2. package/lib/commands/cm/stacks/export.d.ts +10 -0
  3. package/lib/commands/cm/stacks/export.js +108 -0
  4. package/lib/config/index.d.ts +3 -0
  5. package/lib/config/index.js +403 -0
  6. package/lib/export/index.d.ts +1 -0
  7. package/lib/export/index.js +8 -0
  8. package/lib/export/module-exporter.d.ts +15 -0
  9. package/lib/export/module-exporter.js +93 -0
  10. package/lib/export/modules/assets.d.ts +54 -0
  11. package/lib/export/modules/assets.js +303 -0
  12. package/lib/export/modules/base-class.d.ts +48 -0
  13. package/lib/export/modules/base-class.js +117 -0
  14. package/lib/export/modules/content-types.d.ts +15 -0
  15. package/lib/export/modules/content-types.js +72 -0
  16. package/lib/export/modules/custom-roles.d.ts +16 -0
  17. package/lib/export/modules/custom-roles.js +81 -0
  18. package/lib/export/modules/environments.d.ts +12 -0
  19. package/lib/export/modules/environments.js +64 -0
  20. package/lib/export/modules/extensions.d.ts +12 -0
  21. package/lib/export/modules/extensions.js +64 -0
  22. package/lib/export/modules/global-fields.d.ts +14 -0
  23. package/lib/export/modules/global-fields.js +59 -0
  24. package/lib/export/modules/index.d.ts +3 -0
  25. package/lib/export/modules/index.js +38 -0
  26. package/lib/export/modules/labels.d.ts +12 -0
  27. package/lib/export/modules/labels.js +64 -0
  28. package/lib/export/modules/locales.d.ts +16 -0
  29. package/lib/export/modules/locales.js +68 -0
  30. package/lib/export/modules/marketplace-apps.d.ts +18 -0
  31. package/lib/export/modules/marketplace-apps.js +119 -0
  32. package/lib/export/modules/webhooks.d.ts +12 -0
  33. package/lib/export/modules/webhooks.js +63 -0
  34. package/lib/export/modules-js/assets.d.ts +43 -0
  35. package/lib/export/modules-js/assets.js +391 -0
  36. package/lib/export/modules-js/content-types.d.ts +21 -0
  37. package/lib/export/modules-js/content-types.js +75 -0
  38. package/lib/export/modules-js/custom-roles.d.ts +21 -0
  39. package/lib/export/modules-js/custom-roles.js +76 -0
  40. package/lib/export/modules-js/entries.d.ts +18 -0
  41. package/lib/export/modules-js/entries.js +141 -0
  42. package/lib/export/modules-js/environments.d.ts +16 -0
  43. package/lib/export/modules-js/environments.js +62 -0
  44. package/lib/export/modules-js/extensions.d.ts +18 -0
  45. package/lib/export/modules-js/extensions.js +57 -0
  46. package/lib/export/modules-js/global-fields.d.ts +22 -0
  47. package/lib/export/modules-js/global-fields.js +107 -0
  48. package/lib/export/modules-js/index.d.ts +2 -0
  49. package/lib/export/modules-js/index.js +31 -0
  50. package/lib/export/modules-js/labels.d.ts +14 -0
  51. package/lib/export/modules-js/labels.js +56 -0
  52. package/lib/export/modules-js/locales.d.ts +23 -0
  53. package/lib/export/modules-js/locales.js +67 -0
  54. package/lib/export/modules-js/marketplace-apps.d.ts +20 -0
  55. package/lib/export/modules-js/marketplace-apps.js +125 -0
  56. package/lib/export/modules-js/stack.d.ts +18 -0
  57. package/lib/export/modules-js/stack.js +91 -0
  58. package/lib/export/modules-js/webhooks.d.ts +18 -0
  59. package/lib/export/modules-js/webhooks.js +60 -0
  60. package/lib/export/modules-js/workflows.d.ts +16 -0
  61. package/lib/export/modules-js/workflows.js +89 -0
  62. package/lib/types/default-config.d.ts +158 -0
  63. package/lib/types/default-config.js +2 -0
  64. package/lib/types/export-config.d.ts +36 -0
  65. package/lib/types/export-config.js +2 -0
  66. package/lib/types/index.d.ts +88 -0
  67. package/lib/types/index.js +2 -0
  68. package/lib/utils/basic-login.d.ts +8 -0
  69. package/lib/utils/basic-login.js +45 -0
  70. package/lib/utils/common-helper.d.ts +11 -0
  71. package/lib/utils/common-helper.js +78 -0
  72. package/lib/utils/export-config-handler.d.ts +3 -0
  73. package/lib/utils/export-config-handler.js +72 -0
  74. package/lib/utils/file-helper.d.ts +14 -0
  75. package/lib/utils/file-helper.js +120 -0
  76. package/lib/utils/index.d.ts +10 -0
  77. package/lib/utils/index.js +21 -0
  78. package/lib/utils/interactive.d.ts +7 -0
  79. package/lib/utils/interactive.js +84 -0
  80. package/lib/utils/logger.d.ts +8 -0
  81. package/lib/utils/logger.js +154 -0
  82. package/lib/utils/marketplace-app-helper.d.ts +11 -0
  83. package/lib/utils/marketplace-app-helper.js +55 -0
  84. package/lib/utils/setup-branches.d.ts +3 -0
  85. package/lib/utils/setup-branches.js +49 -0
  86. package/lib/utils/setup-export-dir.d.ts +2 -0
  87. package/lib/utils/setup-export-dir.js +12 -0
  88. package/messages/index.json +1 -7
  89. package/oclif.manifest.json +1 -1
  90. package/package.json +38 -23
  91. package/src/app.js +0 -156
  92. package/src/commands/cm/stacks/export.js +0 -202
  93. package/src/config/default.js +0 -360
  94. package/src/lib/export/assets.js +0 -454
  95. package/src/lib/export/content-types.js +0 -90
  96. package/src/lib/export/custom-roles.js +0 -92
  97. package/src/lib/export/entries.js +0 -200
  98. package/src/lib/export/environments.js +0 -74
  99. package/src/lib/export/extensions.js +0 -69
  100. package/src/lib/export/global-fields.js +0 -122
  101. package/src/lib/export/labels.js +0 -67
  102. package/src/lib/export/locales.js +0 -72
  103. package/src/lib/export/marketplace-apps.js +0 -187
  104. package/src/lib/export/stack.js +0 -98
  105. package/src/lib/export/webhooks.js +0 -76
  106. package/src/lib/export/workflows.js +0 -106
  107. package/src/lib/util/export-flags.js +0 -193
  108. package/src/lib/util/helper.js +0 -113
  109. package/src/lib/util/index.js +0 -80
  110. package/src/lib/util/log.js +0 -161
  111. package/src/lib/util/login.js +0 -79
  112. package/src/lib/util/marketplace-app-helper.js +0 -24
  113. package/src/lib/util/setup-branches.js +0 -56
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /*!
3
+ * Contentstack Export
4
+ * Copyright (c) 2019 Contentstack LLC
5
+ * MIT Licensed
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.unlinkFileLogger = exports.log = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const winston = tslib_1.__importStar(require("winston"));
11
+ const path = tslib_1.__importStar(require("path"));
12
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
13
+ const slice = Array.prototype.slice;
14
+ const ansiRegexPattern = [
15
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
16
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
17
+ ].join('|');
18
+ function returnString(args) {
19
+ let returnStr = '';
20
+ if (args && args.length) {
21
+ returnStr = args
22
+ .map(function (item) {
23
+ if (item && typeof item === 'object') {
24
+ try {
25
+ return JSON.stringify(item).replace(/authtoken\":\d"blt................/g, 'authtoken":"blt....');
26
+ }
27
+ catch (error) { }
28
+ return item;
29
+ }
30
+ return item;
31
+ })
32
+ .join(' ')
33
+ .trim();
34
+ }
35
+ returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), '').trim();
36
+ return returnStr;
37
+ }
38
+ const myCustomLevels = {
39
+ levels: {
40
+ warn: 1,
41
+ info: 2,
42
+ debug: 3,
43
+ },
44
+ colors: {
45
+ //colors aren't being used anywhere as of now, we're using chalk to add colors while logging
46
+ info: 'blue',
47
+ debug: 'green',
48
+ warn: 'yellow',
49
+ error: 'red',
50
+ },
51
+ };
52
+ let logger;
53
+ let errorLogger;
54
+ let successTransport;
55
+ let errorTransport;
56
+ function init(_logPath) {
57
+ if (!logger || !errorLogger) {
58
+ const logsDir = path.resolve(_logPath, 'logs', 'export');
59
+ // Create dir if doesn't already exist
60
+ mkdirp_1.default.sync(logsDir);
61
+ successTransport = {
62
+ filename: path.join(logsDir, 'success.log'),
63
+ maxFiles: 20,
64
+ maxsize: 1000000,
65
+ tailable: true,
66
+ level: 'info',
67
+ };
68
+ errorTransport = {
69
+ filename: path.join(logsDir, 'error.log'),
70
+ maxFiles: 20,
71
+ maxsize: 1000000,
72
+ tailable: true,
73
+ level: 'error',
74
+ };
75
+ logger = winston.createLogger({
76
+ transports: [
77
+ new winston.transports.File(successTransport),
78
+ new winston.transports.Console({ format: winston.format.simple() }),
79
+ ],
80
+ levels: myCustomLevels.levels,
81
+ });
82
+ errorLogger = winston.createLogger({
83
+ transports: [
84
+ new winston.transports.File(errorTransport),
85
+ new winston.transports.Console({
86
+ level: 'error',
87
+ format: winston.format.combine(winston.format.colorize({ all: true, colors: { error: 'red' } }), winston.format.simple()),
88
+ }),
89
+ ],
90
+ levels: { error: 0 },
91
+ });
92
+ }
93
+ return {
94
+ log: function (message) {
95
+ const args = slice.call(arguments);
96
+ const logString = returnString(args);
97
+ if (logString) {
98
+ logger.log('info', logString);
99
+ }
100
+ },
101
+ warn: function () {
102
+ const args = slice.call(arguments);
103
+ const logString = returnString(args);
104
+ if (logString) {
105
+ logger.log('warn', logString);
106
+ }
107
+ },
108
+ error: function (message) {
109
+ const args = slice.call(arguments);
110
+ const logString = returnString(args);
111
+ if (logString) {
112
+ errorLogger.log('error', logString);
113
+ }
114
+ },
115
+ debug: function () {
116
+ const args = slice.call(arguments);
117
+ const logString = returnString(args);
118
+ if (logString) {
119
+ logger.log('debug', logString);
120
+ }
121
+ },
122
+ };
123
+ }
124
+ const log = async (config, message, type) => {
125
+ config.data = config.data || path.join(__dirname, 'logs');
126
+ // ignoring the type argument, as we are not using it to create a logfile anymore
127
+ if (type !== 'error') {
128
+ // removed type argument from init method
129
+ init(config.data).log(message);
130
+ }
131
+ else {
132
+ init(config.data).error(message);
133
+ }
134
+ };
135
+ exports.log = log;
136
+ const unlinkFileLogger = () => {
137
+ if (logger) {
138
+ const transports = logger.transports;
139
+ transports.forEach((transport) => {
140
+ if (transport.name === 'file') {
141
+ logger.remove(transport);
142
+ }
143
+ });
144
+ }
145
+ if (errorLogger) {
146
+ const transports = errorLogger.transports;
147
+ transports.forEach((transport) => {
148
+ if (transport.name === 'file') {
149
+ errorLogger.remove(transport);
150
+ }
151
+ });
152
+ }
153
+ };
154
+ exports.unlinkFileLogger = unlinkFileLogger;
@@ -0,0 +1,11 @@
1
+ import { NodeCrypto, HttpClient } from '@contentstack/cli-utilities';
2
+ import { ExportConfig } from '../types';
3
+ export declare const getDeveloperHubUrl: (exportConfig: ExportConfig) => Promise<any>;
4
+ export declare function getOrgUid(config: ExportConfig): Promise<string>;
5
+ export declare function createNodeCryptoInstance(config: ExportConfig): Promise<NodeCrypto>;
6
+ export declare const getStackSpecificApps: (params: {
7
+ developerHubBaseUrl: string;
8
+ httpClient: HttpClient;
9
+ config: ExportConfig;
10
+ skip: number;
11
+ }) => Promise<any>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStackSpecificApps = exports.createNodeCryptoInstance = exports.getOrgUid = exports.getDeveloperHubUrl = void 0;
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const utils_1 = require("../utils");
6
+ const interactive_1 = require("./interactive");
7
+ const getDeveloperHubUrl = async (exportConfig) => {
8
+ const { cma, name } = cli_utilities_1.configHandler.get('region') || {};
9
+ let developerHubBaseUrl = exportConfig === null || exportConfig === void 0 ? void 0 : exportConfig.developerHubUrls[cma];
10
+ if (!developerHubBaseUrl) {
11
+ developerHubBaseUrl = await (0, interactive_1.askDeveloperHub)(name);
12
+ }
13
+ return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
14
+ };
15
+ exports.getDeveloperHubUrl = getDeveloperHubUrl;
16
+ async function getOrgUid(config) {
17
+ const tempAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: config.host });
18
+ const tempStackData = await tempAPIClient
19
+ .stack({ api_key: config.source_stack })
20
+ .fetch()
21
+ .catch((error) => {
22
+ (0, utils_1.log)(this.config, (0, utils_1.formatError)(error), 'error');
23
+ });
24
+ return tempStackData === null || tempStackData === void 0 ? void 0 : tempStackData.org_uid;
25
+ }
26
+ exports.getOrgUid = getOrgUid;
27
+ async function createNodeCryptoInstance(config) {
28
+ const cryptoArgs = { encryptionKey: '' };
29
+ if (config.forceStopMarketplaceAppsPrompt) {
30
+ cryptoArgs['encryptionKey'] = config.marketplaceAppEncryptionKey;
31
+ }
32
+ else {
33
+ cryptoArgs['encryptionKey'] = await cli_utilities_1.cliux.inquire({
34
+ type: 'input',
35
+ name: 'name',
36
+ default: config.marketplaceAppEncryptionKey,
37
+ validate: (url) => {
38
+ if (!url)
39
+ return "Encryption key can't be empty.";
40
+ return true;
41
+ },
42
+ message: 'Enter marketplace app configurations encryption key',
43
+ });
44
+ }
45
+ return new cli_utilities_1.NodeCrypto(cryptoArgs);
46
+ }
47
+ exports.createNodeCryptoInstance = createNodeCryptoInstance;
48
+ const getStackSpecificApps = async (params) => {
49
+ const { developerHubBaseUrl, httpClient, config, skip } = params;
50
+ return httpClient
51
+ .get(`${developerHubBaseUrl}/installations?target_uids=${config.source_stack}&skip=${skip}`)
52
+ .then((data) => data.data)
53
+ .catch((error) => (0, utils_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error'));
54
+ };
55
+ exports.getStackSpecificApps = getStackSpecificApps;
@@ -0,0 +1,3 @@
1
+ import { ExportConfig } from '../types';
2
+ declare const setupBranches: (config: ExportConfig, stackAPIClient: any) => Promise<void>;
3
+ export default setupBranches;
@@ -0,0 +1,49 @@
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 file_helper_1 = require("./file-helper");
6
+ const setupBranches = async (config, stackAPIClient) => {
7
+ if (typeof config !== 'object') {
8
+ throw new Error('Invalid config to setup the branch');
9
+ }
10
+ let branches = [];
11
+ if (config.branchName) {
12
+ // check branch exists
13
+ const result = await stackAPIClient
14
+ .branch(config.branchName)
15
+ .fetch()
16
+ .catch((_err) => { });
17
+ if (result && typeof result === 'object') {
18
+ branches.push(result);
19
+ }
20
+ else {
21
+ throw new Error('No branch found with the given name ' + config.branchName);
22
+ }
23
+ }
24
+ else {
25
+ try {
26
+ const result = await stackAPIClient
27
+ .branch()
28
+ .query()
29
+ .find()
30
+ .catch((_err) => { });
31
+ if (result && result.items && Array.isArray(result.items) && result.items.length > 0) {
32
+ branches = result.items;
33
+ }
34
+ else {
35
+ return;
36
+ }
37
+ }
38
+ catch (error) {
39
+ // Note skips the error
40
+ return;
41
+ }
42
+ }
43
+ (0, file_helper_1.makeDirectory)(config.exportDir);
44
+ // create branch info file
45
+ (0, file_helper_1.writeFileSync)(path.join(config.exportDir, 'branches.json'), branches);
46
+ // add branches list in the
47
+ config.branches = branches;
48
+ };
49
+ exports.default = setupBranches;
@@ -0,0 +1,2 @@
1
+ import { ExportConfig } from '../types';
2
+ export default function setupExportDir(exportConfig: ExportConfig): Promise<void[]>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path_1 = tslib_1.__importDefault(require("path"));
5
+ const file_helper_1 = require("./file-helper");
6
+ async function setupExportDir(exportConfig) {
7
+ (0, file_helper_1.makeDirectory)(exportConfig.exportDir);
8
+ if (exportConfig.branches) {
9
+ return Promise.all(exportConfig.branches.map((branch) => (0, file_helper_1.makeDirectory)(path_1.default.join(exportConfig.exportDir, branch.uid))));
10
+ }
11
+ }
12
+ exports.default = setupExportDir;
@@ -1,7 +1 @@
1
- {
2
- "promptMessageList": {
3
- "promptMasterLocale": "Provide the master locale of the source stack",
4
- "promptSourceStack": "Provide the API Key of the source stack",
5
- "promptPathStoredData": "Provide the path to store the content"
6
- }
7
- }
1
+ {}
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.9",
2
+ "version": "1.7.0",
3
3
  "commands": {
4
4
  "cm:stacks:export": {
5
5
  "id": "cm:stacks:export",
package/package.json CHANGED
@@ -1,33 +1,39 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-export",
3
3
  "description": "Contentstack CLI plugin to export content from stack",
4
- "version": "1.5.9",
4
+ "version": "1.7.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.2.9",
9
- "@contentstack/cli-utilities": "^1.4.5",
8
+ "@contentstack/cli-command": "^1.2.11",
9
+ "@contentstack/cli-utilities": "^1.5.1",
10
10
  "@oclif/command": "^1.8.16",
11
11
  "@oclif/config": "^1.18.3",
12
+ "@oclif/core": "^2.9.3",
12
13
  "async": "^3.2.4",
13
14
  "big-json": "^3.2.0",
14
15
  "bluebird": "^3.7.2",
15
16
  "chalk": "^4.1.2",
16
17
  "is-valid-path": "^0.1.1",
17
18
  "lodash": "^4.17.20",
18
- "mkdirp": "^2.1.3",
19
+ "merge": "^2.1.1",
20
+ "mkdirp": "^1.0.4",
19
21
  "path": "^0.12.7",
20
22
  "progress-stream": "^2.0.0",
21
23
  "promise-limit": "^2.7.0",
22
24
  "proxyquire": "^2.1.3",
25
+ "tslib": "^2.4.1",
23
26
  "winston": "^3.7.2"
24
27
  },
25
28
  "devDependencies": {
26
- "@contentstack/cli-auth": "^1.3.8",
27
- "@contentstack/cli-config": "^1.4.6",
29
+ "@contentstack/cli-auth": "^1.3.11",
30
+ "@contentstack/cli-config": "^1.4.9",
28
31
  "@contentstack/cli-dev-dependencies": "^1.2.3",
29
32
  "@oclif/plugin-help": "^5.1.19",
30
33
  "@oclif/test": "^1.2.6",
34
+ "@types/mkdirp": "^1.0.2",
35
+ "@types/progress-stream": "^2.0.2",
36
+ "@types/mkdirp": "^1.0.2",
31
37
  "assert": "^2.0.0",
32
38
  "chai": "^4.2.0",
33
39
  "dotenv": "^16.0.1",
@@ -37,17 +43,35 @@
37
43
  "globby": "^10.0.2",
38
44
  "mocha": "10.1.0",
39
45
  "nyc": "^15.1.0",
46
+ "oclif": "^3.8.1",
40
47
  "sinon": "^15.0.1",
41
- "oclif": "^3.8.1"
48
+ "ts-node": "^10.9.1",
49
+ "typescript": "^4.9.3"
50
+ },
51
+ "scripts": {
52
+ "build": "npm run clean && npm run compile",
53
+ "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
54
+ "compile": "tsc -b tsconfig.json",
55
+ "postpack": "rm -f oclif.manifest.json",
56
+ "prepack": "pnpm compile && oclif manifest && oclif readme",
57
+ "version": "oclif readme && git add README.md",
58
+ "test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
59
+ "pretest": "tsc -p test",
60
+ "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
61
+ "posttest": "npm run lint",
62
+ "lint": "eslint src/**/*.ts",
63
+ "format": "eslint src/**/*.ts --fix",
64
+ "test:integration": "INTEGRATION_TEST=true mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"",
65
+ "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
42
66
  },
43
67
  "engines": {
44
68
  "node": ">=14.0.0"
45
69
  },
46
70
  "files": [
71
+ "/lib",
72
+ "/messages",
47
73
  "/npm-shrinkwrap.json",
48
- "/oclif.manifest.json",
49
- "/src",
50
- "/messages"
74
+ "/oclif.manifest.json"
51
75
  ],
52
76
  "homepage": "https://github.com/contentstack/cli",
53
77
  "keywords": [
@@ -56,17 +80,9 @@
56
80
  "plugin"
57
81
  ],
58
82
  "license": "MIT",
59
- "scripts": {
60
- "postpack": "rm -f oclif.manifest.json",
61
- "prepack": "oclif manifest && oclif readme",
62
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
63
- "version": "oclif readme && git add README.md",
64
- "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo",
65
- "test:integration": "INTEGRATION_TEST=true mocha --config ./test/.mocharc.js --forbid-only \"test/run.test.js\"",
66
- "test:unit": "mocha --forbid-only \"test/unit/*.test.js\" --unit-test"
67
- },
83
+ "main": "./lib/commands/cm/stacks/export.js",
68
84
  "oclif": {
69
- "commands": "./src/commands",
85
+ "commands": "./lib/commands",
70
86
  "bin": "csdx",
71
87
  "devPlugins": [
72
88
  "@oclif/plugin-help"
@@ -79,9 +95,8 @@
79
95
  },
80
96
  "shortCommandName": {
81
97
  "cm:stacks:export": "EXPRT",
82
- "cm:export": "O-EXPRT"
98
+ "cm:export": "EXPRT"
83
99
  }
84
100
  },
85
- "main": "./src/commands/cm/stacks/export.js",
86
101
  "repository": "https://github.com/contentstack/cli"
87
- }
102
+ }
package/src/app.js DELETED
@@ -1,156 +0,0 @@
1
- /* eslint-disable no-redeclare */
2
- const _ = require('lodash');
3
- const path = require('path');
4
- const chalk = require('chalk');
5
- const util = require('./lib/util');
6
- const login = require('./lib/util/login');
7
- const setupBranches = require('./lib/util/setup-branches');
8
- const { addlogs, unlinkFileLogger } = require('./lib/util/log');
9
- const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
10
-
11
- exports.initial = async (config) => {
12
- return new Promise(async (resolve, reject) => {
13
- config = util.buildAppConfig(config);
14
- util.validateConfig(config);
15
- exports.getConfig = () => {
16
- return config;
17
- };
18
-
19
- const APIClient = await managementSDKClient(config);
20
- const stackAPIClient = APIClient.stack({
21
- api_key: config.source_stack,
22
- management_token: config.management_token,
23
- });
24
-
25
- const fetchBranchAndExport = async (APIClient, stackAPIClient) => {
26
- await setupBranches(config, config.branchName, stackAPIClient);
27
- let types = config.modules.types;
28
-
29
- if (Array.isArray(config.branches) && config.branches.length > 0) {
30
- for (let branch of config.branches) {
31
- config.branchName = branch.uid;
32
- try {
33
- if (config.moduleName) {
34
- await singleExport(APIClient, stackAPIClient, config.moduleName, types, config, branch.uid);
35
- } else {
36
- await allExport(APIClient, stackAPIClient, config, types, branch.uid);
37
- }
38
- } catch (error) {
39
- addlogs(config, `failed export contents '${branch.uid}' ${util.formatError(error)}`, 'error');
40
- }
41
- }
42
- } else {
43
- try {
44
- if (config.moduleName) {
45
- await singleExport(APIClient, stackAPIClient, config.moduleName, types, config);
46
- } else {
47
- await allExport(APIClient, stackAPIClient, config, types);
48
- }
49
- } catch (error) {
50
- addlogs(config, `failed export contents. ${util.formatError(error)}`, 'error');
51
- }
52
- }
53
- };
54
-
55
- if (config.management_token || config.isAuthenticated) {
56
- try {
57
- await fetchBranchAndExport(APIClient, stackAPIClient);
58
- } catch (error) {
59
- addlogs(config, `${util.formatError(error)}`, 'error');
60
- }
61
- resolve();
62
- } else if (
63
- (config.email && config.password) ||
64
- (!config.email && !config.password && config.source_stack && config.access_token) ||
65
- (isAuthenticated() && !config.management_token)
66
- ) {
67
- login
68
- .login(config, APIClient, stackAPIClient)
69
- .then(async function () {
70
- // setup branches
71
- try {
72
- await fetchBranchAndExport(APIClient, stackAPIClient);
73
- unlinkFileLogger();
74
- } catch (error) {
75
- addlogs(config, `${util.formatError(error)}`, 'error');
76
- }
77
- resolve();
78
- })
79
- .catch((error) => {
80
- if (error && error.errors && error.errors.api_key) {
81
- addlogs(config, `Stack Api key '${error.errors.api_key[0]}', Please enter valid Key`, 'error');
82
- addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success');
83
- } else {
84
- addlogs(config, `${util.formatError(error)}`, 'error');
85
- }
86
- });
87
- } else {
88
- reject('Kindly login or provide management_token');
89
- }
90
- });
91
- };
92
-
93
- const singleExport = async (APIClient, stackAPIClient, moduleName, types, config, branchName) => {
94
- try {
95
- if (types.indexOf(moduleName) > -1) {
96
- let iterateList;
97
- if (config.modules.dependency && config.modules.dependency[moduleName]) {
98
- iterateList = config.modules.dependency[moduleName];
99
- } else {
100
- iterateList = ['stack'];
101
- }
102
- iterateList.push(moduleName);
103
-
104
- for (let element of iterateList) {
105
- const ExportModule = require('./lib/export/' + element);
106
- const result = await new ExportModule(config, stackAPIClient, APIClient).start(config, branchName);
107
- if (result && element === 'stack') {
108
- let master_locale = {
109
- master_locale: { code: result.code },
110
- };
111
- config = _.merge(config, master_locale);
112
- }
113
- }
114
- addlogs(config, `Module '${moduleName}' was exported successfully!`, 'success');
115
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
116
- } else {
117
- addlogs(config, 'Please provide valid module name.', 'error');
118
- }
119
- return true;
120
- } catch (error) {
121
- addlogs(config, `${util.formatError(error)}`, 'error');
122
- addlogs(config, `Failed to migrate module '${moduleName}'`, 'error');
123
- addlogs(config, `The log for this is stored at '${path.join(config.data, 'logs', 'export')}'`, 'error');
124
- }
125
- };
126
-
127
- const allExport = async (APIClient, stackAPIClient, config, types, branchName) => {
128
- try {
129
- for (let type of types) {
130
- const ExportModule = require('./lib/export/' + type);
131
- const result = await new ExportModule(config, stackAPIClient, APIClient).start(config, branchName);
132
-
133
- if (result && type === 'stack') {
134
- let master_locale = { master_locale: { code: result.code } };
135
- config = _.merge(config, master_locale);
136
- }
137
- }
138
- addlogs(
139
- config,
140
- chalk.green(
141
- 'The content of stack ' + (config.sourceStackName || config.source_stack) + ' has been exported successfully!',
142
- ),
143
- 'success',
144
- );
145
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
146
- return true;
147
- } catch (error) {
148
- addlogs(config, util.formatError(error), 'error');
149
- addlogs(
150
- config,
151
- `Failed to migrate stack '${config.sourceStackName || config.source_stack}'. Please check error logs for more info.`,
152
- 'error',
153
- );
154
- addlogs(config, `The log for this is stored at '${path.join(config.data, 'logs', 'export')}'`, 'error');
155
- }
156
- };