Skip to content

Commit 381447d

Browse files
committed
feat(utils): add findArrayLiteral
1 parent 1817d47 commit 381447d

File tree

5 files changed

+87
-9
lines changed

5 files changed

+87
-9
lines changed

libs/ddd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/ddd",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"license": "MIT",
55
"author": "Manfred Steyer",
66
"description": "Nx plugin for structuring a monorepo with domains and layers",

libs/ddd/project.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"glob": "generators.json",
2828
"output": "."
2929
},
30+
{
31+
"input": "./libs/ddd",
32+
"glob": "collection.json",
33+
"output": "."
34+
},
3035
{
3136
"input": "./libs/ddd",
3237
"glob": "executors.json",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { tsquery } from '@phenomnomnominal/tsquery';
2+
3+
export function findArrayLiteral(code: string, propName: string): number {
4+
const ast = tsquery.ast(code);
5+
const nodes = tsquery(ast, `PropertyAssignment[name.escapedText=${propName}] ArrayLiteralExpression`);
6+
if (nodes.length === 0) {
7+
return -1;
8+
}
9+
const node = nodes[0];
10+
const bracket = code.indexOf('[', node.pos);
11+
return bracket+1;
12+
}

package-lock.json

Lines changed: 68 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@nrwl/angular": "14.3.6",
2727
"@nrwl/nx-plugin": "^14.3.6",
2828
"@nrwl/schematics": "^8.12.11",
29+
"@phenomnomnominal/tsquery": "^5.0.0",
2930
"@swc/helpers": "~0.3.3",
3031
"rxjs": "~7.4.0",
3132
"tslib": "^2.0.0",

0 commit comments

Comments
 (0)