Ohm-Management - Projektarbeit B-ME
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.

gulpfile.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. var gulp = require("gulp");
  2. var istanbul = require("gulp-istanbul");
  3. var mocha = require("gulp-mocha");
  4. var plumber = require("gulp-plumber");
  5. var jshint = require("gulp-jshint");
  6. var uglify = require("gulp-uglify");
  7. var jscs = require("gulp-jscs");
  8. var coveralls = require("gulp-coveralls");
  9. var rename = require("gulp-rename");
  10. var options = require("yargs").argv;
  11. var pkg = require("./package");
  12. /**
  13. */
  14. var paths = {
  15. testFiles : ["test/**/*-test.js"],
  16. appFiles : ["sift.js"],
  17. allFiles : ["test/**/*-test.js", "sift.js"]
  18. };
  19. /**
  20. */
  21. var mochaOptions = {
  22. bail : options.bail !== 'false',
  23. reporter : options.reporter || 'dot',
  24. grep : options.grep || options.only,
  25. timeout : 500
  26. }
  27. /**
  28. */
  29. gulp.task("test-coverage", function (complete) {
  30. gulp.
  31. src(paths.appFiles).
  32. pipe(istanbul()).
  33. pipe(istanbul.hookRequire()).
  34. on("finish", function () {
  35. gulp.
  36. src(paths.testFiles).
  37. pipe(plumber()).
  38. pipe(mocha(mochaOptions)).
  39. pipe(istanbul.writeReports({
  40. reporters: ["text","text-summary", "lcov"]
  41. })).
  42. on("end", complete);
  43. });
  44. });
  45. /**
  46. */
  47. gulp.task("test-coveralls", ["test-coverage"], function () {
  48. return gulp.
  49. src("coverage/**/lcov.info").
  50. pipe(coveralls());
  51. });
  52. /**
  53. */
  54. gulp.task("minify", function() {
  55. return gulp.
  56. src("./" + pkg.name + ".js").
  57. pipe(uglify()).
  58. pipe(rename(function(path) {
  59. path.basename += ".min";
  60. })).
  61. pipe(gulp.dest("./"));
  62. });
  63. /**
  64. */
  65. gulp.task("lint", function() {
  66. return gulp.run(["jshint", "jscs"]);
  67. });
  68. /**
  69. */
  70. gulp.task("jscs", function() {
  71. return gulp.
  72. src(paths.allFiles).
  73. pipe(jscs({
  74. "preset": "google",
  75. "requireParenthesesAroundIIFE": true,
  76. "maximumLineLength": 200,
  77. "validateLineBreaks": "LF",
  78. "validateIndentation": 2,
  79. "validateQuoteMarks": "\"",
  80. "disallowKeywords": ["with"],
  81. "disallowSpacesInsideObjectBrackets": null,
  82. "disallowImplicitTypeConversion": ["string"],
  83. "requireCurlyBraces": [],
  84. "safeContextKeyword": "self"
  85. }));
  86. });
  87. /**
  88. */
  89. gulp.task("jshint", function() {
  90. return gulp.
  91. src(paths.allFiles).
  92. pipe(jshint({
  93. es3: true,
  94. evil: true
  95. })).
  96. pipe(jshint.reporter('default'));
  97. });
  98. /**
  99. */
  100. gulp.task("test", function (complete) {
  101. gulp.
  102. src(paths.testFiles, { read: false }).
  103. pipe(plumber()).
  104. pipe(mocha(mochaOptions)).
  105. on("error", complete).
  106. on("end", complete);
  107. });
  108. var iofwatch = process.argv.indexOf("watch");
  109. /**
  110. * runs previous tasks (1 or more)
  111. */
  112. gulp.task("watch", function () {
  113. gulp.watch(paths.allFiles, process.argv.slice(2, iofwatch));
  114. });
  115. /**
  116. */
  117. gulp.task("default", function () {
  118. return gulp.run("test-coverage");
  119. });
  120. /**
  121. */
  122. gulp.doneCallback = function (err) {
  123. // a bit hacky, but fixes issue with testing where process
  124. // doesn't exist process. Also fixes case where timeout / interval are set (CC)
  125. if (!~iofwatch) process.exit(err ? 1 : 0);
  126. };