forked from bootstrapworld/wescheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-console-and-editor.rkt
executable file
·172 lines (135 loc) · 6.47 KB
/
build-console-and-editor.rkt
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
#!/usr/bin/env racket
#lang racket/base
(require racket/file
racket/runtime-path
racket/path
racket/port
net/url
(for-syntax racket/base))
;; Assumes closure-library is under externals/closure.
(define-runtime-path closure-dir (build-path "war-src" "closure"))
(define-runtime-path closure-zip-path (build-path "externals" "closure-library-20111110-r1376.zip"))
(define-runtime-path compiler-jar-path (build-path "bin" "compiler.jar"))
(define-runtime-path codemirror-dir (build-path "war" "js" "codemirror2"))
(define appengine-version "1.8.8")
(define appengine-url
(format "http://googleappengine.googlecode.com/files/appengine-java-sdk-~a.zip" appengine-version))
(define appengine-zip-path
(build-path "externals" (format "appengine-java-sdk-~a.zip" appengine-version)))
(define appengine-dir
(build-path "lib" (format "appengine-java-sdk-~a" appengine-version)))
(define (call-system #:pipe-input-from (pipe-input-from #f)
#:pipe-output-to (pipe-output-to #f)
cmd . args)
(define stdin (if pipe-input-from
(open-input-file pipe-input-from)
(current-input-port)))
(define stdout (if pipe-output-to
(begin
(unless (let-values ([(base path dir?) (split-path pipe-output-to)])
(eq? base 'relative))
(make-directory* (path-only pipe-output-to)))
(open-output-file pipe-output-to #:exists 'replace))
(current-output-port)))
(define resolved-cmd
(if (file-exists? cmd)
cmd
(find-executable-path cmd)))
(unless resolved-cmd
(error 'build (format "I could not find ~s in your PATH" cmd)))
(define-values (a-subprocess subprocess-in subprocess-out subprocess-err)
(apply subprocess stdout stdin (current-error-port) resolved-cmd args))
(subprocess-wait a-subprocess)
(when pipe-input-from
(close-input-port stdin))
(when pipe-output-to
(close-output-port stdout)))
(define (build src dest)
(make-directory* (path-only (string-append "war/" dest)))
(call-system (build-path closure-dir "bin" "calcdeps.py")
"-i" (string-append "war-src/js/" src)
"-p" (path->string closure-dir)
"-p" "war-src/js"
"-o" "script"
#:pipe-output-to (string-append "war/js/" dest)))
(define (ensure-codemirror-installed!)
(unless (directory-exists? codemirror-dir)
(fprintf (current-error-port) "Codemirror hasn't been pulled.\n Trying to run: git submodule init/update now...\n")
(call-system "git" "submodule" "init")
(call-system "git" "submodule" "update")
(unless (directory-exists? codemirror-dir)
(fprintf (current-error-port) "Codemirror could not be pulled successfully. Exiting.\n")
(exit 0))))
(define (ensure-closure-library-installed!)
(unless (directory-exists? closure-dir)
(fprintf (current-error-port) "The Closure library has not been installed yet.\n")
(fprintf (current-error-port) "Trying to unpack it into 'war-src/closure'.\n")
(let ([zip-path (normalize-path closure-zip-path)])
(parameterize ([current-directory (build-path closure-dir 'up)])
(call-system "unzip" (path->string zip-path))))
(unless (directory-exists? closure-dir)
(fprintf (current-error-port) "The Closure library could not be installed; please check.\n")
(exit 0))))
(define (ensure-appengine-installed!)
(unless (directory-exists? appengine-dir)
(fprintf (current-error-port)
"The Google AppEngine API hasn't been installed yet.\n")
(cond [(file-exists? appengine-zip-path)
(void)]
[else
(fprintf (current-error-port)
"Trying to download it now... saving to ~s\n" appengine-zip-path)
(fprintf (current-error-port)
"(This will take a while; the API download is about 90 MB.)\n")
(call-with-output-file appengine-zip-path
(lambda (op)
(define ip (get-pure-port (string->url appengine-url)))
(copy-port ip op)
(close-input-port ip)
(close-output-port op)))])
(fprintf (current-error-port)
"The API will be installed in: ~s" appengine-dir)
(sleep 5)
(unless (directory-exists? (build-path appengine-dir 'up))
(make-directory* (build-path appengine-dir 'up)))
(let ([zip-path (normalize-path appengine-zip-path)])
(parameterize ([current-directory (build-path appengine-dir 'up)])
(call-system "unzip" (path->string zip-path))))
(unless (directory-exists? appengine-dir)
(fprintf (current-error-port) "The Google AppEngine library could not be installed; please check.\n")
(exit 0))
(fprintf (current-error-port)
"Google AppEngine API installed.\n")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ensure-codemirror-installed!)
(ensure-closure-library-installed!)
(ensure-appengine-installed!)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(printf "Building properties file for JS\n")
(copy-file "wescheme.properties" "war/wescheme.properties"
#t)
(call-system "python" "bin/make-properties.py"
#:pipe-input-from "wescheme.properties"
#:pipe-output-to "war-src/js/wescheme-properties.js")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(printf "Writing dependency file for Google Closure library\n")
(parameterize ([current-directory "war-src"])
(call-system (build-path closure-dir "bin" "calcdeps.py")
"--dep" "closure"
"--path" "js"
"--output_mode" "deps"
#:pipe-output-to "deps.js"))
;; ######################################################################
(printf "Building splash\n")
(build "splash.js" "splash-calc.js")
(printf "Building console\n")
(build "console.js" "console-calc.js")
(printf "Building view\n")
(build "view.js" "view-calc.js")
(printf "Building run\n")
(build "run.js" "run-calc.js")
(printf "Building editor\n")
(build "openEditor/index.js" "openEditor/openEditor-calc.js")
;; ######################################################################
(printf "Compressing JavaScript libraries. This may take a few minutes, depending if this is the first time this has been run.\n")
(call-system "racket" "bin/compress-js.rkt" #;"--quiet" "--permissive" "war")