gulpfile.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. var gulp = require("gulp"),
  3. minifycss = require("gulp-clean-css"),
  4. uglify = require("gulp-uglify"),
  5. concat = require("gulp-concat"),
  6. header = require("gulp-header"),
  7. buffer = require("vinyl-buffer"),
  8. pkg = require("./package.json"),
  9. debug = require("gulp-debug"),
  10. eslint = require("gulp-eslint"),
  11. prettify = require("gulp-jsbeautifier"),
  12. browserify = require("browserify"),
  13. source = require("vinyl-source-stream"),
  14. rename = require("gulp-rename");
  15. var banner = ["/**",
  16. " * <%= pkg.name %> v<%= pkg.version %>",
  17. " * Copyright <%= pkg.company %>",
  18. " * @link <%= pkg.homepage %>",
  19. " * @license <%= pkg.license %>",
  20. " */",
  21. ""].join("\n");
  22. gulp.task("prettify-js", [], function() {
  23. return gulp.src("./src/js/spell-checker.js")
  24. .pipe(prettify({js: {brace_style: "collapse", indent_char: "\t", indent_size: 1, max_preserve_newlines: 3, space_before_conditional: false}}))
  25. .pipe(gulp.dest("./src/js"));
  26. });
  27. gulp.task("prettify-css", [], function() {
  28. return gulp.src("./src/css/spell-checker.css")
  29. .pipe(prettify({css: {indentChar: "\t", indentSize: 1}}))
  30. .pipe(gulp.dest("./src/css"));
  31. });
  32. gulp.task("lint", ["prettify-js"], function() {
  33. gulp.src("./src/js/**/*.js")
  34. .pipe(debug())
  35. .pipe(eslint())
  36. .pipe(eslint.format())
  37. .pipe(eslint.failAfterError());
  38. });
  39. function taskBrowserify(opts) {
  40. return browserify("./src/js/spell-checker.js", opts)
  41. .bundle();
  42. }
  43. gulp.task("browserify:debug", ["lint"], function() {
  44. return taskBrowserify({debug:true, standalone:"CodeMirrorSpellChecker"})
  45. .pipe(source("spell-checker.debug.js"))
  46. .pipe(buffer())
  47. .pipe(header(banner, {pkg: pkg}))
  48. .pipe(gulp.dest("./debug/"));
  49. });
  50. gulp.task("browserify", ["lint"], function() {
  51. return taskBrowserify({standalone:"CodeMirrorSpellChecker"})
  52. .pipe(source("spell-checker.js"))
  53. .pipe(buffer())
  54. .pipe(header(banner, {pkg: pkg}))
  55. .pipe(gulp.dest("./debug/"));
  56. });
  57. gulp.task("scripts", ["browserify:debug", "browserify", "lint"], function() {
  58. var js_files = ["./debug/spell-checker.js"];
  59. return gulp.src(js_files)
  60. .pipe(concat("spell-checker.min.js"))
  61. .pipe(uglify())
  62. .pipe(buffer())
  63. .pipe(header(banner, {pkg: pkg}))
  64. .pipe(gulp.dest("./dist/"));
  65. });
  66. gulp.task("styles", ["prettify-css"], function() {
  67. var css_files = [
  68. "./src/css/*.css",
  69. ];
  70. return gulp.src(css_files)
  71. .pipe(concat("spell-checker.css"))
  72. .pipe(buffer())
  73. .pipe(header(banner, {pkg: pkg}))
  74. .pipe(gulp.dest("./debug/"))
  75. .pipe(minifycss())
  76. .pipe(rename("spell-checker.min.css"))
  77. .pipe(buffer())
  78. .pipe(header(banner, {pkg: pkg}))
  79. .pipe(gulp.dest("./dist/"));
  80. });
  81. gulp.task("default", ["scripts", "styles"]);