-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (71 loc) · 2.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { join } from "path";
import { WorkspaceSymbols } from "ngast";
import * as ngHtmlParser from "angular-html-parser";
import * as fs from "fs";
function parseProjectComponents() {
const config = join(
"/home/pablo/repos/personal/tx-angular-native-sdk-sample",
"tsconfig.json"
);
const workspace = new WorkspaceSymbols(config);
const components = workspace.getAllComponents();
components.forEach((cmp) => {
cmp.node.members.forEach((member) => {
member.decorators &&
member.decorators.forEach((dec) => {
let _str = "";
dec.expression.arguments &&
dec.expression.arguments.forEach((arg) => {
if (arg.text) _str = arg.text;
arg.properties &&
arg.properties.forEach((prop) => {
console.log(
`str: ${_str} params: ${prop.symbol.escapedName}: ${prop.initializer.text}`
);
});
});
});
});
});
}
function parseTemplateFile(template) {
const TComponents = [];
function parseTemplateNode(children) {
if (children)
children.forEach((child) => {
if (child.name == "T") {
TComponents.push(child);
}
if (child.name == "UT") {
TComponents.push(child);
}
parseTemplateNode(child.children);
});
}
fs.readFile(template, "utf8", function (err, data) {
if (err) throw err;
// console.log(data);
const { rootNodes, errors } = ngHtmlParser.parse(data);
parseTemplateNode(rootNodes);
TComponents.forEach((c) => {
let str = "",
key = "";
c.attrs &&
c.attrs.forEach((a) => {
if (a.name == "_str") {
str = a.value;
}
if (a.name == "_key") {
key = a.value;
}
});
if (str && key) console.log(`${key}: ${str}`);
});
});
}
const template = join(
"/home/pablo/repos/personal/tx-angular-native-sdk-sample/src/app/login",
"login.component.html"
);
parseTemplateFile(template);
parseProjectComponents();