Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import map from 'lodash/map';
import find from 'lodash/find';
import isEmpty from 'lodash/isEmpty';
import fs from 'fs';
import { join, resolve } from 'path';
import { existsSync, readFileSync, writeFileSync } from 'fs';

import { sanitizePath, cliux, log } from '@contentstack/cli-utilities';

Expand Down Expand Up @@ -82,7 +82,7 @@ export default class ContentType extends BaseClass {
try {
this.inMemoryFix = returnFixSchema;

if (!existsSync(this.folderPath)) {
if (!fs.existsSync(this.folderPath)) {
log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
cliux.print($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
return returnFixSchema ? [] : {};
Expand Down Expand Up @@ -170,10 +170,10 @@ export default class ContentType extends BaseClass {
const extensionPath = resolve(this.config.basePath, 'extensions', 'extensions.json');
const marketplacePath = resolve(this.config.basePath, 'marketplace_apps', 'marketplace_apps.json');

if (existsSync(extensionPath)) {
if (fs.existsSync(extensionPath)) {
log.debug(`Loading extensions from: ${extensionPath}`, this.config.auditContext);
try {
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
this.extensions = Object.keys(JSON.parse(fs.readFileSync(extensionPath, 'utf8')));
log.debug(`Loaded ${this.extensions.length} extensions`, this.config.auditContext);
} catch (error) {
log.debug(`Failed to load extensions: ${error}`, this.config.auditContext);
Expand All @@ -182,10 +182,10 @@ export default class ContentType extends BaseClass {
log.debug('No extensions.json found', this.config.auditContext);
}

if (existsSync(marketplacePath)) {
if (fs.existsSync(marketplacePath)) {
log.debug(`Loading marketplace apps from: ${marketplacePath}`, this.config.auditContext);
try {
const marketplaceApps: MarketplaceAppsInstallationData[] = JSON.parse(readFileSync(marketplacePath, 'utf8'));
const marketplaceApps: MarketplaceAppsInstallationData[] = JSON.parse(fs.readFileSync(marketplacePath, 'utf8'));
log.debug(`Found ${marketplaceApps.length} marketplace apps`, this.config.auditContext);

for (const app of marketplaceApps) {
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class ContentType extends BaseClass {
if (contentType.uid) {
const filePath = join(this.folderPath, `${contentType.uid}.json`);
log.debug(`Writing fixed content type to: ${filePath}`, this.config.auditContext);
writeFileSync(filePath, JSON.stringify(contentType));
fs.writeFileSync(filePath, JSON.stringify(contentType));
} else {
log.warn(
`Skipping content type without uid: ${JSON.stringify(contentType).substring(0, 100)}`,
Expand Down
20 changes: 10 additions & 10 deletions packages/contentstack-audit/src/modules/field_rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import map from 'lodash/map';
import fs from 'fs';
import { join, resolve } from 'path';
import { existsSync, readFileSync, writeFileSync } from 'fs';

import { FsUtility, Locale, sanitizePath, cliux, log } from '@contentstack/cli-utilities';

Expand Down Expand Up @@ -95,7 +95,7 @@ export default class FieldRule extends BaseClass {
log.debug(`Field rules folder path: ${this.folderPath}`, this.config.auditContext);
log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);

if (!existsSync(this.folderPath)) {
if (!fs.existsSync(this.folderPath)) {
log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
cliux.print($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
Expand Down Expand Up @@ -412,10 +412,10 @@ export default class FieldRule extends BaseClass {
log.debug(`Extensions path: ${extensionPath}`, this.config.auditContext);
log.debug(`Marketplace apps path: ${marketplacePath}`, this.config.auditContext);

if (existsSync(extensionPath)) {
if (fs.existsSync(extensionPath)) {
log.debug(`Loading extensions from file`, this.config.auditContext);
try {
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
this.extensions = Object.keys(JSON.parse(fs.readFileSync(extensionPath, 'utf8')));
log.debug(`Loaded ${this.extensions.length} extensions`, this.config.auditContext);
} catch (error) {
log.debug(`Error loading extensions: ${error}`, this.config.auditContext);
Expand All @@ -424,10 +424,10 @@ export default class FieldRule extends BaseClass {
log.debug(`Extensions file not found`, this.config.auditContext);
}

if (existsSync(marketplacePath)) {
if (fs.existsSync(marketplacePath)) {
log.debug(`Loading marketplace apps from file`, this.config.auditContext);
try {
const marketplaceApps: MarketplaceAppsInstallationData[] = JSON.parse(readFileSync(marketplacePath, 'utf8'));
const marketplaceApps: MarketplaceAppsInstallationData[] = JSON.parse(fs.readFileSync(marketplacePath, 'utf8'));
log.debug(`Found ${marketplaceApps.length} marketplace apps`, this.config.auditContext);

for (const app of marketplaceApps) {
Expand Down Expand Up @@ -490,7 +490,7 @@ export default class FieldRule extends BaseClass {
continue;
}
const filePath = join(this.folderPath, `${schema.uid}.json`);
writeFileSync(filePath, JSON.stringify(schema));
fs.writeFileSync(filePath, JSON.stringify(schema));
log.debug(`Wrote fixed schema: ${schema.uid} → ${filePath}`, this.config.auditContext);
}
} else {
Expand Down Expand Up @@ -635,12 +635,12 @@ export default class FieldRule extends BaseClass {
log.debug(`Master locales path: ${masterLocalesPath}`, this.config.auditContext);

log.debug(`Loading master locales`, this.config.auditContext);
this.locales = existsSync(masterLocalesPath) ? values(JSON.parse(readFileSync(masterLocalesPath, 'utf8'))) : [];
this.locales = fs.existsSync(masterLocalesPath) ? values(JSON.parse(fs.readFileSync(masterLocalesPath, 'utf8'))) : [];
log.debug(`Loaded ${this.locales.length} master locales`, this.config.auditContext);

if (existsSync(localesPath)) {
if (fs.existsSync(localesPath)) {
log.debug(`Loading additional locales from file`, this.config.auditContext);
this.locales.push(...values(JSON.parse(readFileSync(localesPath, 'utf8'))));
this.locales.push(...values(JSON.parse(fs.readFileSync(localesPath, 'utf8'))));
log.debug(`Total locales after loading: ${this.locales.length}`, this.config.auditContext);
} else {
log.debug(`Additional locales file not found`, this.config.auditContext);
Expand Down
Loading