Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

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