Skip to content

Commit

Permalink
let prettier choose the correct parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJu committed Apr 13, 2018
1 parent ab36fab commit 7fcd4b0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 62 deletions.
1 change: 1 addition & 0 deletions generators/client/templates/angular/.prettierignore.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
target
15 changes: 3 additions & 12 deletions generators/client/templates/angular/.prettierrc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ printWidth: 140
singleQuote: true
tabWidth: 4
useTabs: false
overrides:
- files: "src/**/{*.ts,*.tsx}"
options:
jsxBracketSameLine: false
arrowParens: avoid
parser: typescript
- files: "src/**/*.css"
options:
parser: css
- files: "src/**/*.scss"
options:
parser: scss
# js and ts rules. Prettier is clever, it uses correct rules and correct parser according to file extension.
jsxBracketSameLine: false
arrowParens: avoid
1 change: 1 addition & 0 deletions generators/client/templates/react/.prettierignore.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
target
15 changes: 3 additions & 12 deletions generators/client/templates/react/.prettierrc.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ printWidth: 140
singleQuote: true
tabWidth: 2
useTabs: false
overrides:
- files: "src/**/{*.ts,*.tsx}"
options:
jsxBracketSameLine: false
arrowParens: avoid
parser: typescript
- files: "src/**/*.css"
options:
parser: css
- files: "src/**/*.scss"
options:
parser: scss
# js and ts rules. Prettier is clever, it uses correct rules and correct parser according to file extension.
jsxBracketSameLine: false
arrowParens: avoid
24 changes: 5 additions & 19 deletions generators/generator-base-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const jhipsterUtils = require('./utils');
const constants = require('./generator-constants');
const {
prettierTransform,
defaultTsPrettierOptions,
defaultCssPrettierOptions,
defaultScssPrettierOptions
prettierOptions
} = require('./generator-transforms');

const CLIENT_MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR;
Expand Down Expand Up @@ -1076,24 +1074,12 @@ module.exports = class extends Generator {
*/
registerClientTransforms(generator = this) {
if (!generator.skipClient) {
const typescriptFilter = filter(['src/**/*.{ts,tsx}'], { restore: true });
const myFilter = filter(['src/**/*.{ts,tsx,scss,css}'], { restore: true });
// this pipe will pass through (restore) anything that doesn't match typescriptFilter
generator.registerTransformStream([
typescriptFilter,
prettierTransform(defaultTsPrettierOptions),
typescriptFilter.restore
]);
const scssFilter = filter(['src/**/*.scss'], { restore: true });
generator.registerTransformStream([
scssFilter,
prettierTransform(defaultScssPrettierOptions),
scssFilter.restore
]);
const cssFilter = filter(['src/**/*.css'], { restore: true });
generator.registerTransformStream([
cssFilter,
prettierTransform(defaultCssPrettierOptions),
cssFilter.restore
myFilter,
prettierTransform(prettierOptions),
myFilter.restore
]);
}
}
Expand Down
24 changes: 5 additions & 19 deletions generators/generator-transforms.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
const through = require('through2');
const prettier = require('prettier');

const defaultPrettierOptions = {
const prettierOptions = {
printWidth: 140,
singleQuote: true,
useTabs: false
};

const defaultTsPrettierOptions = Object.assign(defaultPrettierOptions, {
useTabs: false,
// js and ts rules. Prettier is clever, it uses correct rules and correct parser according to file extension.
jsxBracketSameLine: false,
arrowParens: 'avoid',
parser: 'typescript',
});

const defaultCssPrettierOptions = Object.assign(defaultPrettierOptions, {
parser: 'css',
});

const defaultScssPrettierOptions = Object.assign(defaultPrettierOptions, {
parser: 'scss',
});

};

const prettierTransform = function (defaultOptions) {
const transform = (file, encoding, callback) => {
Expand All @@ -42,7 +30,5 @@ const prettierTransform = function (defaultOptions) {

module.exports = {
prettierTransform,
defaultTsPrettierOptions,
defaultCssPrettierOptions,
defaultScssPrettierOptions
prettierOptions
};

0 comments on commit 7fcd4b0

Please sign in to comment.