@contentstack/cli-migration 1.5.0 → 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/README.md CHANGED
@@ -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.5.0 darwin-arm64 node-v20.8.0
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.5.0",
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.5.12",
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",
@@ -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 { printFlagDeprecation, managementSDKClient, flags, isAuthenticated } = require('@contentstack/cli-utilities');
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 = resolve(filePath);
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 = resolve(filePath);
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) {
@@ -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
 
@@ -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 = path.resolve(filePath);
20
+ filePath = pathValidator(filePath);
20
21
  readFile(filePath, 'utf-8', (error, data) => {
21
22
  if (error) {
22
23
  reject(error);
@@ -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()],