@contentstack/cli-cm-import 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
@@ -1,7 +1,6 @@
1
1
  @contentstack/cli-cm-import
2
- =================================
3
2
 
4
- It is Contentstack’s CLI plugin to import content in the stack. To learn how to export and import content in Contentstack, refer to the [Migration guide](https://www.contentstack.com/docs/developers/cli/migration/).
3
+ It is Contentstack’s CLI plugin to import content in the stack. To learn how to export and import content in Contentstack, refer to the [Migration guide](https://www.contentstack.com/docs/developers/cli/migration/).
5
4
 
6
5
  [![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
7
6
 
@@ -9,53 +8,85 @@ It is Contentstack’s CLI plugin to import content in the stack. To learn how t
9
8
  * [Usage](#usage)
10
9
  * [Commands](#commands)
11
10
  <!-- tocstop -->
11
+
12
+ For switching to EU region update the hosts at config/default.js
13
+
14
+ ```js
15
+ {
16
+ host:'https://eu-api.contentstack.com/v3',
17
+ cdn: 'https://eu-cdn.contentstack.com/v3',
18
+ ...
19
+ }
20
+ ```
21
+
22
+ For switching to AZURE-NA region update the hosts at config/default.js
23
+
24
+ ```js
25
+ {
26
+ host:'https://azure-na-api.contentstack.com/v3',
27
+ cdn: 'https://azure-na-cdn.contentstack.com/v3'
28
+ ...
29
+ }
30
+ ```
31
+
12
32
  # Usage
33
+
13
34
  <!-- usage -->
14
35
  ```sh-session
15
36
  $ npm install -g @contentstack/cli-cm-import
16
37
  $ csdx COMMAND
17
38
  running command...
18
39
  $ csdx (-v|--version|version)
19
- @contentstack/cli-cm-import/0.1.1-beta.7 darwin-x64 node-v13.14.0
40
+ @contentstack/cli-cm-import/1.0.0 linux-x64 node-v16.14.2
20
41
  $ csdx --help [COMMAND]
21
42
  USAGE
22
43
  $ csdx COMMAND
23
44
  ...
24
45
  ```
25
46
  <!-- usagestop -->
47
+
26
48
  # Commands
49
+
27
50
  <!-- commands -->
28
- * [`csdx cm:import`](#csdx-cmimport)
51
+ * [`csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]`](#csdx-cmstacksimport--c-value--k-value--d-value--a-value---module-value---backup-dir-value---branch-value---import-webhook-status-disablecurrent)
52
+
53
+ ## `csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]`
29
54
 
30
- ## `csdx cm:import`
55
+ Import script for importing the content into the new stack
31
56
 
32
57
  ```
33
58
  USAGE
34
- $ csdx cm:import
59
+ $ csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>]
60
+ [--branch <value>] [--import-webhook-status disable|current]
35
61
 
36
62
  OPTIONS
37
- -A, --auth-token to use auth token
38
- -a, --management-token-alias=management-token-alias alias of the management token
39
- -b, --backup-dir=backup-dir [optional] backup directory name when using specific module
40
- -c, --config=config [optional] path of config file
41
- -d, --data=data path and location where data is stored
42
- -m, --module=module [optional] specific module name
43
- -s, --stack-uid=stack-uid API key of the target stack
63
+ -B, --branch=branch [optional] branch name
64
+ -a, --alias=alias alias of the management token
65
+ -b, --backup-dir=backup-dir [optional] backup directory name when using specific module
66
+ -c, --config=config [optional] path of config file
67
+ -d, --data-dir=data-dir path and location where data is stored
68
+ -k, --stack-api-key=stack-api-key API key of the target stack
69
+ -m, --module=module [optional] specific module name
70
+ --import-webhook-status=disable|current [default: disable] Webhook state
44
71
 
45
72
  DESCRIPTION
46
73
  ...
47
- Once you export content from the source stack, import it to your destination stack by using the cm:import command.
74
+ Once you export content from the source stack, import it to your destination stack by using the cm:stacks:import
75
+ command.
76
+
77
+ ALIASES
78
+ $ csdx cm:import
48
79
 
49
80
  EXAMPLES
50
- csdx cm:import -A
51
- csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>
52
- csdx cm:import -A -c <path/of/config/dir>
53
- csdx cm:import -A -m <single module name>
54
- csdx cm:import -A -m <single module name> -b <backup dir>
55
- csdx cm:import -a <management_token_alias>
56
- csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>
57
- csdx cm:import -a <management_token_alias> -c <path/of/config/file>
81
+ csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
82
+ csdx cm:stacks:import --config <path/of/config/dir>
83
+ csdx cm:stacks:import --module <single module name>
84
+ csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>
85
+ csdx cm:stacks:import --alias <management_token_alias>
86
+ csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>
87
+ csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
88
+ csdx cm:stacks:import --branch <branch name>
58
89
  ```
59
90
 
60
- _See code: [src/commands/cm/import.js](https://github.com/contentstack/cli/blob/v0.1.1-beta.7/packages/contentstack-import/src/commands/cm/import.js)_
91
+ _See code: [src/commands/cm/stacks/import.js](https://github.com/contentstack/cli/blob/v1.0.0/packages/contentstack-import/src/commands/cm/stacks/import.js)_
61
92
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.7","commands":{"cm:import":{"id":"cm:import","description":"Import script for importing the content into new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:import command.\n","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":[],"examples":["csdx cm:import -A","csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>","csdx cm:import -A -c <path/of/config/dir>","csdx cm:import -A -m <single module name>","csdx cm:import -A -m <single module name> -b <backup dir>","csdx cm:import -a <management_token_alias>","csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>","csdx cm:import -a <management_token_alias> -c <path/of/config/file>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack"},"data":{"name":"data","type":"option","char":"d","description":"path and location where data is stored"},"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"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"}},"args":[]}}}
1
+ {"version":"1.0.0","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"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"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"}},"args":[]}}}
package/package.json CHANGED
@@ -1,67 +1,71 @@
1
1
  {
2
- "name": "@contentstack/cli-cm-import",
3
- "description": "Contentstack CLI plugin to import content into 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
- "axios": "^0.21.1",
13
- "bluebird": "3.5.1",
14
- "configstore": "^5.0.1",
15
- "debug": "4.1.0",
16
- "lodash": "^4.17.20",
17
- "marked": "0.7.0",
18
- "mkdirp": "^1.0.4",
19
- "ncp": "2.0.0",
20
- "request": "2.88.0",
21
- "winston": "2.4.5"
22
- },
23
- "devDependencies": {
24
- "@oclif/dev-cli": "^1.22.2",
25
- "@oclif/plugin-help": "^3.0.1",
26
- "@oclif/test": "^1.2.6",
27
- "chai": "^4.2.0",
28
- "eslint": "^5.16.0",
29
- "eslint-config-oclif": "^3.1.0",
30
- "globby": "^10.0.2",
31
- "mocha": "^8.2.1",
32
- "nyc": "^14.1.1"
33
- },
34
- "engines": {
35
- "node": ">=8.0.0"
36
- },
37
- "files": [
38
- "/npm-shrinkwrap.json",
39
- "/oclif.manifest.json",
40
- "/src",
41
- "/messages"
42
- ],
43
- "homepage": "https://github.com/contentstack/cli",
44
- "keywords": [
45
- "contentstack",
46
- "cli",
47
- "plugin"
48
- ],
49
- "scripts": {
50
- "pack": "npm pack && mv *.tgz ../../build",
51
- "postpack": "rm -f oclif.manifest.json",
52
- "prepack": "oclif-dev manifest && oclif-dev readme",
53
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
54
- "version": "oclif-dev readme && git add README.md"
55
- },
56
- "main": "./src/commands/cm/import.js",
57
- "license": "MIT",
58
- "oclif": {
59
- "commands": "./src/commands",
60
- "bin": "csdx",
61
- "devPlugins": [
62
- "@oclif/plugin-help"
63
- ],
64
- "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-import/<%- commandPath %>"
65
- },
66
- "repository": "https://github.com/contentstack/cli"
67
- }
2
+ "name": "@contentstack/cli-cm-import",
3
+ "description": "Contentstack CLI plugin to import content into 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/management": "^1.3.0",
10
+ "@contentstack/cli-utilities": "^1.0.0",
11
+ "@contentstack/cli-cm-export": "^1.0.0",
12
+ "@oclif/command": "^1.8.16",
13
+ "@oclif/config": "^1.18.3",
14
+ "bluebird": "3.5.1",
15
+ "debug": "^4.1.0",
16
+ "lodash": "^4.17.20",
17
+ "marked": "^4.0.17",
18
+ "mkdirp": "^1.0.4",
19
+ "ncp": "2.0.0",
20
+ "winston": "^3.7.2"
21
+ },
22
+ "devDependencies": {
23
+ "@oclif/dev-cli": "^1.22.2",
24
+ "@oclif/plugin-help": "^5.1.12",
25
+ "@oclif/test": "^1.2.6",
26
+ "chai": "^4.2.0",
27
+ "eslint": "^8.18.0",
28
+ "eslint-config-oclif": "^3.1.0",
29
+ "globby": "^10.0.2",
30
+ "mocha": "^10.0.0",
31
+ "nyc": "^14.1.1"
32
+ },
33
+ "engines": {
34
+ "node": ">=8.0.0"
35
+ },
36
+ "files": [
37
+ "/npm-shrinkwrap.json",
38
+ "/oclif.manifest.json",
39
+ "/src",
40
+ "/messages"
41
+ ],
42
+ "homepage": "https://github.com/contentstack/cli",
43
+ "keywords": [
44
+ "contentstack",
45
+ "cli",
46
+ "plugin"
47
+ ],
48
+ "scripts": {
49
+ "pack": "npm pack && mv *.tgz ../../build",
50
+ "postpack": "rm -f oclif.manifest.json",
51
+ "prepack": "oclif-dev manifest && oclif-dev readme",
52
+ "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
53
+ "version": "oclif-dev readme && git add README.md"
54
+ },
55
+ "csdxConfig": {
56
+ "expiredCommands": {
57
+ "cm:import": "csdx cm:stacks:import"
58
+ }
59
+ },
60
+ "main": "./src/commands/cm/stacks/import.js",
61
+ "license": "MIT",
62
+ "oclif": {
63
+ "commands": "./src/commands",
64
+ "bin": "csdx",
65
+ "devPlugins": [
66
+ "@oclif/plugin-help"
67
+ ],
68
+ "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-import/<%- commandPath %>"
69
+ },
70
+ "repository": "https://github.com/contentstack/cli"
71
+ }
package/src/app.js CHANGED
@@ -4,152 +4,219 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- let ncp = require('ncp')
8
- let Bluebird = require('bluebird')
9
- let fs = require('fs')
10
- let path = require('path')
11
- const chalk = require('chalk')
12
- const helper = require('./lib/util/fs')
13
- let _ = require('lodash')
7
+ let fs = require('fs');
8
+ let ncp = require('ncp');
9
+ let _ = require('lodash');
10
+ let path = require('path');
11
+ const chalk = require('chalk');
12
+ let util = require('./lib/util/index');
13
+ let login = require('./lib/util/login');
14
+ let { addlogs } = require('./lib/util/log');
15
+ const { HttpClient } = require('@contentstack/cli-utilities');
14
16
 
