@contentstack/cli-cm-export 0.1.1-beta.11 → 0.1.1-beta.14
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 +21 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/app.js +3 -2
- package/src/config/default.js +5 -0
- package/src/lib/util/contentstack-management-sdk.js +21 -1
- package/src/lib/util/log.js +61 -22
package/README.md
CHANGED
|
@@ -10,6 +10,25 @@ It is Contentstack’s CLI plugin to export content from the stack. To learn how
|
|
|
10
10
|
* [Commands](#commands)
|
|
11
11
|
<!-- tocstop -->
|
|
12
12
|
|
|
13
|
+
For switching to EU region update the hosts at config/default.js
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
{
|
|
17
|
+
host:'https://eu-api.contentstack.com/v3',
|
|
18
|
+
cdn: 'https://eu-cdn.contentstack.com/v3',
|
|
19
|
+
...
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For switching to AZURE-NA region update the hosts at config/default.js
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
{
|
|
27
|
+
host:'https://azure-na-api.contentstack.com/v3',
|
|
28
|
+
cdn: 'https://azure-na-cdn.contentstack.com/v3',
|
|
29
|
+
...
|
|
30
|
+
}
|
|
31
|
+
```
|
|
13
32
|
# Usage
|
|
14
33
|
|
|
15
34
|
<!-- usage -->
|
|
@@ -18,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-export
|
|
|
18
37
|
$ csdx COMMAND
|
|
19
38
|
running command...
|
|
20
39
|
$ csdx (-v|--version|version)
|
|
21
|
-
@contentstack/cli-cm-export/0.1.1-beta.
|
|
40
|
+
@contentstack/cli-cm-export/0.1.1-beta.14 linux-x64 node-v16.14.2
|
|
22
41
|
$ csdx --help [COMMAND]
|
|
23
42
|
USAGE
|
|
24
43
|
$ csdx COMMAND
|
|
@@ -68,5 +87,5 @@ EXAMPLES
|
|
|
68
87
|
csdx cm:export -A -B [optional] branch name
|
|
69
88
|
```
|
|
70
89
|
|
|
71
|
-
_See code: [src/commands/cm/export.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.
|
|
90
|
+
_See code: [src/commands/cm/export.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.14/packages/contentstack-export/src/commands/cm/export.js)_
|
|
72
91
|
<!-- commandsstop -->
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.1.1-beta.
|
|
1
|
+
{"version":"0.1.1-beta.14","commands":{"cm:export":{"id":"cm:export","description":"Export content from a stack\n...\nExport content from one stack to another\n","pluginName":"@contentstack/cli-cm-export","pluginType":"core","aliases":[],"examples":["csdx cm:export -A","csdx cm:export -A -s <stack_ApiKey> -d <path/of/export/destination/dir>","csdx cm:export -A -c <path/to/config/dir>","csdx cm:export -A -m <single module name>","csdx cm:export -A --secured-assets","csdx cm:export -a <management_token_alias>","csdx cm:export -a <management_token_alias> -d <path/to/export/destination/dir>","csdx cm:export -a <management_token_alias> -c <path/to/config/file>","csdx cm:export -A -m <single module name>","csdx cm:export -A -m <single module name> -t <content type>","csdx cm:export -A -B [optional] branch name"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of the config"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the source stack"},"data":{"name":"data","type":"option","char":"d","description":"path or location to store the data"},"management-token-alias":{"name":"management-token-alias","type":"option","char":"a","description":"alias of the management token"},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"content-type":{"name":"content-type","type":"option","char":"t","description":"[optional] content type"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"secured-assets":{"name":"secured-assets","type":"boolean","description":"[optional] use when assets are secured","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export",
|
|
3
3
|
"description": "Contentstack CLI plugin to export content from stack",
|
|
4
|
-
"version": "0.1.1-beta.
|
|
4
|
+
"version": "0.1.1-beta.14",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
package/src/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-redeclare */
|
|
2
2
|
var util = require("./lib/util");
|
|
3
3
|
var login = require("./lib/util/login");
|
|
4
|
-
var { addlogs } = require("./lib/util/log");
|
|
4
|
+
var { addlogs, unlinkFileLogger } = require("./lib/util/log");
|
|
5
5
|
const setupBranches = require("./lib/util/setup-branches");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
7
|
let path = require("path");
|
|
@@ -46,6 +46,7 @@ exports.initial = async function (config) {
|
|
|
46
46
|
console.log('failed export contents', error)
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
unlinkFileLogger()
|
|
49
50
|
resolve()
|
|
50
51
|
})
|
|
51
52
|
.catch((error) => {
|
|
@@ -89,7 +90,7 @@ var singleExport = async (moduleName, types, config, branchName) => {
|
|
|
89
90
|
const result = await exportedModule.start(config, branchName);
|
|
90
91
|
if (result && iterateList[i] === "stack") {
|
|
91
92
|
let master_locale = {
|
|
92
|
-
master_locale: { code: result.
|
|
93
|
+
master_locale: { code: result.code },
|
|
93
94
|
};
|
|
94
95
|
config = _.merge(config, master_locale);
|
|
95
96
|
}
|
package/src/config/default.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
versioning: false,
|
|
3
|
+
host: 'https://api.contentstack.io/v3',
|
|
4
|
+
// use below hosts for eu region
|
|
5
|
+
// host:'https://eu-api.contentstack.com/v3',
|
|
6
|
+
// use below hosts for azure-na region
|
|
7
|
+
// host:'https://azure-na-api.contentstack.com/v3',
|
|
3
8
|
modules: {
|
|
4
9
|
types: [
|
|
5
10
|
'stack',
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
const contentstacksdk = require('@contentstack/management')
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
const { addlogs } = require('./log');
|
|
2
5
|
|
|
3
6
|
exports.Client = function (config) {
|
|
4
7
|
const option = {
|
|
5
8
|
host: config.host,
|
|
6
9
|
authtoken: config.auth_token,
|
|
7
10
|
api_key: config.source_stack,
|
|
8
|
-
|
|
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
|
+
}
|
|
9
29
|
}
|
|
10
30
|
|
|
11
31
|
if (typeof config.branchName === 'string') {
|
package/src/lib/util/log.js
CHANGED
|
@@ -24,12 +24,11 @@ function returnString(args) {
|
|
|
24
24
|
|
|
25
25
|
var myCustomLevels = {
|
|
26
26
|
levels: {
|
|
27
|
-
error: 0,
|
|
28
27
|
warn: 1,
|
|
29
28
|
info: 2,
|
|
30
29
|
debug: 3,
|
|
31
30
|
},
|
|
32
|
-
colors: {
|
|
31
|
+
colors: { //colors aren't being used anywhere as of now, we're using chalk to add colors while logging
|
|
33
32
|
info: 'blue',
|
|
34
33
|
debug: 'green',
|
|
35
34
|
warn: 'yellow',
|
|
@@ -37,26 +36,52 @@ var myCustomLevels = {
|
|
|
37
36
|
},
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Create dir if doesn't already exist
|
|
43
|
-
mkdirp.sync(logsDir)
|
|
44
|
-
var logPath = path.join(logsDir, logfileName + '.log')
|
|
39
|
+
let logger
|
|
40
|
+
let errorLogger
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
maxFiles: 20,
|
|
49
|
-
maxsize: 1000000,
|
|
50
|
-
tailable: true,
|
|
51
|
-
json: true,
|
|
52
|
-
})]
|
|
42
|
+
let successTransport
|
|
43
|
+
let errorTransport
|
|
53
44
|
|
|
54
|
-
|
|
45
|
+
function init(_logPath) {
|
|
46
|
+
if (!logger || !errorLogger) {
|
|
47
|
+
var logsDir = path.resolve(_logPath, 'logs', 'export')
|
|
48
|
+
// Create dir if doesn't already exist
|
|
49
|
+
mkdirp.sync(logsDir)
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
successTransport = {
|
|
52
|
+
filename: path.join(logsDir, 'success.log'),
|
|
53
|
+
maxFiles: 20,
|
|
54
|
+
maxsize: 1000000,
|
|
55
|
+
tailable: true,
|
|
56
|
+
json: true,
|
|
57
|
+
level: 'info',
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
errorTransport = {
|
|
61
|
+
filename: path.join(logsDir, 'error.log'),
|
|
62
|
+
maxFiles: 20,
|
|
63
|
+
maxsize: 1000000,
|
|
64
|
+
tailable: true,
|
|
65
|
+
json: true,
|
|
66
|
+
level: 'error',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
logger = new (winston.Logger)({
|
|
70
|
+
transports: [
|
|
71
|
+
new (winston.transports.File)(successTransport),
|
|
72
|
+
new (winston.transports.Console)()
|
|
73
|
+
],
|
|
74
|
+
levels: myCustomLevels.levels
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
errorLogger = new (winston.Logger)({
|
|
78
|
+
transports: [
|
|
79
|
+
new (winston.transports.File)(errorTransport),
|
|
80
|
+
new (winston.transports.Console)({ level: 'error' })
|
|
81
|
+
],
|
|
82
|
+
levels: { error: 0 }
|
|
83
|
+
})
|
|
84
|
+
}
|
|
60
85
|
|
|
61
86
|
return {
|
|
62
87
|
log: function () {
|
|
@@ -77,7 +102,7 @@ function init (_logPath, logfileName) {
|
|
|
77
102
|
var args = slice.call(arguments)
|
|
78
103
|
var logString = returnString(args)
|
|
79
104
|
if (logString) {
|
|
80
|
-
|
|
105
|
+
errorLogger.log('error', logString)
|
|
81
106
|
}
|
|
82
107
|
},
|
|
83
108
|
debug: function () {
|
|
@@ -91,9 +116,23 @@ function init (_logPath, logfileName) {
|
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
exports.addlogs = async (config, message, type) => {
|
|
119
|
+
// ignoring the type argument, as we are not using it to create a logfile anymore
|
|
94
120
|
if (type !== 'error') {
|
|
95
|
-
init
|
|
121
|
+
// removed type argument from init method
|
|
122
|
+
init(config.data).log(message)
|
|
96
123
|
} else {
|
|
97
|
-
init(config.data
|
|
124
|
+
init(config.data).error(message)
|
|
98
125
|
}
|
|
99
126
|
}
|
|
127
|
+
|
|
128
|
+
exports.unlinkFileLogger = () => {
|
|
129
|
+
if (logger) {
|
|
130
|
+
const fileLogger = logger.transports.file
|
|
131
|
+
logger.remove(fileLogger)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (errorLogger) {
|
|
135
|
+
const fileLogger = errorLogger.transports.file
|
|
136
|
+
errorLogger.remove(fileLogger)
|
|
137
|
+
}
|
|
138
|
+
}
|