forked from dyoo/WeScheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-console-and-editor.rkt
executable file
·124 lines (91 loc) · 4.46 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
#!/usr/bin/env racket
#lang racket/base
(require racket/file
racket/runtime-path
racket/path
(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 (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)))
(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))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ensure-codemirror-installed!)
(ensure-closure-library-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 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" "war")