Skip to content

Commit

Permalink
Merge branch 'development' into fix/41082
Browse files Browse the repository at this point in the history
  • Loading branch information
aman19K authored Nov 24, 2023
2 parents b3b4295 + f56f374 commit 23eddae
Show file tree
Hide file tree
Showing 43 changed files with 2,605 additions and 488 deletions.
493 changes: 460 additions & 33 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* @returns The function `prepareCSV` returns a Promise that resolves to `void`.
*/
prepareCSV(moduleName: keyof typeof config.moduleConfig, listOfMissingRefs: Record<string, any>): Promise<void> {
const csvStream = csv.format({ headers: true });
const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`);
const assetFileStream = createWriteStream(csvPath);

return new Promise<void>((resolve, reject) => {
assetFileStream.on('error', reject);
csvStream.pipe(assetFileStream).on('close', resolve).on('error', reject);
// file deepcode ignore MissingClose: Will auto close once csv stream end
const ws = createWriteStream(csvPath).on('error', reject);
const defaultColumns = Object.keys(OutputColumn);
const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null;
let missingRefs: RefErrorReturnType[] = Object.values(listOfMissingRefs).flat();
Expand All @@ -301,6 +299,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingRefs = missingRefs.filter((row: RefErrorReturnType) => row[OutputColumn[column]] === value);
}

const rowData: Record<string, string | string[]>[] = [];

for (const issue of missingRefs) {
let row: Record<string, string | string[]> = {};

Expand All @@ -313,11 +313,10 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
row['Fix status'] = row.fixStatus;
}

csvStream.write(row, 'utf8');
rowData.push(row);
}

csvStream.end();
assetFileStream.destroy();
csv.write(rowData, { headers: true }).pipe(ws).on('error', reject).on('finish', resolve);
});
}
}
2 changes: 2 additions & 0 deletions packages/contentstack-audit/test/unit/commands/fix.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import winston from 'winston';
import { expect } from '@oclif/test';
import { fancy } from '@contentstack/cli-dev-dependencies';
Expand All @@ -13,6 +14,7 @@ describe('AuditFix command', () => {
describe('AuditFix run method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(fs, 'rmSync', () => {})
.stub(winston.transports, 'File', () => fsTransport)
.stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} }))
.stub(AuditBaseCommand.prototype, 'start', () => {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('Content types', () => {
});

fancy
.stub(fs, 'rmSync', () => {})
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(ContentType.prototype, 'writeFixContent', async () => {})
.it('perform audit operation on the given CT schema', async () => {
Expand All @@ -120,6 +121,7 @@ describe('Content types', () => {
});

fancy
.stub(fs, 'rmSync', () => {})
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(ContentType.prototype, 'writeFixContent', async () => {})
.it('perform audit and fix operation on the given CT schema', async () => {
Expand Down Expand Up @@ -274,6 +276,7 @@ describe('Content types', () => {
describe('fixGlobalFieldReferences method', () => {
fancy
.stdout({ print: process.env.PRINT === 'true' || false })
.stub(fs, 'rmSync', () => {})
.stub(ContentType.prototype, 'runFixOnSchema', () => {})
.stub(ContentType.prototype, 'lookForReference', () => {})
.it('should identify missing global-field schema and attach with content-type schema', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@contentstack/cli-cm-export": "~1.9.3",
"@contentstack/cli-cm-export": "~1.10.0",
"@contentstack/cli-cm-import": "~1.11.0",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
Expand Down
14 changes: 9 additions & 5 deletions packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.5.0",
"version": "1.6.0",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand All @@ -15,12 +15,15 @@
},
"devDependencies": {
"@oclif/test": "^2.2.10",
"chai": "^4.2.0",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"chai": "^4.3.8",
"debug": "^4.3.1",
"dotenv": "^16.3.1",
"eslint": "^7.32.0",
"eslint-config-oclif": "^4.0.0",
"globby": "^10.0.2",
"mocha": "^10.0.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"oclif": "^3.8.1"
},
Expand All @@ -44,7 +47,8 @@
"postpack": "rm -f oclif.manifest.json",
"prepack": "oclif manifest && oclif readme",
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
"test:unit": "nyc mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.js\"",
"test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.js\" \"test/util/common-utils.test.js\"",
"test:unit:report": "nyc --extension .js mocha --forbid-only \"test/unit/**/*.test.js\" \"test/util/common-utils.test.js\"",
"version": "oclif readme && git add README.md",
"clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
},
Expand All @@ -61,4 +65,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
Loading

0 comments on commit 23eddae

Please sign in to comment.