-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathbuild.frp
225 lines (172 loc) · 7.97 KB
/
build.frp
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
%furipota/1
import core "prelude"
define root = Path.directory self.path
define packages = root / "packages"
define npm-bin name = root / "node_modules" / ".bin" / name
define uglify = npm-bin "uglifyjs"
define browserify = npm-bin "browserify"
define show-file-operation prefix x =
Debug.log "{Path.to-text x.from} -> {Path.to-text x.to}" @ -prefix: prefix
define get-or-else value default-value =
match value with
case ^Ok x then x
case ^Error any then default-value
define babel from to flags @ options =
$((npm-bin "babel") from '--copy-files '--source-map 'inline '--out-dir to ...flags @
-environment: (get-or-else (Record.get options "environment") Record.empty)
)
define mocha reporter flags @ options =
$((npm-bin "mocha")
'--require 'babel-polyfill
'--reporter reporter
'--ui 'bdd
'--recursive
(root / "test" / "build" / "specs")
'--require "./test/source/helpers/promise-rejections.js"
...flags
@ -environment: (get-or-else (Record.get options "environment") Record.empty)
)
define karma configuration =
$((npm-bin "karma") 'start configuration)
define show-shell-error e = match e with
case ^Shell.Error x then x.stack
case ^Shell.Exit-Code x then "The program exited with code {x}"
define show-shell-output stream =
Terminal.show-stream (Stream.map-errors show-shell-error stream)
define summarise-shell-output summary stream =
let show-error e = do
action Terminal.display-line "[ERR] {summary}"
action Terminal.display-line (show-shell-error e)
action Stream.error e
in do
action Terminal.display "[...] {summary}...\r"
action Stream.recover show-error stream
action Terminal.display-line "[OK] {summary}"
define compile-source = do
let source = packages / "base" / "source"
let target = packages / "base" / "build"
action (babel source target [] @ -environment: (-DISABLE_MM_COMMENTS: "true"))
| (summarise-shell-output "Compiling source code for Base")
action (babel source (target / "annotated") [])
| (summarise-shell-output "Compiling annotated source code for Base")
define bundle-source = do
let umd-dist = packages / "base" / "dist" / "umd"
let build = packages / "base" / "build"
action make-directory umd-dist | Debug.trace @ -prefix: "MKDIR"
action $(browserify (build / "index.js")
'--standalone 'folktale
'--outfile (umd-dist / "folktale.js")
) | (summarise-shell-output "Bundling Base package with Browserify")
action $(uglify (umd-dist / "folktale.js") '--mangle '--output (umd-dist / "folktale.min.js"))
| (summarise-shell-output "Minifying the Base bundle")
define compile-test = do
let source = root / "test" / "source"
let target = root / "test" / "build"
let mocha = source / "browser" / "mocha.js"
action (babel source target ["--ignore", mocha] @ -environment: (-NODE_ENV: ""))
| (summarise-shell-output "Compiling test files")
define bundle-test = do
let build = root / "test" / "build" / "browser"
let source = root / "test" / "source" / "browser"
let show-move = show-file-operation "MOVE"
let show-copy = show-file-operation "COPY"
action $(browserify (build / "browser-tests.js")
'--source-map 'inline
'--outfile (build / "tests.tmp.js")
) | (summarise-shell-output "Bundling tests with Browserify")
action move (build / "tests.tmp.js") @ -to: (build / "browser-tests.js") -overwrite: true |> show-move
action copy (source / "mocha.js") @ -to: (build / "mocha.js") -overwrite: true |> show-copy
define compile-annotations = do
let markdown-to-mm = root / "tools" / "markdown-to-mm.js"
let annotations = root / "annotations"
action $('node markdown-to-mm (annotations / "source") (annotations / "build"))
| (summarise-shell-output "Compiling documentation annotations into MetaMagical modules")
define generate-docs language = do
let tool = root / "tools" / "generate-docs.js"
action $('node tool language)
define run-tests reporter @ options =
do action clean
action compile-source
action compile-test
action compile-annotations
action bundle-test
action show-shell-output (mocha reporter [] @ -environment: (-FOLKTALE_ASSERTIONS: options.assertions -ES_VERSION: "2015"))
action show-shell-output (karma (root / "test" / "karma-local.js"))
action Terminal.display-line "---"
action Terminal.display-line "All good!"
define run-lint configuration =
do bind package <- Stream.from-vector [packages / "base"]
action Terminal.display-line "Linting {package}"
action show-shell-output $((npm-bin "eslint") (package / "source") '--config configuration)
# --[ Tasks ]----------------------------------------------------------
export define clean =
# Removes generated artifacts in the repository, giving you a clean project state
do bind artifact <- Stream.from-vector [
root / "packages" / "base" / "build",
root / "packages" / "base" / "dist",
root / "test" / "build",
root / "annotations" / "build"
]
action Terminal.display "[...] Removing {Path.to-text artifact}...\r"
action remove artifact
action Terminal.display-line "[OK] Removed {Path.to-text artifact} "
export define compile =
# Compiles the source code for the project, in all sub-packages.
do action compile-source
export define test =
# Runs all tests for Folktale with a minimal output
run-tests "nyan" @ -assertions: "none"
export define test-spec =
# Like `test`, but uses the detailed spec reporter and outputs warnings
run-tests "spec" @ -assertions: "minimal"
export define test-on-travis =
# Runs all tests and coverage reports we need for Travis CI integration
let nyc = npm-bin "nyc" in
let mocha = npm-bin "mocha" in
let tests = root / "test" / "source" / "specs" in
do action clean
action run-lint (root / ".eslintrc.travis.json")
action compile-source
action compile-test
action compile-annotations
action bundle-test
action show-shell-output $(
nyc mocha '--require 'babel-polyfill '--ui 'bdd '--recursive tests
@ -environment: (-FOLKTALE_ASSERTIONS: "none")
)
action show-shell-output (karma (root / "test" / "karma-local.js"))
action show-shell-output $('npm 'run 'coverage)
action Terminal.display-line "---"
action Terminal.display-line "All good!"
export define documentation =
# Compiles and generates the documentation, starts a Jekyll server as well.
let docs = root / "docs" in
let stylus = npm-bin "stylus" in
do action compile-source
action compile-annotations
action (generate-docs "en") | (summarise-shell-output "Generating English documentation")
action $('bundle 'install @ -working-directory: docs)
| (summarise-shell-output "Installing Ruby dependencies with Bundler")
action $(
stylus (docs / "stylus" / "screen.styl")
'--out (docs / "css" / "screen.css")
) | (summarise-shell-output "Compiling Stylus files into CSS")
action show-shell-output $('bundle 'exec 'jekyll 'serve @ -working-directory: docs)
export define lint =
# Notifies about formatting problems and potential bugs in the source code.
run-lint (root / ".eslintrc.json")
export define release =
# Releases `base`
let release = root / "packages" / "base" / "releases" / "new" in
let pkg = root / "packages" / "base" in
let show-copy = show-file-operation "COPY" in
do action test
action lint
action bundle-source
action make-directory release | Debug.trace @ -prefix: "MKDIR"
action copy (pkg / "build") @ -to: release -overwrite: true |> show-copy
action copy (pkg / "CHANGELOG.md") @ -to: (release / "CHANGELOG.md") -overwrite: true |> show-copy
action copy (pkg / "package.json") @ -to: (release / "package.json") -overwrite: true |> show-copy
action copy (pkg / "CONTRIBUTORS") @ -to: (release / "CONTRIBUTORS") -overwrite: true |> show-copy
action copy (root / "README.md") @ -to: (release / "README.md") -overwrite:true |> show-copy
action $('npm 'pack @ -working-directory: release)