-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.sh
executable file
·139 lines (103 loc) · 4.35 KB
/
build.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# this script will compile the vis library into a tw-plugin
#####################################################################
# Script Configuration
#####################################################################
pluginPrefix="$:/plugins/felixhayashi/vis" # prefix for all tiddlers of this plugin
distPath="dist/felixhayashi/vis/" # output path
srcPath="src/" # plugin's src path
visSrcPath="${srcPath}/vis/dist/" # vis module's dist path
imgSrcPath="${srcPath}/img/" # customised vis-images path
images=($(cd "$imgSrcPath"; echo */*;)) # array of customised vis-images
compress=1 # set this to 0 to disable compression of css and js
#####################################################################
# Program
#####################################################################
#====================================================================
printf "Fetch upstream resources...\n"
#====================================================================
git submodule update --init --recursive
#====================================================================
printf "Perform cleanup...\n"
#====================================================================
# clean up
[ -d $distPath ] && rm -rf $distPath
# create paths
mkdir -p $distPath
mkdir $distPath/tiddlers
#====================================================================
printf "compile and copy images...\n"
#====================================================================
imagesLength=${#images[*]}
for((i = 0; i < $imagesLength; i++)); do
twImgPrefix="img/${images[i]}"
# replace shash with underscore
imgName="${twImgPrefix//\//_}.tid";
# inject meta and content and place it into dist folder
{
printf "title: %s\ntype:%s\n\n" "${pluginPrefix}/${twImgPrefix}" "image/png"
base64 -w 0 "$imgSrcPath/${images[i]}"
} >> "${distPath}/tiddlers/${imgName}"
done
#====================================================================
printf "replace urls...\n"
#====================================================================
{
perl fixurls.pl "$visSrcPath/vis.css" "$pluginPrefix"
} > "$distPath/tiddlers/vis.css.tid"
#====================================================================
printf "minify and copy styles...\n"
#====================================================================
# header with macro
header=\
'title: '${pluginPrefix}/vis.css'
type: text/vnd.tiddlywiki
tags: $:/tags/Stylesheet
\rules except list'
macro=\
'\define datauri(title)
<$macrocall $name="makedatauri" type={{$title$!!type}} text={{$title$}}/>
\end'
# uglifyied content; redirect stdin so its not closed by npm command
body=$(uglifycss $distPath/tiddlers/vis.css.tid < /dev/null)
if [ $compress == 1 ]; then
# uglifyied content; redirect stdin so its not closed by npm command
body=$(uglifycss $distPath/tiddlers/vis.css.tid < /dev/null)
else
# just use as is
body=$(cat $distPath/tiddlers/vis.css.tid)
fi
printf "%s\n\n%s\n\n%s" "$header" "$macro" "$body" > "$distPath/tiddlers/vis.css.tid"
#====================================================================
printf "uglify and copy scripts...\n"
#====================================================================
# header with macro
header=\
'/*\
title: '${pluginPrefix}/vis.js'
type: application/javascript
module-type: library
@preserve
\*/'
header="$header"$'\n'$'\n'"$(cat $srcPath/extra.js)"
if [ $compress == 1 ]; then
# uglifyied content; redirect stdin so its not closed by npm command
body=$(uglifyjs $visSrcPath/vis.js --comments < /dev/null)
else
# just use as is
body=$(cat $visSrcPath/vis.js)
fi
printf "%s\n\n%s\n" "$header" "$body" > $distPath/vis.js
#====================================================================
printf "update version information...\n"
#====================================================================
version="$(cd "$visSrcPath" && git describe --tags $(git rev-list --tags --max-count=1))"
version=${version:1}
expr="s/\"version\": \"[^\"]+\"/\"version\": \"$version\"/g"
sed -i -r -e "$expr" "src/plugin.info"
#====================================================================
printf "copy other stuff...\n"
#====================================================================
cp src/plugin.info $distPath/plugin.info
cp src/tiddlers/* $distPath/tiddlers/
exit