15
- let login = require('./lib/util/login')
16
- let util = require('./lib/util/index')
17
+ exports.initial = function (configData) {
18
+ return new Promise(async function (resolve, reject) {
19
+ let config = util.initialization(configData);
20
+ config.oldPath = config.data;
17
21
 
22
+ if (configData.branchName) {
23
+ await validateIfBranchExist(configData, configData.branchName)
24
+ .catch(() => {
25
+ process.exit()
26
+ })
27
+ }
18
28
 
19
- let { addlogs } = require('./lib/util/log')
29
+ const backupAndImportData = async () => {
30
+ if (fs.existsSync(config.data)) {
31
+ let migrationBackupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
32
+ return createBackup(migrationBackupDirPath, config)
33
+ .then((basePath) => {
34
+ config.data = basePath;
35
+ return util.sanitizeStack(config);
36
+ }).then(() => {
37
+ let importRes
38
+ const types = config.modules.types
20
39
 
21
- exports.initial = function (configData) {
22
- return new Promise(function (resolve, reject) {
23
- let config = util.initialization(configData)
24
- config.oldPath = config.data
25
- if (config && config !== undefined) {
26
- login(config)
27
- .then(function () {
28
- if (fs.existsSync(config.data)) {
29
- let migrationBackupDirPath = path.join(process.cwd(), '_backup_' + Math.floor((Math.random() * 1000)))
30
- return createBackup(migrationBackupDirPath, config).then((basePath) => {
31
- config.data = basePath
32
- return util.sanitizeStack(config)
33
- }).catch(e => {
34
- console.error(e)
35
- process.exit(1)
36
- })
37
- .then(() => {
38
- let types = config.modules.types
39
- if (config.moduleName && config.moduleName !== undefined) {
40
- singleImport(config.moduleName, types, config).then(() => {
41
- return resolve()
42
- })
43
- } else {
44
- allImport(config, types).then(() => {
45
- return resolve()
46
- })
47
- }
48
- }).catch(e => {
49
- console.error(e)
50
- return reject(e)
51
- })
52
- } else {
53
- let filename = path.basename(config.data)
54
- addlogs(config, chalk.red(filename + " Folder does not Exist"), 'error')
55
- return
56
- }
57
- }).catch(error => {
58
- return
59
- })
40
+ if (config.moduleName) {
41
+ importRes = singleImport(config.moduleName, types, config)
42
+ } else {
43
+ importRes = allImport(config, types)
44
+ }
45
+
46
+ importRes
47
+ .then(resolve)
48
+ .catch(reject)
49
+ }).catch((e) => {
50
+ console.error(e);
51
+ reject(e);
52
+ process.exit(1);
53
+ });
54
+ } else {
55
+ let filename = path.basename(config.data);
56
+ addlogs(config, chalk.red(filename + ' Folder does not Exist'), 'error');
57
+ }
60
58
  }
61
- })
62
- }
59
+
60
+ if (config) {
61
+ if (
62
+ (config.email && config.password) ||
63
+ (config.auth_token)
64
+ ) {
65
+ login(config)
66
+ .then(backupAndImportData)
67
+ .catch(reject);
68
+ } else if (config.management_token) {
69
+ await backupAndImportData()
70
+ }
71
+ }
72
+ });
73
+ };
63
74
 
64
75
  let singleImport = async (moduleName, types, config) => {
65
76
  return new Promise(async (resolve, reject) => {
66
77
  if (types.indexOf(moduleName) > -1) {
67
78
  if (!config.master_locale) {
68
79
  try {
69
- var masterLocalResponse = await util.masterLocalDetails(config)
70
- let master_locale = { code: masterLocalResponse.code }
71
- config['master_locale'] = master_locale
80
+ let masterLocalResponse = await util.masterLocalDetails(config);
81
+ let master_locale = { code: masterLocalResponse.code };
82
+ config['master_locale'] = master_locale;
72
83
  } catch (error) {
73
- console.log("Error to fetch the stack details" + error);
84
+ console.log('Error to fetch the stack details' + error);
74
85
  }
75
86
  }
76
- let exportedModule = require('./lib/import/' + moduleName)
77
- exportedModule.start(config).then(async function () {
78
- if (moduleName === 'content-types') {
79
- let ctPath = path.resolve(config.data, config.modules.content_types.dirName)
80
- let fieldPath = path.join(ctPath + '/field_rules_uid.json')
81
- if (fieldPath && fieldPath !== undefined) {
82
- await util.field_rules_update(config, ctPath)
87
+ let exportedModule = require('./lib/import/' + moduleName);
88
+ exportedModule
89
+ .start(config)
90
+ .then(async function (data) {
91
+ if (moduleName === 'content-types') {
92
+ let ctPath = path.resolve(config.data, config.modules.content_types.dirName);
93
+ let fieldPath = path.join(ctPath + '/field_rules_uid.json');
94
+ if (fieldPath && fieldPath !== undefined) {
95
+ await util.field_rules_update(config, ctPath);
96
+ }
83
97
  }
84
- }
85
- addlogs(config, moduleName + ' imported successfully!', 'success')
86
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success')
87
- return resolve()
88
- }).catch(function (error) {
89
- addlogs(config, 'Failed to migrate ' + moduleName, 'error')
90
- addlogs(config, error, 'error')
91
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error')
92
- return reject()
93
- })
98
+ if (!(data && data.empty)) {
99
+ addlogs(config, moduleName + ' imported successfully!', 'success');
100
+ }
101
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
102
+ return resolve();
103
+ })
104
+ .catch(function (error) {
105
+ addlogs(config, 'Failed to migrate ' + moduleName, 'error');
106
+ addlogs(config, error, 'error');
107
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
108
+ return reject(error);
109
+ });
94
110
  } else {
95
- addlogs(config, 'Please provide valid module name.', 'error')
96
- return reject()
111
+ addlogs(config, 'Please provide valid module name.', 'error');
112
+ return reject();
97
113
  }
98
- })
99
- }
114
+ });
115
+ };
100
116
 
