@contentstack/cli-cm-export 1.2.3 → 1.4.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.
- package/LICENSE +1 -1
- package/README.md +74 -22
- package/oclif.manifest.json +128 -1
- package/package.json +15 -14
- package/src/app.js +30 -32
- package/src/commands/cm/stacks/export.js +3 -5
- package/src/config/default.js +5 -0
- package/src/lib/export/assets.js +201 -194
- package/src/lib/export/custom-roles.js +7 -16
- package/src/lib/export/entries.js +6 -1
- package/src/lib/export/environments.js +6 -7
- package/src/lib/export/extensions.js +6 -7
- package/src/lib/export/global-fields.js +12 -12
- package/src/lib/export/labels.js +8 -11
- package/src/lib/export/locales.js +8 -6
- package/src/lib/export/marketplace-apps.js +102 -102
- package/src/lib/export/stack.js +78 -84
- package/src/lib/export/webhooks.js +4 -9
- package/src/lib/export/workflows.js +11 -11
- package/src/lib/util/helper.js +16 -25
- package/src/lib/util/login.js +59 -55
- package/src/lib/util/marketplace-app-helper.js +3 -40
- package/src/lib/util/setup-branches.js +14 -12
- package/src/lib/util/contentstack-management-sdk.js +0 -39
package/src/lib/export/stack.js
CHANGED
|
@@ -4,102 +4,96 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const mkdirp = require('mkdirp');
|
|
9
|
+
const { merge } = require('lodash');
|
|
10
|
+
const helper = require('../util/helper');
|
|
11
|
+
const { addlogs } = require('../util/log');
|
|
12
|
+
const config = require('../../config/default');
|
|
13
|
+
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
14
|
+
module.exports = class ExportStack {
|
|
15
|
+
stackConfig = config.modules.stack;
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
constructor(exportConfig, stackAPIClient, APIClient) {
|
|
18
|
+
this.config = merge(config, exportConfig);
|
|
19
|
+
this.stackAPIClient = stackAPIClient;
|
|
20
|
+
this.APIClient = APIClient;
|
|
21
|
+
this.requestOption = {
|
|
22
|
+
uri: this.config.host + this.config.apis.stacks,
|
|
23
|
+
headers: this.config.headers,
|
|
24
|
+
json: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
async start() {
|
|
29
|
+
const self = this;
|
|
30
|
+
if (self.config.auth_token) {
|
|
31
|
+
const tempAPIClient = await managementSDKClient({ host: config.host });
|
|
32
|
+
const tempStackData = await tempAPIClient
|
|
33
|
+
.stack({ api_key: self.config.source_stack })
|
|
34
|
+
.fetch()
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
console.log(error);
|
|
37
|
+
});
|
|
17
38
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
39
|
+
if (tempStackData && tempStackData.org_uid) {
|
|
40
|
+
self.config.org_uid = tempStackData.org_uid;
|
|
41
|
+
self.config.sourceStackName = tempStackData.name;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
if (!self.config.preserveStackVersion && !self.config.hasOwnProperty('master_locale')) {
|
|
46
|
+
const apiDetails = {
|
|
47
|
+
limit: 100,
|
|
48
|
+
skip: 0,
|
|
49
|
+
include_count: true,
|
|
50
|
+
};
|
|
51
|
+
return self.getLocales(apiDetails);
|
|
52
|
+
} else if (self.config.preserveStackVersion) {
|
|
53
|
+
addlogs(self.config, 'Exporting stack details', 'success');
|
|
54
|
+
let stackFolderPath = path.resolve(self.config.data, stackConfig.dirName);
|
|
55
|
+
let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName);
|
|
30
56
|
|
|
31
|
-
|
|
32
|
-
if (config.auth_token) {
|
|
33
|
-
const stack = await client
|
|
34
|
-
.stack({ api_key: config.source_stack, authtoken: config.auth_token })
|
|
35
|
-
.fetch()
|
|
36
|
-
.catch((error) => {
|
|
37
|
-
console.log(error);
|
|
38
|
-
});
|
|
57
|
+
mkdirp.sync(stackFolderPath);
|
|
39
58
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
return self.APIClient.stack({ api_key: self.config.source_stack })
|
|
61
|
+
.fetch()
|
|
62
|
+
.then((response) => {
|
|
63
|
+
helper.writeFile(stackContentsFile, response);
|
|
64
|
+
addlogs(self.config, 'Exported stack details successfully!', 'success');
|
|
65
|
+
return resolve(response);
|
|
66
|
+
})
|
|
67
|
+
.catch(reject);
|
|
68
|
+
});
|
|
43
69
|
}
|
|
44
70
|
}
|
|
45
71
|
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
limit: 100,
|
|
49
|
-
skip: 0,
|
|
50
|
-
include_count: true,
|
|
51
|
-
};
|
|
52
|
-
return self.getLocales(apiDetails);
|
|
53
|
-
} else if (config.preserveStackVersion) {
|
|
54
|
-
addlogs(config, 'Exporting stack details', 'success');
|
|
55
|
-
let stackFolderPath = path.resolve(config.data, stackConfig.dirName);
|
|
56
|
-
let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName);
|
|
57
|
-
|
|
58
|
-
mkdirp.sync(stackFolderPath);
|
|
59
|
-
|
|
72
|
+
getLocales(apiDetails) {
|
|
73
|
+
const self = this;
|
|
60
74
|
return new Promise((resolve, reject) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
const result = self.stackAPIClient.locale().query(apiDetails);
|
|
76
|
+
|
|
77
|
+
result
|
|
78
|
+
.find()
|
|
64
79
|
.then((response) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
const masterLocalObj = response.items.find((obj) => {
|
|
81
|
+
if (obj.fallback_locale === null) {
|
|
82
|
+
return obj;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
apiDetails.skip += apiDetails.limit;
|
|
86
|
+
if (masterLocalObj) {
|
|
87
|
+
return resolve(masterLocalObj);
|
|
88
|
+
} else if (apiDetails.skip <= response.count) {
|
|
89
|
+
return resolve(self.getLocales(apiDetails));
|
|
90
|
+
} else {
|
|
91
|
+
return reject('Master locale not found');
|
|
92
|
+
}
|
|
68
93
|
})
|
|
69
|
-
.catch(
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
return reject(error);
|
|
96
|
+
});
|
|
70
97
|
});
|
|
71
98
|
}
|
|
72
99
|
};
|
|
73
|
-
|
|
74
|
-
ExportStack.prototype.getLocales = function (apiDetails) {
|
|
75
|
-
let self = this;
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const result = client
|
|
78
|
-
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
79
|
-
.locale()
|
|
80
|
-
.query(apiDetails);
|
|
81
|
-
|
|
82
|
-
result
|
|
83
|
-
.find()
|
|
84
|
-
.then((response) => {
|
|
85
|
-
const masterLocalObj = response.items.find((obj) => {
|
|
86
|
-
if (obj.fallback_locale === null) {
|
|
87
|
-
return obj;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
apiDetails.skip += apiDetails.limit;
|
|
91
|
-
if (masterLocalObj) {
|
|
92
|
-
return resolve(masterLocalObj);
|
|
93
|
-
} else if (apiDetails.skip <= response.count) {
|
|
94
|
-
return resolve(self.getLocales(apiDetails));
|
|
95
|
-
} else {
|
|
96
|
-
return reject('Master locale not found');
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.catch((error) => {
|
|
100
|
-
return reject(error);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
module.exports = ExportStack;
|
|
@@ -13,9 +13,6 @@ const helper = require('../util/helper');
|
|
|
13
13
|
const { formatError } = require('../util');
|
|
14
14
|
const { addlogs } = require('../util/log');
|
|
15
15
|
const config = require('../../config/default');
|
|
16
|
-
const stack = require('../util/contentstack-management-sdk');
|
|
17
|
-
|
|
18
|
-
// Create folder for environments
|
|
19
16
|
|
|
20
17
|
module.exports = class ExportWebhooks {
|
|
21
18
|
config;
|
|
@@ -27,15 +24,14 @@ module.exports = class ExportWebhooks {
|
|
|
27
24
|
};
|
|
28
25
|
webhooksConfig = config.modules.webhooks;
|
|
29
26
|
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
27
|
+
constructor(exportConfig, stackAPIClient) {
|
|
28
|
+
this.stackAPIClient = stackAPIClient;
|
|
29
|
+
this.config = merge(config, exportConfig);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
start() {
|
|
35
33
|
addlogs(this.config, 'Starting webhooks export', 'success');
|
|
36
|
-
|
|
37
34
|
const self = this;
|
|
38
|
-
const client = stack.Client(this.config);
|
|
39
35
|
const webhooksFolderPath = path.resolve(
|
|
40
36
|
this.config.data,
|
|
41
37
|
this.config.branchName || '',
|
|
@@ -43,8 +39,7 @@ module.exports = class ExportWebhooks {
|
|
|
43
39
|
);
|
|
44
40
|
mkdirp.sync(webhooksFolderPath);
|
|
45
41
|
return new Promise((resolve, reject) => {
|
|
46
|
-
|
|
47
|
-
.stack({ api_key: self.config.source_stack, management_token: self.config.management_token })
|
|
42
|
+
self.stackAPIClient
|
|
48
43
|
.webhook()
|
|
49
44
|
.fetchAll(self.requestOptions)
|
|
50
45
|
.then((webhooks) => {
|
|
@@ -13,30 +13,31 @@ const helper = require('../util/helper');
|
|
|
13
13
|
const { addlogs } = require('../util/log');
|
|
14
14
|
const { formatError } = require('../util');
|
|
15
15
|
const config = require('../../config/default');
|
|
16
|
-
const stack = require('../util/contentstack-management-sdk');
|
|
17
16
|
|
|
18
17
|
module.exports = class ExportWorkFlows {
|
|
19
|
-
client;
|
|
20
18
|
config;
|
|
21
19
|
workflows = {};
|
|
22
20
|
workFlowConfig = config.modules.workflows;
|
|
23
21
|
|
|
24
|
-
constructor(
|
|
25
|
-
this.
|
|
22
|
+
constructor(exportConfig, stackAPIClient) {
|
|
23
|
+
this.stackAPIClient = stackAPIClient;
|
|
24
|
+
this.config = merge(config, exportConfig);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
start() {
|
|
29
28
|
addlogs(this.config, 'Starting workflow export', 'success');
|
|
30
29
|
|
|
31
30
|
const self = this;
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const workflowsFolderPath = path.resolve(
|
|
32
|
+
this.config.data,
|
|
33
|
+
this.config.branchName || '',
|
|
34
|
+
this.workFlowConfig.dirName,
|
|
35
|
+
);
|
|
34
36
|
|
|
35
37
|
mkdirp.sync(workflowsFolderPath);
|
|
36
38
|
|
|
37
39
|
return new Promise(function (resolve, reject) {
|
|
38
|
-
return self.
|
|
39
|
-
.stack({ api_key: self.config.source_stack, management_token: self.config.management_token })
|
|
40
|
+
return self.stackAPIClient
|
|
40
41
|
.workflow()
|
|
41
42
|
.fetchAll()
|
|
42
43
|
.then(async (response) => {
|
|
@@ -78,8 +79,7 @@ module.exports = class ExportWorkFlows {
|
|
|
78
79
|
if (stage.SYS_ACL.roles.uids.length) {
|
|
79
80
|
for (let i = 0; i < stage.SYS_ACL.roles.uids.length; i++) {
|
|
80
81
|
const roleUid = stage.SYS_ACL.roles.uids[i];
|
|
81
|
-
const roleData = await self.
|
|
82
|
-
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
82
|
+
const roleData = await self.stackAPIClient
|
|
83
83
|
.role(roleUid)
|
|
84
84
|
.fetch({ include_rules: true, include_permissions: true });
|
|
85
85
|
stage.SYS_ACL.roles.uids[i] = roleData;
|
|
@@ -99,7 +99,7 @@ module.exports = class ExportWorkFlows {
|
|
|
99
99
|
addlogs(self.config, workflow.name + ' workflow was exported successfully', 'success');
|
|
100
100
|
await self.getWorkflowRoles(self, workflow);
|
|
101
101
|
self.workflows[workflow.uid] = workflow;
|
|
102
|
-
|
|
102
|
+
const deleteItems = config.modules.workflows.invalidKeys;
|
|
103
103
|
deleteItems.forEach((e) => delete workflow[e]);
|
|
104
104
|
}
|
|
105
105
|
} catch (error) {
|
package/src/lib/util/helper.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const mkdirp = require('mkdirp');
|
|
10
|
+
const bigJSON = require('big-json');
|
|
11
11
|
|
|
12
|
-
exports.readFileSync =
|
|
13
|
-
|
|
12
|
+
exports.readFileSync = (filePath, parse) => {
|
|
13
|
+
let data;
|
|
14
14
|
parse = typeof parse === 'undefined' ? true : parse;
|
|
15
15
|
filePath = path.resolve(filePath);
|
|
16
16
|
if (fs.existsSync(filePath)) {
|
|
17
|
-
data = parse ? JSON.parse(fs.readFileSync(filePath, '
|
|
17
|
+
data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : data;
|
|
18
18
|
}
|
|
19
19
|
return data;
|
|
20
20
|
};
|
|
@@ -36,14 +36,14 @@ exports.readFile = async (filePath, options = { type: 'json' }) => {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
exports.makeDirectory = async
|
|
39
|
+
exports.makeDirectory = async (path) => {
|
|
40
40
|
if (!path) {
|
|
41
41
|
throw new Error('Invalid path to create directory');
|
|
42
42
|
}
|
|
43
43
|
return mkdirp(path);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
exports.readLargeFile =
|
|
46
|
+
exports.readLargeFile = (filePath, opts = {}) => {
|
|
47
47
|
if (typeof filePath !== 'string') {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
@@ -52,13 +52,13 @@ exports.readLargeFile = function (filePath, opts = {}) {
|
|
|
52
52
|
return new Promise((resolve, reject) => {
|
|
53
53
|
const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
|
|
54
54
|
const parseStream = bigJSON.createParseStream();
|
|
55
|
-
parseStream.on('data',
|
|
55
|
+
parseStream.on('data', (data) => {
|
|
56
56
|
if (opts.type === 'array') {
|
|
57
57
|
return resolve(Object.values(data));
|
|
58
58
|
}
|
|
59
59
|
resolve(data);
|
|
60
60
|
});
|
|
61
|
-
parseStream.on('error',
|
|
61
|
+
parseStream.on('error', (error) => {
|
|
62
62
|
console.log('error', error);
|
|
63
63
|
reject(error);
|
|
64
64
|
});
|
|
@@ -67,7 +67,7 @@ exports.readLargeFile = function (filePath, opts = {}) {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
exports.writeLargeFile =
|
|
70
|
+
exports.writeLargeFile = (filePath, data) => {
|
|
71
71
|
if (typeof filePath !== 'string' || typeof data !== 'object') {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
@@ -76,7 +76,7 @@ exports.writeLargeFile = function (filePath, data) {
|
|
|
76
76
|
const stringifyStream = bigJSON.createStringifyStream({
|
|
77
77
|
body: data,
|
|
78
78
|
});
|
|
79
|
-
|
|
79
|
+
const writeStream = fs.createWriteStream(filePath, 'utf-8');
|
|
80
80
|
stringifyStream.pipe(writeStream);
|
|
81
81
|
writeStream.on('finish', () => {
|
|
82
82
|
resolve();
|
|
@@ -87,12 +87,12 @@ exports.writeLargeFile = function (filePath, data) {
|
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
exports.writeFileSync =
|
|
90
|
+
exports.writeFileSync = (filePath, data) => {
|
|
91
91
|
data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
|
|
92
92
|
fs.writeFileSync(filePath, data);
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
exports.writeFile =
|
|
95
|
+
exports.writeFile = (filePath, data) => {
|
|
96
96
|
return new Promise((resolve, reject) => {
|
|
97
97
|
data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
|
|
98
98
|
fs.writeFile(filePath, data, (error) => {
|
|
@@ -104,16 +104,7 @@ exports.writeFile = function (filePath, data) {
|
|
|
104
104
|
});
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
exports.
|
|
108
|
-
for (var key in arguments) {
|
|
109
|
-
var dirname = path.resolve(arguments[key]);
|
|
110
|
-
if (!fs.existsSync(dirname)) {
|
|
111
|
-
mkdirp.sync(dirname);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
exports.readdir = function (dirPath) {
|
|
107
|
+
exports.readdir = (dirPath) => {
|
|
117
108
|
if (fs.existsSync(path)) {
|
|
118
109
|
return fs.readdirSync(dirPath);
|
|
119
110
|
} else {
|
package/src/lib/util/login.js
CHANGED
|
@@ -7,70 +7,74 @@
|
|
|
7
7
|
* MIT Licensed
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let client;
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const { addlogs } = require('../util/log');
|
|
12
|
+
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
14
13
|
|
|
15
14
|
module.exports.login = (config) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log('Logging into Contentstack');
|
|
21
|
-
client
|
|
22
|
-
.login({ email: config.email, password: config.password })
|
|
23
|
-
.then(function (response) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
managementSDKClient(config)
|
|
17
|
+
.then((APIClient) => {
|
|
18
|
+
if (config.email && config.password) {
|
|
24
19
|
// eslint-disable-next-line no-console
|
|
25
|
-
console.log(
|
|
26
|
-
config.
|
|
20
|
+
console.log('Logging into Contentstack');
|
|
21
|
+
APIClient.login({ email: config.email, password: config.password })
|
|
22
|
+
.then((response) => {
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.log(chalk.green('Contentstack account authenticated successfully!'));
|
|
25
|
+
config.authtoken = response.user.authtoken;
|
|
26
|
+
config.headers = {
|
|
27
|
+
api_key: config.source_stack,
|
|
28
|
+
access_token: config.access_token,
|
|
29
|
+
authtoken: config.authtoken,
|
|
30
|
+
'X-User-Agent': 'contentstack-export/v',
|
|
31
|
+
};
|
|
32
|
+
resolve(config);
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
reject(error);
|
|
36
|
+
});
|
|
37
|
+
} else if (config.auth_token && !config.management_token) {
|
|
38
|
+
const stackAPIClient = APIClient.stack({
|
|
39
|
+
api_key: config.source_stack,
|
|
40
|
+
management_token: config.management_token,
|
|
41
|
+
});
|
|
42
|
+
stackAPIClient
|
|
43
|
+
.users()
|
|
44
|
+
.then(() => {
|
|
45
|
+
resolve();
|
|
46
|
+
})
|
|
47
|
+
.catch((error) => {
|
|
48
|
+
if (error.errors.api_key) {
|
|
49
|
+
return reject(error);
|
|
50
|
+
}
|
|
51
|
+
addlogs(config, error.errorMessage, 'error');
|
|
52
|
+
reject(error);
|
|
53
|
+
});
|
|
54
|
+
} else if (!config.email && !config.password && config.source_stack && config.access_token) {
|
|
55
|
+
addlogs(
|
|
56
|
+
config,
|
|
57
|
+
chalk.yellow('Content types, entries, assets, labels, global fields, extensions modules will be exported'),
|
|
58
|
+
'success',
|
|
59
|
+
);
|
|
60
|
+
addlogs(
|
|
61
|
+
config,
|
|
62
|
+
chalk.yellow(
|
|
63
|
+
'Email, password, or management token is not set in the config, cannot export Webhook and label modules',
|
|
64
|
+
),
|
|
65
|
+
'success',
|
|
66
|
+
);
|
|
27
67
|
config.headers = {
|
|
28
68
|
api_key: config.source_stack,
|
|
29
69
|
access_token: config.access_token,
|
|
30
|
-
authtoken: config.authtoken,
|
|
31
70
|
'X-User-Agent': 'contentstack-export/v',
|
|
32
71
|
};
|
|
33
72
|
resolve(config);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
reject(error);
|
|
37
|
-
});
|
|
38
|
-
} else if (!config.email && !config.password && config.source_stack && config.access_token) {
|
|
39
|
-
addlogs(
|
|
40
|
-
config,
|
|
41
|
-
chalk.yellow('Content types, entries, assets, labels, global fields, extensions modules will be exported'),
|
|
42
|
-
'success',
|
|
43
|
-
);
|
|
44
|
-
addlogs(
|
|
45
|
-
config,
|
|
46
|
-
chalk.yellow(
|
|
47
|
-
'Email, password, or management token is not set in the config, cannot export Webhook and label modules',
|
|
48
|
-
),
|
|
49
|
-
'success',
|
|
50
|
-
);
|
|
51
|
-
config.headers = {
|
|
52
|
-
api_key: config.source_stack,
|
|
53
|
-
access_token: config.access_token,
|
|
54
|
-
'X-User-Agent': 'contentstack-export/v',
|
|
55
|
-
};
|
|
56
|
-
resolve(config);
|
|
57
|
-
// eslint-disable-next-line no-else-return
|
|
58
|
-
} else if (config.auth_token && !config.management_token) {
|
|
59
|
-
client
|
|
60
|
-
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
61
|
-
.users()
|
|
62
|
-
.then(function () {
|
|
73
|
+
// eslint-disable-next-line no-else-return
|
|
74
|
+
} else if (config.management_token) {
|
|
63
75
|
resolve();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return reject(error);
|
|
68
|
-
}
|
|
69
|
-
addlogs(config, error.errorMessage, 'error');
|
|
70
|
-
reject(error);
|
|
71
|
-
});
|
|
72
|
-
} else if (config.management_token) {
|
|
73
|
-
resolve();
|
|
74
|
-
}
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.catch((error) => reject(error));
|
|
75
79
|
});
|
|
76
80
|
};
|
|
@@ -1,42 +1,5 @@
|
|
|
1
1
|
let config = require('../../config/default');
|
|
2
|
-
const
|
|
3
|
-
const { cliux, HttpClient, configHandler } = require('@contentstack/cli-utilities');
|
|
4
|
-
|
|
5
|
-
const getInstalledExtensions = (config) => {
|
|
6
|
-
const client = sdk.Client(config)
|
|
7
|
-
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const queryRequestOptions = {
|
|
10
|
-
include_marketplace_extensions: true
|
|
11
|
-
}
|
|
12
|
-
const {
|
|
13
|
-
management_token_data: { apiKey: api_key, token: management_token } = { apiKey: config.source_stack },
|
|
14
|
-
auth_token
|
|
15
|
-
} = config || { management_token_data: {} }
|
|
16
|
-
|
|
17
|
-
if (api_key && management_token) {
|
|
18
|
-
client
|
|
19
|
-
.stack({ api_key, management_token })
|
|
20
|
-
.extension()
|
|
21
|
-
.query(queryRequestOptions)
|
|
22
|
-
.find()
|
|
23
|
-
.then(({ items }) => resolve(items))
|
|
24
|
-
.catch(reject)
|
|
25
|
-
} else if (api_key && auth_token) {
|
|
26
|
-
const { cma } = configHandler.get('region') || {};
|
|
27
|
-
const headers = {
|
|
28
|
-
api_key,
|
|
29
|
-
authtoken: auth_token
|
|
30
|
-
}
|
|
31
|
-
const httpClient = new HttpClient().headers(headers);
|
|
32
|
-
httpClient.get(`${cma}/v3/extensions/?include_marketplace_extensions=true`)
|
|
33
|
-
.then(({ data: { extensions } }) => resolve(extensions))
|
|
34
|
-
.catch(reject)
|
|
35
|
-
} else {
|
|
36
|
-
resolve([])
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}
|
|
2
|
+
const { cliux, configHandler } = require('@contentstack/cli-utilities');
|
|
40
3
|
|
|
41
4
|
const getDeveloperHubUrl = async () => {
|
|
42
5
|
const { cma, name } = configHandler.get('region') || {};
|
|
@@ -56,6 +19,6 @@ const getDeveloperHubUrl = async () => {
|
|
|
56
19
|
}
|
|
57
20
|
|
|
58
21
|
return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
|
|
59
|
-
}
|
|
22
|
+
};
|
|
60
23
|
|
|
61
|
-
module.exports = {
|
|
24
|
+
module.exports = { getDeveloperHubUrl };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const mkdirp = require('mkdirp');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const helper = require('./helper');
|
|
4
|
-
const { HttpClient } = require('@contentstack/cli-utilities');
|
|
5
4
|
|
|
6
|
-
const setupBranches = async (config, branch) => {
|
|
5
|
+
const setupBranches = async (config, branch, stackAPIClient) => {
|
|
7
6
|
if (typeof config !== 'object') {
|
|
8
7
|
throw new Error('Invalid config to setup the branch');
|
|
9
8
|
}
|
|
@@ -18,21 +17,24 @@ const setupBranches = async (config, branch) => {
|
|
|
18
17
|
|
|
19
18
|
if (typeof branch === 'string') {
|
|
20
19
|
// check branch exists
|
|
21
|
-
const result = await
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
if (result && typeof result
|
|
26
|
-
branches.push(result
|
|
20
|
+
const result = await stackAPIClient
|
|
21
|
+
.branch(branch)
|
|
22
|
+
.fetch()
|
|
23
|
+
.catch((_err) => {});
|
|
24
|
+
if (result && typeof result === 'object') {
|
|
25
|
+
branches.push(result);
|
|
27
26
|
} else {
|
|
28
27
|
throw new Error('No branch found with the name ' + branch);
|
|
29
28
|
}
|
|
30
29
|
} else {
|
|
31
30
|
try {
|
|
32
|
-
const result = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const result = await stackAPIClient
|
|
32
|
+
.branch()
|
|
33
|
+
.query()
|
|
34
|
+
.find()
|
|
35
|
+
.catch((_err) => {});
|
|
36
|
+
if (result && result.items && Array.isArray(result.items) && result.items.length > 0) {
|
|
37
|
+
branches = result.items;
|
|
36
38
|
} else {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const contentstacksdk = require('@contentstack/management');
|
|
2
|
-
const https = require('https');
|
|
3
|
-
|
|
4
|
-
const { addlogs } = require('./log');
|
|
5
|
-
|
|
6
|
-
exports.Client = function (config) {
|
|
7
|
-
const option = {
|
|
8
|
-
host: config.host,
|
|
9
|
-
authtoken: config.auth_token,
|
|
10
|
-
api_key: config.source_stack,
|
|
11
|
-
maxRequests: 10,
|
|
12
|
-
retryLimit: 5,
|
|
13
|
-
timeout: 60000,
|
|
14
|
-
httpsAgent: new https.Agent({
|
|
15
|
-
maxSockets: 100,
|
|
16
|
-
maxFreeSockets: 10,
|
|
17
|
-
keepAlive: true,
|
|
18
|
-
timeout: 60000, // active socket keepalive for 60 seconds
|
|
19
|
-
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
20
|
-
}),
|
|
21
|
-
retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
|
|
22
|
-
logHandler: (level, data) => {},
|
|
23
|
-
retryCondition: (error) => {
|
|
24
|
-
if (error.response.status === 408) {
|
|
25
|
-
addlogs({ data: error.response }, 'Timeout error', 'error');
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
if (typeof config.branchName === 'string') {
|
|
32
|
-
option.headers = {
|
|
33
|
-
branch: config.branchName,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const client = contentstacksdk.client(option);
|
|
38
|
-
return client;
|
|
39
|
-
};
|