25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

114 satır
4.0 KiB

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