Skip to content

Commit

Permalink
Merge pull request #1320 from contentstack/fix/CS-42524
Browse files Browse the repository at this point in the history
fix: path validator issue in all plugins
  • Loading branch information
aman19K authored Mar 4, 2024
2 parents 3901cea + 27f06e3 commit 96cff53
Show file tree
Hide file tree
Showing 41 changed files with 19,961 additions and 126 deletions.
19,857 changes: 19,830 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.9.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-bootstrap/1.9.1 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.9.0",
"version": "1.9.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-bootstrap/src/bootstrap/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
const inquirer = require('inquirer');
import { cliux } from '@contentstack/cli-utilities';
import { cliux, pathValidator } from '@contentstack/cli-utilities';

import messageHandler from '../messages';

Expand Down Expand Up @@ -58,7 +58,7 @@ export async function inquireCloneDirectory(): Promise<string> {
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
},
]);
selectedCustomPath = path.resolve(selectedCustomPath.path);
selectedCustomPath = pathValidator(selectedCustomPath.path);
return selectedCustomPath;
}

Expand Down
16 changes: 8 additions & 8 deletions packages/contentstack-bootstrap/src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { cliux } from '@contentstack/cli-utilities';
import { cliux, pathValidator } from '@contentstack/cli-utilities';
import { continueBootstrapCommand } from '../bootstrap/interactive';
import { AppConfig } from '../config';
import messageHandler from '../messages';
Expand Down Expand Up @@ -154,7 +154,7 @@ const envFileHandler = async (
case 'reactjs':
case 'reactjs-starter':
fileName = `.env.${environmentVariables.environment}.local`;
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
content = `REACT_APP_CONTENTSTACK_API_KEY=${
environmentVariables.api_key
}\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}${
Expand All @@ -173,7 +173,7 @@ const envFileHandler = async (
case 'nextjs':
case 'nextjs-starter':
fileName = `.env.${environmentVariables.environment}.local`;
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
}\n${
Expand All @@ -192,7 +192,7 @@ const envFileHandler = async (
case 'gatsby':
case 'gatsby-starter':
fileName = `.env.${environmentVariables.environment}`;
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
}\n${
Expand Down Expand Up @@ -221,7 +221,7 @@ const envFileHandler = async (
!isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : ''
} \n\t } \n };`;
fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`;
filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
filePath = pathValidator(path.join(clonedDirectory, 'src', 'environments', fileName));
result = await writeEnvFile(content, filePath);
break;
case 'angular-starter':
Expand All @@ -239,15 +239,15 @@ const envFileHandler = async (
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`;
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
result = await writeEnvFile(content, filePath);
break;
case 'nuxtjs':
case 'nuxt-starter':
case 'nuxt3-starter':
case 'stencil-starter':
fileName = production ? '.env.production' : '.env';
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
// Note: Stencil app needs all the env variables, even if they are not having values otherwise the rollup does not work properly and throws process in undefined error.
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
Expand All @@ -266,7 +266,7 @@ const envFileHandler = async (
break;
case 'vue-starter':
fileName = '.env';
filePath = path.join(clonedDirectory, fileName);
filePath = pathValidator(path.join(clonedDirectory, fileName));
content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
}\n${
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-bulk-publish",
"description": "Contentstack CLI plugin for bulk publish actions",
"version": "1.4.2",
"version": "1.4.3",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"dotenv": "^16.1.4",
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-bulk-publish/src/util/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const fs = require('fs');
const path = require('path');
const config = require('../config/index.js');
const chalk = require('chalk');
const {pathValidator} = require('@contentstack/cli-utilities')

function save(key, data) {
let bulkPublish = config ? config : {};
let filePath = path.join(process.cwd(), config.json);
let filePath = pathValidator(config.json);
bulkPublish[key] = data;
fs.writeFile(filePath, JSON.stringify(bulkPublish), (error) => {
if (error) {
Expand Down Expand Up @@ -49,7 +50,7 @@ function get(key, filePath) {

function updateMissing(key, flags) {
let savedConfig;
savedConfig = get(key, path.resolve(flags.config));
savedConfig = get(key, pathValidator(flags.config));
Object.keys(savedConfig).forEach((element) => {
if (flags[element] === undefined) {
console.log(`Using ${element} from config file`);
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.10.1 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-clone/1.10.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.10.1",
"version": "1.10.2",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.0",
"@contentstack/cli-cm-import": "~1.14.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"async": "^3.2.4",
"chalk": "^4.1.0",
"child_process": "^1.0.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-clone/src/lib/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var winston = require('winston');
var path = require('path');
var mkdirp = require('mkdirp');
const { pathValidator } = require('@contentstack/cli-utilities');
var slice = Array.prototype.slice;

function returnString(args) {
Expand Down Expand Up @@ -41,10 +42,10 @@ var myCustomLevels = {
};

function init(_logPath, logfileName) {
var logsDir = path.resolve(_logPath, 'logs', 'import');
var logsDir = pathValidator(path.resolve(_logPath, 'logs', 'import'));
// Create dir if doesn't already exist
mkdirp.sync(logsDir);
var logPath = path.join(logsDir, logfileName + '.log');
var logPath = path.join(logsDir, pathValidator(logfileName) + '.log');

var transports = [
new winston.transports.File({
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"format": "eslint src/**/*.ts --fix"
},
"dependencies": {
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"contentstack": "^3.10.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"chalk": "^4.1.0",
"fast-csv": "^4.3.6",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.11.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-export/1.11.1 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-export",
"description": "Contentstack CLI plugin to export content from stack",
"version": "1.11.0",
"version": "1.11.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-export/src/commands/cm/stacks/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
flags,
ContentstackClient,
FlagInput,
pathValidator
} from '@contentstack/cli-utilities';
import { ModuleExporter } from '../../../export';
import { setupExportConfig, log, formatError, writeExportMetaFile } from '../../../utils';
Expand Down Expand Up @@ -98,7 +99,7 @@ export default class ExportCommand extends Command {
static aliases: string[] = ['cm:export'];

async run(): Promise<void> {
let exportDir: string = path.join(process.cwd(), 'logs');
let exportDir: string = pathValidator('logs');
try {
const { flags } = await this.parse(ExportCommand);
let exportConfig = await setupExportConfig(flags);
Expand All @@ -112,7 +113,7 @@ export default class ExportCommand extends Command {
writeExportMetaFile(exportConfig);
}
log(exportConfig, `The content of the stack ${exportConfig.apiKey} has been exported successfully!`, 'success');
log(exportConfig, `The log has been stored at '${path.join(exportDir, 'logs', 'export')}'`, 'success');
log(exportConfig, `The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`, 'success');
} catch (error) {
log({ data: exportDir } as ExportConfig, `Failed to export stack content - ${formatError(error)}`, 'error');
log({ data: exportDir } as ExportConfig, `The log has been stored at ${exportDir}`, 'info');
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@contentstack/cli-audit": "~1.4.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@contentstack/management": "~1.15.3",
"@oclif/core": "^2.9.3",
"big-json": "^3.2.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/contentstack-import/src/commands/cm/stacks/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
flags,
FlagInput,
ContentstackClient,
pathValidator
} from '@contentstack/cli-utilities';

import { ImportConfig } from '../../../types';
Expand Down Expand Up @@ -143,19 +144,19 @@ export default class ImportCommand extends Command {

log(
importConfig,
`The log has been stored at '${path.join(importConfig.backupDir, 'logs', 'import')}'`,
`The log has been stored at '${pathValidator(path.join(importConfig.backupDir, 'logs', 'import'))}'`,
'success',
);
} catch (error) {
log(
{ data: backupDir ?? path.join(backupDir || __dirname, 'logs', 'import') } as ImportConfig,
{ data: backupDir ?? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) } as ImportConfig,
`Failed to import stack content - ${formatError(error)}`,
'error',
);
log(
{ data: backupDir } as ImportConfig,
`The log has been stored at ${
{ data: backupDir } ? path.join(backupDir || __dirname, 'logs', 'import') : path.join(__dirname, 'logs')
{ data: backupDir } ? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) : pathValidator(path.join(__dirname, 'logs'))
}`,
'info',
);
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/src/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';
import { LogEntry } from 'winston/index';
import { Logger } from '@contentstack/cli-utilities';
import { Logger, pathValidator } from '@contentstack/cli-utilities';
import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger';

import { ImportConfig } from '../types';
Expand All @@ -26,7 +26,7 @@ export function log(entryOrMessage: MessageType, logType?: LogsType, hidden?: bo

export function initLogger(config?: ImportConfig | undefined) {
if (!logger) {
const basePath = join(config?.data ?? process.cwd(), 'logs', 'import');
const basePath = pathValidator(join(config?.data ?? process.cwd(), 'logs', 'import'));
logger = new Logger(Object.assign(config ?? {}, { basePath }));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-launch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@apollo/client": "^3.7.9",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@oclif/core": "^2.9.3",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-migrate-rte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-migrate-rte
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-migrate-rte/1.4.15 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-migrate-rte/1.4.16 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-migrate-rte/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-migrate-rte",
"description": "Contentstack CLI plugin to migrate HTML RTE to JSON RTE",
"version": "1.4.15",
"version": "1.4.16",
"author": "contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.12",
"@contentstack/cli-utilities": "~1.6.0",
"@contentstack/json-rte-serializer": "~2.0.4",
"collapse-whitespace": "^1.1.7",
"chalk": "^4.1.2",
Expand Down
Loading

0 comments on commit 96cff53

Please sign in to comment.