@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 +21 -0
- package/README.md +54 -23
- package/oclif.manifest.json +1 -1
- package/package.json +70 -66
- package/src/app.js +170 -103
- package/src/commands/cm/stacks/import.js +186 -0
- package/src/config/default.js +17 -57
- package/src/lib/import/assets.js +347 -281
- package/src/lib/import/content-types.js +203 -172
- package/src/lib/import/entries.js +1274 -681
- package/src/lib/import/environments.js +97 -82
- package/src/lib/import/extensions.js +95 -77
- package/src/lib/import/global-fields.js +114 -103
- package/src/lib/import/labels.js +118 -98
- package/src/lib/import/locales.js +124 -111
- package/src/lib/import/webhooks.js +76 -59
- package/src/lib/import/workflows.js +88 -68
- package/src/lib/util/contentstack-management-sdk.js +21 -8
- package/src/lib/util/extensionsUidReplace.js +34 -22
- package/src/lib/util/fs.js +3 -4
- package/src/lib/util/import-flags.js +150 -111
- package/src/lib/util/index.js +134 -130
- package/src/lib/util/log.js +73 -35
- package/src/lib/util/login.js +37 -36
- package/src/lib/util/lookupReplaceAssets.js +167 -61
- package/src/lib/util/lookupReplaceEntries.js +144 -66
- package/src/lib/util/removeReferenceFields.js +29 -26
- package/src/lib/util/schemaTemplate.js +31 -33
- package/src/lib/util/supress-mandatory-fields.js +14 -8
- package/src/lib/util/upload.js +29 -28
- package/src/commands/cm/import.js +0 -159
- package/src/lib/import/.DS_Store +0 -0
- package/src/lib/util/request.js +0 -82
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
|
[](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/
|
|
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-
|
|
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
|
-
|
|
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
|
-
-
|
|
38
|
-
-a, --
|
|
39
|
-
-b, --backup-dir=backup-dir
|
|
40
|
-
-c, --config=config
|
|
41
|
-
-d, --data=data
|
|
42
|
-
-
|
|
43
|
-
-
|
|
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
|
|
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 -
|
|
51
|
-
csdx cm:import
|
|
52
|
-
csdx cm:import
|
|
53
|
-
csdx cm:import
|
|
54
|
-
csdx cm:import
|
|
55
|
-
csdx cm:import
|
|
56
|
-
csdx cm:import
|
|
57
|
-
csdx cm:import
|
|
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/
|
|
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 -->
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let path = require('path')
|
|
11
|
-
const chalk = require('chalk')
|
|
12
|
-
|
|
13
|
-
let
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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(
|
|
84
|
+
console.log('Error to fetch the stack details' + error);
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
|
-
let exportedModule = require('./lib/import/' + moduleName)
|
|
77
|
-
exportedModule
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
121
|
+
let type = types[i];
|
|
122
|
+
let exportedModule = require('./lib/import/' + type);
|
|
107
123
|
if (i === 0 && !config.master_locale) {
|
|
108
|
-
|
|
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(
|
|
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(
|
|
118
|
-
|
|
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(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
};
|