This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
forked from swagger-api/swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Cakefile
112 lines (96 loc) · 3.98 KB
/
Cakefile
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
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'
sourceFiles = [
'SwaggerUi'
'view/HeaderView'
'view/MainView'
'view/ResourceView'
'view/OperationView'
'view/ParameterView'
]
task 'clean', 'Removes distribution', ->
console.log 'Clearing dist...'
exec 'rm -rf dist'
task 'dist', 'Build a distribution', ->
console.log "Build distribution in ./dist"
fs.mkdirSync('dist') if not path.existsSync('dist')
fs.mkdirSync('dist/lib') if not path.existsSync('dist/lib')
appContents = new Array remaining = sourceFiles.length
for file, index in sourceFiles then do (file, index) ->
console.log " : Reading src/main/coffeescript/#{file}.coffee"
fs.readFile "src/main/coffeescript/#{file}.coffee", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
precompileTemplates() if --remaining is 0
precompileTemplates= ->
console.log ' : Precompiling templates...'
templateFiles = fs.readdirSync('src/main/template')
templateContents = new Array remaining = templateFiles.length
for file, index in templateFiles then do (file, index) ->
console.log " : Compiling src/main/template/#{file}"
exec "handlebars src/main/template/#{file} -f dist/_#{file}.js", (err, stdout, stderr) ->
throw err if err
fs.readFile 'dist/_' + file + '.js', 'utf8', (err, fileContents) ->
throw err if err
templateContents[index] = fileContents
fs.unlink 'dist/_' + file + '.js'
if --remaining is 0
templateContents.push '\n\n'
fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) ->
throw err if err
build()
build = ->
console.log ' : Collecting Coffeescript source...'
appContents.push '\n\n'
fs.writeFile 'dist/_swagger-ui.coffee', appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
console.log ' : Compiling...'
exec 'coffee --compile dist/_swagger-ui.coffee', (err, stdout, stderr) ->
throw err if err
fs.unlink 'dist/_swagger-ui.coffee'
console.log ' : Combining with javascript...'
exec 'cat src/main/javascript/doc.js dist/_swagger-ui-templates.js dist/_swagger-ui.js > dist/swagger-ui.js', (err, stdout, stderr) ->
throw err if err
fs.unlink 'dist/_swagger-ui.js'
fs.unlink 'dist/_swagger-ui-templates.js'
console.log ' : Minifying all...'
exec 'java -jar "./bin/yuicompressor-2.4.7.jar" --type js -o ' + 'dist/swagger-ui.min.js ' + 'dist/swagger-ui.js', (err, stdout, stderr) ->
throw err if err
pack()
pack = ->
console.log ' : Packaging...'
exec 'cp -r lib dist'
exec 'cp -r src/main/html/* dist'
console.log ' !'
task 'spec', "Run the test suite", ->
exec "open spec.html", (err, stdout, stderr) ->
throw err if err
task 'watch', 'Watch source files for changes and autocompile', ->
# Function which watches all files in the passed directory
watchFiles = (dir) ->
files = fs.readdirSync(dir)
for file, index in files then do (file, index) ->
console.log " : " + dir + "/#{file}"
fs.watchFile dir + "/#{file}", (curr, prev) ->
if +curr.mtime isnt +prev.mtime
invoke 'dist'
notify "Watching source files for changes..."
# Watch specific source files
for file, index in sourceFiles then do (file, index) ->
console.log " : " + "src/main/coffeescript/#{file}.coffee"
fs.watchFile "src/main/coffeescript/#{file}.coffee", (curr, prev) ->
if +curr.mtime isnt +prev.mtime
invoke 'dist'
# watch all files in these folders
watchFiles("src/main/template")
watchFiles("src/main/javascript")
watchFiles("src/main/html")
watchFiles("src/test")
notify = (message) ->
return unless message?
console.log message
# options =
# title: 'CoffeeScript'
# image: 'bin/CoffeeScript.png'
# try require('growl') message, options