@contentstack/cli-cm-export 0.1.1-beta.9 → 1.1.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 +21 -0
- package/README.md +44 -29
- package/oclif.manifest.json +1 -1
- package/package.json +72 -68
- package/src/app.js +97 -104
- package/src/commands/cm/stacks/export.js +184 -0
- package/src/config/default.js +34 -59
- package/src/lib/export/assets.js +324 -223
- package/src/lib/export/content-types.js +72 -68
- package/src/lib/export/custom-roles.js +91 -0
- package/src/lib/export/entries.js +190 -135
- package/src/lib/export/environments.js +52 -47
- package/src/lib/export/extensions.js +50 -45
- package/src/lib/export/global-fields.js +17 -31
- package/src/lib/export/labels.js +52 -45
- package/src/lib/export/locales.js +74 -42
- package/src/lib/export/marketplace-apps.js +154 -0
- package/src/lib/export/stack.js +87 -47
- package/src/lib/export/webhooks.js +58 -50
- package/src/lib/export/workflows.js +85 -44
- package/src/lib/util/contentstack-management-sdk.js +26 -6
- package/src/lib/util/export-flags.js +140 -126
- package/src/lib/util/helper.js +20 -20
- package/src/lib/util/index.js +32 -19
- package/src/lib/util/log.js +109 -53
- package/src/lib/util/login.js +55 -40
- package/src/lib/util/marketplace-app-helper.js +42 -0
- package/src/lib/util/setup-branches.js +29 -38
- package/src/commands/cm/export.js +0 -142
- package/src/lib/util/request.js +0 -78
|
@@ -1,17 +1,17 @@
|
|
|
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('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
10
|
|
|
11
|
-
const helper = require('../util/helper')
|
|
12
|
-
let stack = require('../util/contentstack-management-sdk')
|
|
13
|
-
const {addlogs} = require('../util/log')
|
|
14
|
-
let config
|
|
11
|
+
const helper = require('../util/helper');
|
|
12
|
+
let stack = require('../util/contentstack-management-sdk');
|
|
13
|
+
const { addlogs } = require('../util/log');
|
|
14
|
+
let config;
|
|
15
15
|
|
|
16
16
|
function ExportEnvironments() {
|
|
17
17
|
this.requestOptions = {
|
|
@@ -20,46 +20,51 @@ function ExportEnvironments() {
|
|
|
20
20
|
asc: 'updated_at',
|
|
21
21
|
},
|
|
22
22
|
json: true,
|
|
23
|
-
}
|
|
24
|
-
this.master = {}
|
|
25
|
-
this.environments = {}
|
|
23
|
+
};
|
|
24
|
+
this.master = {};
|
|
25
|
+
this.environments = {};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
ExportEnvironments.prototype.start = function (mergConfig) {
|
|
29
|
-
this.master = {}
|
|
30
|
-
this.environments = {}
|
|
31
|
-
let self = this
|
|
32
|
-
config = mergConfig
|
|
33
|
-
addlogs(config, 'Starting environment export', 'success')
|
|
34
|
-
const environmentConfig = config.modules.environments
|
|
35
|
-
const environmentsFolderPath = path.resolve(config.data,
|
|
29
|
+
this.master = {};
|
|
30
|
+
this.environments = {};
|
|
31
|
+
let self = this;
|
|
32
|
+
config = mergConfig;
|
|
33
|
+
addlogs(config, 'Starting environment export', 'success');
|
|
34
|
+
const environmentConfig = config.modules.environments;
|
|
35
|
+
const environmentsFolderPath = path.resolve(config.data, config.branchName || '', environmentConfig.dirName);
|
|
36
36
|
// Create folder for environments
|
|
37
|
-
mkdirp.sync(environmentsFolderPath)
|
|
38
|
-
let client = stack.Client(config)
|
|
37
|
+
mkdirp.sync(environmentsFolderPath);
|
|
38
|
+
let client = stack.Client(config);
|
|
39
39
|
return new Promise(function (resolve, reject) {
|
|
40
|
-
client
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
client
|
|
41
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
42
|
+
.environment()
|
|
43
|
+
.query(self.requestOptions.qs)
|
|
44
|
+
.find()
|
|
45
|
+
.then((environmentResponse) => {
|
|
46
|
+
if (environmentResponse.items.length !== 0) {
|
|
47
|
+
for (let i = 0, total = environmentResponse.count; i < total; i++) {
|
|
48
|
+
let envUid = environmentResponse.items[i].uid;
|
|
49
|
+
self.master[envUid] = '';
|
|
50
|
+
self.environments[envUid] = environmentResponse.items[i];
|
|
51
|
+
delete self.environments[envUid].uid;
|
|
52
|
+
delete self.environments[envUid]['ACL'];
|
|
53
|
+
}
|
|
54
|
+
helper.writeFile(path.join(environmentsFolderPath, environmentConfig.fileName), self.environments);
|
|
55
|
+
addlogs(config, chalk.green('All the environments have been exported successfully'), 'success');
|
|
56
|
+
return resolve();
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
}
|
|
58
|
+
if (environmentResponse.items.length === 0) {
|
|
59
|
+
addlogs(config, 'No environments found', 'success');
|
|
60
|
+
return resolve();
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.catch((error) => {
|
|
64
|
+
addlogs(config, error, 'error');
|
|
65
|
+
reject(error);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
64
69
|
|
|
65
|
-
module.exports = new ExportEnvironments()
|
|
70
|
+
module.exports = new ExportEnvironments();
|
|
@@ -1,61 +1,66 @@
|
|
|
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('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
10
|
|
|
11
|
-
const helper = require('../util/helper')
|
|
12
|
-
const {addlogs} = require('../util/log')
|
|
11
|
+
const helper = require('../util/helper');
|
|
12
|
+
const { addlogs } = require('../util/log');
|
|
13
13
|
|
|
14
|
-
let config = require('../../config/default')
|
|
15
|
-
const extensionConfig = config.modules.extensions
|
|
16
|
-
const stack = require('../util/contentstack-management-sdk')
|
|
14
|
+
let config = require('../../config/default');
|
|
15
|
+
const extensionConfig = config.modules.extensions;
|
|
16
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
17
17
|
|
|
18
18
|
function ExportExtensions() {
|
|
19
19
|
this.queryRequestOptions = {
|
|
20
20
|
include_count: true,
|
|
21
21
|
asc: 'updated_at',
|
|
22
|
-
}
|
|
23
|
-
this.master = {}
|
|
24
|
-
this.extensions = {}
|
|
22
|
+
};
|
|
23
|
+
this.master = {};
|
|
24
|
+
this.extensions = {};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
ExportExtensions.prototype.start = function (mergeConfig) {
|
|
28
|
-
this.master = {}
|
|
29
|
-
this.extensions = {}
|
|
30
|
-
addlogs(config, 'Starting extension export', 'success')
|
|
31
|
-
let self = this
|
|
32
|
-
config = mergeConfig
|
|
33
|
-
let extensionsFolderPath = path.resolve(config.data,
|
|
28
|
+
this.master = {};
|
|
29
|
+
this.extensions = {};
|
|
30
|
+
addlogs(config, 'Starting extension export', 'success');
|
|
31
|
+
let self = this;
|
|
32
|
+
config = mergeConfig;
|
|
33
|
+
let extensionsFolderPath = path.resolve(config.data, config.branchName || '', extensionConfig.dirName);
|
|
34
34
|
// Create folder for extensions
|
|
35
|
-
mkdirp.sync(extensionsFolderPath)
|
|
36
|
-
let client = stack.Client(config)
|
|
35
|
+
mkdirp.sync(extensionsFolderPath);
|
|
36
|
+
let client = stack.Client(config);
|
|
37
37
|
return new Promise(function (resolve, reject) {
|
|
38
|
-
client
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
client
|
|
39
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
40
|
+
.extension()
|
|
41
|
+
.query(self.queryRequestOptions)
|
|
42
|
+
.find()
|
|
43
|
+
.then((extension) => {
|
|
44
|
+
if (extension.items.length !== 0) {
|
|
45
|
+
for (let i = 0, total = extension.count; i < total; i++) {
|
|
46
|
+
let extUid = extension.items[i].uid;
|
|
47
|
+
self.master[extUid] = '';
|
|
48
|
+
self.extensions[extUid] = extension.items[i];
|
|
49
|
+
delete self.extensions[extUid].uid;
|
|
50
|
+
delete self.extensions[extUid].SYS_ACL;
|
|
51
|
+
}
|
|
52
|
+
helper.writeFile(path.join(extensionsFolderPath, extensionConfig.fileName), self.extensions);
|
|
53
|
+
addlogs(config, chalk.green('All the extensions have been exported successfully'), 'success');
|
|
54
|
+
return resolve();
|
|
47
55
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
}
|
|
56
|
+
addlogs(config, 'No extensions found', 'success');
|
|
57
|
+
return resolve();
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
addlogs(config, error, 'error');
|
|
61
|
+
return reject();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
60
65
|
|
|
61
|
-
module.exports = new ExportExtensions()
|
|
66
|
+
module.exports = new ExportExtensions();
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
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(
|
|
11
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
12
|
+
const helper = require('../util/helper');
|
|
13
|
+
const { addlogs } = require('../util/log');
|
|
14
14
|
|
|
15
|
-
let config = require(
|
|
15
|
+
let config = require('../../config/default');
|
|
16
16
|
const limit = 100;
|
|
17
17
|
const validKeys = config.modules.globalfields.validKeys;
|
|
18
18
|
let globalfieldsFolderPath;
|
|
@@ -22,7 +22,7 @@ function ExportGlobalFields() {
|
|
|
22
22
|
this.requestOptions = {
|
|
23
23
|
qs: {
|
|
24
24
|
include_count: true,
|
|
25
|
-
asc:
|
|
25
|
+
asc: 'updated_at',
|
|
26
26
|
limit: limit,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
@@ -34,16 +34,12 @@ ExportGlobalFields.prototype = {
|
|
|
34
34
|
start: function (credentialConfig) {
|
|
35
35
|
this.master = {};
|
|
36
36
|
this.globalfields = {};
|
|
37
|
-
config = {...config, ...credentialConfig};
|
|
38
|
-
globalfieldsFolderPath = path.resolve(
|
|
39
|
-
config.data,
|
|
40
|
-
(config.branchName || ""),
|
|
41
|
-
globalfieldsConfig.dirName
|
|
42
|
-
);
|
|
37
|
+
config = { ...config, ...credentialConfig };
|
|
38
|
+
globalfieldsFolderPath = path.resolve(config.data, config.branchName || '', globalfieldsConfig.dirName);
|
|
43
39
|
// Create folder for Global Fields
|
|
44
40
|
mkdirp.sync(globalfieldsFolderPath);
|
|
45
41
|
const self = this;
|
|
46
|
-
addlogs(config,
|
|
42
|
+
addlogs(config, 'Starting Global Fields export', 'success');
|
|
47
43
|
return new Promise(function (resolve, reject) {
|
|
48
44
|
try {
|
|
49
45
|
return self
|
|
@@ -71,7 +67,7 @@ ExportGlobalFields.prototype = {
|
|
|
71
67
|
},
|
|
72
68
|
getGlobalFields: function (skip, globalFieldConfig) {
|
|
73
69
|
const self = this;
|
|
74
|
-
if (typeof skip !==
|
|
70
|
+
if (typeof skip !== 'number') {
|
|
75
71
|
skip = 0;
|
|
76
72
|
self.requestOptions.qs.skip = skip;
|
|
77
73
|
} else {
|
|
@@ -91,8 +87,8 @@ ExportGlobalFields.prototype = {
|
|
|
91
87
|
.then((globalFieldResponse) => {
|
|
92
88
|
try {
|
|
93
89
|
if (globalFieldResponse.items.length === 0) {
|
|
94
|
-
addlogs(globalFieldConfig,
|
|
95
|
-
return resolve(
|
|
90
|
+
addlogs(globalFieldConfig, 'No global fields found', 'success');
|
|
91
|
+
return resolve('No Global Fields');
|
|
96
92
|
}
|
|
97
93
|
globalFieldResponse.items.forEach(function (globalField) {
|
|
98
94
|
for (const key in globalField) {
|
|
@@ -109,10 +105,7 @@ ExportGlobalFields.prototype = {
|
|
|
109
105
|
return resolve();
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
return self
|
|
113
|
-
.getGlobalFields(skip, globalFieldConfig)
|
|
114
|
-
.then(resolve)
|
|
115
|
-
.catch(reject);
|
|
108
|
+
return self.getGlobalFields(skip, globalFieldConfig).then(resolve).catch(reject);
|
|
116
109
|
} catch (error) {
|
|
117
110
|
return reject(error);
|
|
118
111
|
}
|
|
@@ -122,15 +115,8 @@ ExportGlobalFields.prototype = {
|
|
|
122
115
|
writeGlobalFields: function () {
|
|
123
116
|
const self = this;
|
|
124
117
|
return new Promise(function (resolve) {
|
|
125
|
-
helper.writeFile(
|
|
126
|
-
|
|
127
|
-
self.global_fields
|
|
128
|
-
);
|
|
129
|
-
addlogs(
|
|
130
|
-
config,
|
|
131
|
-
chalk.green("Global Fields export completed successfully"),
|
|
132
|
-
"success"
|
|
133
|
-
);
|
|
118
|
+
helper.writeFile(path.join(globalfieldsFolderPath, globalfieldsConfig.fileName), self.global_fields);
|
|
119
|
+
addlogs(config, chalk.green('Global Fields export completed successfully'), 'success');
|
|
134
120
|
return resolve();
|
|
135
121
|
});
|
|
136
122
|
},
|
package/src/lib/export/labels.js
CHANGED
|
@@ -4,62 +4,69 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
let {addlogs} = require('../util/log')
|
|
11
|
+
let helper = require('../util/helper');
|
|
12
|
+
let { addlogs } = require('../util/log');
|
|
14
13
|
|
|
15
|
-
const stack = require('../util/contentstack-management-sdk')
|
|
16
|
-
let config = require('../../config/default')
|
|
17
|
-
let labelConfig = config.modules.labels
|
|
18
|
-
let client
|
|
14
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
15
|
+
let config = require('../../config/default');
|
|
16
|
+
let labelConfig = config.modules.labels;
|
|
17
|
+
let client;
|
|
19
18
|
|
|
20
19
|
function ExportLabels() {
|
|
21
20
|
this.requestOptions = {
|
|
22
21
|
url: config.host + config.apis.labels,
|
|
23
22
|
headers: config.headers,
|
|
24
23
|
json: true,
|
|
25
|
-
}
|
|
26
|
-
this.labels = {}
|
|
24
|
+
};
|
|
25
|
+
this.labels = {};
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
ExportLabels.prototype.start = function (credentialConfig) {
|
|
30
|
-
addlogs(config, 'Starting labels export', 'success')
|
|
31
|
-
this.labels = {}
|
|
32
|
-
let self = this
|
|
33
|
-
config = credentialConfig
|
|
34
|
-
client = stack.Client(config)
|
|
35
|
-
let labelsFolderPath = path.resolve(config.data,
|
|
29
|
+
addlogs(config, 'Starting labels export', 'success');
|
|
30
|
+
this.labels = {};
|
|
31
|
+
let self = this;
|
|
32
|
+
config = credentialConfig;
|
|
33
|
+
client = stack.Client(config);
|
|
34
|
+
let labelsFolderPath = path.resolve(config.data, config.branchName || '', labelConfig.dirName);
|
|
36
35
|
// Create locale folder
|
|
37
|
-
mkdirp.sync(labelsFolderPath)
|
|
36
|
+
mkdirp.sync(labelsFolderPath);
|
|
38
37
|
return new Promise(function (resolve, reject) {
|
|
39
|
-
return client
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return resolve()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
38
|
+
return client
|
|
39
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
40
|
+
.label()
|
|
41
|
+
.query()
|
|
42
|
+
.find()
|
|
43
|
+
.then((response) => {
|
|
44
|
+
if (response.items.length !== 0) {
|
|
45
|
+
response.items.forEach(function (label) {
|
|
46
|
+
addlogs(config, label.name + ' labels was exported successfully', 'success');
|
|
47
|
+
self.labels[label.uid] = label;
|
|
48
|
+
let deleteItems = config.modules.labels.invalidKeys;
|
|
49
|
+
deleteItems.forEach((e) => delete label[e]);
|
|
50
|
+
});
|
|
51
|
+
addlogs(config, chalk.green('All the labels have been exported successfully'), 'success');
|
|
52
|
+
} else {
|
|
53
|
+
addlogs(config, 'No labels found', 'success');
|
|
54
|
+
}
|
|
55
|
+
helper.writeFile(path.join(labelsFolderPath, labelConfig.fileName), self.labels);
|
|
56
|
+
return resolve();
|
|
57
|
+
})
|
|
58
|
+
.catch(function (error) {
|
|
59
|
+
if (error.statusCode === 401) {
|
|
60
|
+
addlogs(
|
|
61
|
+
config,
|
|
62
|
+
chalk.red('You are not allowed to export label, Unless you provide email and password in config', 'error'),
|
|
63
|
+
);
|
|
64
|
+
return resolve();
|
|
65
|
+
}
|
|
66
|
+
addlogs(config, error, 'error');
|
|
67
|
+
return reject();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
64
71
|
|
|
65
|
-
module.exports = new ExportLabels()
|
|
72
|
+
module.exports = new ExportLabels();
|
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
10
|
-
|
|
11
|
-
const helper = require('../util/helper')
|
|
12
|
-
const {addlogs} = require('../util/log')
|
|
13
|
-
let config = require('../../config/default')
|
|
14
|
-
let localeConfig = config.modules.locales
|
|
15
|
-
const masterLocale = config.master_locale
|
|
16
|
-
let requiredKeys = localeConfig.requiredKeys
|
|
17
|
-
let stack = require('../util/contentstack-management-sdk')
|
|
18
|
-
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
19
10
|
|
|
11
|
+
const helper = require('../util/helper');
|
|
12
|
+
const { addlogs } = require('../util/log');
|
|
13
|
+
let config = require('../../config/default');
|
|
14
|
+
let localeConfig = config.modules.locales;
|
|
15
|
+
const masterLocale = config.master_locale;
|
|
16
|
+
let requiredKeys = localeConfig.requiredKeys;
|
|
17
|
+
let stack = require('../util/contentstack-management-sdk');
|
|
18
|
+
let client
|
|
20
19
|
function ExportLocales() {
|
|
21
20
|
this.qs = {
|
|
22
21
|
include_count: true,
|
|
@@ -29,43 +28,76 @@ function ExportLocales() {
|
|
|
29
28
|
only: {
|
|
30
29
|
BASE: requiredKeys,
|
|
31
30
|
},
|
|
32
|
-
}
|
|
33
|
-
this.locales = {}
|
|
31
|
+
};
|
|
32
|
+
this.locales = {};
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
ExportLocales.prototype.start = function (credentialConfig) {
|
|
37
|
-
this.locales = {}
|
|
38
|
-
addlogs(credentialConfig, 'Starting locale export', 'success')
|
|
36
|
+
this.locales = {};
|
|
37
|
+
addlogs(credentialConfig, 'Starting locale export', 'success');
|
|
38
|
+
let self = this;
|
|
39
|
+
config = credentialConfig;
|
|
40
|
+
self.localesFolderPath = path.resolve(config.data, config.branchName || '', localeConfig.dirName);
|
|
41
|
+
mkdirp.sync(self.localesFolderPath);
|
|
42
|
+
client = stack.Client(config);
|
|
43
|
+
const apiDetails = {
|
|
44
|
+
limit: 100,
|
|
45
|
+
skip: 0,
|
|
46
|
+
include_count: true,
|
|
47
|
+
}
|
|
48
|
+
return self.getLocales(apiDetails)
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
ExportLocales.prototype.getLocales = function (apiDetails) {
|
|
39
53
|
let self = this
|
|
40
|
-
config = credentialConfig
|
|
41
|
-
let localesFolderPath = path.resolve(config.data, (config.branchName || ""), localeConfig.dirName)
|
|
42
|
-
mkdirp.sync(localesFolderPath)
|
|
43
54
|
|
|
44
|
-
let client = stack.Client(config)
|
|
45
55
|
return new Promise(function (resolve, reject) {
|
|
46
|
-
client
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
client
|
|
57
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
58
|
+
.locale()
|
|
59
|
+
.query({ ...self.qs, ...apiDetails })
|
|
60
|
+
.find()
|
|
61
|
+
.then((localeResponse) => {
|
|
62
|
+
if (localeResponse.items.length !== 0) {
|
|
63
|
+
localeResponse.items.forEach(function (locale) {
|
|
64
|
+
addlogs(config, locale.name + ' locale was exported successfully', 'success');
|
|
65
|
+
for (const key in locale) {
|
|
66
|
+
if (requiredKeys.indexOf(key) === -1) {
|
|
67
|
+
delete locale[key];
|
|
68
|
+
}
|
|
54
69
|
}
|
|
70
|
+
self.locales[locale.uid] = locale;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
helper.writeFile(path.join(self.localesFolderPath, localeConfig.fileName), self.locales);
|
|
74
|
+
|
|
75
|
+
apiDetails.skip += apiDetails.limit;
|
|
76
|
+
|
|
77
|
+
if (apiDetails.skip > localeResponse.count) {
|
|
78
|
+
addlogs(config, chalk.green('All the locales have been exported successfully'), 'success');
|
|
79
|
+
return resolve();
|
|
55
80
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
|
|
82
|
+
return self
|
|
83
|
+
.getLocales(apiDetails)
|
|
84
|
+
.then(resolve)
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
console.log('Get locales errror', error && error.message);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
} else if (localeResponse.items.length === 0) {
|
|
90
|
+
addlogs(config, 'No languages found except the master language', 'success');
|
|
91
|
+
helper.writeFile(path.join(self.localesFolderPath, localeConfig.fileName), self.locales);
|
|
92
|
+
return resolve();
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
addlogs(config, error, 'error');
|
|
98
|
+
return reject(error);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
69
101
|
}
|
|
70
102
|
|
|
71
|
-
module.exports = new ExportLocales()
|
|
103
|
+
module.exports = new ExportLocales();
|