@contentstack/cli-cm-export 0.1.0-beta → 0.1.1-beta.11
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/README.md +23 -13
- package/oclif.manifest.json +1 -1
- package/package.json +16 -12
- package/src/app.js +149 -66
- package/src/commands/cm/export.js +74 -50
- package/src/config/default.js +39 -1
- package/src/lib/export/assets.js +28 -9
- package/src/lib/export/content-types.js +8 -2
- package/src/lib/export/entries.js +7 -7
- package/src/lib/export/environments.js +4 -2
- package/src/lib/export/extensions.js +4 -2
- package/src/lib/export/global-fields.js +108 -82
- package/src/lib/export/labels.js +6 -4
- package/src/lib/export/locales.js +8 -6
- package/src/lib/export/stack.js +34 -16
- package/src/lib/export/webhooks.js +4 -2
- package/src/lib/export/workflows.js +60 -0
- package/src/lib/util/contentstack-management-sdk.js +7 -0
- package/src/lib/util/export-flags.js +95 -31
- package/src/lib/util/index.js +1 -5
- package/src/lib/util/log.js +0 -1
- package/src/lib/util/login.js +10 -11
- package/src/lib/util/request.js +8 -13
- package/src/lib/util/setup-branches.js +62 -0
package/src/lib/export/assets.js
CHANGED
|
@@ -37,9 +37,13 @@ function ExportAssets() {
|
|
|
37
37
|
|
|
38
38
|
ExportAssets.prototype = {
|
|
39
39
|
start: function (credentialConfig) {
|
|
40
|
+
this.assetContents = {}
|
|
41
|
+
this.folderData = []
|
|
42
|
+
this.assetDownloadRetry = {};
|
|
43
|
+
this.assetDownloadRetryLimit = 3;
|
|
40
44
|
let self = this
|
|
41
45
|
config = credentialConfig
|
|
42
|
-
assetsFolderPath = path.resolve(config.data, assetConfig.dirName)
|
|
46
|
+
assetsFolderPath = path.resolve(config.data, (config.branchName || ""), assetConfig.dirName)
|
|
43
47
|
assetContentsFile = path.resolve(assetsFolderPath, 'assets.json')
|
|
44
48
|
folderJSONPath = path.resolve(assetsFolderPath, 'folders.json')
|
|
45
49
|
client = stack.Client(config)
|
|
@@ -48,9 +52,10 @@ ExportAssets.prototype = {
|
|
|
48
52
|
// Create asset folder
|
|
49
53
|
mkdirp.sync(assetsFolderPath)
|
|
50
54
|
return new Promise(function (resolve, reject) {
|
|
55
|
+
//TBD: getting all the assets should have optimized
|
|
51
56
|
return self.getAssetCount().then(function (count) {
|
|
52
57
|
if (typeof count !== 'number' || count === 0) {
|
|
53
|
-
addlogs(config, '
|
|
58
|
+
addlogs(config, 'No assets found', 'success')
|
|
54
59
|
return resolve()
|
|
55
60
|
}
|
|
56
61
|
const assetBatches = []
|
|
@@ -66,9 +71,9 @@ ExportAssets.prototype = {
|
|
|
66
71
|
// log.success(chalk.white('The following asset has been downloaded successfully: ' +
|
|
67
72
|
// assetJSON.uid))
|
|
68
73
|
}).catch(function (error) {
|
|
69
|
-
|
|
74
|
+
addlogs(config, chalk.red('The following asset failed to download\n' + JSON.stringify(
|
|
70
75
|
assetJSON)))
|
|
71
|
-
|
|
76
|
+
addlogs(config, error, 'error')
|
|
72
77
|
})
|
|
73
78
|
}, {
|
|
74
79
|
concurrency: vLimit,
|
|
@@ -157,7 +162,6 @@ ExportAssets.prototype = {
|
|
|
157
162
|
})
|
|
158
163
|
},
|
|
159
164
|
getAssetCount: function (folder) {
|
|
160
|
-
let self = this
|
|
161
165
|
return new Promise(function (resolve, reject) {
|
|
162
166
|
if (folder && typeof folder === 'boolean') {
|
|
163
167
|
let queryOptions = {include_folders: true, query: {'is_dir': true}, include_count: true}
|
|
@@ -182,7 +186,6 @@ ExportAssets.prototype = {
|
|
|
182
186
|
})
|
|
183
187
|
},
|
|
184
188
|
getAssetJSON: function (skip) {
|
|
185
|
-
let self = this
|
|
186
189
|
return new Promise(function (resolve, reject) {
|
|
187
190
|
if (typeof skip !== 'number') {
|
|
188
191
|
skip = 0
|
|
@@ -209,6 +212,10 @@ ExportAssets.prototype = {
|
|
|
209
212
|
let self = this
|
|
210
213
|
let assetVersionInfo = bucket || []
|
|
211
214
|
return new Promise(function (resolve, reject) {
|
|
215
|
+
if (self.assetDownloadRetry[uid + version] > self.assetDownloadRetryLimit) {
|
|
216
|
+
return reject(new Error('Asset Max download retry limit exceeded! ' + uid));
|
|
217
|
+
}
|
|
218
|
+
|
|
212
219
|
if (version <= 0) {
|
|
213
220
|
const assetVersionInfoFile = path.resolve(assetsFolderPath, uid, '_contentstack_' + uid + '.json')
|
|
214
221
|
helper.writeFile(assetVersionInfoFile, assetVersionInfo)
|
|
@@ -230,8 +237,17 @@ ExportAssets.prototype = {
|
|
|
230
237
|
assetVersionInfo = _.uniqWith(assetVersionInfo, _.isEqual)
|
|
231
238
|
self.getVersionedAssetJSON(uid, --version, assetVersionInfo)
|
|
232
239
|
.then(resolve)
|
|
233
|
-
|
|
240
|
+
.catch(reject)
|
|
234
241
|
}).catch(reject)
|
|
242
|
+
}).catch((error) => {
|
|
243
|
+
if (error.status === 408) {
|
|
244
|
+
// retrying when timeout
|
|
245
|
+
(self.assetDownloadRetry[uid+version] ? ++self.assetDownloadRetry[uid+version] : self.assetDownloadRetry[uid+version] = 1 )
|
|
246
|
+
return self.getVersionedAssetJSON(uid, version, assetVersionInfo)
|
|
247
|
+
.then(resolve)
|
|
248
|
+
.catch(reject)
|
|
249
|
+
}
|
|
250
|
+
reject(error);
|
|
235
251
|
})
|
|
236
252
|
})
|
|
237
253
|
},
|
|
@@ -246,9 +262,12 @@ ExportAssets.prototype = {
|
|
|
246
262
|
return resolve()
|
|
247
263
|
}
|
|
248
264
|
self.assetStream = {
|
|
249
|
-
url:
|
|
250
|
-
|
|
265
|
+
url: config.securedAssets
|
|
266
|
+
? `${asset.url}?authtoken=${config.authtoken || config.auth_token}`
|
|
267
|
+
: asset.url,
|
|
268
|
+
};
|
|
251
269
|
|
|
270
|
+
self.assetStream.url = encodeURI(self.assetStream.url);
|
|
252
271
|
const assetStreamRequest = nativeRequest(self.assetStream)
|
|
253
272
|
assetStreamRequest.on('response', function () {
|
|
254
273
|
helper.makeDirectory(assetFolderPath)
|
|
@@ -35,10 +35,16 @@ function ExportContentTypes() {
|
|
|
35
35
|
|
|
36
36
|
ExportContentTypes.prototype = {
|
|
37
37
|
start: function (credentialConfig) {
|
|
38
|
+
this.content_types = []
|
|
38
39
|
let self = this
|
|
39
40
|
config = credentialConfig
|
|
40
|
-
contentTypesFolderPath = path.resolve(config.data, contentTypeConfig.dirName)
|
|
41
|
+
contentTypesFolderPath = path.resolve(config.data, (config.branchName || ""), contentTypeConfig.dirName)
|
|
42
|
+
|
|
41
43
|
client = stack.Client(config)
|
|
44
|
+
// If content type id is provided then use it as part of query
|
|
45
|
+
if (Array.isArray(config.contentTypes) && config.contentTypes.length > 0) {
|
|
46
|
+
self.requestOptions.qs.uid = {'$in': config.contentTypes}
|
|
47
|
+
}
|
|
42
48
|
// Create folder for content types
|
|
43
49
|
mkdirp.sync(contentTypesFolderPath)
|
|
44
50
|
addlogs(config, 'Starting content type export', 'success')
|
|
@@ -97,7 +103,7 @@ ExportContentTypes.prototype = {
|
|
|
97
103
|
helper.writeFile(path.join(contentTypesFolderPath, content_type.uid + '.json'),
|
|
98
104
|
content_type)
|
|
99
105
|
})
|
|
100
|
-
addlogs(config, chalk.green('Content type
|
|
106
|
+
addlogs(config, chalk.green('Content type(s) exported successfully'), 'success')
|
|
101
107
|
return resolve()
|
|
102
108
|
})
|
|
103
109
|
},
|
|
@@ -42,9 +42,9 @@ function exportEntries() {
|
|
|
42
42
|
exportEntries.prototype.start = function (credentialConfig) {
|
|
43
43
|
let self = this
|
|
44
44
|
config = credentialConfig
|
|
45
|
-
entryFolderPath = path.resolve(config.data, config.modules.entries.dirName)
|
|
46
|
-
localesFilePath = path.resolve(config.data, config.modules.locales.dirName, config.modules.locales.fileName)
|
|
47
|
-
schemaFilePath = path.resolve(config.data,
|
|
45
|
+
entryFolderPath = path.resolve(config.data, (config.branchName || ""), config.modules.entries.dirName)
|
|
46
|
+
localesFilePath = path.resolve(config.data, (config.branchName || ""), config.modules.locales.dirName, config.modules.locales.fileName)
|
|
47
|
+
schemaFilePath = path.resolve(config.data, (config.branchName || ""), config.modules.content_types.dirName, 'schema.json')
|
|
48
48
|
client = stack.Client(config)
|
|
49
49
|
addlogs(config, 'Starting entry migration', 'success')
|
|
50
50
|
return new Promise(function (resolve, reject) {
|
|
@@ -130,7 +130,7 @@ exportEntries.prototype.getEntries = function (apiDetails) {
|
|
|
130
130
|
},
|
|
131
131
|
}
|
|
132
132
|
client.stack({api_key: config.source_stack, management_token: config.management_token}).contentType(apiDetails.content_type).entry().query(queryrequestObject).find()
|
|
133
|
-
|
|
133
|
+
.then(entriesList => {
|
|
134
134
|
// /entries/content_type_uid/locale.json
|
|
135
135
|
if (!fs.existsSync(path.join(entryFolderPath, apiDetails.content_type))) {
|
|
136
136
|
mkdirp.sync(path.join(entryFolderPath, apiDetails.content_type))
|
|
@@ -179,9 +179,9 @@ exportEntries.prototype.getEntries = function (apiDetails) {
|
|
|
179
179
|
})
|
|
180
180
|
})
|
|
181
181
|
}
|
|
182
|
-
if (apiDetails.skip > entriesList.
|
|
183
|
-
addlogs(config, '
|
|
184
|
-
'
|
|
182
|
+
if (apiDetails.skip > entriesList.count) {
|
|
183
|
+
addlogs(config, 'Exported entries of ' + apiDetails.content_type +
|
|
184
|
+
' to the ' + apiDetails.locale + ' language successfully', 'success')
|
|
185
185
|
return resolve()
|
|
186
186
|
}
|
|
187
187
|
apiDetails.skip += limit
|
|
@@ -26,11 +26,13 @@ function ExportEnvironments() {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
ExportEnvironments.prototype.start = function (mergConfig) {
|
|
29
|
+
this.master = {}
|
|
30
|
+
this.environments = {}
|
|
29
31
|
let self = this
|
|
30
32
|
config = mergConfig
|
|
31
33
|
addlogs(config, 'Starting environment export', 'success')
|
|
32
34
|
const environmentConfig = config.modules.environments
|
|
33
|
-
const environmentsFolderPath = path.resolve(config.data, environmentConfig.dirName)
|
|
35
|
+
const environmentsFolderPath = path.resolve(config.data, (config.branchName || ""), environmentConfig.dirName)
|
|
34
36
|
// Create folder for environments
|
|
35
37
|
mkdirp.sync(environmentsFolderPath)
|
|
36
38
|
let client = stack.Client(config)
|
|
@@ -50,7 +52,7 @@ ExportEnvironments.prototype.start = function (mergConfig) {
|
|
|
50
52
|
return resolve()
|
|
51
53
|
}
|
|
52
54
|
if (environmentResponse.items.length === 0) {
|
|
53
|
-
addlogs(config, 'No environments
|
|
55
|
+
addlogs(config, 'No environments found', 'success')
|
|
54
56
|
return resolve()
|
|
55
57
|
}
|
|
56
58
|
}).catch(error => {
|
|
@@ -25,10 +25,12 @@ function ExportExtensions() {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
ExportExtensions.prototype.start = function (mergeConfig) {
|
|
28
|
+
this.master = {}
|
|
29
|
+
this.extensions = {}
|
|
28
30
|
addlogs(config, 'Starting extension export', 'success')
|
|
29
31
|
let self = this
|
|
30
32
|
config = mergeConfig
|
|
31
|
-
let extensionsFolderPath = path.resolve(config.data, extensionConfig.dirName)
|
|
33
|
+
let extensionsFolderPath = path.resolve(config.data, (config.branchName || ""), extensionConfig.dirName)
|
|
32
34
|
// Create folder for extensions
|
|
33
35
|
mkdirp.sync(extensionsFolderPath)
|
|
34
36
|
let client = stack.Client(config)
|
|
@@ -47,7 +49,7 @@ ExportExtensions.prototype.start = function (mergeConfig) {
|
|
|
47
49
|
addlogs(config, chalk.green('All the extensions have been exported successfully'), 'success')
|
|
48
50
|
return resolve()
|
|
49
51
|
}
|
|
50
|
-
addlogs(config,
|
|
52
|
+
addlogs(config, 'No extensions found', 'success')
|
|
51
53
|
return resolve()
|
|
52
54
|
}).catch(error => {
|
|
53
55
|
addlogs(config, error, 'error')
|
|
@@ -1,113 +1,139 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
2
|
+
* Contentstack Export
|
|
3
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require(
|
|
8
|
-
const path = require(
|
|
9
|
-
const chalk = require(
|
|
7
|
+
const mkdirp = require("mkdirp");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const chalk = require("chalk");
|
|
10
10
|
|
|
11
|
-
const stack = require(
|
|
12
|
-
const helper = require(
|
|
13
|
-
const {addlogs} = require(
|
|
14
|
-
|
|
15
|
-
let config = require('../../config/default')
|
|
16
|
-
const globalfieldsConfig = config.modules.globalfields
|
|
17
|
-
const globalfieldsFolderPath = path.resolve(config.data, globalfieldsConfig.dirName)
|
|
18
|
-
const validKeys = globalfieldsConfig.validKeys
|
|
19
|
-
const limit = 100
|
|
20
|
-
|
|
21
|
-
// Create folder for Global Fields
|
|
22
|
-
mkdirp.sync(globalfieldsFolderPath)
|
|
11
|
+
const stack = require("../util/contentstack-management-sdk");
|
|
12
|
+
const helper = require("../util/helper");
|
|
13
|
+
const { addlogs } = require("../util/log");
|
|
23
14
|
|
|
15
|
+
let config = require("../../config/default");
|
|
16
|
+
const limit = 100;
|
|
17
|
+
const validKeys = config.modules.globalfields.validKeys;
|
|
18
|
+
let globalfieldsFolderPath;
|
|
19
|
+
const globalfieldsConfig = config.modules.globalfields;
|
|
24
20
|
function ExportGlobalFields() {
|
|
25
|
-
this.global_fields = []
|
|
21
|
+
this.global_fields = [];
|
|
26
22
|
this.requestOptions = {
|
|
27
23
|
qs: {
|
|
28
24
|
include_count: true,
|
|
29
|
-
asc:
|
|
25
|
+
asc: "updated_at",
|
|
30
26
|
limit: limit,
|
|
31
27
|
},
|
|
32
|
-
}
|
|
33
|
-
this.master = {}
|
|
34
|
-
this.globalfields = {}
|
|
28
|
+
};
|
|
29
|
+
this.master = {};
|
|
30
|
+
this.globalfields = {};
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
ExportGlobalFields.prototype = {
|
|
38
34
|
start: function (credentialConfig) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
this.master = {};
|
|
36
|
+
this.globalfields = {};
|
|
37
|
+
config = {...config, ...credentialConfig};
|
|
38
|
+
globalfieldsFolderPath = path.resolve(
|
|
39
|
+
config.data,
|
|
40
|
+
(config.branchName || ""),
|
|
41
|
+
globalfieldsConfig.dirName
|
|
42
|
+
);
|
|
43
|
+
// Create folder for Global Fields
|
|
44
|
+
mkdirp.sync(globalfieldsFolderPath);
|
|
45
|
+
const self = this;
|
|
46
|
+
addlogs(config, "Starting Global Fields export", "success");
|
|
42
47
|
return new Promise(function (resolve, reject) {
|
|
43
48
|
try {
|
|
44
|
-
return self
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
return self
|
|
50
|
+
.getGlobalFields(null, config)
|
|
51
|
+
.then(function (result) {
|
|
52
|
+
if (!result) {
|
|
53
|
+
return self
|
|
54
|
+
.writeGlobalFields()
|
|
55
|
+
.then(() => {
|
|
56
|
+
return resolve();
|
|
57
|
+
})
|
|
58
|
+
.catch((error) => {
|
|
59
|
+
return reject(error);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return resolve();
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
return reject(error);
|
|
66
|
+
});
|
|
56
67
|
} catch (error) {
|
|
57
|
-
return reject(error)
|
|
68
|
+
return reject(error);
|
|
58
69
|
}
|
|
59
|
-
})
|
|
70
|
+
});
|
|
60
71
|
},
|
|
61
|
-
getGlobalFields: function (skip,
|
|
62
|
-
const self = this
|
|
63
|
-
if (typeof skip !==
|
|
64
|
-
skip = 0
|
|
65
|
-
self.requestOptions.qs.skip = skip
|
|
72
|
+
getGlobalFields: function (skip, globalFieldConfig) {
|
|
73
|
+
const self = this;
|
|
74
|
+
if (typeof skip !== "number") {
|
|
75
|
+
skip = 0;
|
|
76
|
+
self.requestOptions.qs.skip = skip;
|
|
66
77
|
} else {
|
|
67
|
-
self.requestOptions.qs.skip = skip
|
|
78
|
+
self.requestOptions.qs.skip = skip;
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
let client = stack.Client(
|
|
80
|
+
|
|
81
|
+
let client = stack.Client(globalFieldConfig);
|
|
71
82
|
return new Promise(function (resolve, reject) {
|
|
72
|
-
client
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
client
|
|
84
|
+
.stack({
|
|
85
|
+
api_key: globalFieldConfig.source_stack,
|
|
86
|
+
management_token: globalFieldConfig.management_token,
|
|
87
|
+
})
|
|
88
|
+
.globalField()
|
|
89
|
+
.query(self.requestOptions.qs)
|
|
90
|
+
.find()
|
|
91
|
+
.then((globalFieldResponse) => {
|
|
92
|
+
try {
|
|
93
|
+
if (globalFieldResponse.items.length === 0) {
|
|
94
|
+
addlogs(globalFieldConfig, "No global fields found", "success");
|
|
95
|
+
return resolve("No Global Fields");
|
|
84
96
|
}
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
globalFieldResponse.items.forEach(function (globalField) {
|
|
98
|
+
for (const key in globalField) {
|
|
99
|
+
if (validKeys.indexOf(key) === -1) {
|
|
100
|
+
delete globalField[key];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
self.global_fields.push(globalField);
|
|
104
|
+
});
|
|
87
105
|
|
|
88
|
-
|
|
106
|
+
skip += limit;
|
|
89
107
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
if (skip > globalFieldResponse.count) {
|
|
109
|
+
return resolve();
|
|
110
|
+
}
|
|
93
111
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
return self
|
|
113
|
+
.getGlobalFields(skip, globalFieldConfig)
|
|
114
|
+
.then(resolve)
|
|
115
|
+
.catch(reject);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return reject(error);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
102
121
|
},
|
|
103
122
|
writeGlobalFields: function () {
|
|
104
|
-
const self = this
|
|
123
|
+
const self = this;
|
|
105
124
|
return new Promise(function (resolve) {
|
|
106
|
-
helper.writeFile(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
helper.writeFile(
|
|
126
|
+
path.join(globalfieldsFolderPath, globalfieldsConfig.fileName),
|
|
127
|
+
self.global_fields
|
|
128
|
+
);
|
|
129
|
+
addlogs(
|
|
130
|
+
config,
|
|
131
|
+
chalk.green("Global Fields export completed successfully"),
|
|
132
|
+
"success"
|
|
133
|
+
);
|
|
134
|
+
return resolve();
|
|
135
|
+
});
|
|
110
136
|
},
|
|
111
|
-
}
|
|
137
|
+
};
|
|
112
138
|
|
|
113
|
-
module.exports = new ExportGlobalFields()
|
|
139
|
+
module.exports = new ExportGlobalFields();
|
package/src/lib/export/labels.js
CHANGED
|
@@ -28,10 +28,11 @@ function ExportLabels() {
|
|
|
28
28
|
|
|
29
29
|
ExportLabels.prototype.start = function (credentialConfig) {
|
|
30
30
|
addlogs(config, 'Starting labels export', 'success')
|
|
31
|
+
this.labels = {}
|
|
31
32
|
let self = this
|
|
32
33
|
config = credentialConfig
|
|
33
34
|
client = stack.Client(config)
|
|
34
|
-
let labelsFolderPath = path.resolve(config.data, labelConfig.dirName)
|
|
35
|
+
let labelsFolderPath = path.resolve(config.data, (config.branchName || ""), labelConfig.dirName)
|
|
35
36
|
// Create locale folder
|
|
36
37
|
mkdirp.sync(labelsFolderPath)
|
|
37
38
|
return new Promise(function (resolve, reject) {
|
|
@@ -39,13 +40,14 @@ ExportLabels.prototype.start = function (credentialConfig) {
|
|
|
39
40
|
.then((response) => {
|
|
40
41
|
if (response.items.length !== 0) {
|
|
41
42
|
response.items.forEach(function (label) {
|
|
42
|
-
|
|
43
|
-
addlogs(config, chalk.white(label.name + ' labels was exported successfully'), 'success')
|
|
43
|
+
addlogs(config, label.name + ' labels was exported successfully', 'success')
|
|
44
44
|
self.labels[label.uid] = label
|
|
45
|
+
let deleteItems = config.modules.labels.invalidKeys
|
|
46
|
+
deleteItems.forEach(e => delete label[e])
|
|
45
47
|
})
|
|
46
48
|
addlogs(config, chalk.green('All the labels have been exported successfully'), 'success')
|
|
47
49
|
} else {
|
|
48
|
-
addlogs(config, 'No labels
|
|
50
|
+
addlogs(config, 'No labels found', 'success')
|
|
49
51
|
}
|
|
50
52
|
helper.writeFile(path.join(labelsFolderPath, labelConfig.fileName), self.labels)
|
|
51
53
|
return resolve()
|
|
@@ -16,6 +16,7 @@ const masterLocale = config.master_locale
|
|
|
16
16
|
let requiredKeys = localeConfig.requiredKeys
|
|
17
17
|
let stack = require('../util/contentstack-management-sdk')
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
function ExportLocales() {
|
|
20
21
|
this.qs = {
|
|
21
22
|
include_count: true,
|
|
@@ -33,10 +34,11 @@ function ExportLocales() {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
ExportLocales.prototype.start = function (credentialConfig) {
|
|
37
|
+
this.locales = {}
|
|
36
38
|
addlogs(credentialConfig, 'Starting locale export', 'success')
|
|
37
39
|
let self = this
|
|
38
40
|
config = credentialConfig
|
|
39
|
-
let localesFolderPath = path.resolve(config.data, localeConfig.dirName)
|
|
41
|
+
let localesFolderPath = path.resolve(config.data, (config.branchName || ""), localeConfig.dirName)
|
|
40
42
|
mkdirp.sync(localesFolderPath)
|
|
41
43
|
|
|
42
44
|
let client = stack.Client(config)
|
|
@@ -45,23 +47,23 @@ ExportLocales.prototype.start = function (credentialConfig) {
|
|
|
45
47
|
.then(localeResponse => {
|
|
46
48
|
if (localeResponse.items.length !== 0) {
|
|
47
49
|
localeResponse.items.forEach(function (locale) {
|
|
48
|
-
addlogs(credentialConfig, 'locale was exported successfully', 'success')
|
|
50
|
+
addlogs(credentialConfig, locale.name + ' locale was exported successfully', 'success')
|
|
49
51
|
for (const key in locale) {
|
|
50
52
|
if (requiredKeys.indexOf(key) === -1) {
|
|
51
|
-
delete locale
|
|
53
|
+
delete locale[key]
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
self.locales[locale.uid] = locale
|
|
55
57
|
})
|
|
56
58
|
addlogs(credentialConfig, chalk.green('All the locales have been exported successfully'), 'success')
|
|
57
59
|
} else if (localeResponse.items.length === 0) {
|
|
58
|
-
addlogs(credentialConfig, 'No
|
|
60
|
+
addlogs(credentialConfig, 'No languages found except the master language', 'success')
|
|
59
61
|
}
|
|
60
62
|
helper.writeFile(path.join(localesFolderPath, localeConfig.fileName), self.locales)
|
|
61
|
-
resolve()
|
|
63
|
+
return resolve()
|
|
62
64
|
}).catch(error => {
|
|
63
65
|
addlogs(credentialConfig, error, 'error')
|
|
64
|
-
reject()
|
|
66
|
+
return reject()
|
|
65
67
|
})
|
|
66
68
|
})
|
|
67
69
|
}
|
package/src/lib/export/stack.js
CHANGED
|
@@ -8,10 +8,11 @@ var chalk = require('chalk')
|
|
|
8
8
|
var mkdirp = require('mkdirp')
|
|
9
9
|
var path = require('path')
|
|
10
10
|
|
|
11
|
-
var request = require('../util/request')
|
|
12
11
|
var app = require('../../app')
|
|
13
12
|
var helper = require('../util/helper')
|
|
14
13
|
var {addlogs} = require('../util/log')
|
|
14
|
+
const stack = require('../util/contentstack-management-sdk')
|
|
15
|
+
|
|
15
16
|
|
|
16
17
|
let config = require('../../config/default')
|
|
17
18
|
|
|
@@ -28,22 +29,39 @@ function ExportStack () {
|
|
|
28
29
|
|
|
29
30
|
ExportStack.prototype.start = function (credentialConfig) {
|
|
30
31
|
config = credentialConfig
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
client = stack.Client(config)
|
|
33
|
+
if (!config.preserveStackVersion && !config.hasOwnProperty("master_locale")) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var result = client.stack({ api_key: credentialConfig.source_stack, management_token: credentialConfig.management_token }).locale().query()
|
|
36
|
+
result.find()
|
|
37
|
+
.then(response => {
|
|
38
|
+
var masterLocalObj = response.items.filter(obj => {
|
|
39
|
+
if (obj.fallback_locale === null) {
|
|
40
|
+
return obj
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return resolve(masterLocalObj[0])
|
|
44
|
+
}).catch(error => {
|
|
45
|
+
return reject(error)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
} else if(config.preserveStackVersion) {
|
|
49
|
+
addlogs(config, 'Exporting stack details', 'success')
|
|
50
|
+
let stackFolderPath = path.resolve(config.data, stackConfig.dirName)
|
|
51
|
+
let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName)
|
|
52
|
+
|
|
53
|
+
mkdirp.sync(stackFolderPath)
|
|
54
|
+
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
return client.stack({api_key: config.source_stack}).fetch()
|
|
57
|
+
.then(response => {
|
|
58
|
+
helper.writeFile(stackContentsFile, response)
|
|
59
|
+
addlogs(config, 'Exported stack details successfully!', 'success')
|
|
60
|
+
return resolve(response)
|
|
61
|
+
})
|
|
62
|
+
.catch(reject)
|
|
44
63
|
})
|
|
45
|
-
|
|
46
|
-
})
|
|
64
|
+
}
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
module.exports = new ExportStack()
|
|
@@ -29,10 +29,12 @@ function ExportWebhooks() {
|
|
|
29
29
|
|
|
30
30
|
ExportWebhooks.prototype.start = function (credentialConfig) {
|
|
31
31
|
addlogs(config, 'Starting webhooks export', 'success')
|
|
32
|
+
this.master = {}
|
|
33
|
+
this.webhooks = {}
|
|
32
34
|
let self = this
|
|
33
35
|
config = credentialConfig
|
|
34
36
|
client = stack.Client(config)
|
|
35
|
-
const webhooksFolderPath = path.resolve(config.data, webhooksConfig.dirName)
|
|
37
|
+
const webhooksFolderPath = path.resolve(config.data, (config.branchName || ""), webhooksConfig.dirName)
|
|
36
38
|
mkdirp.sync(webhooksFolderPath)
|
|
37
39
|
return new Promise(function (resolve, reject) {
|
|
38
40
|
client.stack({api_key: config.source_stack, management_token: config.management_token}).webhook().fetchAll(self.requestOptions)
|
|
@@ -49,7 +51,7 @@ ExportWebhooks.prototype.start = function (credentialConfig) {
|
|
|
49
51
|
addlogs(config, chalk.green('All the webhooks have been exported successfully'), 'success')
|
|
50
52
|
return resolve()
|
|
51
53
|
}
|
|
52
|
-
addlogs(config, 'No webhooks
|
|
54
|
+
addlogs(config, 'No webhooks found', 'success')
|
|
53
55
|
return resolve()
|
|
54
56
|
}).catch(function (error) {
|
|
55
57
|
if (error.statusCode === 401) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Contentstack Export
|
|
3
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const mkdirp = require('mkdirp')
|
|
8
|
+
const path = require('path')
|
|
9
|
+
const chalk = require('chalk')
|
|
10
|
+
|
|
11
|
+
let helper = require('../util/helper')
|
|
12
|
+
let {addlogs} = require('../util/log')
|
|
13
|
+
|
|
14
|
+
const stack = require('../util/contentstack-management-sdk')
|
|
15
|
+
let config = require('../../config/default')
|
|
16
|
+
let workFlowConfig = config.modules.workflows
|
|
17
|
+
let client
|
|
18
|
+
|
|
19
|
+
function ExportWorkFlows() {
|
|
20
|
+
this.workflows = {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ExportWorkFlows.prototype.start = function (credentialConfig) {
|
|
24
|
+
addlogs(config, 'Starting workflow export', 'success')
|
|
25
|
+
this.workflows = {}
|
|
26
|
+
let self = this
|
|
27
|
+
config = credentialConfig
|
|
28
|
+
client = stack.Client(config)
|
|
29
|
+
|
|
30
|
+
let workflowsFolderPath = path.resolve(config.data, (config.branchName || ""), workFlowConfig.dirName)
|
|
31
|
+
mkdirp.sync(workflowsFolderPath)
|
|
32
|
+
return new Promise(function (resolve, reject) {
|
|
33
|
+
return client.stack({api_key: config.source_stack, management_token: config.management_token}).workflow().fetchAll()
|
|
34
|
+
.then(response => {
|
|
35
|
+
if (response.items.length !== 0) {
|
|
36
|
+
response.items.forEach(function (workflow) {
|
|
37
|
+
addlogs(config, workflow.name + ' workflow was exported successfully', 'success')
|
|
38
|
+
self.workflows[workflow.uid] = workflow
|
|
39
|
+
let deleteItems = config.modules.workflows.invalidKeys
|
|
40
|
+
deleteItems.forEach(e => delete workflow[e])
|
|
41
|
+
})
|
|
42
|
+
addlogs(config, chalk.green('All the workflow have been exported successfully'), 'success')
|
|
43
|
+
}
|
|
44
|
+
if (response.items.length === 0) {
|
|
45
|
+
addlogs(config, 'No workflow were found in the Stack', 'success')
|
|
46
|
+
}
|
|
47
|
+
helper.writeFile(path.join(workflowsFolderPath, workFlowConfig.fileName), self.workflows)
|
|
48
|
+
return resolve()
|
|
49
|
+
}).catch(function (error) {
|
|
50
|
+
if (error.statusCode === 401) {
|
|
51
|
+
addlogs(config, chalk.red('You are not allowed to export workflow, Unless you provide email and password in config', 'error'))
|
|
52
|
+
return resolve()
|
|
53
|
+
}
|
|
54
|
+
addlogs(config, error, 'error')
|
|
55
|
+
return resolve()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = new ExportWorkFlows()
|