-
Notifications
You must be signed in to change notification settings - Fork 18
/
build
executable file
·134 lines (98 loc) · 2.65 KB
/
build
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
#!/usr/bin/env tclsh8.6
set build_id [clock format [ clock seconds ] -format "%Y%m%d%H%M"]
set resources [ lindex $argv 0 ]
if {$resources == "false"} {
set resources 0
} else {
set resources 1
}
set my_path [ file normalize [ info script ] ]
set dir [ file dirname $my_path ]
file delete -force /tmp/dkt
file mkdir /tmp/dkt
file mkdir /tmp/dkt/static
file mkdir /tmp/dkt/app
file mkdir /tmp/dkt/app/templates
cd static
puts [ exec ./drnjs ]
cd ../app
puts [ exec ./drnlua ]
cd ..
proc read_file { filename } {
set f [open $filename "rb"]
set data [read $f]
close $f
return $data
}
proc write_file {filename data} {
# truncate if exists, else create
set fd [open $filename w]
try {
puts -nonewline $fd $data
} finally {
close $fd
}
}
proc get_files { dir pattern } {
set files [ glob -nocomplain -directory $dir $pattern ]
return $files
}
proc copy_files { src dst patterns } {
foreach ext $patterns {
set files [ get_files $src *.$ext ]
foreach file $files {
set file_only [ file tail $file ]
file copy -force $file $dst/$file_only
}
}
}
copy_files $dir/app /tmp/dkt/app {json lua}
copy_files $dir/app/templates /tmp/dkt/app/templates {el}
file delete /tmp/dkt/app/external_creds.lua
if { $resources } {
file copy -force $dir/static/fonts /tmp/dkt/static/fonts
file copy -force $dir/static/images /tmp/dkt/static/images
file copy -force $dir/static/libs /tmp/dkt/static/libs
copy_files $dir/static /tmp/dkt/static {html css txt png ico json js jpg gif jpeg}
}
file copy -force $dir/emails /tmp/dkt/emails
set f [open /tmp/dkt/app/version.txt wb]
puts $f $build_id
close $f
set jsfiles [ get_files $dir/static "*.js" ]
set outdir [file normalize "/tmp/dkt/static"]
set closdir [file normalize "$dir/clos/"]
proc handle_loader {outdir build_id} {
set path "$outdir/loader.js"
set old_content [read_file $path]
set old "loader_load\(\)"
set new "loader_load\(\"$build_id\"\)"
set map [list $old $new]
set new_content [string map $map $old_content]
write_file $path $new_content
}
handle_loader $outdir $build_id
puts "Minifying Javascript files"
foreach file $jsfiles {
set file_only [ file tail $file ]
if {$file_only != "loader.js"} {
puts -nonewline "$file_only... "
flush stdout
set result [ exec java -jar $closdir/compiler.jar --js_output_file=$outdir/$file_only $file]
if {$result != "" } {
puts $result
exit 1
}
puts "OK"
}
}
set targetjs [ get_files /tmp/dkt/static *.js ]
foreach file $targetjs {
set tagged [string map [list .js $build_id.js] $file]
file copy -force $file $tagged
}
puts "Making zip..."
set prev [pwd]
cd /tmp
puts [ exec zip -r $build_id.zip dkt ]
cd $prev