101
117
  let allImport = async (config, types) => {
102
118
  return new Promise(async (resolve, reject) => {
103
119
  try {
104
120
  for (let i = 0; i < types.length; i++) {
105
- let type = types[i]
106
- var exportedModule = require('./lib/import/' + type)
121
+ let type = types[i];
122
+ let exportedModule = require('./lib/import/' + type);
107
123
  if (i === 0 && !config.master_locale) {
108
- var masterLocalResponse = await util.masterLocalDetails(config)
109
- let master_locale = { code: masterLocalResponse.code }
110
- config['master_locale'] = master_locale
124
+ let masterLocalResponse = await util.masterLocalDetails(config);
125
+ let master_locale = { code: masterLocalResponse.code };
126
+ config['master_locale'] = master_locale;
111
127
  }
112
- await exportedModule.start(config).then(result => {
128
+ await exportedModule.start(config).then((_result) => {
113
129
  return
114
- })
130
+ }).catch(function (error) {
131
+ addlogs(config, 'Failed to migrate ' + type, 'error');
132
+ addlogs(config, error, 'error');
133
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
134
+ return reject(error);
135
+ });
115
136
  }
116
137
  if (config.target_stack && config.source_stack) {
117
- addlogs(config, chalk.green('The data of the ' + config.sourceStackName + ' stack has been imported into ' + config.destinationStackName + ' stack successfully!'), 'success')
118
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'import'), 'success')
138
+ addlogs(
139
+ config,
140
+ chalk.green(
141
+ 'The data of the ' +
142
+ config.sourceStackName +
143
+ ' stack has been imported into ' +
144
+ config.destinationStackName +
145
+ ' stack successfully!',
146
+ ),
147
+ 'success',
148
+ );
149
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'import'), 'success');
119
150
  } else {
120
- addlogs(config, chalk.green('Stack: ' + config.target_stack + ' has been imported succesfully!'), 'success')
121
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success')
151
+ addlogs(config, chalk.green('Stack: ' + config.target_stack + ' has been imported succesfully!'), 'success');
152
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
122
153
  }
