@contentstack/cli-migration 0.1.1-beta.1 → 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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -25
  3. package/oclif.manifest.json +1 -1
  4. package/package.json +17 -12
  5. package/src/actions/action-list.js +11 -11
  6. package/src/actions/index.js +33 -34
  7. package/src/commands/cm/stacks/migration.js +299 -0
  8. package/src/config/api-config.js +5 -6
  9. package/src/config/default-options.js +2 -2
  10. package/src/config/index.js +2 -2
  11. package/src/config/master-locale.js +2 -2
  12. package/src/modules/base.js +33 -33
  13. package/src/modules/content-types.js +76 -76
  14. package/src/modules/fields.js +73 -73
  15. package/src/modules/index.js +2 -2
  16. package/src/modules/locale.js +13 -13
  17. package/src/modules/migration.js +45 -46
  18. package/src/modules/parser.js +68 -47
  19. package/src/services/content-types.js +160 -163
  20. package/src/services/index.js +2 -2
  21. package/src/services/locales.js +33 -35
  22. package/src/utils/auto-retry.js +14 -12
  23. package/src/utils/callsite.js +14 -14
  24. package/src/utils/constants.js +35 -33
  25. package/src/utils/contentstack-sdk.js +42 -43
  26. package/src/utils/error-handler.js +8 -8
  27. package/src/utils/error-helper.js +41 -40
  28. package/src/utils/fs-helper.js +24 -10
  29. package/src/utils/get-batches.js +4 -4
  30. package/src/utils/get-config.js +6 -6
  31. package/src/utils/group-by.js +17 -17
  32. package/src/utils/index.js +2 -2
  33. package/src/utils/logger.js +42 -52
  34. package/src/utils/object-helper.js +7 -7
  35. package/src/utils/safe-promise.js +2 -2
  36. package/src/utils/schema-helper.js +12 -12
  37. package/src/utils/success-handler.js +5 -5
  38. package/src/validators/api-error.js +10 -8
  39. package/src/validators/base-validator.js +14 -14
  40. package/src/validators/create-content-type-validator.js +21 -25
  41. package/src/validators/edit-content-type-validator.js +21 -24
  42. package/src/validators/field-validator.js +10 -8
  43. package/src/validators/index.js +2 -2
  44. package/src/validators/migration-error.js +9 -7
  45. package/src/validators/schema-validator.js +11 -9
  46. package/src/validators/type-error.js +11 -10
  47. package/src/commands/cm/migration.js +0 -182
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,8 +1,6 @@
1
- @contentstack/cli-migration
2
- ===========================
3
-
4
- The Contentstack CLI’s “Migration” plugin allows developers to automate the content migration process and easily migrate your content from your system to Contentstack.
1
+ # @contentstack/cli-migration
5
2
 
3
+ The Contentstack CLI’s “Migration” plugin allows developers to automate the content migration process and easily migrate your content from your system to Contentstack.
6
4
 
