@contentstack/cli-cm-export 1.1.0 → 1.2.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.
- package/README.md +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +14 -5
- package/src/app.js +52 -45
- package/src/commands/cm/stacks/export.js +3 -3
- package/src/config/default.js +8 -6
- package/src/lib/export/assets.js +254 -228
- package/src/lib/export/content-types.js +72 -101
- package/src/lib/export/custom-roles.js +83 -68
- package/src/lib/export/entries.js +168 -225
- package/src/lib/export/environments.js +57 -52
- package/src/lib/export/extensions.js +50 -46
- package/src/lib/export/global-fields.js +64 -61
- package/src/lib/export/labels.js +57 -57
- package/src/lib/export/locales.js +57 -91
- package/src/lib/export/marketplace-apps.js +120 -122
- package/src/lib/export/stack.js +22 -24
- package/src/lib/export/webhooks.js +59 -54
- package/src/lib/export/workflows.js +86 -78
- package/src/lib/util/export-flags.js +7 -8
- package/src/lib/util/helper.js +83 -2
- package/src/lib/util/index.js +36 -1
- package/src/lib/util/log.js +6 -3
- package/src/lib/util/marketplace-app-helper.js +25 -6
- package/src/lib/util/setup-branches.js +5 -7
|
@@ -1,252 +1,195 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
1
|
const path = require('path');
|
|
9
|
-
const _ = require('lodash');
|
|
10
|
-
const Promise = require('bluebird');
|
|
11
2
|
const chalk = require('chalk');
|
|
12
|
-
const mkdirp = require('mkdirp');
|
|
13
3
|
const { addlogs } = require('../util/log');
|
|
4
|
+
const fileHelper = require('../util/helper');
|
|
5
|
+
const { executeTask, formatError } = require('../util');
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
class EntriesExport {
|
|
8
|
+
constructor(exportConfig, stackAPIClient) {
|
|
9
|
+
this.stackAPIClient = stackAPIClient;
|
|
10
|
+
this.exportConfig = exportConfig;
|
|
11
|
+
this.entriesConfig = exportConfig.modules.entries;
|
|
12
|
+
this.entriesRootPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName);
|
|
13
|
+
this.localesFilePath = path.resolve(
|
|
14
|
+
exportConfig.data,
|
|
15
|
+
exportConfig.branchName || '',
|
|
16
|
+
exportConfig.modules.locales.dirName,
|
|
17
|
+
exportConfig.modules.locales.fileName,
|
|
18
|
+
);
|
|
19
|
+
this.schemaFilePath = path.resolve(
|
|
20
|
+
exportConfig.data,
|
|
21
|
+
exportConfig.branchName || '',
|
|
22
|
+
exportConfig.modules.content_types.dirName,
|
|
23
|
+
'schema.json',
|
|
24
|
+
);
|
|
25
|
+
this.fetchConcurrency = this.entriesConfig.fetchConcurrency || exportConfig.fetchConcurrency;
|
|
26
|
+
this.writeConcurrency = this.entriesConfig.writeConcurrency || exportConfig.writeConcurrency;
|
|
27
|
+
}
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
async start() {
|
|
30
|
+
try {
|
|
31
|
+
addlogs(this.exportConfig, 'Starting entries export', 'info');
|
|
32
|
+
const locales = await fileHelper.readFile(this.localesFilePath);
|
|
33
|
+
const contentTypes = await fileHelper.readFile(this.schemaFilePath);
|
|
34
|
+
if (contentTypes.length === 0) {
|
|
35
|
+
addlogs(this.exportConfig, 'No content types found to export entries');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const entryRequestOptions = this.createRequestObjects(locales, contentTypes);
|
|
39
|
+
for (let requestOption of entryRequestOptions) {
|
|
40
|
+
await fileHelper.makeDirectory(path.join(this.entriesRootPath, requestOption.content_type));
|
|
41
|
+
const entries = await this.getEntries(requestOption);
|
|
42
|
+
let entriesFilePath = path.join(
|
|
43
|
+
this.entriesRootPath,
|
|
44
|
+
requestOption.content_type,
|
|
45
|
+
requestOption.locale + '.json',
|
|
46
|
+
);
|
|
47
|
+
await fileHelper.writeFile(entriesFilePath, entries);
|
|
48
|
+
addlogs(
|
|
49
|
+
this.exportConfig,
|
|
50
|
+
`Exported entries of type ${requestOption.content_type} locale ${requestOption.locale}`,
|
|
51
|
+
'success',
|
|
52
|
+
);
|
|
53
|
+
if (this.exportConfig.versioning) {
|
|
54
|
+
addlogs(
|
|
55
|
+
this.exportConfig,
|
|
56
|
+
`Started export versioned entries of type ${requestOption.content_type} locale ${requestOption.locale}`,
|
|
57
|
+
'info',
|
|
58
|
+
);
|
|
59
|
+
for (let entry of entries) {
|
|
60
|
+
const versionedEntries = await this.getEntryByVersion(
|
|
61
|
+
{
|
|
62
|
+
...requestOption,
|
|
63
|
+
uid: entry.uid,
|
|
64
|
+
},
|
|
65
|
+
entry._version,
|
|
66
|
+
);
|
|
67
|
+
let versionedEntryPath = path.join(
|
|
68
|
+
this.entriesRootPath,
|
|
69
|
+
requestOption.locale,
|
|
70
|
+
requestOption.content_type,
|
|
71
|
+
entry.uid,
|
|
72
|
+
);
|
|
73
|
+
await fileHelper.makeDirectory(versionedEntryPath);
|
|
74
|
+
if (versionedEntries.length > 0) {
|
|
75
|
+
const write = (versionedEntry) =>
|
|
76
|
+
fileHelper.writeFile(
|
|
77
|
+
path.join(versionedEntryPath, 'version-' + versionedEntry._version + '.json'),
|
|
78
|
+
versionedEntry,
|
|
79
|
+
);
|
|
80
|
+
await executeTask(versionedEntries, write.bind(this), { concurrency: this.writeConcurrency });
|
|
81
|
+
addlogs(
|
|
82
|
+
this.exportConfig,
|
|
83
|
+
`Exported versioned entries of type ${requestOption.content_type} locale ${requestOption.locale}`,
|
|
84
|
+
'success',
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
addlogs(this.exportConfig, chalk.green('Entries exported successfully'), 'success');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
addlogs(this.exportConfig, chalk.red(`Failed to export entries ${formatError(error)}`), 'error');
|
|
93
|
+
throw new Error('Failed to export entries');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
29
96
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
97
|
+
async getEntries(requestOptions, skip = 0, entries = {}) {
|
|
98
|
+
let requestObject = {
|
|
99
|
+
locale: requestOptions.locale,
|
|
100
|
+
skip,
|
|
101
|
+
limit: this.entriesConfig.limit,
|
|
34
102
|
include_count: true,
|
|
35
103
|
include_publish_details: true,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
104
|
+
query: {
|
|
105
|
+
locale: requestOptions.locale,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
41
108
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'schema.json',
|
|
57
|
-
);
|
|
58
|
-
client = stack.Client(config);
|
|
59
|
-
addlogs(config, 'Starting entry migration', 'success');
|
|
60
|
-
return new Promise(function (resolve) {
|
|
61
|
-
locales = helper.readFile(localesFilePath);
|
|
62
|
-
let apiBucket = [];
|
|
63
|
-
content_types = helper.readFile(schemaFilePath);
|
|
64
|
-
if (content_types.length !== 0) {
|
|
65
|
-
content_types.forEach((content_type) => {
|
|
66
|
-
if (Object.keys(locales).length !== 0) {
|
|
67
|
-
for (let _locale in locales) {
|
|
68
|
-
apiBucket.push({
|
|
69
|
-
content_type: content_type.uid,
|
|
70
|
-
locale: locales[_locale].code,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
apiBucket.push({
|
|
75
|
-
content_type: content_type.uid,
|
|
76
|
-
locale: config.master_locale.code,
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
return Promise.map(
|
|
80
|
-
apiBucket,
|
|
81
|
-
function (apiDetails) {
|
|
82
|
-
return self.getEntries(apiDetails);
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
concurrency: 1,
|
|
86
|
-
},
|
|
87
|
-
)
|
|
88
|
-
.then(function () {
|
|
89
|
-
addlogs(config, 'Entry migration completed successfully', 'success');
|
|
90
|
-
return resolve();
|
|
91
|
-
})
|
|
92
|
-
.catch((error) => {
|
|
93
|
-
console.log('Error getting entries', error && error.message);
|
|
94
|
-
});
|
|
109
|
+
const entriesSearchResponse = await this.stackAPIClient
|
|
110
|
+
.contentType(requestOptions.content_type)
|
|
111
|
+
.entry()
|
|
112
|
+
.query(requestObject)
|
|
113
|
+
.find();
|
|
114
|
+
|
|
115
|
+
if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) {
|
|
116
|
+
// clean up attribs and add to parent entry list
|
|
117
|
+
this.sanitizeAttribs(entriesSearchResponse.items, entries);
|
|
118
|
+
skip += this.entriesConfig.limit || 100;
|
|
119
|
+
if (skip > entriesSearchResponse.count) {
|
|
120
|
+
return entries;
|
|
121
|
+
}
|
|
122
|
+
return await this.getEntries(requestOptions, skip, entries);
|
|
95
123
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
};
|
|
124
|
+
return entries;
|
|
125
|
+
}
|
|
100
126
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
let queryRequestObject = {
|
|
105
|
-
locale: apiDetails.locale,
|
|
127
|
+
async getEntryByVersion(requestOptions, version, entries = []) {
|
|
128
|
+
const queryRequestObject = {
|
|
129
|
+
locale: requestOptions.locale,
|
|
106
130
|
except: {
|
|
107
|
-
BASE: invalidKeys,
|
|
131
|
+
BASE: this.entriesConfig.invalidKeys,
|
|
108
132
|
},
|
|
109
|
-
version
|
|
133
|
+
version,
|
|
110
134
|
};
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
.
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
mkdirp.sync(entryPath);
|
|
119
|
-
helper.writeFile(path.join(entryPath, 'version-' + singleEntry._version + '.json'), singleEntry);
|
|
120
|
-
addlogs(
|
|
121
|
-
config,
|
|
122
|
-
'Completed version backup of entry: ' +
|
|
123
|
-
singleEntry.uid +
|
|
124
|
-
', version: ' +
|
|
125
|
-
singleEntry._version +
|
|
126
|
-
', content type: ' +
|
|
127
|
-
apiDetails.content_type,
|
|
128
|
-
'success',
|
|
129
|
-
);
|
|
130
|
-
if (--apiDetails.version !== 0) {
|
|
131
|
-
return self.getEntry(apiDetails).then(resolve).catch(reject);
|
|
132
|
-
}
|
|
133
|
-
return resolve();
|
|
134
|
-
})
|
|
135
|
-
.catch((error) => {
|
|
136
|
-
addlogs(config, error, 'error');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
exportEntries.prototype.getEntries = function (apiDetails) {
|
|
142
|
-
let self = this;
|
|
143
|
-
return new Promise(function (resolve, reject) {
|
|
144
|
-
if (typeof apiDetails.skip !== 'number') {
|
|
145
|
-
apiDetails.skip = 0;
|
|
135
|
+
const entryResponse = await this.stackAPIClient
|
|
136
|
+
.contentType(requestOptions.content_type)
|
|
137
|
+
.entry(requestOptions.uid)
|
|
138
|
+
.fetch(queryRequestObject);
|
|
139
|
+
entries.push(entryResponse);
|
|
140
|
+
if (--version > 0) {
|
|
141
|
+
return await this.getEntryByVersion(requestOptions, version, entries);
|
|
146
142
|
}
|
|
143
|
+
return entries;
|
|
144
|
+
}
|
|
147
145
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
limit:
|
|
146
|
+
async getEntriesCount(requestOptions) {
|
|
147
|
+
let requestObject = {
|
|
148
|
+
locale: requestOptions.locale,
|
|
149
|
+
limit: 1,
|
|
152
150
|
include_count: true,
|
|
153
151
|
include_publish_details: true,
|
|
154
152
|
query: {
|
|
155
|
-
locale:
|
|
153
|
+
locale: requestOptions.locale,
|
|
156
154
|
},
|
|
157
155
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.contentType(
|
|
156
|
+
|
|
157
|
+
const entriesSearchResponse = await this.stackAPIClient
|
|
158
|
+
.contentType(requestOptions.content_type)
|
|
161
159
|
.entry()
|
|
162
|
-
.query(
|
|
163
|
-
.find()
|
|
164
|
-
.then((entriesList) => {
|
|
165
|
-
// /entries/content_type_uid/locale.json
|
|
166
|
-
if (!fs.existsSync(path.join(entryFolderPath, apiDetails.content_type))) {
|
|
167
|
-
mkdirp.sync(path.join(entryFolderPath, apiDetails.content_type));
|
|
168
|
-
}
|
|
169
|
-
let entriesFilePath = path.join(entryFolderPath, apiDetails.content_type, apiDetails.locale + '.json');
|
|
170
|
-
let entries = helper.readFile(entriesFilePath);
|
|
171
|
-
entries = entries || {};
|
|
172
|
-
entriesList.items.forEach(function (entry) {
|
|
173
|
-
invalidKeys.forEach((e) => delete entry[e]);
|
|
174
|
-
entries[entry.uid] = entry;
|
|
175
|
-
});
|
|
176
|
-
helper.writeFile(entriesFilePath, entries);
|
|
160
|
+
.query(requestObject)
|
|
161
|
+
.find();
|
|
177
162
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
function (entry) {
|
|
190
|
-
let entryDetails = {
|
|
191
|
-
content_type: apiDetails.content_type,
|
|
192
|
-
uid: entry.uid,
|
|
193
|
-
version: entry._version,
|
|
194
|
-
locale: apiDetails.locale,
|
|
195
|
-
};
|
|
196
|
-
return self.getEntry(entryDetails).catch(reject);
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
concurrency: 1,
|
|
200
|
-
},
|
|
201
|
-
).then(function () {
|
|
202
|
-
if (apiDetails.skip > entriesList.items.length) {
|
|
203
|
-
addlogs(
|
|
204
|
-
config,
|
|
205
|
-
'Completed fetching ' +
|
|
206
|
-
apiDetails.content_type +
|
|
207
|
-
" content type's entries in " +
|
|
208
|
-
apiDetails.locale +
|
|
209
|
-
' locale',
|
|
210
|
-
'success',
|
|
211
|
-
);
|
|
212
|
-
return resolve();
|
|
213
|
-
}
|
|
214
|
-
apiDetails.skip += limit;
|
|
215
|
-
return self
|
|
216
|
-
.getEntries(apiDetails)
|
|
217
|
-
.then(function () {
|
|
218
|
-
return resolve();
|
|
219
|
-
})
|
|
220
|
-
.catch(function (error) {
|
|
221
|
-
return reject(error);
|
|
222
|
-
});
|
|
163
|
+
return entriesSearchResponse.count;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
createRequestObjects(locales, contentTypes) {
|
|
167
|
+
let requestObjects = [];
|
|
168
|
+
contentTypes.forEach((contentType) => {
|
|
169
|
+
if (Object.keys(locales).length !== 0) {
|
|
170
|
+
for (let locale in locales) {
|
|
171
|
+
requestObjects.push({
|
|
172
|
+
content_type: contentType.uid,
|
|
173
|
+
locale: locales[locale].code,
|
|
223
174
|
});
|
|
224
175
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
apiDetails.content_type +
|
|
230
|
-
' to the ' +
|
|
231
|
-
apiDetails.locale +
|
|
232
|
-
' language successfully',
|
|
233
|
-
'success',
|
|
234
|
-
);
|
|
235
|
-
return resolve();
|
|
236
|
-
}
|
|
237
|
-
apiDetails.skip += limit;
|
|
238
|
-
return self
|
|
239
|
-
.getEntries(apiDetails)
|
|
240
|
-
.then(resolve)
|
|
241
|
-
.catch((error) => {
|
|
242
|
-
console.log('Get Entries errror', error && error.message);
|
|
243
|
-
});
|
|
244
|
-
})
|
|
245
|
-
.catch((error) => {
|
|
246
|
-
console.log('Entries fetch errror', error && error.message);
|
|
247
|
-
addlogs(config, error, 'error');
|
|
176
|
+
}
|
|
177
|
+
requestObjects.push({
|
|
178
|
+
content_type: contentType.uid,
|
|
179
|
+
locale: this.exportConfig.master_locale.code,
|
|
248
180
|
});
|
|
249
|
-
|
|
250
|
-
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return requestObjects;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
sanitizeAttribs(entries, entriesList = {}) {
|
|
187
|
+
entries.forEach((entry) => {
|
|
188
|
+
this.entriesConfig.invalidKeys.forEach((key) => delete entry[key]);
|
|
189
|
+
entriesList[entry.uid] = entry;
|
|
190
|
+
});
|
|
191
|
+
return entriesList;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
251
194
|
|
|
252
|
-
module.exports =
|
|
195
|
+
module.exports = EntriesExport;
|
|
@@ -3,68 +3,73 @@
|
|
|
3
3
|
* Copyright (c) 2019 Contentstack LLC
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
const mkdirp = require('mkdirp');
|
|
8
6
|
const path = require('path');
|
|
9
7
|
const chalk = require('chalk');
|
|
8
|
+
const mkdirp = require('mkdirp');
|
|
10
9
|
|
|
11
10
|
const helper = require('../util/helper');
|
|
12
|
-
let stack = require('../util/contentstack-management-sdk');
|
|
13
11
|
const { addlogs } = require('../util/log');
|
|
14
|
-
|
|
12
|
+
const { formatError } = require('../util');
|
|
13
|
+
let stack = require('../util/contentstack-management-sdk');
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
module.exports = class ExportEnvironments {
|
|
16
|
+
config = {};
|
|
17
|
+
master = {};
|
|
18
|
+
environments = {};
|
|
19
|
+
requestOptions = {
|
|
20
|
+
json: true,
|
|
18
21
|
qs: {
|
|
19
|
-
include_count: true,
|
|
20
22
|
asc: 'updated_at',
|
|
23
|
+
include_count: true,
|
|
21
24
|
},
|
|
22
|
-
json: true,
|
|
23
25
|
};
|
|
24
|
-
this.master = {};
|
|
25
|
-
this.environments = {};
|
|
26
|
-
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
constructor(mergeConfig) {
|
|
28
|
+
this.config = mergeConfig;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
start() {
|
|
32
|
+
const self = this;
|
|
33
|
+
const client = stack.Client(self.config);
|
|
34
|
+
const environmentConfig = self.config.modules.environments;
|
|
35
|
+
const environmentsFolderPath = path.resolve(
|
|
36
|
+
self.config.data,
|
|
37
|
+
self.config.branchName || '',
|
|
38
|
+
environmentConfig.dirName,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Create folder for environments
|
|
42
|
+
mkdirp.sync(environmentsFolderPath);
|
|
43
|
+
addlogs(self.config, 'Starting environment export', 'success');
|
|
44
|
+
|
|
45
|
+
return new Promise(function (resolve, reject) {
|
|
46
|
+
client
|
|
47
|
+
.stack({ api_key: self.config.source_stack, management_token: self.config.management_token })
|
|
48
|
+
.environment()
|
|
49
|
+
.query(self.requestOptions.qs)
|
|
50
|
+
.find()
|
|
51
|
+
.then((environmentResponse) => {
|
|
52
|
+
if (environmentResponse.items.length !== 0) {
|
|
53
|
+
for (let i = 0, total = environmentResponse.count; i < total; i++) {
|
|
54
|
+
let envUid = environmentResponse.items[i].uid;
|
|
55
|
+
self.master[envUid] = '';
|
|
56
|
+
self.environments[envUid] = environmentResponse.items[i];
|
|
57
|
+
delete self.environments[envUid].uid;
|
|
58
|
+
delete self.environments[envUid]['ACL'];
|
|
59
|
+
}
|
|
60
|
+
helper.writeFileSync(path.join(environmentsFolderPath, environmentConfig.fileName), self.environments);
|
|
61
|
+
addlogs(self.config, chalk.green('All the environments have been exported successfully'), 'success');
|
|
62
|
+
return resolve();
|
|
63
|
+
}
|
|
64
|
+
if (environmentResponse.items.length === 0) {
|
|
65
|
+
addlogs(self.config, 'No environments found', 'success');
|
|
66
|
+
resolve();
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
.catch((error) => {
|
|
64
|
-
addlogs(config, error, 'error');
|
|
65
|
-
reject(error);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
+
})
|
|
69
|
+
.catch((error) => {
|
|
70
|
+
addlogs(self.config, `Environments export failed ${formatError(error)}`, 'error');
|
|
71
|
+
reject(error);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
68
75
|
};
|
|
69
|
-
|
|
70
|
-
module.exports = new ExportEnvironments();
|
|
@@ -10,57 +10,61 @@ const chalk = require('chalk');
|
|
|
10
10
|
|
|
11
11
|
const helper = require('../util/helper');
|
|
12
12
|
const { addlogs } = require('../util/log');
|
|
13
|
-
|
|
13
|
+
const { formatError } = require('../util');
|
|
14
14
|
let config = require('../../config/default');
|
|
15
|
-
const extensionConfig = config.modules.extensions;
|
|
16
15
|
const stack = require('../util/contentstack-management-sdk');
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
module.exports = class ExportExtensions {
|
|
18
|
+
master = {};
|
|
19
|
+
extensions = {};
|
|
20
|
+
extensionConfig = config.modules.extensions;
|
|
21
|
+
queryRequestOptions = {
|
|
21
22
|
asc: 'updated_at',
|
|
23
|
+
include_count: true,
|
|
22
24
|
};
|
|
23
|
-
this.master = {};
|
|
24
|
-
this.extensions = {};
|
|
25
|
-
}
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
constructor(mergeConfig) {
|
|
27
|
+
this.config = mergeConfig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
start() {
|
|
31
|
+
addlogs(this.config, 'Starting extension export', 'success');
|
|
32
|
+
|
|
33
|
+
const self = this;
|
|
34
|
+
const extensionsFolderPath = path.resolve(
|
|
35
|
+
this.config.data,
|
|
36
|
+
this.config.branchName || '',
|
|
37
|
+
this.extensionConfig.dirName,
|
|
38
|
+
);
|
|
39
|
+
// Create folder for extensions
|
|
40
|
+
mkdirp.sync(extensionsFolderPath);
|
|
41
|
+
let client = stack.Client(this.config);
|
|
42
|
+
return new Promise(function (resolve, reject) {
|
|
43
|
+
client
|
|
44
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
45
|
+
.extension()
|
|
46
|
+
.query(self.queryRequestOptions)
|
|
47
|
+
.find()
|
|
48
|
+
.then((extension) => {
|
|
49
|
+
if (extension.items.length !== 0) {
|
|
50
|
+
for (let i = 0, total = extension.count; i < total; i++) {
|
|
51
|
+
let extUid = extension.items[i].uid;
|
|
52
|
+
self.master[extUid] = '';
|
|
53
|
+
self.extensions[extUid] = extension.items[i];
|
|
54
|
+
delete self.extensions[extUid].uid;
|
|
55
|
+
delete self.extensions[extUid].SYS_ACL;
|
|
56
|
+
}
|
|
57
|
+
helper.writeFileSync(path.join(extensionsFolderPath, self.extensionConfig.fileName), self.extensions);
|
|
58
|
+
addlogs(self.config, chalk.green('All the extensions have been exported successfully'), 'success');
|
|
59
|
+
return resolve();
|
|
51
60
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return reject();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
61
|
+
addlogs(self.config, 'No extensions found', 'success');
|
|
62
|
+
resolve();
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
addlogs(self.config, `Failed to export extensions ${formatError(error)}`, 'error');
|
|
66
|
+
reject();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
64
70
|
};
|
|
65
|
-
|
|
66
|
-
module.exports = new ExportExtensions();
|