You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Cakefile 4.7 KiB

12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
11 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
12 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. fs = require 'fs'
  2. path = require 'path'
  3. {exec} = require 'child_process'
  4. less = require 'less'
  5. sourceFiles = [
  6. 'SwaggerUi'
  7. 'view/HeaderView'
  8. 'view/MainView'
  9. 'view/ResourceView'
  10. 'view/OperationView'
  11. 'view/StatusCodeView'
  12. 'view/ParameterView'
  13. 'view/SignatureView'
  14. 'view/ContentTypeView'
  15. 'view/ResponseContentTypeView'
  16. 'view/ParameterContentTypeView'
  17. ]
  18. task 'clean', 'Removes distribution', ->
  19. console.log 'Clearing dist...'
  20. exec 'rm -rf dist'
  21. task 'dist', 'Build a distribution', ->
  22. console.log "Build distribution in ./dist"
  23. fs.mkdirSync('dist') if not path.existsSync('dist')
  24. fs.mkdirSync('dist/lib') if not path.existsSync('dist/lib')
  25. appContents = new Array remaining = sourceFiles.length
  26. for file, index in sourceFiles then do (file, index) ->
  27. console.log " : Reading src/main/coffeescript/#{file}.coffee"
  28. fs.readFile "src/main/coffeescript/#{file}.coffee", 'utf8', (err, fileContents) ->
  29. throw err if err
  30. appContents[index] = fileContents
  31. precompileTemplates() if --remaining is 0
  32. precompileTemplates= ->
  33. console.log ' : Precompiling templates...'
  34. templateFiles = fs.readdirSync('src/main/template')
  35. templateContents = new Array remaining = templateFiles.length
  36. for file, index in templateFiles then do (file, index) ->
  37. console.log " : Compiling src/main/template/#{file}"
  38. exec "handlebars src/main/template/#{file} -f dist/_#{file}.js", (err, stdout, stderr) ->
  39. throw err if err
  40. fs.readFile 'dist/_' + file + '.js', 'utf8', (err, fileContents) ->
  41. throw err if err
  42. templateContents[index] = fileContents
  43. fs.unlink 'dist/_' + file + '.js'
  44. if --remaining is 0
  45. templateContents.push '\n\n'
  46. fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) ->
  47. throw err if err
  48. build()
  49. build = ->
  50. console.log ' : Collecting Coffeescript source...'
  51. appContents.push '\n\n'
  52. fs.writeFile 'dist/_swagger-ui.coffee', appContents.join('\n\n'), 'utf8', (err) ->
  53. throw err if err
  54. console.log ' : Compiling...'
  55. exec 'coffee --compile dist/_swagger-ui.coffee', (err, stdout, stderr) ->
  56. throw err if err
  57. fs.unlink 'dist/_swagger-ui.coffee'
  58. console.log ' : Combining with javascript...'
  59. exec 'cat src/main/javascript/doc.js dist/_swagger-ui-templates.js dist/_swagger-ui.js > dist/swagger-ui.js', (err, stdout, stderr) ->
  60. throw err if err
  61. fs.unlink 'dist/_swagger-ui.js'
  62. fs.unlink 'dist/_swagger-ui-templates.js'
  63. console.log ' : Minifying all...'
  64. exec 'java -jar "./bin/yuicompressor-2.4.7.jar" --type js -o ' + 'dist/swagger-ui.min.js ' + 'dist/swagger-ui.js', (err, stdout, stderr) ->
  65. throw err if err
  66. lessc()
  67. lessc = ->
  68. # Someone who knows CoffeeScript should make this more Coffee-licious
  69. console.log ' : Compiling LESS...'
  70. less.render fs.readFileSync("src/main/less/screen.less", 'utf8'), (err, css) ->
  71. console.log err
  72. fs.writeFileSync("src/main/html/css/screen.css", css)
  73. pack()
  74. pack = ->
  75. console.log ' : Packaging...'
  76. exec 'cp -r lib dist'
  77. console.log ' : Copied swagger-ui libs'
  78. exec 'cp -r node_modules/swagger-client/lib/swagger.js dist/lib'
  79. console.log ' : Copied swagger dependencies'
  80. exec 'cp -r src/main/html/* dist'
  81. console.log ' : Copied html dependencies'
  82. console.log ' !'
  83. task 'spec', "Run the test suite", ->
  84. exec "open spec.html", (err, stdout, stderr) ->
  85. throw err if err
  86. task 'watch', 'Watch source files for changes and autocompile', ->
  87. # Function which watches all files in the passed directory
  88. watchFiles = (dir) ->
  89. files = fs.readdirSync(dir)
  90. for file, index in files then do (file, index) ->
  91. console.log " : " + dir + "/#{file}"
  92. fs.watchFile dir + "/#{file}", (curr, prev) ->
  93. if +curr.mtime isnt +prev.mtime
  94. invoke 'dist'
  95. notify "Watching source files for changes..."
  96. # Watch specific source files
  97. for file, index in sourceFiles then do (file, index) ->
  98. console.log " : " + "src/main/coffeescript/#{file}.coffee"
  99. fs.watchFile "src/main/coffeescript/#{file}.coffee", (curr, prev) ->
  100. if +curr.mtime isnt +prev.mtime
  101. invoke 'dist'
  102. # watch all files in these folders
  103. watchFiles("src/main/template")
  104. watchFiles("src/main/javascript")
  105. watchFiles("src/main/html")
  106. watchFiles("src/main/less")
  107. watchFiles("src/test")
  108. notify = (message) ->
  109. return unless message?
  110. console.log message
  111. # options =
  112. # title: 'CoffeeScript'
  113. # image: 'bin/CoffeeScript.png'
  114. # try require('growl') message, options