-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.awk
44 lines (44 loc) · 1.16 KB
/
comment.awk
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
# gawk -f comment.awk ./node_modules/lib-ruby-parser/index.d.ts
{
if (/Represents/)
{
i = 0
sub(/\s+\/\/\s*/, "")
comments[i++] = $0
recording = !recording
}
else if (/export class/ && recording)
{
recording = !recording
z = 0
for (k in comments)
{
classes[$3][z++] = comments[k]
# print "class: " $3 ", comment idx: " k ", comment:" comments[k]
}
delete comments
}
else if (recording)
{
sub(/\s+\/\/\s*/, "")
comments[i++] = $0
}
}
END {
for (cname in classes)
{
contents = "<!-- BEGIN_AUTOGENERATED -->\n# " cname " Node Formatting" "\n"
for (cc in classes[cname])
{
contents = contents "\n" classes[cname][cc]
}
contents = contents "\n<!-- END_AUTOGENERATED -->"
tmp_docfile = "./tmp/src/nodes/" cname ".fixtures.md.tmp"
docfile = "./src/nodes/" cname ".fixtures.md"
headerfile = "./tmp/src/nodes/" cname ".header.md"
print contents > headerfile
printf("awk 'NR==1{while ((getline line < \"%s\") > 0) {print line}} NR!=1{print}' %s > %s\n", headerfile, docfile, tmp_docfile) | "sh"
printf("mv %s %s\n", tmp_docfile, docfile) | "sh"
close("sh")
}
}