File size: 3,950 Bytes
7510827
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
###
#
# Builds the SQLite JS/WASM distribution zip file.
#
# Usage: $0 build-name ?flags?
#
# build-name is the dir/archive name prefix for the
# build and defaults to sqlite-wasm.
#
# -?|--help = Show this text
#
# -0    = Use -O0 instead of ${optFlag}
#
# -1    = Use make -j1 instead of ${makeFlag}
#
# -64   = Include 64-bit builds
#
# --noclean = do not run 'make clean' first
#
# --snapshot = gives the archive name a distinctive suffix
#
###

function die(){
    local rc=$1
    shift
    echo "Error: $@" 1>&2
    exit $rc
}

dirTop=../..
buildName=
b64=0
optFlag=-Oz
clean=1
makeFlag=-j4
snapshotSuffix=
for arg in $@; do
    case $arg in

        -64) b64=1
             ;;

        -0) optFlag=-O0
            ;;

        -1) makeFlag=
            ;;

        --noclean) clean=0
                   ;;

        --snapshot)
            snapshotSuffix=$(date +%Y%m%d)
            ;;

        -?|--help)
            sed -n -e '2,/^###/p' $0
            exit
            ;;

        *) if [[ x != x${buildName} ]]; then
               die 1 "Unhandled argument: $arg"
           fi
           buildName=$arg
           ;;
    esac
done

make=
for i in gmake make; do
    make=$(which $i 2>/dev/null)
    [[ x != x${make} ]] && break
done
[[ x = x$make ]] && die 127 "Cannot find make"


[[ x = x${buildName} ]] && buildName=sqlite-wasm

buildName=${buildName}${snapshotSuffix}

echo "Creating the SQLite wasm dist bundle..."

#
# Generates files which, when built, will also build all of the pieces
# neaded for the dist bundle.
#
tgtFiles=(
    demo-worker1-promiser.html
    demo-worker1-promiser.js
    demo-worker1-promiser-esm.html
    demo-worker1-promiser.mjs

    tester1.html
    tester1-esm.html
    tester1-worker.html
    tester1.js
    tester1.mjs
)

if [[ 1 = $b64 ]]; then
    tgtFiles+=(
        tester1-64bit.html
        tester1-esm-64bit.html
        tester1-worker-64bit.html
        tester1-64bit.js
        tester1-64bit.mjs
    )
fi

[[ 1 = $clean ]] && $make clean
$make $makeFlag \
      t-version-info t-stripccomments \
      ${tgtFiles[@]} \
      "emcc_opt=${optFlag}" || die $?

dirTmp=d.dist
rm -fr $dirTmp
mkdir -p $dirTmp/jswasm || die $?
mkdir -p $dirTmp/common || die $?

# Static files for the top-most dir:
fTop=(
    demo-123.html
    demo-123-worker.html
    demo-123.js

    demo-worker1.html
    demo-worker1.js

    demo-jsstorage.html
    demo-jsstorage.js

    module-symbols.html
)

# Files for the jswasm subdir sans jswasm prefix:
#
# fJ1 = JS files to stripccomments -k on
# fJ2 = JS files to stripccomments -k -k on
fJ1=(
    sqlite3-opfs-async-proxy.js
    sqlite3-worker1.js
    sqlite3-worker1.mjs
    sqlite3-worker1-bundler-friendly.mjs
    sqlite3-worker1-promiser.js
    sqlite3-worker1-promiser.mjs
    sqlite3-worker1-promiser-bundler-friendly.mjs
)
fJ2=(
    sqlite3.js
    sqlite3.mjs
)

# fW = list of wasm files to copy from jswasm/.
fW=(sqlite3.wasm)
if [[ 1 = $b64 ]]; then
    fW+=(sqlite3-64bit.wasm)
fi

function fcp() {
    cp -p $@ || die $?
    chmod +w ${@: -1}
}

function scc(){
    ${dirTop}/tool/stripccomments $@ || die $?
}

jw=jswasm
fcp ${tgtFiles[@]} $dirTmp/.
fcp README-dist.txt $dirTmp/README.txt
fcp index-dist.html $dirTmp/index.html
fcp common/*.css common/SqliteTestUtil.js $dirTmp/common/.

for i in ${fTop[@]}; do
    fcp $i $dirTmp/.
done

for i in ${fW[@]}; do
    fcp $jw/$i $dirTmp/$jw/.
done

for i in ${fJ1[@]}; do
    scc -k < $jw/$i > $dirTmp/$jw/$i || die $?
done

for i in ${fJ2[@]}; do
    scc -k -k < $jw/$i > $dirTmp/$jw/$i || die $?
done

#
# Done copying files. Now zip it up...
#
svi=./version-info
vnum=$($svi --download-version)
[ "" = "$vnum" ] && die "version number is empty!"
vdir=${buildName}-${vnum}
fzip=${vdir}.zip
rm -fr ${vdir} ${fzip}
mv $dirTmp $vdir || die $?
zip -rq9 $fzip $(find $vdir -type f | sort) || die $?
ls -la $fzip
unzip -lv $fzip || die $?
cat <<EOF
**
** Unzipped files are in $vdir
**
EOF