gulpfile.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // jshint node:true
  2. 'use strict';
  3. const gulp = require('gulp'),
  4. del = require('del'),
  5. vinylPaths = require('vinyl-paths'),
  6. $ = require('gulp-load-plugins')();
  7. const paths = {
  8. langs: ['src/langs/**.js', '!src/langs/en.js'],
  9. icons: ['src/ui/icons/**.svg', 'plugins/*/ui/icons/**.svg'],
  10. scripts: ['src/trumbowyg.js'],
  11. styles: ['src/ui/sass/trumbowyg.scss'],
  12. pluginsScripts: ['plugins/*/**.js'],
  13. pluginsStyles: ['plugins/*/ui/sass/**.scss']
  14. };
  15. const pkg = require('./package.json');
  16. const banner = [
  17. '/**',
  18. ' * <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
  19. ' * <%= description %>',
  20. ' * ------------------------',
  21. ' * @link <%= pkg.homepage %>',
  22. ' * @license <%= pkg.license %>',
  23. ' * @author <%= pkg.author.name %>',
  24. ' * Twitter : @AlexandreDemode',
  25. ' * Website : <%= pkg.author.url.replace("http://", "") %>',
  26. ' */',
  27. '\n'
  28. ].join('\n');
  29. const bannerLight = [
  30. '/** <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
  31. ' - <%= pkg.homepage.replace("http://", "") %>',
  32. ' - License <%= pkg.license %>',
  33. ' - Author : <%= pkg.author.name %>',
  34. ' / <%= pkg.author.url.replace("http://", "") %>',
  35. ' */',
  36. '\n'
  37. ].join('');
  38. gulp.task('clean', function () {
  39. return gulp.src('dist/*')
  40. .pipe(vinylPaths(del));
  41. });
  42. gulp.task('test', ['test-scripts', 'test-plugins-scripts', 'test-langs']);
  43. gulp.task('test-scripts', function () {
  44. return gulp.src(paths.scripts)
  45. .pipe($.jshint())
  46. .pipe($.jshint.reporter('jshint-stylish'));
  47. });
  48. gulp.task('test-plugins-scripts', function () {
  49. return gulp.src(paths.pluginsScripts)
  50. .pipe($.jshint())
  51. .pipe($.jshint.reporter('jshint-stylish'));
  52. });
  53. gulp.task('test-langs', function () {
  54. return gulp.src(paths.langs)
  55. .pipe($.jshint())
  56. .pipe($.jshint.reporter('jshint-stylish'));
  57. });
  58. gulp.task('scripts', ['test-scripts'], function () {
  59. return gulp.src(paths.scripts)
  60. .pipe($.header(banner, {pkg: pkg, description: 'Trumbowyg core file'}))
  61. .pipe($.newer('dist/trumbowyg.js'))
  62. .pipe($.concat('trumbowyg.js', {newLine: '\r\n\r\n'}))
  63. .pipe(gulp.dest('dist/'))
  64. .pipe($.size({title: 'trumbowyg.js'}))
  65. .pipe($.rename({suffix: '.min'}))
  66. .pipe($.uglify())
  67. .pipe($.header(bannerLight, {pkg: pkg}))
  68. .pipe(gulp.dest('dist/'))
  69. .pipe($.size({title: 'trumbowyg.min.js'}));
  70. });
  71. gulp.task('plugins-scripts', ['test-scripts'], function () {
  72. return gulp.src(paths.pluginsScripts)
  73. .pipe(gulp.dest('dist/plugins/'))
  74. .pipe($.rename({suffix: '.min'}))
  75. .pipe($.uglify())
  76. .pipe(gulp.dest('dist/plugins/'));
  77. });
  78. gulp.task('langs', ['test-langs'], function () {
  79. return gulp.src(paths.langs)
  80. .pipe(gulp.dest('dist/langs/'))
  81. .pipe($.rename({suffix: '.min'}))
  82. .pipe($.uglify({
  83. preserveComments: 'all'
  84. }))
  85. .pipe(gulp.dest('dist/langs/'));
  86. });
  87. gulp.task('icons', function () {
  88. return gulp.src(paths.icons)
  89. .pipe($.rename({prefix: 'trumbowyg-'}))
  90. .pipe($.svgmin())
  91. .pipe($.svgstore({inlineSvg: true}))
  92. .pipe(gulp.dest('dist/ui/'));
  93. });
  94. gulp.task('styles', function () {
  95. return gulp.src(paths.styles)
  96. .pipe($.sass())
  97. .pipe($.autoprefixer(['last 1 version', '> 1%', 'ff >= 20', 'ie >= 9', 'opera >= 12', 'Android >= 2.2'], {cascade: true}))
  98. .pipe($.header(banner, {pkg: pkg, description: 'Default stylesheet for Trumbowyg editor'}))
  99. .pipe(gulp.dest('dist/ui/'))
  100. .pipe($.size({title: 'trumbowyg.css'}))
  101. .pipe($.rename({suffix: '.min'}))
  102. .pipe($.minifyCss())
  103. .pipe($.header(bannerLight, {pkg: pkg}))
  104. .pipe(gulp.dest('dist/ui/'))
  105. .pipe($.size({title: 'trumbowyg.min.css'}));
  106. });
  107. gulp.task('sass-dist', ['styles'], function () {
  108. return gulp.src(paths.styles)
  109. .pipe($.header(banner, {pkg: pkg, description: 'Default stylesheet for Trumbowyg editor'}))
  110. .pipe(gulp.dest('dist/ui/sass'));
  111. });
  112. gulp.task('plugins-styles', function () {
  113. return gulp.src(paths.pluginsStyles)
  114. .pipe($.sass())
  115. .pipe($.autoprefixer(['last 1 version', '> 1%', 'ff >= 20', 'ie >= 9', 'opera >= 12', 'Android >= 2.2'], {cascade: true}))
  116. .pipe($.header(banner, {pkg: pkg, description: 'Trumbowyg plugin stylesheet'}))
  117. .pipe($.rename(function (path) {
  118. path.dirname += '/..';
  119. }))
  120. .pipe(gulp.dest('dist/plugins/'))
  121. .pipe($.rename({suffix: '.min'}))
  122. .pipe($.minifyCss())
  123. .pipe($.header(bannerLight, {pkg: pkg}))
  124. .pipe(gulp.dest('dist/plugins/'))
  125. .pipe($.size({title: 'Plugins styles'}));
  126. });
  127. gulp.task('plugins-sass-dist', ['plugins-styles'], function () {
  128. return gulp.src(paths.pluginsStyles)
  129. .pipe($.header(banner, {pkg: pkg, description: 'Default stylesheet for Trumbowyg editor plugin'}))
  130. .pipe(gulp.dest('dist/plugins'));
  131. });
  132. gulp.task('watch', function () {
  133. gulp.watch(paths.icons, ['icons']);
  134. gulp.watch(paths.scripts, ['scripts']);
  135. gulp.watch(paths.langs, ['langs']);
  136. gulp.watch(paths.pluginsScripts, ['plugins-scripts']);
  137. gulp.watch(paths.pluginsStyles, ['plugins-styles']);
  138. gulp.watch(paths.styles, ['styles']);
  139. gulp.watch(['dist/**', 'dist/*/**'], function (file) {
  140. $.livereload.changed(file);
  141. });
  142. $.livereload.listen();
  143. });
  144. gulp.task('build', ['scripts', 'plugins-scripts', 'langs', 'icons', 'sass-dist', 'plugins-sass-dist']);
  145. gulp.task('default', ['build', 'watch']);