@contentstack/cli-cm-import 1.2.4 → 1.3.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/README.md +84 -24
- package/oclif.manifest.json +129 -1
- package/package.json +6 -8
- package/src/app.js +47 -59
- package/src/commands/cm/stacks/import.js +1 -1
- package/src/config/default.js +1 -1
- package/src/lib/import/assets.js +261 -247
- package/src/lib/import/content-types.js +19 -21
- package/src/lib/import/custom-roles.js +7 -17
- package/src/lib/import/entries.js +344 -360
- package/src/lib/import/environments.js +5 -7
- package/src/lib/import/extensions.js +6 -9
- package/src/lib/import/global-fields.js +7 -17
- package/src/lib/import/labels.js +5 -8
- package/src/lib/import/locales.js +5 -10
- package/src/lib/import/marketplace-apps.js +389 -414
- package/src/lib/import/webhooks.js +4 -6
- package/src/lib/import/workflows.js +6 -15
- package/src/lib/util/extensionsUidReplace.js +2 -33
- package/src/lib/util/index.js +71 -72
- package/src/lib/util/login.js +45 -42
- package/src/lib/util/lookupReplaceAssets.js +6 -97
- package/src/lib/util/marketplace-app-helper.js +10 -37
- package/src/lib/util/upload.js +30 -23
- package/src/lib/util/contentstack-management-sdk.js +0 -41
package/README.md
CHANGED
|
@@ -36,8 +36,8 @@ For switching to AZURE-NA region update the hosts at config/default.js
|
|
|
36
36
|
$ npm install -g @contentstack/cli-cm-import
|
|
37
37
|
$ csdx COMMAND
|
|
38
38
|
running command...
|
|
39
|
-
$ csdx (
|
|
40
|
-
@contentstack/cli-cm-import/1.
|
|
39
|
+
$ csdx (--version)
|
|
40
|
+
@contentstack/cli-cm-import/1.3.0 linux-x64 node-v16.19.0
|
|
41
41
|
$ csdx --help [COMMAND]
|
|
42
42
|
USAGE
|
|
43
43
|
$ csdx COMMAND
|
|
@@ -49,6 +49,7 @@ USAGE
|
|
|
49
49
|
|
|
50
50
|
<!-- commands -->
|
|
51
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
|
+
* [`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-1)
|
|
52
53
|
|
|
53
54
|
## `csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]`
|
|
54
55
|
|
|
@@ -56,37 +57,96 @@ Import script for importing the content into the new stack
|
|
|
56
57
|
|
|
57
58
|
```
|
|
58
59
|
USAGE
|
|
59
|
-
$ csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
-B, --branch
|
|
64
|
-
-a, --alias
|
|
65
|
-
-b, --backup-dir
|
|
66
|
-
-c, --config
|
|
67
|
-
-d, --data-dir
|
|
68
|
-
-k, --stack-api-key
|
|
69
|
-
-m, --module
|
|
70
|
-
-y, --yes
|
|
71
|
-
--import-webhook-status
|
|
60
|
+
$ csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>]
|
|
61
|
+
[--branch <value>] [--import-webhook-status disable|current]
|
|
62
|
+
|
|
63
|
+
FLAGS
|
|
64
|
+
-B, --branch=<value> [optional] branch name
|
|
65
|
+
-a, --alias=<value> alias of the management token
|
|
66
|
+
-b, --backup-dir=<value> [optional] backup directory name when using specific module
|
|
67
|
+
-c, --config=<value> [optional] path of config file
|
|
68
|
+
-d, --data-dir=<value> path and location where data is stored
|
|
69
|
+
-k, --stack-api-key=<value> API key of the target stack
|
|
70
|
+
-m, --module=<value> [optional] specific module name
|
|
71
|
+
-y, --yes [optional] Override marketplace prompts
|
|
72
|
+
--import-webhook-status=<option> [default: disable] [optional] Webhook state
|
|
73
|
+
<options: disable|current>
|
|
72
74
|
|
|
73
75
|
DESCRIPTION
|
|
76
|
+
Import script for importing the content into the new stack
|
|
74
77
|
...
|
|
75
|
-
Once you export content from the source stack, import it to your destination stack by using the cm:stacks:import
|
|
78
|
+
Once you export content from the source stack, import it to your destination stack by using the cm:stacks:import
|
|
76
79
|
command.
|
|
77
80
|
|
|
81
|
+
|
|
78
82
|
ALIASES
|
|
79
83
|
$ csdx cm:import
|
|
80
84
|
|
|
81
85
|
EXAMPLES
|
|
82
|
-
csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
|
|
83
|
-
|
|
84
|
-
csdx cm:stacks:import --
|
|
85
|
-
|
|
86
|
-
csdx cm:stacks:import --
|
|
87
|
-
|
|
88
|
-
csdx cm:stacks:import --
|
|
89
|
-
|
|
86
|
+
$ csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
|
|
87
|
+
|
|
88
|
+
$ csdx cm:stacks:import --config <path/of/config/dir>
|
|
89
|
+
|
|
90
|
+
$ csdx cm:stacks:import --module <single module name>
|
|
91
|
+
|
|
92
|
+
$ csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>
|
|
93
|
+
|
|
94
|
+
$ csdx cm:stacks:import --alias <management_token_alias>
|
|
95
|
+
|
|
96
|
+
$ csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>
|
|
97
|
+
|
|
98
|
+
$ csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
|
|
99
|
+
|
|
100
|
+
$ csdx cm:stacks:import --branch <branch name> --yes
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## `csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]`
|
|
104
|
+
|
|
105
|
+
Import script for importing the content into the new stack
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
USAGE
|
|
109
|
+
$ csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>]
|
|
110
|
+
[--branch <value>] [--import-webhook-status disable|current]
|
|
111
|
+
|
|
112
|
+
FLAGS
|
|
113
|
+
-B, --branch=<value> [optional] branch name
|
|
114
|
+
-a, --alias=<value> alias of the management token
|
|
115
|
+
-b, --backup-dir=<value> [optional] backup directory name when using specific module
|
|
116
|
+
-c, --config=<value> [optional] path of config file
|
|
117
|
+
-d, --data-dir=<value> path and location where data is stored
|
|
118
|
+
-k, --stack-api-key=<value> API key of the target stack
|
|
119
|
+
-m, --module=<value> [optional] specific module name
|
|
120
|
+
-y, --yes [optional] Override marketplace prompts
|
|
121
|
+
--import-webhook-status=<option> [default: disable] [optional] Webhook state
|
|
122
|
+
<options: disable|current>
|
|
123
|
+
|
|
124
|
+
DESCRIPTION
|
|
125
|
+
Import script for importing the content into the new stack
|
|
126
|
+
...
|
|
127
|
+
Once you export content from the source stack, import it to your destination stack by using the cm:stacks:import
|
|
128
|
+
command.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
ALIASES
|
|
132
|
+
$ csdx cm:import
|
|
133
|
+
|
|
134
|
+
EXAMPLES
|
|
135
|
+
$ csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
|
|
136
|
+
|
|
137
|
+
$ csdx cm:stacks:import --config <path/of/config/dir>
|
|
138
|
+
|
|
139
|
+
$ csdx cm:stacks:import --module <single module name>
|
|
140
|
+
|
|
141
|
+
$ csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>
|
|
142
|
+
|
|
143
|
+
$ csdx cm:stacks:import --alias <management_token_alias>
|
|
144
|
+
|
|
145
|
+
$ csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>
|
|
146
|
+
|
|
147
|
+
$ csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
|
|
148
|
+
|
|
149
|
+
$ csdx cm:stacks:import --branch <branch name> --yes
|
|
90
150
|
```
|
|
91
151
|
|
|
92
152
|
_See code: [src/commands/cm/stacks/import.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-import/src/commands/cm/stacks/import.js)_
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1,129 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": "1.3.0",
|
|
3
|
+
"commands": {
|
|
4
|
+
"cm:stacks:import": {
|
|
5
|
+
"id": "cm:stacks:import",
|
|
6
|
+
"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",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"usage": "cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]",
|
|
9
|
+
"pluginName": "@contentstack/cli-cm-import",
|
|
10
|
+
"pluginAlias": "@contentstack/cli-cm-import",
|
|
11
|
+
"pluginType": "core",
|
|
12
|
+
"aliases": [
|
|
13
|
+
"cm:import"
|
|
14
|
+
],
|
|
15
|
+
"examples": [
|
|
16
|
+
"csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>",
|
|
17
|
+
"csdx cm:stacks:import --config <path/of/config/dir>",
|
|
18
|
+
"csdx cm:stacks:import --module <single module name>",
|
|
19
|
+
"csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>",
|
|
20
|
+
"csdx cm:stacks:import --alias <management_token_alias>",
|
|
21
|
+
"csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>",
|
|
22
|
+
"csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>",
|
|
23
|
+
"csdx cm:stacks:import --branch <branch name> --yes"
|
|
24
|
+
],
|
|
25
|
+
"flags": {
|
|
26
|
+
"config": {
|
|
27
|
+
"name": "config",
|
|
28
|
+
"type": "option",
|
|
29
|
+
"char": "c",
|
|
30
|
+
"description": "[optional] path of config file",
|
|
31
|
+
"multiple": false
|
|
32
|
+
},
|
|
33
|
+
"stack-uid": {
|
|
34
|
+
"name": "stack-uid",
|
|
35
|
+
"type": "option",
|
|
36
|
+
"char": "s",
|
|
37
|
+
"description": "API key of the target stack",
|
|
38
|
+
"hidden": true,
|
|
39
|
+
"multiple": false
|
|
40
|
+
},
|
|
41
|
+
"stack-api-key": {
|
|
42
|
+
"name": "stack-api-key",
|
|
43
|
+
"type": "option",
|
|
44
|
+
"char": "k",
|
|
45
|
+
"description": "API key of the target stack",
|
|
46
|
+
"multiple": false
|
|
47
|
+
},
|
|
48
|
+
"data": {
|
|
49
|
+
"name": "data",
|
|
50
|
+
"type": "option",
|
|
51
|
+
"description": "path and location where data is stored",
|
|
52
|
+
"hidden": true,
|
|
53
|
+
"multiple": false
|
|
54
|
+
},
|
|
55
|
+
"data-dir": {
|
|
56
|
+
"name": "data-dir",
|
|
57
|
+
"type": "option",
|
|
58
|
+
"char": "d",
|
|
59
|
+
"description": "path and location where data is stored",
|
|
60
|
+
"multiple": false
|
|
61
|
+
},
|
|
62
|
+
"alias": {
|
|
63
|
+
"name": "alias",
|
|
64
|
+
"type": "option",
|
|
65
|
+
"char": "a",
|
|
66
|
+
"description": "alias of the management token",
|
|
67
|
+
"multiple": false
|
|
68
|
+
},
|
|
69
|
+
"management-token-alias": {
|
|
70
|
+
"name": "management-token-alias",
|
|
71
|
+
"type": "option",
|
|
72
|
+
"description": "alias of the management token",
|
|
73
|
+
"hidden": true,
|
|
74
|
+
"multiple": false
|
|
75
|
+
},
|
|
76
|
+
"auth-token": {
|
|
77
|
+
"name": "auth-token",
|
|
78
|
+
"type": "boolean",
|
|
79
|
+
"char": "A",
|
|
80
|
+
"description": "to use auth token",
|
|
81
|
+
"hidden": true,
|
|
82
|
+
"allowNo": false
|
|
83
|
+
},
|
|
84
|
+
"module": {
|
|
85
|
+
"name": "module",
|
|
86
|
+
"type": "option",
|
|
87
|
+
"char": "m",
|
|
88
|
+
"description": "[optional] specific module name",
|
|
89
|
+
"multiple": false
|
|
90
|
+
},
|
|
91
|
+
"backup-dir": {
|
|
92
|
+
"name": "backup-dir",
|
|
93
|
+
"type": "option",
|
|
94
|
+
"char": "b",
|
|
95
|
+
"description": "[optional] backup directory name when using specific module",
|
|
96
|
+
"multiple": false
|
|
97
|
+
},
|
|
98
|
+
"branch": {
|
|
99
|
+
"name": "branch",
|
|
100
|
+
"type": "option",
|
|
101
|
+
"char": "B",
|
|
102
|
+
"description": "[optional] branch name",
|
|
103
|
+
"multiple": false
|
|
104
|
+
},
|
|
105
|
+
"import-webhook-status": {
|
|
106
|
+
"name": "import-webhook-status",
|
|
107
|
+
"type": "option",
|
|
108
|
+
"description": "[optional] Webhook state",
|
|
109
|
+
"required": false,
|
|
110
|
+
"multiple": false,
|
|
111
|
+
"options": [
|
|
112
|
+
"disable",
|
|
113
|
+
"current"
|
|
114
|
+
],
|
|
115
|
+
"default": "disable"
|
|
116
|
+
},
|
|
117
|
+
"yes": {
|
|
118
|
+
"name": "yes",
|
|
119
|
+
"type": "boolean",
|
|
120
|
+
"char": "y",
|
|
121
|
+
"description": "[optional] Override marketplace prompts",
|
|
122
|
+
"required": false,
|
|
123
|
+
"allowNo": false
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"args": {}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "^1.0
|
|
9
|
-
"@contentstack/
|
|
10
|
-
"@contentstack/cli-utilities": "^1.0.5",
|
|
11
|
-
"@oclif/command": "^1.8.16",
|
|
8
|
+
"@contentstack/cli-command": "^1.1.0",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.1.0",
|
|
12
10
|
"@oclif/config": "^1.18.3",
|
|
13
11
|
"big-json": "^3.2.0",
|
|
14
12
|
"bluebird": "^3.7.2",
|
|
@@ -21,7 +19,7 @@
|
|
|
21
19
|
"winston": "^3.7.2"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
|
-
"
|
|
22
|
+
"oclif": "^3.1.2",
|
|
25
23
|
"@oclif/test": "^1.2.6",
|
|
26
24
|
"chai": "^4.2.0",
|
|
27
25
|
"eslint": "^8.18.0",
|
|
@@ -48,9 +46,9 @@
|
|
|
48
46
|
"scripts": {
|
|
49
47
|
"pack": "npm pack && mv *.tgz ../../build",
|
|
50
48
|
"postpack": "rm -f oclif.manifest.json",
|
|
51
|
-
"prepack": "oclif
|
|
49
|
+
"prepack": "oclif manifest && oclif readme",
|
|
52
50
|
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
53
|
-
"version": "oclif
|
|
51
|
+
"version": "oclif readme && git add README.md"
|
|
54
52
|
},
|
|
55
53
|
"csdxConfig": {
|
|
56
54
|
"expiredCommands": {
|
package/src/app.js
CHANGED
|
@@ -4,30 +4,29 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const ncp = require('ncp');
|
|
9
|
+
const path = require('path');
|
|
11
10
|
const chalk = require('chalk');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const { HttpClient } = require('@contentstack/cli-utilities');
|
|
17
|
-
const stack = require('./lib/util/contentstack-management-sdk');
|
|
11
|
+
const util = require('./lib/util/index');
|
|
12
|
+
const login = require('./lib/util/login');
|
|
13
|
+
const { addlogs } = require('./lib/util/log');
|
|
14
|
+
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
18
15
|
|
|
19
|
-
exports.initial =
|
|
20
|
-
return new Promise(async
|
|
21
|
-
|
|
16
|
+
exports.initial = (configData) => {
|
|
17
|
+
return new Promise(async (resolve, reject) => {
|
|
18
|
+
const config = util.initialization(configData);
|
|
22
19
|
config.oldPath = config.data;
|
|
20
|
+
const APIClient = await managementSDKClient(config);
|
|
21
|
+
const stackAPIClient = APIClient.stack({ api_key: config.target_stack, management_token: config.management_token });
|
|
23
22
|
|
|
24
23
|
if (configData.branchName) {
|
|
25
|
-
await validateIfBranchExist(configData, configData.branchName).catch(() => {
|
|
24
|
+
await validateIfBranchExist(stackAPIClient, configData, configData.branchName).catch(() => {
|
|
26
25
|
process.exit();
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
const backupAndImportData = async () => {
|
|
29
|
+
const backupAndImportData = async (APIClient, stackAPIClient) => {
|
|
31
30
|
if (fs.existsSync(config.data)) {
|
|
32
31
|
let migrationBackupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
|
|
33
32
|
return createBackup(migrationBackupDirPath, config)
|
|
@@ -40,15 +39,15 @@ exports.initial = function (configData) {
|
|
|
40
39
|
const types = config.modules.types;
|
|
41
40
|
|
|
42
41
|
if (config.moduleName) {
|
|
43
|
-
importRes = singleImport(config.moduleName, types, config);
|
|
42
|
+
importRes = singleImport(APIClient, stackAPIClient, config.moduleName, types, config);
|
|
44
43
|
} else {
|
|
45
|
-
importRes = allImport(config, types);
|
|
44
|
+
importRes = allImport(APIClient, stackAPIClient, config, types);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
importRes.then(resolve).catch(reject);
|
|
49
48
|
})
|
|
50
49
|
.catch((error) => {
|
|
51
|
-
addlogs(config, `Failed to import contents ${formatError(error)}`, 'error');
|
|
50
|
+
addlogs(config, `Failed to import contents ${util.formatError(error)}`, 'error');
|
|
52
51
|
reject(e);
|
|
53
52
|
process.exit(1);
|
|
54
53
|
});
|
|
@@ -60,32 +59,28 @@ exports.initial = function (configData) {
|
|
|
60
59
|
|
|
61
60
|
if (config) {
|
|
62
61
|
if ((config.email && config.password) || config.auth_token) {
|
|
63
|
-
login(config).then(backupAndImportData).catch(reject);
|
|
62
|
+
login(config).then(backupAndImportData(APIClient, stackAPIClient)).catch(reject);
|
|
64
63
|
} else if (config.management_token) {
|
|
65
|
-
await backupAndImportData();
|
|
64
|
+
await backupAndImportData(APIClient, stackAPIClient);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
let singleImport = async (moduleName, types, config) => {
|
|
70
|
+
let singleImport = async (APIClient, stackAPIClient, moduleName, types, config) => {
|
|
72
71
|
try {
|
|
73
|
-
const stackClient = stack
|
|
74
|
-
.Client(config)
|
|
75
|
-
.stack({ api_key: config.target_stack, management_token: config.management_token });
|
|
76
|
-
|
|
77
72
|
if (types.indexOf(moduleName) > -1) {
|
|
78
73
|
if (!config.master_locale) {
|
|
79
74
|
try {
|
|
80
|
-
let masterLocalResponse = await util.masterLocalDetails(
|
|
75
|
+
let masterLocalResponse = await util.masterLocalDetails(stackAPIClient);
|
|
81
76
|
let master_locale = { code: masterLocalResponse.code };
|
|
82
77
|
config['master_locale'] = master_locale;
|
|
83
78
|
} catch (error) {
|
|
84
|
-
addlogs(config, `Failed to get master locale detail from the stack ${formatError(error)}`, 'error');
|
|
79
|
+
addlogs(config, `Failed to get master locale detail from the stack ${util.formatError(error)}`, 'error');
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
82
|
let ImportModule = require('./lib/import/' + moduleName);
|
|
88
|
-
const importResponse = await new ImportModule(config,
|
|
83
|
+
const importResponse = await new ImportModule(config, stackAPIClient, APIClient).start();
|
|
89
84
|
if (moduleName === 'content-types') {
|
|
90
85
|
let ctPath = path.resolve(config.data, config.modules.content_types.dirName);
|
|
91
86
|
let fieldPath = path.join(ctPath + '/field_rules_uid.json');
|
|
@@ -103,25 +98,22 @@ let singleImport = async (moduleName, types, config) => {
|
|
|
103
98
|
}
|
|
104
99
|
} catch (error) {
|
|
105
100
|
addlogs(config, 'Failed to migrate ' + moduleName, 'error');
|
|
106
|
-
addlogs(config, formatError(error), 'error');
|
|
101
|
+
addlogs(config, util.formatError(error), 'error');
|
|
107
102
|
addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
|
|
108
103
|
}
|
|
109
104
|
};
|
|
110
105
|
|
|
111
|
-
let allImport = async (config, types) => {
|
|
106
|
+
let allImport = async (APIClient, stackAPIClient, config, types) => {
|
|
112
107
|
try {
|
|
113
|
-
const stackClient = stack
|
|
114
|
-
.Client(config)
|
|
115
|
-
.stack({ api_key: config.target_stack, management_token: config.management_token });
|
|
116
108
|
for (let i = 0; i < types.length; i++) {
|
|
117
109
|
let type = types[i];
|
|
118
110
|
if (i === 0 && !config.master_locale) {
|
|
119
|
-
let masterLocalResponse = await util.masterLocalDetails(
|
|
111
|
+
let masterLocalResponse = await util.masterLocalDetails(stackAPIClient);
|
|
120
112
|
let master_locale = { code: masterLocalResponse.code };
|
|
121
113
|
config['master_locale'] = master_locale;
|
|
122
114
|
}
|
|
123
115
|
let ImportModule = require('./lib/import/' + type);
|
|
124
|
-
await new ImportModule(config,
|
|
116
|
+
await new ImportModule(config, stackAPIClient, APIClient).start(config);
|
|
125
117
|
}
|
|
126
118
|
if (config.target_stack && config.source_stack) {
|
|
127
119
|
addlogs(
|
|
@@ -157,12 +149,12 @@ let allImport = async (config, types) => {
|
|
|
157
149
|
),
|
|
158
150
|
'error',
|
|
159
151
|
);
|
|
160
|
-
addlogs(config, formatError(error), 'error');
|
|
152
|
+
addlogs(config, util.formatError(error), 'error');
|
|
161
153
|
addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
|
|
162
154
|
}
|
|
163
155
|
};
|
|
164
156
|
|
|
165
|
-
|
|
157
|
+
const createBackup = (backupDirPath, config) => {
|
|
166
158
|
return new Promise((resolve, reject) => {
|
|
167
159
|
if (config.hasOwnProperty('useBackedupDir') && fs.existsSync(config.useBackedupDir)) {
|
|
168
160
|
return resolve(config.useBackedupDir);
|
|
@@ -184,33 +176,29 @@ function createBackup(backupDirPath, config) {
|
|
|
184
176
|
});
|
|
185
177
|
}
|
|
186
178
|
});
|
|
187
|
-
}
|
|
179
|
+
};
|
|
188
180
|
|
|
189
|
-
const validateIfBranchExist = async (config, branch) => {
|
|
190
|
-
return new Promise(async
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
181
|
+
const validateIfBranchExist = async (stackAPIClient, config, branch) => {
|
|
182
|
+
return new Promise(async (resolve, reject) => {
|
|
183
|
+
try {
|
|
184
|
+
const data = await stackAPIClient
|
|
185
|
+
.branch(branch)
|
|
186
|
+
.fetch()
|
|
187
|
+
.catch((_err) => {});
|
|
188
|
+
if (data && typeof data === 'object') {
|
|
196
189
|
if (data.error_message) {
|
|
197
190
|
addlogs(config, chalk.red(data.error_message), 'error');
|
|
198
191
|
addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
|
|
199
|
-
reject();
|
|
192
|
+
reject({ message: 'No branch found with the name ' + branch, error: error_message });
|
|
193
|
+
} else {
|
|
194
|
+
resolve(data);
|
|
200
195
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
reject();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
if (result && typeof result === 'object' && typeof result.branch === 'object') {
|
|
211
|
-
resolve(result.branch);
|
|
212
|
-
} else {
|
|
213
|
-
reject({ message: 'No branch found with the name ' + branch });
|
|
196
|
+
} else {
|
|
197
|
+
reject({ message: 'No branch found with the name ' + branch, error: {} });
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
|
|
201
|
+
reject({ message: 'No branch found with the name ' + branch, error });
|
|
214
202
|
}
|
|
215
203
|
});
|
|
216
204
|
};
|
|
@@ -15,7 +15,7 @@ const { printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
|
15
15
|
class ImportCommand extends Command {
|
|
16
16
|
async run() {
|
|
17
17
|
let self = this;
|
|
18
|
-
const importCommandFlags = self.parse(ImportCommand)
|
|
18
|
+
const { flags: importCommandFlags } = await self.parse(ImportCommand);
|
|
19
19
|
const extConfig = importCommandFlags.config;
|
|
20
20
|
let targetStack = importCommandFlags['stack-uid'] || importCommandFlags['stack-api-key'];
|
|
21
21
|
const data = importCommandFlags.data || importCommandFlags['data-dir'];
|
package/src/config/default.js
CHANGED