Skip to content

Commit

Permalink
feat: add blob pattern support for entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MarsiBarsi committed Apr 29, 2021
1 parent 7de80ef commit e978551
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 1,142 deletions.
3 changes: 1 addition & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"@nrwl/angular:application": {
"style": "less",
"linter": "eslint",
"unitTestRunner": "jest",
"e2eTestRunner": "cypress"
"unitTestRunner": "jest"
},
"@nrwl/angular:library": {
"style": "less",
Expand Down
1 change: 1 addition & 0 deletions libs/ng-morph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@angular-devkit/schematics": ">=11.0.0"
},
"dependencies": {
"minimatch": "3.0.4",
"ts-morph": "10.0.2",
"jsonc-parser": "3.0.0"
},
Expand Down
15 changes: 13 additions & 2 deletions libs/ng-morph/properties/helpers/get-properties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class A {
`
class B {
static d = 's';
static hello2 = 'hello';
}
`
);
Expand All @@ -39,7 +41,7 @@ class B {
it('should find two properties', () => {
const declarations = getProperties(getClasses('some/path/**.ts'));

expect(declarations.length).toEqual(2);
expect(declarations.length).toEqual(3);
});

it('should find one property', () => {
Expand All @@ -48,7 +50,7 @@ class B {
expect(declarations.length).toEqual(1);
});

it('should find one property by name', () => {
it('should find one property by name pattern **', () => {
const declarations = getProperties(getClasses('some/path/**.ts'), {
name: 'd',
isStatic: true,
Expand All @@ -57,6 +59,15 @@ class B {
expect(declarations.length).toEqual(1);
});

it('should find one property by blob pattern **/*', () => {
const declarations = getProperties(getClasses('**/*.ts'), {
name: 'hello*',
isStatic: true,
});

expect(declarations.length).toEqual(1);
});

afterEach(() => {
resetActiveProject();
});
Expand Down
9 changes: 8 additions & 1 deletion libs/ng-morph/utils/helpers/match-query.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as minimatch from 'minimatch';
import { coerceArray } from 'ng-morph/utils';
import { Structure, WriterFunction } from 'ts-morph';

Expand Down Expand Up @@ -63,7 +64,13 @@ export function matchQuery<T extends Structure>(
Object.keys(query).every((key) =>
coerceArray(value[key])
.map(coerceName)
.some((v) => coerceArray(query[key]).includes(v))
.some((v) => {
const patterns = coerceArray(query[key]);

return typeof v === 'string'
? patterns.some((pattern) => pattern && minimatch(v, pattern))
: patterns.includes(v);
})
)
);
}
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"default": {
"runner": "@nrwl/nx-cloud",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"],
"cacheableOperations": ["build", "lint", "test"],
"accessToken": "YWUxOTUxOWUtMDk5ZS00ZmIzLTk0ZDgtODE4M2QwYjIxN2M5fHJlYWQtd3JpdGU=",
"canTrackAnalytics": false,
"showUsageWarnings": true
Expand Down
Loading

0 comments on commit e978551

Please sign in to comment.