-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from de-don/feature/specify-patterns
Add option angularOrganizePatterns
- Loading branch information
Showing
7 changed files
with
167 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import minimatch from 'minimatch'; | ||
|
||
export function checkFilePath(filePath: string, patterns: string[]): boolean { | ||
if (!patterns.length) { | ||
return true; | ||
} | ||
|
||
return patterns.some(pattern => minimatch(filePath, pattern)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type PluginOptions = { | ||
componentDecoratorOrder: string[]; | ||
directiveDecoratorOrder: string[]; | ||
angularOrganizePatterns: string[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import {Parser, ParserOptions} from 'prettier'; | ||
import {transformNode} from './transform-node'; | ||
import {PluginOptions} from './types/plugin-options.type'; | ||
import {checkFilePath} from './check-file-path'; | ||
|
||
export function wrapParser(parser: Parser): Parser { | ||
return { | ||
...parser, | ||
parse: (text, parsers, options) => { | ||
parse: (text, parsers, opts) => { | ||
const options = opts as ParserOptions & PluginOptions; | ||
const parsedNode = parser.parse(text, parsers, options); | ||
return transformNode(parsedNode, options as ParserOptions & PluginOptions); | ||
|
||
if (!checkFilePath(options.filepath, options.angularOrganizePatterns)) { | ||
return parsedNode; | ||
} | ||
|
||
return transformNode(parsedNode, options); | ||
}, | ||
}; | ||
} |