gulpfile.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/simplemde.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/simplemde.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/simplemde.js", opts)
  41. .bundle();
  42. }
  43. gulp.task("browserify:debug", ["lint"], function() {
  44. return taskBrowserify({debug:true, standalone:"SimpleMDE"})
  45. .pipe(source("simplemde.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:"SimpleMDE"})
  52. .pipe(source("simplemde.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/simplemde.js"];
  59. return gulp.src(js_files)
  60. .pipe(concat("simplemde.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. "./node_modules/codemirror/lib/codemirror.css",
  69. "./src/css/*.css",
  70. "./node_modules/codemirror-spell-checker/src/css/spell-checker.css"
  71. ];
  72. return gulp.src(css_files)
  73. .pipe(concat("simplemde.css"))
  74. .pipe(buffer())
  75. .pipe(header(banner, {pkg: pkg}))
  76. .pipe(gulp.dest("./debug/"))
  77. .pipe(minifycss())
  78. .pipe(rename("simplemde.min.css"))
  79. .pipe(buffer())
  80. .pipe(header(banner, {pkg: pkg}))
  81. .pipe(gulp.dest("./dist/"));
  82. });
  83. gulp.task("default", ["scripts", "styles"]);