@contentstack/cli-migration 1.0.4 → 1.2.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 +1 -1
- package/README.md +60 -14
- package/oclif.manifest.json +135 -1
- package/package.json +13 -14
- package/src/commands/cm/stacks/migration.js +10 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ The Contentstack CLI’s “Migration” plugin allows developers to automate th
|
|
|
20
20
|
$ npm install -g @contentstack/cli-migration
|
|
21
21
|
$ csdx COMMAND
|
|
22
22
|
running command...
|
|
23
|
-
$ csdx (
|
|
24
|
-
@contentstack/cli-migration/1.0
|
|
23
|
+
$ csdx (--version)
|
|
24
|
+
@contentstack/cli-migration/1.2.0 linux-x64 node-v16.19.1
|
|
25
25
|
$ csdx --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ csdx COMMAND
|
|
@@ -33,6 +33,7 @@ USAGE
|
|
|
33
33
|
|
|
34
34
|
<!-- commands -->
|
|
35
35
|
* [`csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]`](#csdx-cmstacksmigration--k-value--a-value---file-path-value---branch-value---config-file-value---config-value---multiple)
|
|
36
|
+
* [`csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]`](#csdx-cmstacksmigration--k-value--a-value---file-path-value---branch-value---config-file-value---config-value---multiple-1)
|
|
36
37
|
|
|
37
38
|
## `csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]`
|
|
38
39
|
|
|
@@ -40,34 +41,79 @@ Contentstack migration script.
|
|
|
40
41
|
|
|
41
42
|
```
|
|
42
43
|
USAGE
|
|
43
|
-
$ csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>]
|
|
44
|
-
|
|
44
|
+
$ csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>]
|
|
45
|
+
[--config <value>] [--multiple]
|
|
46
|
+
|
|
47
|
+
FLAGS
|
|
48
|
+
-B, --branch=<value> Use this flag to add the branch name where you want to perform the migration.
|
|
49
|
+
-a, --alias=<value> Use this flag to add the management token alias.
|
|
50
|
+
-k, --stack-api-key=<value> With this flag add the API key of your stack.
|
|
51
|
+
--config=<value>... [optional] inline configuration, <key1>:<value1>
|
|
52
|
+
--config-file=<value> [optional] Path of the JSON configuration file
|
|
53
|
+
--file-path=<value> Use this flag to provide the path of the file of the migration script provided by the
|
|
54
|
+
user.
|
|
55
|
+
--multiple This flag helps you to migrate multiple content files in a single instance.
|
|
56
|
+
|
|
57
|
+
DESCRIPTION
|
|
58
|
+
Contentstack migration script.
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
--
|
|
51
|
-
|
|
60
|
+
ALIASES
|
|
61
|
+
$ csdx cm:migration
|
|
62
|
+
|
|
63
|
+
EXAMPLES
|
|
64
|
+
$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>
|
|
65
|
+
|
|
66
|
+
$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>
|
|
67
|
+
|
|
68
|
+
$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>
|
|
69
|
+
|
|
70
|
+
$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>
|
|
71
|
+
|
|
72
|
+
$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path>
|
|
52
73
|
|
|
53
|
-
|
|
54
|
-
|
|
74
|
+
$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>
|
|
75
|
+
```
|
|
55
76
|
|
|
56
|
-
|
|
77
|
+
## `csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]`
|
|
78
|
+
|
|
79
|
+
Contentstack migration script.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
USAGE
|
|
83
|
+
$ csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>]
|
|
84
|
+
[--config <value>] [--multiple]
|
|
85
|
+
|
|
86
|
+
FLAGS
|
|
87
|
+
-B, --branch=<value> Use this flag to add the branch name where you want to perform the migration.
|
|
88
|
+
-a, --alias=<value> Use this flag to add the management token alias.
|
|
89
|
+
-k, --stack-api-key=<value> With this flag add the API key of your stack.
|
|
90
|
+
--config=<value>... [optional] inline configuration, <key1>:<value1>
|
|
91
|
+
--config-file=<value> [optional] Path of the JSON configuration file
|
|
92
|
+
--file-path=<value> Use this flag to provide the path of the file of the migration script provided by the
|
|
93
|
+
user.
|
|
94
|
+
--multiple This flag helps you to migrate multiple content files in a single instance.
|
|
95
|
+
|
|
96
|
+
DESCRIPTION
|
|
97
|
+
Contentstack migration script.
|
|
57
98
|
|
|
58
99
|
ALIASES
|
|
59
100
|
$ csdx cm:migration
|
|
60
101
|
|
|
61
102
|
EXAMPLES
|
|
62
103
|
$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>
|
|
104
|
+
|
|
63
105
|
$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>
|
|
106
|
+
|
|
64
107
|
$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>
|
|
108
|
+
|
|
65
109
|
$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>
|
|
110
|
+
|
|
66
111
|
$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path>
|
|
112
|
+
|
|
67
113
|
$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>
|
|
68
114
|
```
|
|
69
115
|
|
|
70
|
-
_See code: [src/commands/cm/stacks/migration.js](https://github.com/contentstack/cli
|
|
116
|
+
_See code: [src/commands/cm/stacks/migration.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-migration/src/commands/cm/stacks/migration.js)_
|
|
71
117
|
<!-- commandsstop -->
|
|
72
118
|
|
|
73
119
|
### Points to remember
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1,135 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": "1.2.0",
|
|
3
|
+
"commands": {
|
|
4
|
+
"cm:stacks:migration": {
|
|
5
|
+
"id": "cm:stacks:migration",
|
|
6
|
+
"description": "Contentstack migration script.",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"usage": "cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]",
|
|
9
|
+
"pluginName": "@contentstack/cli-migration",
|
|
10
|
+
"pluginAlias": "@contentstack/cli-migration",
|
|
11
|
+
"pluginType": "core",
|
|
12
|
+
"aliases": [
|
|
13
|
+
"cm:migration"
|
|
14
|
+
],
|
|
15
|
+
"examples": [
|
|
16
|
+
"$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>",
|
|
17
|
+
"$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>",
|
|
18
|
+
"$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>",
|
|
19
|
+
"$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>",
|
|
20
|
+
"$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ",
|
|
21
|
+
"$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>"
|
|
22
|
+
],
|
|
23
|
+
"flags": {
|
|
24
|
+
"stack-api-key": {
|
|
25
|
+
"name": "stack-api-key",
|
|
26
|
+
"type": "option",
|
|
27
|
+
"char": "k",
|
|
28
|
+
"description": "With this flag add the API key of your stack.",
|
|
29
|
+
"multiple": false,
|
|
30
|
+
"dependsOn": [
|
|
31
|
+
"authtoken"
|
|
32
|
+
],
|
|
33
|
+
"exclusive": [
|
|
34
|
+
"alias"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"alias": {
|
|
38
|
+
"name": "alias",
|
|
39
|
+
"type": "option",
|
|
40
|
+
"char": "a",
|
|
41
|
+
"description": "Use this flag to add the management token alias.",
|
|
42
|
+
"multiple": false,
|
|
43
|
+
"exclusive": [
|
|
44
|
+
"authtoken"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"file-path": {
|
|
48
|
+
"name": "file-path",
|
|
49
|
+
"type": "option",
|
|
50
|
+
"description": "Use this flag to provide the path of the file of the migration script provided by the user.",
|
|
51
|
+
"multiple": false
|
|
52
|
+
},
|
|
53
|
+
"branch": {
|
|
54
|
+
"name": "branch",
|
|
55
|
+
"type": "option",
|
|
56
|
+
"char": "B",
|
|
57
|
+
"description": "Use this flag to add the branch name where you want to perform the migration.",
|
|
58
|
+
"multiple": false
|
|
59
|
+
},
|
|
60
|
+
"config-file": {
|
|
61
|
+
"name": "config-file",
|
|
62
|
+
"type": "option",
|
|
63
|
+
"description": "[optional] Path of the JSON configuration file",
|
|
64
|
+
"multiple": false
|
|
65
|
+
},
|
|
66
|
+
"config": {
|
|
67
|
+
"name": "config",
|
|
68
|
+
"type": "option",
|
|
69
|
+
"description": "[optional] inline configuration, <key1>:<value1>",
|
|
70
|
+
"multiple": true
|
|
71
|
+
},
|
|
72
|
+
"multiple": {
|
|
73
|
+
"name": "multiple",
|
|
74
|
+
"type": "boolean",
|
|
75
|
+
"description": "This flag helps you to migrate multiple content files in a single instance.",
|
|
76
|
+
"allowNo": false
|
|
77
|
+
},
|
|
78
|
+
"api-key": {
|
|
79
|
+
"name": "api-key",
|
|
80
|
+
"type": "option",
|
|
81
|
+
"char": "k",
|
|
82
|
+
"description": "With this flag add the API key of your stack.",
|
|
83
|
+
"hidden": true,
|
|
84
|
+
"multiple": false,
|
|
85
|
+
"dependsOn": [
|
|
86
|
+
"authtoken"
|
|
87
|
+
],
|
|
88
|
+
"exclusive": [
|
|
89
|
+
"alias"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"authtoken": {
|
|
93
|
+
"name": "authtoken",
|
|
94
|
+
"type": "boolean",
|
|
95
|
+
"char": "A",
|
|
96
|
+
"description": "Use this flag to use the auth token of the current session. After logging in CLI, an auth token is generated for each new session.",
|
|
97
|
+
"hidden": true,
|
|
98
|
+
"allowNo": false,
|
|
99
|
+
"dependsOn": [
|
|
100
|
+
"api-key"
|
|
101
|
+
],
|
|
102
|
+
"exclusive": [
|
|
103
|
+
"alias"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"management-token-alias": {
|
|
107
|
+
"name": "management-token-alias",
|
|
108
|
+
"type": "option",
|
|
109
|
+
"description": "alias of the management token",
|
|
110
|
+
"hidden": true,
|
|
111
|
+
"multiple": false,
|
|
112
|
+
"exclusive": [
|
|
113
|
+
"authtoken"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
"filePath": {
|
|
117
|
+
"name": "filePath",
|
|
118
|
+
"type": "option",
|
|
119
|
+
"char": "n",
|
|
120
|
+
"description": "Use this flag to provide the path of the file of the migration script provided by the user.",
|
|
121
|
+
"hidden": true,
|
|
122
|
+
"multiple": false
|
|
123
|
+
},
|
|
124
|
+
"multi": {
|
|
125
|
+
"name": "multi",
|
|
126
|
+
"type": "boolean",
|
|
127
|
+
"description": "This flag helps you to migrate multiple content files in a single instance.",
|
|
128
|
+
"hidden": true,
|
|
129
|
+
"allowNo": false
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"args": {}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-migration",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": "@contentstack",
|
|
5
5
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contentstack/cli-command": "^1.0
|
|
8
|
-
"@contentstack/
|
|
9
|
-
"@contentstack/
|
|
7
|
+
"@contentstack/cli-command": "^1.2.0",
|
|
8
|
+
"@contentstack/cli-utilities": "^1.2.0",
|
|
9
|
+
"@contentstack/management": "^1.6.1",
|
|
10
10
|
"@oclif/command": "^1.8.16",
|
|
11
11
|
"@oclif/config": "^1.18.3",
|
|
12
12
|
"async": "^3.2.4",
|
|
@@ -14,25 +14,23 @@
|
|
|
14
14
|
"cardinal": "^2.1.1",
|
|
15
15
|
"chalk": "^4.1.0",
|
|
16
16
|
"dot-object": "^2.1.4",
|
|
17
|
-
"dotenv": "^
|
|
17
|
+
"dotenv": "^16.0.3",
|
|
18
18
|
"listr": "^0.14.3",
|
|
19
19
|
"winston": "^3.7.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@oclif/
|
|
23
|
-
"@oclif/test": "^1.2.8",
|
|
22
|
+
"@oclif/test": "^2.2.10",
|
|
24
23
|
"chai": "^4.3.4",
|
|
25
24
|
"eslint": "^8.18.0",
|
|
26
|
-
"eslint-config-oclif": "^3.1.0",
|
|
27
|
-
"eslint-config-oclif-typescript": "^0.2.0",
|
|
28
25
|
"globby": "^10.0.2",
|
|
29
26
|
"husky": "^4.2.5",
|
|
30
|
-
"jsdoc": "^
|
|
27
|
+
"jsdoc": "^4.0.0",
|
|
31
28
|
"jsdoc-to-markdown": "^7.0.1",
|
|
32
29
|
"mkdirp": "^1.0.4",
|
|
33
30
|
"mocha": "^10.0.0",
|
|
34
31
|
"nock": "^13.1.1",
|
|
35
|
-
"nyc": "^15.1.0"
|
|
32
|
+
"nyc": "^15.1.0",
|
|
33
|
+
"oclif": "^3.1.2"
|
|
36
34
|
},
|
|
37
35
|
"engines": {
|
|
38
36
|
"node": ">=8.3.0"
|
|
@@ -53,14 +51,15 @@
|
|
|
53
51
|
"bin": "csdx",
|
|
54
52
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-migration/<%- commandPath %>"
|
|
55
53
|
},
|
|
56
|
-
"repository": "contentstack/cli
|
|
54
|
+
"repository": "contentstack/cli",
|
|
57
55
|
"scripts": {
|
|
58
56
|
"postpack": "rm -f oclif.manifest.json",
|
|
59
57
|
"posttest": "eslint ./src",
|
|
60
58
|
"generate-api-ref-md-doc": "nyc jsdoc2md ./src/modules/* > ./docs/api-reference.md",
|
|
61
|
-
"prepack": "oclif
|
|
59
|
+
"prepack": "oclif manifest && oclif readme && pnpm generate-api-ref-md-doc",
|
|
62
60
|
"test": "nyc mocha \"test/**/*.test.js\"",
|
|
63
|
-
"version": "oclif
|
|
61
|
+
"version": "oclif readme && git add README.md",
|
|
62
|
+
"clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
|
|
64
63
|
},
|
|
65
64
|
"csdxConfig": {
|
|
66
65
|
"expiredCommands": {
|
|
@@ -6,14 +6,13 @@
|
|
|
6
6
|
// Dependencies
|
|
7
7
|
const Listr = require('listr');
|
|
8
8
|
const { resolve, extname } = require('path');
|
|
9
|
-
const { Command
|
|
9
|
+
const { Command } = require('@contentstack/cli-command');
|
|
10
10
|
const { waterfall } = require('async');
|
|
11
11
|
const { Parser } = require('../../../modules');
|
|
12
12
|
const { ActionList } = require('../../../actions');
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const chalk = require('chalk');
|
|
15
|
-
const { configHandler } = require('@contentstack/cli-utilities');
|
|
16
|
-
const { printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
15
|
+
const { configHandler, printFlagDeprecation, managementSDKClient, flags } = require('@contentstack/cli-utilities');
|
|
17
16
|
|
|
18
17
|
const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators');
|
|
19
18
|
|
|
@@ -46,8 +45,8 @@ class MigrationCommand extends Command {
|
|
|
46
45
|
|
|
47
46
|
async run() {
|
|
48
47
|
// TODO: filePath validation required.
|
|
49
|
-
const migrationCommandFlags = this.parse(MigrationCommand)
|
|
50
|
-
const { branch } = migrationCommandFlags;
|
|
48
|
+
const { flags: migrationCommandFlags } = await this.parse(MigrationCommand);
|
|
49
|
+
const { branch } = migrationCommandFlags || {};
|
|
51
50
|
const filePath = migrationCommandFlags['file-path'] || migrationCommandFlags.filePath;
|
|
52
51
|
const multi = migrationCommandFlags.multiple || migrationCommandFlags.multi;
|
|
53
52
|
const authtoken = configHandler.get('authtoken');
|
|
@@ -82,6 +81,7 @@ class MigrationCommand extends Command {
|
|
|
82
81
|
set('config', mapInstance, configObj);
|
|
83
82
|
}
|
|
84
83
|
|
|
84
|
+
const APIClient = await managementSDKClient({ host: this.cmaHost })
|
|
85
85
|
let stackSDKInstance;
|
|
86
86
|
if (branch) {
|
|
87
87
|
set(BRANCH, mapInstance, branch);
|
|
@@ -93,13 +93,13 @@ class MigrationCommand extends Command {
|
|
|
93
93
|
set(MANAGEMENT_TOKEN, mapInstance, managementToken);
|
|
94
94
|
set(API_KEY, mapInstance, managementToken.apiKey);
|
|
95
95
|
if (branch) {
|
|
96
|
-
stackSDKInstance =
|
|
96
|
+
stackSDKInstance = APIClient.stack({
|
|
97
97
|
management_token: managementToken.token,
|
|
98
98
|
api_key: managementToken.apiKey,
|
|
99
99
|
branch_uid: branch,
|
|
100
100
|
});
|
|
101
101
|
} else {
|
|
102
|
-
stackSDKInstance =
|
|
102
|
+
stackSDKInstance = APIClient.stack({
|
|
103
103
|
management_token: managementToken.token,
|
|
104
104
|
api_key: managementToken.apiKey,
|
|
105
105
|
});
|
|
@@ -108,19 +108,18 @@ class MigrationCommand extends Command {
|
|
|
108
108
|
} else if (authtoken) {
|
|
109
109
|
set(AUTH_TOKEN, mapInstance, authtoken);
|
|
110
110
|
set(API_KEY, mapInstance, apiKey);
|
|
111
|
-
this.managementAPIClient = { authtoken: this.authToken };
|
|
112
111
|
if (branch) {
|
|
113
|
-
stackSDKInstance =
|
|
112
|
+
stackSDKInstance = APIClient.stack({
|
|
114
113
|
api_key: apiKey,
|
|
115
114
|
branch_uid: branch,
|
|
116
115
|
});
|
|
117
116
|
} else {
|
|
118
|
-
stackSDKInstance =
|
|
117
|
+
stackSDKInstance = APIClient.stack({ api_key: apiKey });
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
set(MANAGEMENT_SDK, mapInstance, stackSDKInstance);
|
|
123
|
-
set(MANAGEMENT_CLIENT, mapInstance,
|
|
122
|
+
set(MANAGEMENT_CLIENT, mapInstance, APIClient);
|
|
124
123
|
|
|
125
124
|
if (multi) {
|
|
126
125
|
await this.execMultiFiles(filePath, mapInstance);
|