@contentstack/cli-cm-export 0.1.1-beta.7 → 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Contentstack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,6 +10,26 @@ 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
+ ```
32
+
13
33
  # Usage
14
34
 
15
35
  <!-- usage -->
@@ -18,7 +38,7 @@ $ npm install -g @contentstack/cli-cm-export
18
38
  $ csdx COMMAND
19
39
  running command...
20
40
  $ csdx (-v|--version|version)
21
- @contentstack/cli-cm-export/0.1.1-beta.7 darwin-x64 node-v14.16.0
41
+ @contentstack/cli-cm-export/1.0.0 linux-x64 node-v16.14.2
22
42
  $ csdx --help [COMMAND]
23
43
  USAGE
24
44
  $ csdx COMMAND
@@ -29,39 +49,39 @@ USAGE
29
49
  # Commands
30
50
 
31
51
  <!-- commands -->
32
- * [`csdx cm:export`](#csdx-cmexport)
52
+ * [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets)
33
53
 
34
- ## `csdx cm:export`
54
+ ## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
35
55
 
36
56
  Export content from a stack
37
57
 
38
58
  ```
39
59
  USAGE
40
- $ csdx cm:export
60
+ $ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
61
+ <value>] [--branch <value>] [--secured-assets]
41
62
 
42
63
  OPTIONS
43
- -A, --auth-token to use auth token
44
- -a, --management-token-alias=management-token-alias alias of the management token
45
- -c, --config=config [optional] path of the config
46
- -d, --data=data path or location to store the data
47
- -m, --module=module [optional] specific module name
48
- -s, --stack-uid=stack-uid API key of the source stack
49
- --secured-assets [optional] use when assets are secured
50
-
51
- DESCRIPTION
52
- ...
53
- Export content from one stack to another
64
+ -B, --branch=branch [optional] branch name
65
+ -a, --alias=alias alias of the management token
66
+ -c, --config=config [optional] path of the config
67
+ -d, --data-dir=data-dir path or location to store the data
68
+ -k, --stack-api-key=stack-api-key API key of the source stack
69
+ -m, --module=module [optional] specific module name
70
+ -t, --content-types=content-types [optional] content type
71
+ --secured-assets [optional] use when assets are secured
72
+
73
+ ALIASES
74
+ $ csdx cm:export
54
75
 
55
76
  EXAMPLES
