Skip to content

Commit

Permalink
feat(general): set --progress mode by default
Browse files Browse the repository at this point in the history
Closes #444
  • Loading branch information
buchslava committed Jul 6, 2017
1 parent 69eb07e commit d5a5a29
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test-travis": "istanbul cover mocha _mocha -- -R spec --timeout 200000 --compilers ts:ts-node/register --recursive test/**/*.spec.ts && codecov",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"github-release": "conventional-github-releaser -p angular",
"build": "tsc && touch lib/package.json && echo \\{\\\"version\\\": \\\"1.8.0\\\"\\} > lib/package.json",
"build": "tsc && touch lib/package.json && echo \\{\\\"version\\\": \\\"1.9.0\\\"\\} > lib/package.json",
"prepublish": "npm run build",
"preversion": "npm test",
"version": "npm run changelog && git add CHANGELOG.md",
Expand Down
4 changes: 2 additions & 2 deletions src/cli-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ if (isValidationExpected) {
throw err;
}

if (settings.progress && hasIssue) {
if (!settings.silent && hasIssue) {
console.log(`\nValidation was finished with issues. Details are here: ${validationTransport.file}.`);
}

if (settings.progress && !hasIssue) {
if (!settings.silent && !hasIssue) {
console.log('\nValidation was finished successfully.');
}

Expand Down
12 changes: 6 additions & 6 deletions src/utils/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ const argv = yargs
'validate "ddf-example" and its subdirectories that contain spaces')
.example(`${myName} ../ddf-example --exclude-dirs '"dir1 with spaces","dir2 with spaces"'`,
'validate "ddf-example" and its subdirectories that contain spaces: case 2')
.example(`${myName} ../ddf-example -i --compress-datapackage --heap 4096`,'Create compressed datapackage.json via 4Gb heap')
.example(`${myName} ../ddf-example -i --compress-datapackage --heap 4096`, 'Create compressed datapackage.json via 4Gb heap')
.describe('i', 'Generate datapackage.json file')
.describe('compress-datapackage','Compress datapackage.json file')
.describe('compress-datapackage', 'Compress datapackage.json file')
.describe('translations', 'Rewrite "translations" section in existing datapackage.json')
.describe('content', 'Rewrite "resources" and "ddfSchema" sections in existing datapackage.json')
.describe('j', 'Fix wrong JSONs')
.describe('rules', 'print information regarding supported rules')
.describe('multithread', 'validate datapoints in separate threads')
.describe('datapointless', 'forget about datapoint validation')
.describe('progress', 'show progress of validation and save result to a file')
.describe('silent', `don't show progress of validation and print issues to the screen`)
.describe('hidden', 'allow hidden folders validation')
.describe('include-tags', 'Process only issues by selected tags')
.describe('exclude-tags', 'Process all tags except selected')
.describe('include-rules', 'Process only issues by selected rules')
.describe('exclude-rules', 'Process all rules except selected')
.describe('exclude-dirs',
'Process all directories except selected. Directories should be separated via "," character')
.describe('heap','Set custom heap size')
.describe('heap', 'Set custom heap size')
.argv;

export const getDDFRootFolder = () => head(argv._) || process.cwd();
Expand All @@ -56,13 +56,13 @@ export const getSettings = () => {
settings.isJsonAutoCorrectionMode = !!argv.j;
settings.versionShouldBePrinted = !!argv.v;
settings.datapointlessMode = !!argv.datapointless;
settings.progress = !!argv.progress;
settings.silent = !!argv.silent;
settings.updateDataPackageTranslations = !!argv.translations;
settings.updateDataPackageContent = !!argv.content;
settings.isPrintRules = !!argv.rules;
settings.isCheckHidden = !!argv.hidden;
settings.isMultithread = !!argv.multithread;
settings.compressDatapackage = argv['compress-datapackage'];
settings.compressDatapackage = argv['compress-datapackage'];
};

setMiscSettings();
Expand Down
16 changes: 10 additions & 6 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import * as fs from 'fs';
import { includes } from 'lodash';
import { Logger, Transport } from 'winston';
import { terminal as term } from 'terminal-kit';
import { getSettings } from '../utils/args';

const settings = getSettings();

const args = process.argv.join(' ');
const isSeparateThread = includes(args, 'thread.js');

export class Progress {
public title: string;
public isEnabled: boolean;
Expand All @@ -14,7 +18,7 @@ export class Progress {

constructor(title: string, totalSteps: number) {
this.title = title;
this.isEnabled = +totalSteps > 1;
this.isEnabled = +totalSteps > 1 && !isSeparateThread;

if (this.isEnabled) {
this.step = (100 / (+totalSteps)) / 100;
Expand Down Expand Up @@ -58,32 +62,32 @@ export class ValidationTransport extends Transport {
this.name = 'InfoTransport';
this.level = 'notice';

if (settings.progress) {
if (!settings.silent && !process.env.SILENT_MODE) {
const dateLabel = new Date().toISOString().replace(/:/g, '');

this.file = `validation-${dateLabel}.log`;
}
}

log(level: string, msg: string, meta: any, callback: Function) {
if (level === 'progressInit' && settings.progress) {
if (level === 'progressInit' && !settings.silent && !process.env.SILENT_MODE) {
if (this.progress) {
this.progress.resume();
}

this.progress = new Progress(msg, meta.total as number);
}

if (level === 'progress' && settings.progress) {
if (level === 'progress' && !settings.silent && !process.env.SILENT_MODE) {
this.progress.update();
}

if (level === 'notice') {
if (!settings.progress) {
if (settings.silent) {
console.log(msg);
}

if (settings.progress) {
if (!settings.silent && !process.env.SILENT_MODE) {
fs.appendFile(this.file, msg, (err) => {
if (err) {
return callback(err)
Expand Down
2 changes: 2 additions & 0 deletions test/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { JSONValidator, StreamValidator, SimpleValidator, validate } from '../sr

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('api', () => {
describe('when JSONValidator', () => {
describe('and DDF dataset is correct', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/concept-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {allRules} from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('rules for concept', () => {
let ddfDataSet = null;

Expand Down
2 changes: 2 additions & 0 deletions test/csv-checker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {CsvChecker} from '../src/data/csv-checker';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('csv checker', () => {
it('should be no errors for correct csv file', done => {
const csvChecker = new CsvChecker('./test/fixtures/good-folder/ddf--concepts.csv');
Expand Down
2 changes: 2 additions & 0 deletions test/data-package-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { allRules } from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('ddf datapackage.json validation', () => {
describe('when INCORRECT_FILE', () => {
it('any issue should NOT be found for folder (fixtures/good-folder)', done => {
Expand Down
2 changes: 2 additions & 0 deletions test/data-point-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Issue } from '../src/ddf-rules/issue';
const expect = chai.expect;
const CONCURRENT_OPERATIONS_AMOUNT = 30;

process.env.SILENT_MODE = true;

describe('rules for data points', () => {
describe(`when data set is correct ('fixtures/good-folder')`, () => {
const ddfDataSet = new DdfDataSet('./test/fixtures/good-folder', null);
Expand Down
2 changes: 2 additions & 0 deletions test/datapackage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { DataPackage } from '../src/data/data-package';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('datapackage validation', () => {
describe('when "ddf--unpop--wpp_population" dataset', () => {
it('should datapackage be created propery', done => {
Expand Down
2 changes: 2 additions & 0 deletions test/ddf-json-corrector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {DdfJsonCorrector} from '../src/ddf-definitions/ddf-json-corrector';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('ddf json corrector', () => {
describe('when wrong json is NOT found', () => {
const dummyCompaniesPath = './test/fixtures/dummy-companies';
Expand Down
2 changes: 2 additions & 0 deletions test/ddf-root.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { DDFRoot } from '../src/data/ddf-root';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('ddf root folder validation', () => {
describe('when DDF folder (fixtures/good-folder)', () => {
it('ddf folder should present', done => {
Expand Down
2 changes: 2 additions & 0 deletions test/ddf-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getDdfSchema } from '../src/data/ddf-schema';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('ddf schema creation', () => {
it('for dummy-companies', done => {
const dataPackage = new DataPackage('./test/fixtures/ddf-schema', {});
Expand Down
2 changes: 2 additions & 0 deletions test/empty-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {allRules} from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('general rules', () => {
describe('when "EMPTY_DATA" rule', () => {
it('any issue should NOT be found for folder without the problem (fixtures/good-folder)', done => {
Expand Down
2 changes: 2 additions & 0 deletions test/entity-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { allRules } from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('rules for entry', () => {
let ddfDataSet = null;

Expand Down
2 changes: 2 additions & 0 deletions test/general-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { allRules } from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('general rules', () => {
describe('when DDF folder is correct', () => {
it('there should be no issues for "NON_DDF_DATA_SET" rule', done => {
Expand Down
2 changes: 2 additions & 0 deletions test/issues-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Issue } from '../src/ddf-rules/issue';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('issues filter', () => {
describe('when issues filter was constructed with "include-tags" and "exclude-tags"', () => {
it('should WRONG_TAGS_COMBINATION_ERROR', done => {
Expand Down
2 changes: 1 addition & 1 deletion test/translation-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Issue } from '../src/ddf-rules/issue';
const CONCURRENT_OPERATIONS_AMOUNT = 30;
const expect = chai.expect;

/*eslint-disable camelcase*/
process.env.SILENT_MODE = true;

describe('translation rules', () => {
describe('when "UNEXPECTED_TRANSLATION_HEADER" rule', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unexpected-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {allRules} from '../src/ddf-rules';

const expect = chai.expect;

process.env.SILENT_MODE = true;

describe('general rules', () => {
describe('when "UNEXPECTED_DATA" rule', () => {
it('any issue should NOT be found for folder without the problem (fixtures/good-folder)', done => {
Expand Down

0 comments on commit d5a5a29

Please sign in to comment.