@contentstack/cli-cm-export 0.1.1-beta.15 → 0.1.1-beta.16

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
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-export
37
37
  $ csdx COMMAND
38
38
  running command...
39
39
  $ csdx (-v|--version|version)
40
- @contentstack/cli-cm-export/0.1.1-beta.15 linux-x64 node-v16.14.2
40
+ @contentstack/cli-cm-export/0.1.1-beta.16 linux-x64 node-v16.14.2
41
41
  $ csdx --help [COMMAND]
42
42
  USAGE
43
43
  $ csdx COMMAND
@@ -87,5 +87,5 @@ EXAMPLES
87
87
  csdx cm:export -A -B [optional] branch name
88
88
  ```
89
89
 
90
- _See code: [src/commands/cm/export.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.15/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.16/packages/contentstack-export/src/commands/cm/export.js)_
91
91
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.15","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.16","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.15",
4
+ "version": "0.1.1-beta.16",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -17,6 +17,7 @@
17
17
  "fs": "0.0.1-security",
18
18
  "is-valid-path": "^0.1.1",
19
19
  "lodash": "^4.17.20",
20
+ "mkdirp": "^1.0.4",
20
21
  "path": "^0.12.7",
21
22
  "progress-stream": "^2.0.0",
22
23
  "proxyquire": "^2.1.3",
@@ -32,7 +33,7 @@
32
33
  "eslint": "^5.16.0",
33
34
  "eslint-config-oclif": "^3.1.0",
34
35
  "globby": "^10.0.2",
35
- "mocha": "^8.2.1",
36
+ "mocha": "^10.0.0",
36
37
  "nyc": "^14.1.1",
37
38
  "sinon": "^9.0.2"
38
39
  },
@@ -9,13 +9,13 @@ const path = require('path')
9
9
  const chalk = require('chalk')
10
10
 
11
11
  const helper = require('../util/helper')
12
- const {addlogs} = require('../util/log')
12
+ const { addlogs } = require('../util/log')
13
13
  let config = require('../../config/default')
14
14
  let localeConfig = config.modules.locales
15
15
  const masterLocale = config.master_locale
16
16
  let requiredKeys = localeConfig.requiredKeys
17
17
  let stack = require('../util/contentstack-management-sdk')
18
-
18
+ let client
19
19
 
20
20
  function ExportLocales() {
21
21
  this.qs = {
@@ -40,32 +40,64 @@ ExportLocales.prototype.start = function (credentialConfig) {
40
40
  config = credentialConfig
41
41
  let localesFolderPath = path.resolve(config.data, (config.branchName || ""), localeConfig.dirName)
42
42
  mkdirp.sync(localesFolderPath)
43
+ self.localesFolderPath = localesFolderPath
44
+
45
+ client = stack.Client(config);
46
+ const apiDetails = {
47
+ limit: 100,
48
+ skip: 0,
49
+ include_count: true,
50
+ }
51
+ return self.getLocales(apiDetails)
52
+
53
+ }
54
+
55
+ ExportLocales.prototype.getLocales = function (apiDetails) {
56
+ let self = this
43
57
 
44
- let client = stack.Client(config)
45
58
  return new Promise(function (resolve, reject) {
46
- client.stack({api_key: config.source_stack, management_token: config.management_token}).locale().query(self.qs).find()
47
- .then(localeResponse => {
48
- if (localeResponse.items.length !== 0) {
49
- localeResponse.items.forEach(function (locale) {
50
- addlogs(credentialConfig, locale.name + ' locale was exported successfully', 'success')
51
- for (const key in locale) {
52
- if (requiredKeys.indexOf(key) === -1) {
53
- delete locale[key]
59
+ client
60
+ .stack({ api_key: config.source_stack, management_token: config.management_token })
61
+ .locale()
62
+ .query({ ...self.qs, ...apiDetails })
63
+ .find()
64
+ .then((localeResponse) => {
65
+ if (localeResponse.items.length !== 0) {
66
+ localeResponse.items.forEach(function (locale) {
67
+ addlogs(config, locale.name + ' locale was exported successfully', 'success');
68
+ for (const key in locale) {
69
+ if (requiredKeys.indexOf(key) === -1) {
70
+ delete locale[key];
71
+ }
54
72
  }
73
+ self.locales[locale.uid] = locale;
74
+ });
75
+
76
+ helper.writeFile(path.join(self.localesFolderPath, localeConfig.fileName), self.locales);
77
+
78
+ apiDetails.skip += apiDetails.limit;
79
+
80
+ if (apiDetails.skip > localeResponse.count) {
81
+ addlogs(config, chalk.green('All the locales have been exported successfully'), 'success');
82
+ return resolve();
55
83
  }
56
- self.locales[locale.uid] = locale
57
- })
58
- addlogs(credentialConfig, chalk.green('All the locales have been exported successfully'), 'success')
59
- } else if (localeResponse.items.length === 0) {
60
- addlogs(credentialConfig, 'No languages found except the master language', 'success')
61
- }
62
- helper.writeFile(path.join(localesFolderPath, localeConfig.fileName), self.locales)
63
- return resolve()
64
- }).catch(error => {
65
- addlogs(credentialConfig, error, 'error')
66
- return reject()
67
- })
68
- })
84
+
85
+ return self
86
+ .getLocales(apiDetails)
87
+ .then(resolve)
88
+ .catch((error) => {
89
+ console.log('Get locales errror', error && error.message);
90
+ });
91
+
92
+ } else if (localeResponse.items.length === 0) {
93
+ addlogs(config, 'No languages found except the master language', 'success');
94
+ }
95
+ })
96
+ .catch((error) => {
97
+ addlogs(config, error, 'error');
98
+ return reject(error);
99
+ });
100
+ });
69
101
  }
70
102
 
71
103
  module.exports = new ExportLocales()
@@ -10,7 +10,7 @@ var path = require('path')
10
10
 
11
11
  var app = require('../../app')
12
12
  var helper = require('../util/helper')
13
- var {addlogs} = require('../util/log')
13
+ var { addlogs } = require('../util/log')
14
14
  const stack = require('../util/contentstack-management-sdk')
15
15
 
16
16
 
@@ -19,7 +19,7 @@ let config = require('../../config/default')
19
19
  var stackConfig = config.modules.stack
20
20
  let client
21
21
 
22
- function ExportStack () {
22
+ function ExportStack() {
23
23
  this.requestOption = {
24
24
  uri: config.host + config.apis.stacks,
25
25
  headers: config.headers,
@@ -30,38 +30,62 @@ function ExportStack () {
30
30
  ExportStack.prototype.start = function (credentialConfig) {
31
31
  config = credentialConfig
32
32
  client = stack.Client(config)
33
+ let self = this
33
34
  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) {
35
+ const apiDetails = {
36
+ limit: 100,
37
+ skip: 0,
38
+ include_count: true,
39
+ }
40
+ return self.getLocales(apiDetails)
41
+ } else if (config.preserveStackVersion) {
49
42
  addlogs(config, 'Exporting stack details', 'success')
50
43
  let stackFolderPath = path.resolve(config.data, stackConfig.dirName)
51
44
  let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName)
52
-
45
+
53
46
  mkdirp.sync(stackFolderPath)
54
-
47
+
55
48
  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)
49
+ return client.stack({ api_key: config.source_stack }).fetch()
50
+ .then(response => {
51
+ helper.writeFile(stackContentsFile, response)
52
+ addlogs(config, 'Exported stack details successfully!', 'success')
53
+ return resolve(response)
54
+ })
55
+ .catch(reject)
63
56
  })
64
57
  }
65
58
  }
66
59
 
60
+ ExportStack.prototype.getLocales = function (apiDetails) {
61
+ let self = this
62
+ return new Promise((resolve, reject) => {
63
+ const result = client
64
+ .stack({ api_key: config.source_stack, management_token: config.management_token })
65
+ .locale()
66
+ .query(apiDetails)
67
+
68
+ result
69
+ .find()
70
+ .then((response) => {
71
+ const masterLocalObj = response.items.find((obj) => {
72
+ if (obj.fallback_locale === null) {
73
+ return obj;
74
+ }
75
+ });
76
+ apiDetails.skip += apiDetails.limit;
77
+ if (masterLocalObj) { return resolve(masterLocalObj); }
78
+ else if (apiDetails.skip <= response.count) {
79
+ return resolve(self.getLocales(apiDetails))
80
+ }
81
+ else {
82
+ return reject('Master locale not found');
83
+ }
84
+ })
85
+ .catch((error) => {
86
+ return reject(error);
87
+ });
88
+ });
89
+ }
90
+
67
91
  module.exports = new ExportStack()