ngx-decorate-preprocessor
v1.1.18
Published
Preprocess files for ngx-decorate
Downloads
6
Readme
Preprocess files for ngx-decorate.
Installation:
npm install -D ngx-decorate-preprocessor
Note: If you use tslint you might need to re-run your fixes on changed files.
CLI usage
Format files
ngx-decorate-preprocess format --globs "path/to/src/**/*.ts" --indent 2
Test formatting
Test if files that need formatting aren't formatted; exit with non-zero code on failure.
ngx-decorate-preprocess test --globs "path/to/src/**/*.ts" --indent 2
Node usage
import {formatAsync, formatSync} from 'ngx-decorate-preprocessor';
import * as fs from 'fs';
// File indentation level. Optional, defaults to 2
const indent = 4;
const fileContents = fs.readFileSync('/path/to/file.ts', 'utf8');
// Sync mode
const formattedContents = formatSync(fileContents, indent);
if (fileContents !== formattedContents) {
fs.writeFileSync('/path/to/file.ts', formattedContents);
}
// Async mode
formatAsync(fileContents, indent)
.then(formattedContents => {
if (formattedContents !== fileContents) {
return new Promise((resolve, reject) => {
fs.writeFile('/path/to/file.ts', formattedContents, err => {
if (err) {
reject(err);
} else {
resolve();
}
})
})
}
})