@contentstack/cli-migration 1.4.2 → 1.5.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/LICENSE +1 -1
- package/README.md +2 -2
- package/package.json +5 -5
- package/src/commands/cm/stacks/migration.js +13 -7
- package/src/utils/callsite.js +2 -1
- package/src/utils/error-helper.js +6 -4
- package/src/utils/fs-helper.js +2 -1
- package/src/utils/logger.js +2 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ The Contentstack CLI’s “Migration” plugin allows developers to automate th
|
|
|
5
5
|
[](https://oclif.io)
|
|
6
6
|
[](https://npmjs.org/package/@contentstack/cli-migration)
|
|
7
7
|
[](https://npmjs.org/package/@contentstack/cli-migration)
|
|
8
|
-
[](https://github.com
|
|
8
|
+
[](https://github.com/***REMOVED***/cli-migration/blob/master/package.json)
|
|
9
9
|
|
|
10
10
|
<!-- toc -->
|
|
11
11
|
* [@contentstack/cli-migration](#contentstackcli-migration)
|
|
@@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration
|
|
|
21
21
|
$ csdx COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ csdx (--version)
|
|
24
|
-
@contentstack/cli-migration/1.
|
|
24
|
+
@contentstack/cli-migration/1.5.1 darwin-arm64 node-v20.8.0
|
|
25
25
|
$ csdx --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ csdx COMMAND
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-migration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"author": "@contentstack",
|
|
5
5
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@contentstack/cli-command": "~1.2.16",
|
|
8
|
-
"@contentstack/cli-utilities": "~1.
|
|
8
|
+
"@contentstack/cli-utilities": "~1.6.0",
|
|
9
9
|
"async": "^3.2.4",
|
|
10
10
|
"callsites": "^3.1.0",
|
|
11
11
|
"cardinal": "^2.1.1",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"winston": "^3.7.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@oclif/test": "^2.
|
|
19
|
+
"@oclif/test": "^2.5.6",
|
|
20
20
|
"chai": "^4.3.4",
|
|
21
21
|
"eslint": "^8.18.0",
|
|
22
22
|
"globby": "^10.0.2",
|
|
23
23
|
"husky": "^8.0.3",
|
|
24
24
|
"jsdoc": "^4.0.0",
|
|
25
|
-
"jsdoc-to-markdown": "^
|
|
25
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
26
26
|
"mkdirp": "^1.0.4",
|
|
27
27
|
"nock": "^13.1.1",
|
|
28
28
|
"nyc": "^15.1.0",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
"cm:migration": "O-MGRTN"
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|
|
@@ -12,7 +12,13 @@ const { Parser } = require('../../../modules');
|
|
|
12
12
|
const { ActionList } = require('../../../actions');
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const chalk = require('chalk');
|
|
15
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
printFlagDeprecation,
|
|
17
|
+
managementSDKClient,
|
|
18
|
+
flags,
|
|
19
|
+
isAuthenticated,
|
|
20
|
+
pathValidator,
|
|
21
|
+
} = require('@contentstack/cli-utilities');
|
|
16
22
|
|
|
17
23
|
const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators');
|
|
18
24
|
|
|
@@ -77,7 +83,7 @@ class MigrationCommand extends Command {
|
|
|
77
83
|
let configObj = config.reduce((a, v) => {
|
|
78
84
|
//NOTE: Temp code to handle only one spilt(Window absolute path issue).Need to replace with hardcoded config key
|
|
79
85
|
let [key, ...value] = v.split(':');
|
|
80
|
-
value = value?.length > 1 ? value?.join(':') : value?.join(
|
|
86
|
+
value = value?.length > 1 ? value?.join(':') : value?.join();
|
|
81
87
|
return { ...a, [key]: value };
|
|
82
88
|
}, {});
|
|
83
89
|
set('config', mapInstance, configObj);
|
|
@@ -132,7 +138,7 @@ class MigrationCommand extends Command {
|
|
|
132
138
|
|
|
133
139
|
async execSingleFile(filePath, mapInstance) {
|
|
134
140
|
// Resolved absolute path
|
|
135
|
-
const resolvedMigrationPath =
|
|
141
|
+
const resolvedMigrationPath = pathValidator(filePath);
|
|
136
142
|
// User provided migration function
|
|
137
143
|
const migrationFunc = require(resolvedMigrationPath);
|
|
138
144
|
|
|
@@ -166,15 +172,15 @@ class MigrationCommand extends Command {
|
|
|
166
172
|
this.log(error.message);
|
|
167
173
|
} else if (error.errorMessage) {
|
|
168
174
|
this.log(error.errorMessage);
|
|
169
|
-
}else{
|
|
170
|
-
this.log(error)
|
|
175
|
+
} else {
|
|
176
|
+
this.log(error);
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
async execMultiFiles(filePath, mapInstance) {
|
|
176
182
|
// Resolved absolute path
|
|
177
|
-
const resolvedMigrationPath =
|
|
183
|
+
const resolvedMigrationPath = pathValidator(filePath);
|
|
178
184
|
try {
|
|
179
185
|
const files = fs.readdirSync(resolvedMigrationPath);
|
|
180
186
|
for (const element of files) {
|
|
@@ -182,7 +188,7 @@ class MigrationCommand extends Command {
|
|
|
182
188
|
if (extname(file) === '.js') {
|
|
183
189
|
success(chalk`{white Executing file:} {grey {bold ${file}}}`);
|
|
184
190
|
// eslint-disable-next-line no-await-in-loop
|
|
185
|
-
await this.execSingleFile(resolve(filePath, file), mapInstance);
|
|
191
|
+
await this.execSingleFile(pathValidator(resolve(filePath, file)), mapInstance);
|
|
186
192
|
}
|
|
187
193
|
}
|
|
188
194
|
} catch (error) {
|
package/src/utils/callsite.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const getCallsites = require('callsites');
|
|
4
4
|
const { parse, resolve } = require('path');
|
|
5
|
+
const { pathValidator } = require('@contentstack/cli-utilities');
|
|
5
6
|
|
|
6
7
|
function getFileDirectory(path) {
|
|
7
|
-
const parentPath = resolve(path, '../'); // Assuming that will be 2 folders up
|
|
8
|
+
const parentPath = pathValidator(resolve(path, '../')); // Assuming that will be 2 folders up
|
|
8
9
|
return parse(parentPath).dir;
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { highlight } = require('cardinal');
|
|
2
2
|
const { keys } = Object;
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
+
const isEmpty = require('lodash/isEmpty')
|
|
4
5
|
|
|
5
6
|
const { readFile } = require('./fs-helper');
|
|
6
7
|
const groupBy = require('./group-by');
|
|
@@ -50,10 +51,11 @@ module.exports = (errors) => {
|
|
|
50
51
|
|
|
51
52
|
messages.push(`${fileErrorsMessage}${errorMessages}`);
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (isEmpty(messages) && errors !== undefined && isEmpty(errorsByFile)) {
|
|
55
|
+
console.error('Migration error---', errors);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(messages.join('\n'));
|
|
58
|
+
}
|
|
57
59
|
// eslint-disable-next-line
|
|
58
60
|
console.log(chalk`{bold.red Migration unsuccessful}`);
|
|
59
61
|
};
|
package/src/utils/fs-helper.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { existsSync, mkdirSync, readFileSync, readFile } = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const { pathValidator } = require('@contentstack/cli-utilities');
|
|
5
6
|
|
|
6
7
|
exports.makeDir = (dirname) => {
|
|
7
8
|
!this.existsSync(dirname) && mkdirSync(dirname);
|
|
@@ -16,7 +17,7 @@ exports.readFile = (filePath) => {
|
|
|
16
17
|
|
|
17
18
|
exports.readJSONFile = (filePath) => {
|
|
18
19
|
return new Promise((resolve, reject) => {
|
|
19
|
-
filePath =
|
|
20
|
+
filePath = pathValidator(filePath);
|
|
20
21
|
readFile(filePath, 'utf-8', (error, data) => {
|
|
21
22
|
if (error) {
|
|
22
23
|
reject(error);
|
package/src/utils/logger.js
CHANGED
|
@@ -4,6 +4,7 @@ const { createLogger, format, transports } = require('winston');
|
|
|
4
4
|
const { resolve, join } = require('path');
|
|
5
5
|
const { slice } = Array.prototype;
|
|
6
6
|
const { stringify } = JSON;
|
|
7
|
+
const { pathValidator } = require('@contentstack/cli-utilities');
|
|
7
8
|
|
|
8
9
|
const { combine, label, printf, colorize } = format;
|
|
9
10
|
|
|
@@ -32,7 +33,7 @@ function init(logFileName) {
|
|
|
32
33
|
// Create dir if does not exist
|
|
33
34
|
makeDir(logsDir);
|
|
34
35
|
|
|
35
|
-
const logPath = join(logsDir, logFileName + '.log');
|
|
36
|
+
const logPath = pathValidator(join(logsDir, logFileName + '.log'));
|
|
36
37
|
const logger = createLogger({
|
|
37
38
|
format: combine(colorize(), label({ label: 'Migration' }), customFormat),
|
|
38
39
|
transports: [new transports.File({ filename: logPath }), new transports.Console()],
|