zents-cli
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
37 lines (36 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const yeoman_generator_1 = tslib_1.__importDefault(require("yeoman-generator"));
const gulp_filter_1 = tslib_1.__importDefault(require("gulp-filter"));
const prettier_1 = require("prettier");
const path_1 = require("path");
const through2_1 = tslib_1.__importDefault(require("through2"));
class default_1 extends yeoman_generator_1.default {
constructor(args, options) {
super(args, options);
this._registerPrettierTransform();
this.sourceRoot(path_1.join(__dirname, '..', '..', 'templates'));
if (typeof this.options.cwd === 'string') {
this.destinationRoot(this.options.cwd);
}
}
_registerPrettierTransform() {
const transform = (file, _encoding, next) => {
const str = file.contents.toString('utf8');
const data = prettier_1.format(str, {
printWidth: 100,
semi: false,
singleQuote: true,
trailingComma: 'all',
parser: 'typescript',
});
file.contents = Buffer.from(data);
return next(null, file);
};
const prettierFilter = gulp_filter_1.default(['**/*.{ts,tsx}', '.eslintrc.js'], { restore: true });
// @ts-ignore
this.registerTransformStream([prettierFilter, through2_1.default.obj(transform), prettierFilter.restore]);
}
}
exports.default = default_1;