@contentstack/cli-migration 1.0.0 → 1.0.1
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 +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/src/commands/cm/stacks/migration.js +20 -14
- package/src/modules/migration.js +21 -14
- package/src/services/content-types.js +1 -4
- package/src/services/locales.js +0 -1
- package/src/utils/map.js +3 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration
|
|
|
21
21
|
$ csdx COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ csdx (-v|--version|version)
|
|
24
|
-
@contentstack/cli-migration/1.0.
|
|
24
|
+
@contentstack/cli-migration/1.0.1 darwin-arm64 node-v16.17.0
|
|
25
25
|
$ csdx --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ csdx COMMAND
|
|
@@ -67,7 +67,7 @@ EXAMPLES
|
|
|
67
67
|
$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
_See code: [src/commands/cm/stacks/migration.js](https://github.com/contentstack/cli-migration/blob/v1.0.
|
|
70
|
+
_See code: [src/commands/cm/stacks/migration.js](https://github.com/contentstack/cli-migration/blob/v1.0.1/src/commands/cm/stacks/migration.js)_
|
|
71
71
|
<!-- commandsstop -->
|
|
72
72
|
|
|
73
73
|
### Points to remember
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.1","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,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-migration",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "@contentstack",
|
|
5
5
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contentstack/cli-command": "^1.0.
|
|
7
|
+
"@contentstack/cli-command": "^1.0.1",
|
|
8
8
|
"@contentstack/management": "^1.3.0",
|
|
9
|
-
"@contentstack/cli-utilities": "^1.0.
|
|
9
|
+
"@contentstack/cli-utilities": "^1.0.2",
|
|
10
10
|
"@oclif/command": "^1.8.16",
|
|
11
11
|
"@oclif/config": "^1.18.3",
|
|
12
12
|
"async": "^3.2.4",
|
|
@@ -187,24 +187,30 @@ class MigrationCommand extends Command {
|
|
|
187
187
|
const _tasks = [];
|
|
188
188
|
const results = [];
|
|
189
189
|
|
|
190
|
+
const taskFn = (reqObj) => {
|
|
191
|
+
const { failedTitle, successTitle, tasks } = reqObj;
|
|
192
|
+
|
|
193
|
+
return async (ctx, task) => {
|
|
194
|
+
const [err, result] = await safePromise(waterfall(tasks));
|
|
195
|
+
if (err) {
|
|
196
|
+
ctx.error = true;
|
|
197
|
+
task.title = failedTitle;
|
|
198
|
+
throw err;
|
|
199
|
+
}
|
|
200
|
+
result && results.push(result);
|
|
201
|
+
task.title = successTitle;
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
190
206
|
for (const element of requests) {
|
|
191
207
|
let reqObj = element;
|
|
192
|
-
const { title
|
|
193
|
-
const
|
|
208
|
+
const { title } = reqObj;
|
|
209
|
+
const taskObj = {
|
|
194
210
|
title: title,
|
|
195
|
-
task:
|
|
196
|
-
const [err, result] = await safePromise(waterfall(tasks));
|
|
197
|
-
if (err) {
|
|
198
|
-
ctx.error = true;
|
|
199
|
-
task.title = failedTitle;
|
|
200
|
-
throw err;
|
|
201
|
-
}
|
|
202
|
-
result && results.push(result);
|
|
203
|
-
task.title = successTitle;
|
|
204
|
-
return result;
|
|
205
|
-
},
|
|
211
|
+
task: taskFn(reqObj)
|
|
206
212
|
};
|
|
207
|
-
_tasks.push(
|
|
213
|
+
_tasks.push(taskObj);
|
|
208
214
|
}
|
|
209
215
|
return _tasks;
|
|
210
216
|
}
|
package/src/modules/migration.js
CHANGED
|
@@ -79,25 +79,32 @@ class Migration extends _Migration(ContentType) {
|
|
|
79
79
|
async getTasks(_requests) {
|
|
80
80
|
const _tasks = [];
|
|
81
81
|
const results = [];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const taskFn = (reqObj) => {
|
|
83
|
+
const { failedTitle, successTitle, tasks } = reqObj;
|
|
84
|
+
|
|
85
|
+
return async (ctx, _task) => {
|
|
86
|
+
const [err, result] = await safePromise(waterfall(tasks));
|
|
87
|
+
if (err) {
|
|
88
|
+
ctx.error = true;
|
|
89
|
+
_task.title = failedTitle;
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
result && results.push(result);
|
|
93
|
+
_task.title = successTitle;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const element of _requests) {
|
|
99
|
+
let reqObj = element;
|
|
100
|
+
const { title } = reqObj;
|
|
85
101
|
const task = {
|
|
86
102
|
title: title,
|
|
87
|
-
task:
|
|
88
|
-
const [err, result] = await safePromise(waterfall(tasks));
|
|
89
|
-
if (err) {
|
|
90
|
-
ctx.error = true;
|
|
91
|
-
_task.title = failedTitle;
|
|
92
|
-
throw err;
|
|
93
|
-
}
|
|
94
|
-
result && results.push(result);
|
|
95
|
-
_task.title = successTitle;
|
|
96
|
-
return result;
|
|
97
|
-
},
|
|
103
|
+
task: taskFn(reqObj)
|
|
98
104
|
};
|
|
99
105
|
_tasks.push(task);
|
|
100
106
|
}
|
|
107
|
+
|
|
101
108
|
return _tasks;
|
|
102
109
|
}
|
|
103
110
|
}
|
|
@@ -301,15 +301,12 @@ class ContentTypeService {
|
|
|
301
301
|
// TODO: Need a better way to handle this
|
|
302
302
|
missingField = uids.includes(fieldToMove) ? null : fieldToMove;
|
|
303
303
|
|
|
304
|
-
// against && (missingField = !uids.includes(against) ? against : null);
|
|
305
304
|
if (!missingField && against) {
|
|
306
305
|
missingField = uids.includes(against) ? null : against;
|
|
307
306
|
}
|
|
308
307
|
|
|
309
308
|
// Handling both the scenarios
|
|
310
|
-
if (found === 0) {
|
|
311
|
-
isValid = false;
|
|
312
|
-
} else if (against && found === 1) {
|
|
309
|
+
if ((found === 0) || (against && (found === 1))) {
|
|
313
310
|
isValid = false;
|
|
314
311
|
}
|
|
315
312
|
|
package/src/services/locales.js
CHANGED
|
@@ -5,7 +5,6 @@ const { safePromise, constants, map: _map } = require('../utils');
|
|
|
5
5
|
const { MANAGEMENT_SDK } = constants;
|
|
6
6
|
const { get, getMapInstance } = _map;
|
|
7
7
|
const mapInstance = getMapInstance();
|
|
8
|
-
this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
|
|
9
8
|
|
|
10
9
|
class LocaleService {
|
|
11
10
|
constructor() {
|
package/src/utils/map.js
CHANGED
|
@@ -10,10 +10,10 @@ exports.get = (id, mapInstance, data = []) => {
|
|
|
10
10
|
// Create key if does not exist
|
|
11
11
|
let __data = mapInstance.get(id)
|
|
12
12
|
|
|
13
|
-
!__data
|
|
14
|
-
mapInstance.set(id, data)
|
|
13
|
+
if (!__data) {
|
|
14
|
+
mapInstance.set(id, data)
|
|
15
15
|
__data = mapInstance.get(id)
|
|
16
|
-
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
return __data
|
|
19
19
|
}
|