-
Notifications
You must be signed in to change notification settings - Fork 17
/
transpile-sources.sh
executable file
·118 lines (89 loc) · 3.23 KB
/
transpile-sources.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
#!/bin/bash
source ./helpers.sh
####
#### BUILDS SOURCES
####
#### Expects sources to be in /usr/src/app/ with the app in
#### /usr/src/app/app/ and stores the resulting build in /usr/src/build
# Clean starting state
rm -Rf /usr/src/processing /usr/src/build
# Copy template (/usr/src/app/) and app (/usr/src/app/app/) sources
# without package.json, which we want to skip as it would conflict
# building sources.
cp -R /usr/src/app /usr/src/processing
rm -f /usr/src/processing/app/package.json
## CoffeeScript
##
## Coffeescript is transpiled ready for nodejs. This is then moved into
## app so we have the javascript available which other preprocessors may
## expect to exist.
##
## In order to generate the sourcemaps correctly, it seems we have to be
## next to the folder where we want the sources to land, but in order to
## transpile correctly we also need the node_modules for babel and the
## babelrc file. We temporarily move those around.
cd /usr/src/
# prepare the build folders
mkdir /usr/src/build /usr/src/build.coffee
cp -R /usr/src/processing/app/* /usr/src/build/
cp /usr/src/processing/babel.config.json /usr/src/
cp -R /usr/src/processing/node_modules/ /usr/src/
# make the build and move to coffeescript-transpilation
/usr/src/app/node_modules/.bin/coffee -M -m --compile -t --output ./build.coffee/ ./build
mv build.coffee/ /usr/src/processing/coffeescript-transpilation
# clean up
rm -Rf /usr/src/build /usr/src/node_modules/
rm /usr/src/babel.config.json
## TypeScript and ES6
##
## Transpiles TypeScript and ES6 to something nodejs wants to run.
cd /usr/src/processing/
mkdir typescript-transpilation build
cp -R ./app/* build
docker-rsync /usr/src/processing/coffeescript-transpilation/ /usr/src/processing/build/
/usr/src/app/node_modules/.bin/babel \
./build/ \
--out-dir ./typescript-transpilation/ \
--source-maps true \
--extensions ".ts,.js"
rm -Rf ./build
mv typescript-transpilation /usr/src/build
# We move the coffeescript files again because the previous step will
# have built the sources coffeescript generated, but these sources were
# already node compliant. We could make coffeescript emit ES6 and
# transpile them to nodejs in this step, but that breaks SourceMaps.
docker-rsync /usr/src/processing/coffeescript-transpilation/ /usr/src/build/
# We move all unhandled files (non js, ts, coffee) into the sources for
# later use.
docker-rsync \
--exclude "*.js" \
--exclude "*.ts" \
--exclude "*.coffee" \
--exclude "node_modules/" \
--exclude "./Dockerfile" \
/usr/src/processing/app/ /usr/src/build/
##############
# Node modules
##############
cd /usr/src/processing/
## template modules
cp -R /usr/src/processing/node_modules /usr/src/build/
## app modules
if [ -d /usr/src/processing/app/node_modules ]
then
docker-rsync /usr/src/processing/app/node_modules /usr/src/build/
fi
## mu helpers
cd /usr/src/processing/
mkdir /usr/src/processing/built-mu
/usr/src/app/node_modules/.bin/babel \
/usr/src/processing/helpers/mu/ \
--source-maps true \
--out-dir /usr/src/processing/built-mu \
--extensions ".js"
cp -R /usr/src/processing/built-mu /usr/src/build/node_modules/mu
## Clean temporary folders
##
## We have created garbage, let's remove it
cd /usr/src/
rm -Rf /usr/src/processing