7
5
  [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
8
6
  [![Version](https://img.shields.io/npm/v/@contentstack/cli-migration.svg)](https://npmjs.org/package/@contentstack/cli-migration)
@@ -10,60 +8,70 @@ The Contentstack CLI’s “Migration” plugin allows developers to automate th
10
8
  [![License](https://img.shields.io/npm/l/@contentstack/cli-migration.svg)](https://github.com/ninadhatkar/cli-migration/blob/master/package.json)
11
9
 
12
10
  <!-- toc -->
11
+ * [@contentstack/cli-migration](#contentstackcli-migration)
13
12
  * [Usage](#usage)
14
13
  * [Commands](#commands)
15
14
  <!-- tocstop -->
15
+
16
16
  # Usage
17
+
17
18
  <!-- usage -->
18
19
  ```sh-session
19
20
  $ npm install -g @contentstack/cli-migration
20
21
  $ csdx COMMAND
21
22
  running command...
22
23
  $ csdx (-v|--version|version)
23
- @contentstack/cli-migration/0.1.1-beta.1 linux-x64 node-v12.18.4
24
+ @contentstack/cli-migration/1.0.0 linux-x64 node-v16.14.2
24
25
  $ csdx --help [COMMAND]
25
26
  USAGE
26
27
  $ csdx COMMAND
27
28
  ...
28
29
  ```
29
30
  <!-- usagestop -->
31
+
30
32
  # Commands
33
+
31
34
  <!-- commands -->
32
- * [`csdx cm:migration`](#csdx-cmmigration)
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)
33
36
 
34
- ## `csdx cm:migration`
37
+ ## `csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]`
35
38
 
36
39
  Contentstack migration script.
37
40
 
38
41
  ```
39
- Contentstack migration script.
40
-
41
42
  USAGE
42
- $ csdx cm:migration
43
+ $ csdx cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>]
44
+ [--config <value>] [--multiple]
43
45
 
44
46
  OPTIONS
45
- -A, --authtoken Use this flag to use the auth token of the current session. After
46
- logging in CLI, an auth token is generated for each new session.
47
+ -B, --branch=branch Use this flag to add the branch name where you want to perform the migration.
48
+ -a, --alias=alias Use this flag to add the management token alias.
49
+ -k, --stack-api-key=stack-api-key With this flag add the API key of your stack.
50
+ --config=config [optional] inline configuration, <key1>:<value1>
51
+ --config-file=config-file [optional] Path of the JSON configuration file
47
52
 
48
- -B, --branch=branch Use this flag to add the branch name where you want to perform
49
- the migration.
53
+ --file-path=file-path Use this flag to provide the path of the file of the migration script provided by
54
+ the user.
50
55
 
51
- -a, --management-token-alias=management-token-alias Use this flag to add the management token alias.
56
+ --multiple This flag helps you to migrate multiple content files in a single instance.
52
57
 
53
- -k, --api-key=api-key With this flag add the API key of your stack.
54
-
55
- -n, --filePath=filePath Use this flag to provide the path of the file of the migration
56
- script provided by the user.
58
+ ALIASES
59
+ $ csdx cm:migration
57
60
 
58
- --multi This flag helps you to migrate multiple content files in a single
59
- instance.
61
+ EXAMPLES
62
+ $ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>
63
+ $ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>
64
+ $ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>
65
+ $ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>
66
+ $ csdx cm:migration --multiple --file-path <migration/scripts/dir/path>
67
+ $ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>
60
68
  ```
61
69
 
62
- _See code: [src/commands/cm/migration.js](https://github.com/contentstack/cli-migration/blob/v0.1.1-beta.1/src/commands/cm/migration.js)_
70
+ _See code: [src/commands/cm/stacks/migration.js](https://github.com/contentstack/cli-migration/blob/v1.0.0/src/commands/cm/stacks/migration.js)_
63
71
  <!-- commandsstop -->
64
72
 
65
73
  ### Points to remember
66
74
 
67
- * Currently, the Migration plugin does not support Group fields migration. You can pass a custom schema to the createField method to migrate Group fields. [here](packages/contentstack-migration/examples/)
68
- * Currently, the Migration plugin does not support Global fields migration. You can migrate Global fields by creating an SDK instance and adding it to content types using the createField method.[here](packages/contentstack-migration/examples/)
69
- * Currently, the Migration plugin does not support migration of Entries. You can migrate entries by creating an SDK instance to create/ update/ delete entries for your content type. [here](packages/contentstack-migration/examples/)
75
+ - Currently, the Migration plugin does not support Group fields migration. You can pass a custom schema to the createField method to migrate Group fields. [here](packages/contentstack-migration/examples/)
76
+ - Currently, the Migration plugin does not support Global fields migration. You can migrate Global fields by creating an SDK instance and adding it to content types using the createField method.[here](packages/contentstack-migration/examples/)
77
+ - Currently, the Migration plugin does not support migration of Entries. You can migrate entries by creating an SDK instance to create/ update/ delete entries for your content type. [here](packages/contentstack-migration/examples/)
@@ -1 +1 @@
1
- {"version":"0.1.1-beta.1","commands":{"cm:migration":{"id":"cm:migration","description":"Contentstack migration script.","pluginName":"@contentstack/cli-migration","pluginType":"core","aliases":[],"flags":{"api-key":{"name":"api-key","type":"option","char":"k","description":"With this flag add the API key of your stack."},"authtoken":{"name":"authtoken","type":"boolean","char":"A","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.","allowNo":false},"management-token-alias":{"name":"management-token-alias","type":"option","char":"a","description":"Use this flag to add the management token alias."},"filePath":{"name":"filePath","type":"option","char":"n","description":"Use this flag to provide the path of the file of the migration script provided by the user."},"branch":{"name":"branch","type":"option","char":"B","description":"Use this flag to add the branch name where you want to perform the migration."},"multi":{"name":"multi","type":"boolean","description":"This flag helps you to migrate multiple content files in a single instance.","allowNo":false}},"args":[]}}}
1
+ {"version":"1.0.0","commands":{"cm:stacks:migration":{"id":"cm:stacks:migration","description":"Contentstack migration script.","usage":"cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]","pluginName":"@contentstack/cli-migration","pluginType":"core","aliases":["cm:migration"],"examples":["$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>","$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>","$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>","$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>","$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ","$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>"],"flags":{"api-key":{"name":"api-key","type":"option","char":"k","description":"With this flag add the API key of your stack.","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"With this flag add the API key of your stack."},"authtoken":{"name":"authtoken","type":"boolean","char":"A","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.","hidden":true,"allowNo":false},"alias":{"name":"alias","type":"option","char":"a","description":"Use this flag to add the management token alias."},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"filePath":{"name":"filePath","type":"option","char":"n","description":"Use this flag to provide the path of the file of the migration script provided by the user.","hidden":true},"file-path":{"name":"file-path","type":"option","description":"Use this flag to provide the path of the file of the migration script provided by the user."},"branch":{"name":"branch","type":"option","char":"B","description":"Use this flag to add the branch name where you want to perform the migration."},"config-file":{"name":"config-file","type":"option","description":"[optional] Path of the JSON configuration file"},"config":{"name":"config","type":"option","description":"[optional] inline configuration, <key1>:<value1>"},"multi":{"name":"multi","type":"boolean","description":"This flag helps you to migrate multiple content files in a single instance.","hidden":true,"allowNo":false},"multiple":{"name":"multiple","type":"boolean","description":"This flag helps you to migrate multiple content files in a single instance.","allowNo":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
2
  "name": "@contentstack/cli-migration",
3
- "version": "0.1.1-beta.1",
3
+ "version": "1.0.0",
4
4
  "author": "@contentstack",
5
5
  "bugs": "https://github.com/contentstack/cli/issues",
6
6
  "dependencies": {
7
- "@contentstack/cli-command": "^0.1.1-beta.2",
8
- "@contentstack/management": "github:contentstack/contentstack-management-javascript#65e8588",
9
- "@oclif/command": "^1.6.1",
10
- "@oclif/config": "^1.15.1",
11
- "async": "^3.2.0",
12
- "axios": "^0.21.1",
7
+ "@contentstack/cli-command": "^1.0.0",
8
+ "@contentstack/management": "^1.3.0",
9
+ "@contentstack/cli-utilities": "^1.0.0",
10
+ "@oclif/command": "^1.8.16",
11
+ "@oclif/config": "^1.18.3",
12
+ "async": "^3.2.4",
13
13
  "callsites": "^3.1.0",
14
14
  "cardinal": "^2.1.1",
15
15
  "chalk": "^4.1.0",
16
16
  "dot-object": "^2.1.4",
17
17
  "dotenv": "^8.2.0",
18
18
  "listr": "^0.14.3",
19
- "winston": "^3.3.3"
19
+ "winston": "^3.7.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@oclif/dev-cli": "^1.26.0",
23
- "@oclif/plugin-help": "^2.2.3",
23
+ "@oclif/plugin-help": "^5.1.12",
24
24
  "@oclif/test": "^1.2.8",
25
25
  "chai": "^4.3.4",
26
- "eslint": "^5.16.0",
26
+ "eslint": "^8.18.0",
27
27
  "eslint-config-oclif": "^3.1.0",
28
28
  "eslint-config-oclif-typescript": "^0.2.0",
29
29
  "globby": "^10.0.2",
@@ -31,7 +31,7 @@
31
31
  "jsdoc": "^3.6.7",
32
32
  "jsdoc-to-markdown": "^7.0.1",
33
33
  "mkdirp": "^1.0.4",
34
- "mocha": "^5.2.0",
34
+ "mocha": "^10.0.0",
35
35
  "nock": "^13.1.1",
36
36
  "nyc": "^14.1.1"
37
37
  },
@@ -64,5 +64,10 @@
64
64
  "prepack": "oclif-dev manifest && oclif-dev readme && npm run generate-api-ref-md-doc",
65
65
  "test": "nyc mocha \"test/**/*.test.js\"",
66
66
  "version": "oclif-dev readme && git add README.md"
67
+ },
68
+ "csdxConfig": {
69
+ "expiredCommands": {
70
+ "cm:migration": "csdx cm:stacks:migration"
71
+ }
67
72
  }
68
- }
73
+ }
@@ -1,32 +1,32 @@
1
1
  /* eslint-disable no-unused-expressions */
2
- 'use strict'
2
+ 'use strict';
3
3
 
4
4
  class ActionList {
5
5
  constructor(actionList, typeErrors) {
6
- typeErrors && (this.typeErrors = typeErrors)
7
- actionList && (this.actionList = actionList)
8
- this.validators = []
6
+ typeErrors && (this.typeErrors = typeErrors);
7
+ actionList && (this.actionList = actionList);
8
+ this.validators = [];
9
9
  }
10
10
 
11
11
  addValidators(validator) {
12
- this.validators.push(validator)
12
+ this.validators.push(validator);
13
13
  }
14
14
 
15
15
  validate() {
16
- const {validators, actionList} = this
16
+ const { validators, actionList } = this;
17
17
 
18
- let errors = []
18
+ let errors = [];
19
19
  for (const action of actionList) {
20
20
  for (const validator of validators) {
21
21
  if (validator.isApplicable(action)) {
22
- errors = validator.validate(action)
23
- break
22
+ errors = validator.validate(action);
23
+ break;
24
24
  }
25
25
  }
26
26
  }
27
27
 
28
- return errors
28
+ return errors;
29
29
  }
30
30
  }
31
31
 
32
- module.exports = ActionList
32
+ module.exports = ActionList;
@@ -1,9 +1,9 @@
1
- 'use strict'
1
+ 'use strict';
2
2
 
3
3
  // Utils
4
- const {constants} = require('../utils')
4
+ const { constants } = require('../utils');
5
5
  // Properties
6
- const {actions, validationAction} = constants
6
+ const { actions, validationAction } = constants;
7
7
  const {
8
8
  create,
9
9
  customTask,
@@ -16,11 +16,11 @@ const {
16
16
  schema,
17
17
  __migrationError,
18
18
  field,
19
- } = validationAction
19
+ } = validationAction;
20
20
 
21
21
  const actionCreators = {
22
22
  customTasks: (callsite, opts) => {
23
- const {CUSTOM_TASK} = actions
23
+ const { CUSTOM_TASK } = actions;
24
24
  return {
25
25
  type: customTask,
26
26
  meta: {
@@ -33,11 +33,11 @@ const actionCreators = {
33
33
  options: opts,
34
34
  action: CUSTOM_TASK,
35
35
  },
36
- }
36
+ };
37
37
  },
38
38
  contentType: {
39
39
  create: (callsite, id, opts) => {
40
- const {CREATE_CT} = actions
40
+ const { CREATE_CT } = actions;
41
41
  return {
42
42
  type: create,
43
43
  meta: {
@@ -51,10 +51,10 @@ const actionCreators = {
51
51
  options: opts,
52
52
  action: CREATE_CT,
53
53
  },
54
- }
54
+ };
55
55
  },
56
56
  edit: (callsite, id, opts) => {
57
- const {EDIT_CT} = actions
57
+ const { EDIT_CT } = actions;
58
58
 
59
59
  return {
60
60
  type: edit,
@@ -69,7 +69,7 @@ const actionCreators = {
69
69
  options: opts,
70
70
  action: EDIT_CT,
71
71
  },
72
- }
72
+ };
73
73
  },
74
74
  // delete: () => { },
75
75
  transformEntries: (callsite, id, opts) => {
@@ -84,7 +84,7 @@ const actionCreators = {
84
84
  payload: {
85
85
  options: opts,
86
86
  },
87
- }
87
+ };
88
88
  },
89
89
  deriveLinkedEntries: (callsite, id, opts) => {
90
90
  return {
@@ -98,7 +98,7 @@ const actionCreators = {
98
98
  payload: {
99
99
  options: opts,
100
100
  },
101
- }
101
+ };
102
102
  },
103
103
  transformEntriesToType: (callsite, id, opts) => {
104
104
  return {
@@ -112,9 +112,9 @@ const actionCreators = {
112
112
  payload: {
113
113
  options: opts,
114
114
  },
115
- }
115
+ };
116
116
  },
117
- typeError: (callsite, id, {typeErrors}) => {
117
+ typeError: (callsite, id, { typeErrors }) => {
118
118
  return {
119
119
  type: typeError,
120
120
  meta: {
@@ -123,8 +123,8 @@ const actionCreators = {
123
123
  line: callsite.getLineNumber(),
124
124
  },
125
125
  },
126
- payload: {typeErrors},
127
- }
126
+ payload: { typeErrors },
127
+ };
128
128
  },
129
129
  apiError: (callsite, id, opts) => {
130
130
  return {
@@ -135,8 +135,8 @@ const actionCreators = {
135
135
  line: callsite.getLineNumber(),
136
136
  },
137
137
  },
138
- payload: {apiError: opts},
139
- }
138
+ payload: { apiError: opts },
139
+ };
140
140
  },
141
141
  fromFields: (callsite, id, opts) => {
142
142
  return {
@@ -147,8 +147,8 @@ const actionCreators = {
147
147
  line: callsite.getLineNumber(),
148
148
  },
149
149
  },
150
- payload: {fromField: opts.fromField},
151
- }
150
+ payload: { fromField: opts.fromField },
151
+ };
152
152
  },
153
153
  toFields: (callsite, id, opts) => {
154
154
  return {
@@ -159,8 +159,8 @@ const actionCreators = {
159
159
  line: callsite.getLineNumber(),
160
160
  },
161
161
  },
162
- payload: {toField: opts.toField},
163
- }
162
+ payload: { toField: opts.toField },
163
+ };
164
164
  },
165
165
  toReferenceFields: (callsite, id, opts) => {
166
166
  return {
@@ -171,8 +171,8 @@ const actionCreators = {
171
171
  line: callsite.getLineNumber(),
172
172
  },
173
173
  },
174
- payload: {toField: opts.toReferenceField},
175
- }
174
+ payload: { toField: opts.toReferenceField },
175
+ };
176
176
  },
177
177
  deriveFields: (callsite, id, opts) => {
178
178
  return {
@@ -183,8 +183,8 @@ const actionCreators = {
183
183
  line: callsite.getLineNumber(),
184
184
  },
185
185
  },
186
- payload: {deriveField: opts.deriveField},
187
- }
186
+ payload: { deriveField: opts.deriveField },
187
+ };
188
188
  },
189
189
  migrationError: (callsite, id, opts) => {
190
190
  return {
@@ -195,8 +195,8 @@ const actionCreators = {
195
195
  line: callsite.getLineNumber(),
196
196
  },
197
197
  },
198
- payload: {migrationError: opts},
199
- }
198
+ payload: { migrationError: opts },
199
+ };
200
200
  },
201
201
  field: (callsite, id, opts) => {
202
202
  return {
@@ -207,12 +207,11 @@ const actionCreators = {
207
207
  line: callsite.getLineNumber(),
208
208
  },
209
209
  },
210
- payload: {field: opts},
211
- }
210
+ payload: { field: opts },
211
+ };
212
212
  },
213
-
214
213
  },
215
- }
214
+ };
216
215
 
217
- exports.actionCreators = actionCreators
218
- exports.ActionList = require('./action-list')
216
+ exports.actionCreators = actionCreators;
217
+ exports.ActionList = require('./action-list');