1
+ #! /bin/bash
2
+
3
+ # Script that bundles the dev-app using the Google Closure compiler.
4
+ # This is script is used to verify closure-compatiblity of all Material components.
5
+
6
+ set -e -o pipefail
7
+
8
+ # Go to the project root directory
9
+ cd $( dirname $0 ) /../..
10
+
11
+ # Build the demo-app and also create the release output.
12
+ $( npm bin) /gulp build:devapp
13
+ $( npm bin) /gulp :package:release
14
+
15
+ # Rebuild demo-app with ES2015 modules. Closure compiler is then able to parse imports.
16
+ $( npm bin) /tsc -p src/demo-app/ --target ES2015 --module ES2015
17
+
18
+ # Re-compile RxJS sources into ES2015. Otherwise closure compiler can't parse it properly.
19
+ $( npm bin) /ngc -p scripts/closure-compiler/tsconfig-rxjs.json
20
+
21
+ # Create a list of all RxJS source files.
22
+ rxjsSourceFiles=$( find dist/packages/rxjs -name ' *.js' ) ;
23
+
24
+ # Due a Closure Compiler issue https://github.com/google/closure-compiler/issues/2247
25
+ # we need to add exports to the different RxJS ES2015 files.
26
+ for i in $rxjsSourceFiles ; do
27
+ echo " export var __CLOSURE_WORKAROUND__" >> $i
28
+ done
29
+
30
+ OPTS=(
31
+ " --language_in=ES6_STRICT"
32
+ " --language_out=ES5"
33
+ " --compilation_level=ADVANCED_OPTIMIZATIONS"
34
+ " --js_output_file=dist/closure/closure-bundle.js"
35
+ " --variable_renaming_report=dist/closure/variable_renaming_report"
36
+ " --property_renaming_report=dist/closure/property_renaming_report"
37
+ " --warning_level=QUIET"
38
+ " --rewrite_polyfills=false"
39
+
40
+ # List of path prefixes to be removed from ES6 & CommonJS modules.
41
+ " --js_module_root=dist/packages"
42
+ " --js_module_root=dist/release"
43
+ " --js_module_root=node_modules/@angular/core"
44
+ " --js_module_root=node_modules/@angular/common"
45
+ " --js_module_root=node_modules/@angular/compiler"
46
+ " --js_module_root=node_modules/@angular/forms"
47
+ " --js_module_root=node_modules/@angular/http"
48
+ " --js_module_root=node_modules/@angular/router"
49
+ " --js_module_root=node_modules/@angular/platform-browser"
50
+ " --js_module_root=node_modules/@angular/platform-browser/animations"
51
+ " --js_module_root=node_modules/@angular/platform-browser-dynamic"
52
+ " --js_module_root=node_modules/@angular/animations"
53
+ " --js_module_root=node_modules/@angular/animations/browser"
54
+
55
+ # Flags to simplify debugging.
56
+ " --formatting=PRETTY_PRINT"
57
+ " --debug"
58
+
59
+ # Include the Material FESM bundle
60
+ dist/release/@angular/material.js
61
+
62
+ # Include all Angular FESM bundles.
63
+ node_modules/@angular/core/@angular/core.js
64
+ node_modules/@angular/common/@angular/common.js
65
+ node_modules/@angular/compiler/@angular/compiler.js
66
+ node_modules/@angular/forms/@angular/forms.js
67
+ node_modules/@angular/http/@angular/http.js
68
+ node_modules/@angular/router/@angular/router.js
69
+ node_modules/@angular/platform-browser/@angular/platform-browser.js
70
+ node_modules/@angular/platform-browser/@angular/platform-browser/animations.js
71
+ node_modules/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic.js
72
+ node_modules/@angular/animations/@angular/animations.js
73
+ node_modules/@angular/animations/@angular/animations/browser.js
74
+
75
+ # Include other dependencies like Zone.js and RxJS
76
+ node_modules/zone.js/dist/zone.js
77
+ $rxjsSourceFiles
78
+
79
+ # Include all files from the demo-app package.
80
+ $( find dist/packages/demo-app -name ' *.js' )
81
+
82
+ " --entry_point=./dist/packages/demo-app/main.js"
83
+ " --dependency_mode=STRICT"
84
+ )
85
+
86
+ # Write closure flags to a closure flagfile.
87
+ closureFlags=$( mktemp)
88
+ echo ${OPTS[*]} > $closureFlags
89
+
90
+ # Run the Google Closure compiler java runnable.
91
+ java -jar node_modules/google-closure-compiler/compiler.jar --flagfile $closureFlags
92
+
93
+ echo " Finished bundling the dev-app using google closure compiler.."
0 commit comments