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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var del = require('del')
  2. , gulp = require('gulp')
  3. , chmod = require('gulp-chmod')
  4. , concat = require('gulp-concat')
  5. , header = require('gulp-header')
  6. , rename = require('gulp-rename')
  7. , size = require('gulp-size')
  8. , trim = require('gulp-trimlines')
  9. , uglify = require('gulp-uglify')
  10. , wrapUmd = require('gulp-wrap')
  11. , request = require('request')
  12. , fs = require('fs')
  13. , pkg = require('./package.json')
  14. var headerLong = ['/*!'
  15. , '* <%= pkg.name %> - <%= pkg.description %>'
  16. , '* @version <%= pkg.version %>'
  17. , '* <%= pkg.homepage %>'
  18. , '*'
  19. , '* @copyright <%= pkg.author %>'
  20. , '* @license <%= pkg.license %>'
  21. , '*'
  22. , '* BUILT: <%= pkg.buildDate %>'
  23. , '*/;'
  24. , ''].join('\n')
  25. var headerShort = '/*! <%= pkg.name %> v<%= pkg.version %> <%= pkg.license %>*/;'
  26. // all files in the right order (currently we don't use any dependency management system)
  27. var parts = [
  28. 'src/svg.js'
  29. , 'src/regex.js'
  30. , 'src/utilities.js'
  31. , 'src/default.js'
  32. , 'src/color.js'
  33. , 'src/array.js'
  34. , 'src/pointarray.js'
  35. , 'src/patharray.js'
  36. , 'src/number.js'
  37. , 'src/element.js'
  38. , 'src/fx.js'
  39. , 'src/boxes.js'
  40. , 'src/matrix.js'
  41. , 'src/point.js'
  42. , 'src/attr.js'
  43. , 'src/transform.js'
  44. , 'src/style.js'
  45. , 'src/parent.js'
  46. , 'src/ungroup.js'
  47. , 'src/container.js'
  48. , 'src/viewbox.js'
  49. , 'src/event.js'
  50. , 'src/defs.js'
  51. , 'src/group.js'
  52. , 'src/arrange.js'
  53. , 'src/mask.js'
  54. , 'src/clip.js'
  55. , 'src/gradient.js'
  56. , 'src/pattern.js'
  57. , 'src/doc.js'
  58. , 'src/shape.js'
  59. , 'src/bare.js'
  60. , 'src/use.js'
  61. , 'src/rect.js'
  62. , 'src/ellipse.js'
  63. , 'src/line.js'
  64. , 'src/poly.js'
  65. , 'src/pointed.js'
  66. , 'src/path.js'
  67. , 'src/image.js'
  68. , 'src/text.js'
  69. , 'src/textpath.js'
  70. , 'src/nested.js'
  71. , 'src/hyperlink.js'
  72. , 'src/marker.js'
  73. , 'src/sugar.js'
  74. , 'src/set.js'
  75. , 'src/data.js'
  76. , 'src/memory.js'
  77. , 'src/selector.js'
  78. , 'src/helpers.js'
  79. , 'src/polyfill.js'
  80. ]
  81. gulp.task('clean', function() {
  82. return del([ 'dist/*' ])
  83. })
  84. /**
  85. * Compile everything in /src to one unified file in the order defined in the MODULES constant
  86. * wrap the whole thing in a UMD wrapper (@see https://github.com/umdjs/umd)
  87. * add the license information to the header plus the build time stamp‏
  88. */
  89. gulp.task('unify', ['clean'], function() {
  90. pkg.buildDate = Date()
  91. return gulp.src(parts)
  92. .pipe(concat('svg.js', { newLine: '\n' }))
  93. // wrap the whole thing in an immediate function call
  94. .pipe(wrapUmd({ src: 'src/umd.js'}))
  95. .pipe(header(headerLong, { pkg: pkg }))
  96. .pipe(trim({ leading: false }))
  97. .pipe(chmod(644))
  98. .pipe(gulp.dest('dist'))
  99. .pipe(size({ showFiles: true, title: 'Full' }))
  100. })
  101. /**
  102. ‎* uglify the file and show the size of the result
  103. * add the license info
  104. * show the gzipped file size
  105. */
  106. gulp.task('minify', ['unify'], function() {
  107. return gulp.src('dist/svg.js')
  108. .pipe(uglify())
  109. .pipe(rename({ suffix:'.min' }))
  110. .pipe(size({ showFiles: true, title: 'Minified' }))
  111. .pipe(header(headerShort, { pkg: pkg }))
  112. .pipe(chmod(644))
  113. .pipe(gulp.dest('dist'))
  114. .pipe(size({ showFiles: true, gzip: true, title: 'Gzipped' }))
  115. })
  116. /**
  117. ‎* rebuild documentation using documentup
  118. */
  119. gulp.task('docs', function() {
  120. fs.readFile('README.md', 'utf8', function (err, data) {
  121. request.post(
  122. 'http://documentup.com/compiled'
  123. , { form: { content: data, name: 'SVG.js', theme: 'v1' } }
  124. , function (error, response, body) {
  125. // Replace stylesheet
  126. body = body.replace('//documentup.com/stylesheets/themes/v1.css', 'svgjs.css')
  127. // Write file
  128. fs.writeFile('docs/index.html', body, function(err) {})
  129. }
  130. )
  131. })
  132. })
  133. gulp.task('default', ['clean', 'unify', 'minify'])