@contentstack/cli-cm-export 0.1.1-beta.10 → 0.1.1-beta.13

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 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.10 linux-x64 node-v12.22.7
40
+ @contentstack/cli-cm-export/0.1.1-beta.13 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.10/packages/contentstack-export/src/commands/cm/export.js)_
90
+ _See code: [src/commands/cm/export.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.13/packages/contentstack-export/src/commands/cm/export.js)_
72
91
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.10","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":[]}}}
1
+ {"version":"0.1.1-beta.13","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.10",
4
+ "version": "0.1.1-beta.13",
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) => {
@@ -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',
@@ -39,6 +39,8 @@ ExportAssets.prototype = {
39
39
  start: function (credentialConfig) {
40
40
  this.assetContents = {}
41
41
  this.folderData = []
42
+ this.assetDownloadRetry = {};
43
+ this.assetDownloadRetryLimit = 3;
42
44
  let self = this
43
45
  config = credentialConfig
44
46
  assetsFolderPath = path.resolve(config.data, (config.branchName || ""), assetConfig.dirName)
@@ -69,9 +71,9 @@ ExportAssets.prototype = {
69
71
  // log.success(chalk.white('The following asset has been downloaded successfully: ' +
70
72
  // assetJSON.uid))
71
73
  }).catch(function (error) {
72
- addlogs(self.configchalk.red('The following asset failed to download\n' + JSON.stringify(
74
+ addlogs(config, chalk.red('The following asset failed to download\n' + JSON.stringify(
73
75
  assetJSON)))
74
- addlogs(config, error, 'error')
76
+ addlogs(config, error, 'error')
75
77
  })
76
78
  }, {
77
79
  concurrency: vLimit,
@@ -210,6 +212,10 @@ ExportAssets.prototype = {
210
212
  let self = this
211
213
  let assetVersionInfo = bucket || []
212
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
+
213
219
  if (version <= 0) {
214
220
  const assetVersionInfoFile = path.resolve(assetsFolderPath, uid, '_contentstack_' + uid + '.json')
215
221
  helper.writeFile(assetVersionInfoFile, assetVersionInfo)
@@ -231,8 +237,17 @@ ExportAssets.prototype = {
231
237
  assetVersionInfo = _.uniqWith(assetVersionInfo, _.isEqual)
232
238
  self.getVersionedAssetJSON(uid, --version, assetVersionInfo)
233
239
  .then(resolve)
234
- .catch(reject)
240
+ .catch(reject)
235
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);
236
251
  })
237
252
  })
238
253
  },
@@ -252,6 +267,7 @@ ExportAssets.prototype = {
252
267
  : asset.url,
253
268
  };
254
269
 
270
+ self.assetStream.url = encodeURI(self.assetStream.url);
255
271
  const assetStreamRequest = nativeRequest(self.assetStream)
256
272
  assetStreamRequest.on('response', function () {
257
273
  helper.makeDirectory(assetFolderPath)
@@ -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
- function init (_logPath, logfileName) {
41
- var logsDir = path.resolve(_logPath, 'logs', 'export')
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
- var transports = [new (winston.transports.File)({
47
- filename: logPath,
48
- maxFiles: 20,
49
- maxsize: 1000000,
50
- tailable: true,
51
- json: true,
52
- })]
42
+ let successTransport
43
+ let errorTransport
53
44
 
54
- transports.push(new (winston.transports.Console)())
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
- var logger = new(winston.Logger)({
57
- transports: transports,
58
- levels: myCustomLevels.levels
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
- logger.log('error', logString)
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(config.data, type).log(message)
121
+ // removed type argument from init method
122
+ init(config.data).log(message)
96
123
  } else {
97
- init(config.data, type).error(message)
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
+ }