123
- return resolve()
154
+ return resolve();
124
155
  } catch (error) {
125
- addlogs(config, chalk.red('Failed to migrate stack: ' + config.target_stack + '. Please check error logs for more info'), 'error')
126
- addlogs(config, error, 'error')
127
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error')
128
- return reject()
156
+ addlogs(
157
+ config,
158
+ chalk.red('Failed to migrate stack: ' + config.target_stack + '. Please check error logs for more info'),
159
+ 'error',
160
+ );
161
+ addlogs(config, error, 'error');
162
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
163
+ return reject(error);
129
164
  }
130
- })
131
- }
165
+ });
166
+ };
132
167
 
133
168
  function createBackup(backupDirPath, config) {
134
169
  return new Promise((resolve, reject) => {
135
170
  if (config.hasOwnProperty('useBackedupDir') && fs.existsSync(config.useBackedupDir)) {
136
- return resolve(config.useBackedupDir)
171
+ return resolve(config.useBackedupDir);
137
172
  }
138
- ncp.limit = config.backupConcurrency || 16
173
+ ncp.limit = config.backupConcurrency || 16;
139
174
  if (path.isAbsolute(config.data)) {
140
175
  return ncp(config.data, backupDirPath, (error) => {
141
176
  if (error) {
142
- return reject(error)
177
+ return reject(error);
143
178
  }
144
- return resolve(backupDirPath)
145
- })
179
+ return resolve(backupDirPath);
180
+ });
146
181
  } else {
147
182
  ncp(config.data, backupDirPath, (error) => {
148
183
  if (error) {
149
- return reject(error)
184
+ return reject(error);
150
185
  }
151
- return resolve(backupDirPath)
186
+ return resolve(backupDirPath);
187
+ });
188
+ }
189
+ });
190
+ }
191
+
192
+ const validateIfBranchExist = async (config, branch) => {
193
+ return new Promise(async function (resolve, reject) {
194
+ const headers = { api_key: config.target_stack, authtoken: config.auth_token }
195
+ const httpClient = new HttpClient().headers(headers)
196
+ const result = await httpClient
197
+ .get(`https://${config.host}/v3/stacks/branches/${branch}`)
198
+ .then(({ data }) => {
199
+ if (data.error_message) {
200
+ addlogs(config, chalk.red(data.error_message), 'error');
201
+ addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
202
+ reject()
203
+ }
204
+
205
+ return data
206
+ }).catch((err) => {
207
+ console.log(err)
208
+ addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
209
+ reject()
152
210
  })
211
+
212
+ if (
213
+ result &&
214
+ typeof result === 'object' &&
215
+ typeof result.branch === 'object'
216
+ ) {
217
+ resolve(result.branch)
218
+ } else {
219
+ reject({ message: 'No branch found with the name ' + branch })
153
220
  }
154
- })
155
- }
221
+ });
222
+ };