Skip to content

Commit c24e036

Browse files
committed
fix path related issues
1 parent 612fecb commit c24e036

File tree

31 files changed

+81
-72
lines changed

31 files changed

+81
-72
lines changed

packages/contentstack-audit/src/audit-base-command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid';
55
import isEmpty from 'lodash/isEmpty';
66
import { join, resolve } from 'path';
77
import cloneDeep from 'lodash/cloneDeep';
8-
import { cliux, ux } from '@contentstack/cli-utilities';
8+
import { cliux, sanitizepath, ux } from '@contentstack/cli-utilities';
99
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';
1010

1111
import config from './config';
@@ -396,7 +396,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
396396
}
397397

398398
// NOTE write int json
399-
writeFileSync(join(this.sharedConfig.reportPath, `${moduleName}.json`), JSON.stringify(listOfMissingRefs));
399+
writeFileSync(join(sanitizepath(this.sharedConfig.reportPath), `${sanitizepath(moduleName)}.json`), JSON.stringify(listOfMissingRefs));
400400

401401
// NOTE write into CSV
402402
return this.prepareCSV(moduleName, listOfMissingRefs);
@@ -417,7 +417,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
417417
listOfMissingRefs: Record<string, any>,
418418
): Promise<void> {
419419
if(Object.keys(config.moduleConfig).includes(moduleName)){
420-
const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`);
420+
const csvPath = join(sanitizepath(this.sharedConfig.reportPath), `${sanitizepath(moduleName)}.csv`);
421421
return new Promise<void>((resolve, reject) => {
422422
// file deepcode ignore MissingClose: Will auto close once csv stream end
423423
const ws = createWriteStream(csvPath).on('error', reject);

packages/contentstack-bootstrap/src/bootstrap/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const envFileHandler = async (
221221
!isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : ''
222222
} \n\t } \n };`;
223223
fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`;
224-
filePath = pathValidator(path.join(clonedDirectory, 'src', 'environments', fileName));
224+
filePath = pathValidator(path.join(sanitizepath(clonedDirectory), 'src', 'environments', sanitizepath(fileName)));
225225
result = await writeEnvFile(content, filePath);
226226
break;
227227
case 'angular-starter':

packages/contentstack-export/src/export/modules-js/assets.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ module.exports = class ExportAssets {
283283

284284
if (version <= 0) {
285285
if(validateUids(uid)){
286-
const assetVersionInfoFile = path.resolve(self.assetsFolderPath, uid, '_contentstack_' + uid + '.json');
286+
const assetVersionInfoFile = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(uid), '_contentstack_' + sanitizepath(uid) + '.json');
287287
fileHelper.writeFileSync(assetVersionInfoFile, assetVersionInfo);
288288
return resolve();
289289
}
@@ -332,8 +332,8 @@ module.exports = class ExportAssets {
332332
if(!validateUids(asset.uid) && !validateFileName(asset.filename)) {
333333
reject(`UIDs not valid`)
334334
}
335-
const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), asset.uid);
336-
const assetFilePath = path.resolve(sanitizepath(assetFolderPath), asset.filename);
335+
const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(asset.uid));
336+
const assetFilePath = path.resolve(sanitizepath(assetFolderPath), sanitizepath(asset.filename));
337337

338338
if (fs.existsSync(assetFilePath)) {
339339
log(

packages/contentstack-export/src/export/modules-js/content-types.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22
const chalk = require('chalk');
33
const { fileHelper, executeTask, formatError, log } = require('../../utils');
4+
const { sanitizepath } = require('@contentstack/cli-utilities');
45

56
class ContentTypesExport {
67
constructor(exportConfig, stackAPIClient) {
@@ -18,9 +19,9 @@ class ContentTypesExport {
1819
this.qs.uid = { $in: this.exportConfig.contentTypes };
1920
}
2021
this.contentTypesPath = path.resolve(
21-
exportConfig.data,
22-
exportConfig.branchName || '',
23-
this.contentTypesConfig.dirName,
22+
sanitizepath(exportConfig.data),
23+
sanitizepath(exportConfig.branchName) || '',
24+
sanitizepath(this.contentTypesConfig.dirName),
2425
);
2526
this.contentTypes = [];
2627
this.fetchConcurrency = this.contentTypesConfig.fetchConcurrency || this.exportConfig.fetchConcurrency;
@@ -76,7 +77,7 @@ class ContentTypesExport {
7677
async writeContentTypes(contentTypes) {
7778
function write(contentType) {
7879
return fileHelper.writeFile(
79-
path.join(this.contentTypesPath, `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`),
80+
path.join(sanitizepath(this.contentTypesPath), `${sanitizepath (contentType.uid === 'schema' ? 'schema|1' : contentType.uid)}.json`),
8081
contentType,
8182
);
8283
}

packages/contentstack-export/src/export/modules-js/entries.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ const path = require('path');
22
const chalk = require('chalk');
33
const { values } = require('lodash');
44
const { executeTask, formatError, fileHelper, log } = require('../../utils');
5+
const { sanitizepath } = require('@contentstack/cli-utilities');
56

67
class EntriesExport {
78
constructor(exportConfig, stackAPIClient) {
89
this.stackAPIClient = stackAPIClient;
910
this.exportConfig = exportConfig;
1011
this.entriesConfig = exportConfig.modules.entries;
11-
this.entriesRootPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName);
12+
this.entriesRootPath = path.resolve((sanitizepath(exportConfig.data)), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName));
1213
this.localesFilePath = path.resolve(
13-
exportConfig.data,
14-
exportConfig.branchName || '',
15-
exportConfig.modules.locales.dirName,
16-
exportConfig.modules.locales.fileName,
14+
sanitizepath(exportConfig.data),
15+
sanitizepath(exportConfig.branchName || ''),
16+
sanitizepath(exportConfig.modules.locales.dirName),
17+
sanitizepath(exportConfig.modules.locales.fileName),
1718
);
1819
this.schemaFilePath = path.resolve(
19-
exportConfig.data,
20-
exportConfig.branchName || '',
21-
exportConfig.modules.content_types.dirName,
20+
sanitizepath(exportConfig.data),
21+
sanitizepath(exportConfig.branchName || ''),
22+
sanitizepath(exportConfig.modules.content_types.dirName),
2223
'schema.json',
2324
);
2425
this.fetchConcurrency = this.entriesConfig.fetchConcurrency || exportConfig.fetchConcurrency;
@@ -78,7 +79,7 @@ class EntriesExport {
7879
if (versionedEntries.length > 0) {
7980
const write = (versionedEntry) =>
8081
fileHelper.writeFile(
81-
path.join(versionedEntryPath, 'version-' + versionedEntry._version + '.json'),
82+
path.join(sanitizepath(versionedEntryPath), 'version-' + sanitizepath(versionedEntry._version) + '.json'),
8283
versionedEntry,
8384
);
8485
await executeTask(versionedEntries, write.bind(this), { concurrency: this.writeConcurrency });

packages/contentstack-export/src/export/modules-js/global-fields.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const mkdirp = require('mkdirp');
1010
const { merge } = require('lodash');
1111
const { formatError, log, fileHelper } = require('../../utils');
1212
const { default: config } = require('../../config');
13+
const { sanitizepath } = require('@contentstack/cli-utilities');
1314

1415
module.exports = class ExportGlobalFields {
1516
limit = 100;
@@ -34,9 +35,9 @@ module.exports = class ExportGlobalFields {
3435
this.config = merge(config, exportConfig);
3536
this.stackAPIClient = stackAPIClient;
3637
this.globalfieldsFolderPath = path.resolve(
37-
this.config.data,
38-
this.config.branchName || '',
39-
this.globalfieldsConfig.dirName,
38+
sanitizepath(this.config.data),
39+
sanitizepath(this.config.branchName || ''),
40+
sanitizepath(this.globalfieldsConfig.dirName),
4041
);
4142
}
4243

packages/contentstack-export/src/export/modules-js/locales.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22
const chalk = require('chalk');
33
const { formatError, log, fileHelper } = require('../../utils');
4+
const { sanitizepath } = require('@contentstack/cli-utilities');
45
class LocaleExport {
56
constructor(exportConfig, stackAPIClient) {
67
this.stackAPIClient = stackAPIClient;
@@ -15,7 +16,7 @@ class LocaleExport {
1516
},
1617
};
1718

18-
this.localesPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.localeConfig.dirName);
19+
this.localesPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.localeConfig.dirName));
1920
this.locales = {};
2021
this.masterLocale = {};
2122
this.fetchConcurrency = this.localeConfig.fetchConcurrency || this.exportConfig.fetchConcurrency;

packages/contentstack-export/src/export/modules/content-types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities';
33
import { log, formatError, fsUtil, executeTask } from '../../utils';
44
import { ExportConfig, ModuleClassParams } from '../../types';
55
import BaseClass from './base-class';
6+
import { sanitizepath } from '@contentstack/cli-utilities';
67

78
export default class ContentTypesExport extends BaseClass {
89
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
@@ -43,9 +44,9 @@ export default class ContentTypesExport extends BaseClass {
4344
}
4445

4546
this.contentTypesDirPath = path.resolve(
46-
exportConfig.data,
47-
exportConfig.branchName || '',
48-
this.contentTypesConfig.dirName,
47+
sanitizepath(exportConfig.data),
48+
sanitizepath(exportConfig.branchName || ''),
49+
sanitizepath(this.contentTypesConfig.dirName),
4950
);
5051
this.contentTypes = [];
5152
}
@@ -98,7 +99,7 @@ export default class ContentTypesExport extends BaseClass {
9899
async writeContentTypes(contentTypes: Record<string, unknown>[]) {
99100
function write(contentType: Record<string, unknown>) {
100101
return fsUtil.writeFile(
101-
path.join(this.contentTypesDirPath, `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`),
102+
path.join(sanitizepath(this.contentTypesDirPath), `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`),
102103
contentType,
103104
);
104105
}

packages/contentstack-export/src/export/modules/entries.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContentstackClient, FsUtility } from '@contentstack/cli-utilities';
33
import { log, formatError, fsUtil } from '../../utils';
44
import { ExportConfig, ModuleClassParams } from '../../types';
55
import BaseClass, { ApiOptions } from './base-class';
6+
import { sanitizepath } from '@contentstack/cli-utilities';
67

78
export default class EntriesExport extends BaseClass {
89
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
@@ -28,17 +29,17 @@ export default class EntriesExport extends BaseClass {
2829
this.stackAPIClient = stackAPIClient;
2930
this.exportConfig = exportConfig;
3031
this.entriesConfig = exportConfig.modules.entries;
31-
this.entriesDirPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName);
32+
this.entriesDirPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName));
3233
this.localesFilePath = path.resolve(
33-
exportConfig.data,
34-
exportConfig.branchName || '',
35-
exportConfig.modules.locales.dirName,
36-
exportConfig.modules.locales.fileName,
34+
sanitizepath(exportConfig.data),
35+
sanitizepath(exportConfig.branchName || ''),
36+
sanitizepath(exportConfig.modules.locales.dirName),
37+
sanitizepath(exportConfig.modules.locales.fileName),
3738
);
3839
this.schemaFilePath = path.resolve(
39-
exportConfig.data,
40-
exportConfig.branchName || '',
41-
exportConfig.modules.content_types.dirName,
40+
sanitizepath(exportConfig.data),
41+
sanitizepath(exportConfig.branchName || ''),
42+
sanitizepath(exportConfig.modules.content_types.dirName),
4243
'schema.json',
4344
);
4445
}
@@ -118,7 +119,7 @@ export default class EntriesExport extends BaseClass {
118119

119120
if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) {
120121
if (options.skip === 0) {
121-
const entryBasePath = path.join(this.entriesDirPath, options.contentType, options.locale);
122+
const entryBasePath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType), sanitizepath(options.locale));
122123
await fsUtil.makeDirectory(entryBasePath);
123124
this.entriesFileHelper = new FsUtility({
124125
moduleName: 'entries',
@@ -131,7 +132,7 @@ export default class EntriesExport extends BaseClass {
131132
}
132133
this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true });
133134
if (this.entriesConfig.exportVersions) {
134-
let versionedEntryPath = path.join(this.entriesDirPath, options.contentType, options.locale, 'versions');
135+
let versionedEntryPath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType),sanitizepath(options.locale), 'versions');
135136
fsUtil.makeDirectory(versionedEntryPath);
136137
await this.fetchEntriesVersions(entriesSearchResponse.items, {
137138
locale: options.locale,
@@ -152,7 +153,7 @@ export default class EntriesExport extends BaseClass {
152153
options: { locale: string; contentType: string; versionedEntryPath: string },
153154
): Promise<void> {
154155
const onSuccess = ({ response, apiData: entry }: any) => {
155-
fsUtil.writeFile(path.join(options.versionedEntryPath, `${entry.uid}.json`), response);
156+
fsUtil.writeFile(path.join(sanitizepath(options.versionedEntryPath), `${entry.uid}.json`), response);
156157
log(
157158
this.exportConfig,
158159
`Exported versioned entries of type '${options.contentType}' locale '${options.locale}'`,

packages/contentstack-export/src/export/modules/global-fields.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities';
33
import { log, formatError, fsUtil } from '../../utils';
44
import { ExportConfig, ModuleClassParams } from '../../types';
55
import BaseClass from './base-class';
6+
import { sanitizepath } from '@contentstack/cli-utilities';
67

78
export default class GlobalFieldsExport extends BaseClass {
89
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
@@ -35,9 +36,9 @@ export default class GlobalFieldsExport extends BaseClass {
3536
limit: this.globalFieldsConfig.limit,
3637
};
3738
this.globalFieldsDirPath = path.resolve(
38-
exportConfig.data,
39-
exportConfig.branchName || '',
40-
this.globalFieldsConfig.dirName,
39+
sanitizepath(exportConfig.data),
40+
sanitizepath(exportConfig.branchName || ''),
41+
sanitizepath(this.globalFieldsConfig.dirName),
4142
);
4243
this.globalFields = [];
4344
}

0 commit comments

Comments
 (0)