56
- csdx cm:export -A
57
- csdx cm:export -A -s <stack_ApiKey> -d <path/of/export/destination/dir>
58
- csdx cm:export -A -c <path/to/config/dir>
59
- csdx cm:export -A -m <single module name>
60
- csdx cm:export -A --secured-assets
61
- csdx cm:export -a <management_token_alias>
62
- csdx cm:export -a <management_token_alias> -d <path/to/export/destination/dir>
63
- csdx cm:export -a <management_token_alias> -c <path/to/config/file>
77
+ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
78
+ csdx cm:stacks:export --config <path/to/config/dir>
79
+ csdx cm:stacks:export --alias <management_token_alias>
80
+ csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
81
+ csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
82
+ csdx cm:stacks:export --module <single module name>
83
+ csdx cm:stacks:export --branch [optional] branch name
64
84
  ```
65
85
 
66
- _See code: [src/commands/cm/export.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.7/packages/contentstack-export/src/commands/cm/export.js)_
86
+ _See code: [src/commands/cm/stacks/export.js](https://github.com/contentstack/cli/blob/v1.0.0/packages/contentstack-export/src/commands/cm/stacks/export.js)_
67
87
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.7","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>"],"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"},"secured-assets":{"name":"secured-assets","type":"boolean","description":"[optional] use when assets are secured","allowNo":false}},"args":[]}}}
1
+ {"version":"1.0.0","commands":{"cm:stacks:export":{"id":"cm:stacks:export","description":"Export content from a stack","usage":"cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]","pluginName":"@contentstack/cli-cm-export","pluginType":"core","aliases":["cm:export"],"examples":["csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:export --config <path/to/config/dir>","csdx cm:stacks:export --alias <management_token_alias>","csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>","csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>","csdx cm:stacks:export --module <single module name>","csdx cm:stacks:export --branch [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","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the source stack"},"data":{"name":"data","type":"option","description":"path or location to store the data","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path or location to store the data"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"content-types":{"name":"content-types","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,70 +1,74 @@
1
1
  {
2
- "name": "@contentstack/cli-cm-export",
3
- "description": "Contentstack CLI plugin to export content from stack",
4
- "version": "0.1.1-beta.7",
5
- "author": "Contentstack",
6
- "bugs": "https://github.com/contentstack/cli/issues",
7
- "dependencies": {
8
- "@contentstack/cli-command": "0.1.0-beta",
9
- "@contentstack/management": "^1.2.1",
10
- "@oclif/command": "^1.6.1",
11
- "@oclif/config": "^1.15.1",
12
- "async": "^3.2.0",
13
- "axios": "^0.21.1",
14
- "bluebird": "^3.7.2",
15
- "cli-ux": "^5.4.6",
16
- "configstore": "^5.0.1",
17
- "fs": "0.0.1-security",
18
- "is-valid-path": "^0.1.1",
19
- "lodash": "^4.17.20",
20
- "path": "^0.12.7",
21
- "proxyquire": "^2.1.3",
22
- "request": "^2.88.2",
23
- "winston": "^2.2.0"
24
- },
25
- "devDependencies": {
26
- "@oclif/dev-cli": "^1.22.2",
27
- "@oclif/plugin-help": "^3.0.1",
28
- "@oclif/test": "^1.2.6",
29
- "assert": "^2.0.0",
30
- "chai": "^4.2.0",
31
- "eslint": "^5.16.0",
32
- "eslint-config-oclif": "^3.1.0",
33
- "globby": "^10.0.2",
34
- "mocha": "^8.2.1",
35
- "nyc": "^14.1.1",
36
- "sinon": "^9.0.2"
37
- },
38
- "engines": {
39
- "node": ">=8.0.0"
40
- },
41
- "files": [
42
- "/npm-shrinkwrap.json",
43
- "/oclif.manifest.json",
44
- "/src",
45
- "/messages"
46
- ],
47
- "homepage": "https://github.com/contentstack/cli",
48
- "keywords": [
49
- "contentstack",
50
- "cli",
51
- "plugin"
52
- ],
53
- "license": "MIT",
54
- "scripts": {
55
- "postpack": "rm -f oclif.manifest.json",
56
- "prepack": "oclif-dev manifest && oclif-dev readme",
57
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
58
- "version": "oclif-dev readme && git add README.md"
59
- },
60
- "oclif": {
61
- "commands": "./src/commands",
62
- "bin": "csdx",
63
- "devPlugins": [
64
- "@oclif/plugin-help"
65
- ],
66
- "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-export/<%- commandPath %>"
67
- },
68
- "main": "./src/commands/cm/export.js",
69
- "repository": "https://github.com/contentstack/cli"
2
+ "name": "@contentstack/cli-cm-export",
3
+ "description": "Contentstack CLI plugin to export content from stack",
4
+ "version": "1.0.0",
5
+ "author": "Contentstack",
6
+ "bugs": "https://github.com/contentstack/cli/issues",
7
+ "dependencies": {
8
+ "@contentstack/cli-command": "^1.0.0",
9
+ "@contentstack/cli-utilities": "^1.0.0",
10
+ "@contentstack/management": "^1.3.0",
11
+ "@oclif/command": "^1.8.16",
12
+ "@oclif/config": "^1.18.3",
13
+ "async": "^3.2.4",
14
+ "bluebird": "^3.7.2",
15
+ "fs": "0.0.1-security",
16
+ "is-valid-path": "^0.1.1",
17
+ "lodash": "^4.17.20",
18
+ "mkdirp": "^1.0.4",
19
+ "path": "^0.12.7",
20
+ "progress-stream": "^2.0.0",
21
+ "proxyquire": "^2.1.3",
22
+ "winston": "^3.7.2"
23
+ },
24
+ "devDependencies": {
25
+ "@oclif/dev-cli": "^1.22.2",
26
+ "@oclif/plugin-help": "^5.1.12",
27
+ "@oclif/test": "^1.2.6",
28
+ "assert": "^2.0.0",
29
+ "chai": "^4.2.0",
30
+ "eslint": "^8.18.0",
31
+ "eslint-config-oclif": "^3.1.0",
32
+ "globby": "^10.0.2",
33
+ "mocha": "^10.0.0",
34
+ "nyc": "^14.1.1",
35
+ "sinon": "^9.0.2"
36
+ },
37
+ "engines": {
38
+ "node": ">=8.0.0"
39
+ },
40
+ "files": [
41
+ "/npm-shrinkwrap.json",
42
+ "/oclif.manifest.json",
43
+ "/src",
44
+ "/messages"
45
+ ],
46
+ "homepage": "https://github.com/contentstack/cli",
47
+ "keywords": [
48
+ "contentstack",
49
+ "cli",
50
+ "plugin"
51
+ ],
52
+ "license": "MIT",
53
+ "scripts": {
54
+ "postpack": "rm -f oclif.manifest.json",
55
+ "prepack": "oclif-dev manifest && oclif-dev readme",
56
+ "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
57
+ "version": "oclif-dev readme && git add README.md"
58
+ },
59
+ "oclif": {
60
+ "commands": "./src/commands",
61
+ "bin": "csdx",
62
+ "devPlugins": [
63
+ "@oclif/plugin-help"
64
+ ],
65
+ "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-export/<%- commandPath %>"
66
+ },
67
+ "csdxConfig": {
68
+ "expiredCommands": {
69
+ "cm:export": "csdx cm:stacks:export"
70
+ }
71
+ },
72
+ "main": "./src/commands/cm/stacks/export.js",
73
+ "repository": "https://github.com/contentstack/cli"
70
74
  }
package/src/app.js CHANGED
@@ -1,90 +1,144 @@
1
1
  /* eslint-disable no-redeclare */
2
- var util = require('./lib/util')
3
- var login = require('./lib/util/login')
4
- var {addlogs} = require('./lib/util/log')
5
- const chalk = require('chalk')
6
- let path = require('path')
7
- let _ = require('lodash')
2
+ var util = require('./lib/util');
3
+ var login = require('./lib/util/login');
4
+ var { addlogs, unlinkFileLogger } = require('./lib/util/log');
5
+ const setupBranches = require('./lib/util/setup-branches');
6
+ const chalk = require('chalk');
7
+ let path = require('path');
8
+ let _ = require('lodash');
8
9
 
9
10
  exports.initial = async function (config) {
10
- return new Promise(function (resolve, reject) {
11
- config = util.buildAppConfig(config)
12
- util.validateConfig(config)
11
+ return new Promise(async function (resolve, reject) {
12
+ config = util.buildAppConfig(config);
13
+ util.validateConfig(config);
13
14
  exports.getConfig = function () {
14
- return config
15
+ return config;
16
+ };
17
+
18
+ const fetchBranchAndExport = async () => {
19
+ await setupBranches(config, config.branchName);
20
+ var types = config.modules.types;
21
+ if (Array.isArray(config.branches) && config.branches.length > 0) {
22
+ for (let branch of config.branches) {
23
+ config.branchName = branch.uid;
24
+ try {
25
+ if (config.moduleName) {
26
+ await singleExport(config.moduleName, types, config, branch.uid);
27
+ } else {
28
+ await allExport(config, types, branch.uid);
29
+ }
30
+ } catch (error) {
31
+ console.log('failed export branch', branch.uid, error);
32
+ }
33
+ }
34
+ } else {
35
+ try {
36
+ if (config.moduleName) {
37
+ await singleExport(config.moduleName, types, config);
38
+ } else {
39
+ await allExport(config, types);
40
+ }
41
+ } catch (error) {
42
+ console.log('failed export contents', error && error.message);
43
+ }
44
+ }
15
45
  }
46
+
16
47
  // try {
17
- login.login(config).then(async function () {
18
- var types = config.modules.types
19
- if (config.moduleName && config.moduleName !== undefined) {
20
- singleExport(config.moduleName, types, config)
21
- return resolve()
22
- } else {
23
- allExport(config, types).then(() => {
24
- return resolve()
48
+ if (
49
+ (config.email && config.password) ||
50
+ (!config.email && !config.password && config.source_stack && config.access_token) ||
51
+ (config.auth_token && !config.management_token)
52
+ ) {
53
+ login
54
+ .login(config)
55
+ .then(async function () {
56
+ // setup branches
57
+ await fetchBranchAndExport()
58
+ unlinkFileLogger();
59
+ resolve();
25
60
  })
26
- }
27
- }).catch(error => {
28
- if (error.errors.api_key) {
29
- addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'))
30
- addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success')
31
- } else {
32
- let objKey = Object.keys(error.errors)
33
- addlogs(config, chalk.red('Stack fail to export, ' + objKey + '' + error.errors[objKey][0]), 'error')
34
- }
35
- })
36
- })
37
- }
61
+ .catch((error) => {
62
+ console.log('error', error && error.message);
63
+ if (error && error.errors && error.errors.api_key) {
64
+ addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'));
65
+ addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success');
66
+ } else {
67
+ console.log('Stack fail to export');
68
+ }
69
+ reject(error);
70
+ });
71
+ } else if (config.management_token) {
72
+ await fetchBranchAndExport()
73
+ resolve();
74
+ }
75
+ });
76
+ };
38
77
 
39
- var singleExport = async (moduleName, types, config) => {
40
- var types = config.modules.types
78
+ var singleExport = async (moduleName, types, config, branchName) => {
41
79
  try {
42
80
  if (types.indexOf(moduleName) > -1) {
43
- let iterateList = ['stack', moduleName]
81
+ let iterateList;
82
+ if (config.modules.dependency && config.modules.dependency[moduleName]) {
83
+ iterateList = config.modules.dependency[moduleName];
84
+ } else {
85
+ iterateList = ['stack'];
86
+ }
87
+ iterateList.push(moduleName);
88
+
44
89
  for (let i = 0; i < iterateList.length; i++) {
45
- var exportedModule = require('./lib/export/' + iterateList[i])
46
- await exportedModule.start(config).then(function (result) {
47
- if (iterateList[i] === 'stack') {
48
- let master_locale = { master_locale: { code: result.master_locale } }
49
- config = _.merge(config, master_locale)
50
- }
51
- })
90
+ var exportedModule = require('./lib/export/' + iterateList[i]);
91
+ const result = await exportedModule.start(config, branchName);
92
+ if (result && iterateList[i] === 'stack') {
93
+ let master_locale = {
94
+ master_locale: { code: result.code },
95
+ };
96
+ config = _.merge(config, master_locale);
97
+ }
52
98
  }
53
- addlogs(config, moduleName + ' was exported successfully!', 'success')
54
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success')
99
+ addlogs(config, moduleName + ' was exported successfully!', 'success');
100
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
55
101
  } else {
56
- addlogs(config, 'Please provide valid module name.', 'error')
102
+ addlogs(config, 'Please provide valid module name.', 'error');
57
103
  }
104
+ return true;
58
105
  } catch (error) {
59
- addlogs(config, 'Failed to migrate ' + moduleName, 'error')
60
- addlogs(config, error, 'error')
61
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error')
106
+ addlogs(config, 'Failed to migrate ' + moduleName, 'error');
107
+ addlogs(config, error, 'error');
108
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
109
+ throw error;
62
110
  }
63
- }
111
+ };
64
112
 
65
- var allExport = async (config, types) => {
113
+ var allExport = async (config, types, branchName) => {
66
114
  // eslint-disable-next-line no-async-promise-executor
67
115
  return new Promise(async (resolve, reject) => {
68
116
  try {
69
117
  for (let i = 0; i < types.length; i++) {
70
- let type = types[i]
71
- var exportedModule = require('./lib/export/' + type)
72
- await exportedModule.start(config).then(result => {
73
- if (type === 'stack') {
74
- let master_locale = { master_locale: { code: result.code } }
75
- config = _.merge(config, master_locale)
76
- }
77
- return
78
- })
118
+ let type = types[i];
119
+ var exportedModule = require('./lib/export/' + type);
120
+ const result = await exportedModule.start(config, branchName);
121
+ if (result && type === 'stack') {
122
+ let master_locale = { master_locale: { code: result.code } };
123
+ config = _.merge(config, master_locale);
124
+ }
79
125
  }
80
- addlogs(config, chalk.green('The content of the ' + config.source_stack + ' has been exported succesfully!'), 'success')
81
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success')
82
- return resolve()
126
+ addlogs(
127
+ config,
128
+ chalk.green('The content of the ' + config.source_stack + ' has been exported successfully!'),
129
+ 'success',
130
+ );
131
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
132
+ return resolve();
83
133
  } catch (error) {
84
- addlogs(config, chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'), 'error')
85
- addlogs(config, chalk.red(error.errorMessage), 'error')
86
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error')
87
- return reject(error)
134
+ addlogs(
135
+ config,
136
+ chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'),
137
+ 'error',
138
+ );
139
+ addlogs(config, chalk.red(error && error.errorMessage), 'error');
140
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
141
+ return reject(error);
88
142
  }
89
- })
90
- }
143
+ });
144
+ };