-
Notifications
You must be signed in to change notification settings - Fork 40
/
sync.sh
executable file
·50 lines (36 loc) · 1.72 KB
/
sync.sh
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
#!/bin/bash
## Sync dependent files with each other:
## - parinfer.js symbols => code.md
## - package.json version => parinfer.js
jsfile=parinfer.js
testjsfile=testParsingLib.js
docfile=doc/code.md
##----------------------------------------------------------------------------
## Doc Symbol sync
##----------------------------------------------------------------------------
# ref links for each top-level function name
fn_links=$(perl -n -e'/^ function (\w+)/ && print "[`$1`]:../parinfer.js#L$.\n"' $jsfile)
# ref links for each top-level var name
var_links=$(perl -n -e'/^ (const|let) ([\w_]+) = / && print "[`$2`]:../parinfer.js#L$.\n"' $jsfile)
# ref links for each top-level result key
result_links=$(perl -n -e'/^\s+(\w+):.*\/\/\s*\@doc / && print "[`result.$1`]:../parinfer.js#L$.\n"' $jsfile)
# where to insert the ref links
lineno=$(perl -n -e'/<!-- END OF DOC/ && print $.' $docfile)
# add ref links to the docs
docs=$(head -n $lineno $docfile)
printf "$docs\n$var_links\n$fn_links\n$result_links\n" > $docfile
echo "Updated $docfile with $jsfile symbol locations."
##----------------------------------------------------------------------------
## Version sync
##----------------------------------------------------------------------------
# Get package.json version.
version=$(perl -n -e'/"version": "(.+)"/ && print "$1"' package.json)
# Sync version to code files.
sed -i.bak "s|^// Parinfer .*|// Parinfer $version|" $jsfile
sed -i.bak "s|^// Parinfer Test .*|// Parinfer Test $version|" $testjsfile
sed -i.bak "s|^ version: .*| version: \"$version\",|" $jsfile
rm ${jsfile}.bak
rm ${testjsfile}.bak
echo "Updated $jsfile with package.json version $version"
echo "Updated $testjsfile with package.json version $version"
echo