gulpfile.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var runSequence = require('run-sequence');
  4. var spawn = require('child_process').spawn;
  5. const format = require('gulp-clang-format');
  6. const clangFormat = require('clang-format');
  7. var runSpawn = function(done, task, opt_arg) {
  8. opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
  9. var child = spawn(task, opt_arg, {stdio: 'inherit'});
  10. var running = false;
  11. child.on('close', function() {
  12. if (!running) {
  13. running = true;
  14. done();
  15. }
  16. });
  17. child.on('error', function() {
  18. if (!running) {
  19. console.error('gulp encountered a child error');
  20. running = true;
  21. done();
  22. }
  23. });
  24. };
  25. gulp.task('copy', function() {
  26. return gulp.src(['**/*.apk', 'package.json'])
  27. .pipe(gulp.dest('built/'));
  28. });
  29. gulp.task('format:enforce', () => {
  30. return gulp.src(['lib/**/*.ts']).pipe(
  31. format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
  32. });
  33. gulp.task('format', () => {
  34. return gulp.src(['lib/**/*.ts'], { base: '.' }).pipe(
  35. format.format('file', clangFormat)).pipe(gulp.dest('.'));
  36. });
  37. gulp.task('tsc', function(done) {
  38. runSpawn(done, process.execPath, ['node_modules/typescript/bin/tsc']);
  39. });
  40. gulp.task('prepublish', function(done) {
  41. runSequence('format', 'tsc', 'copy', done);
  42. });
  43. gulp.task('default',['prepublish']);
  44. gulp.task('build',['prepublish']);
  45. gulp.task('test', ['build'], function(done) {
  46. var opt_arg = [];
  47. opt_arg.push('node_modules/jasmine/bin/jasmine.js');
  48. runSpawn(done, process.execPath, opt_arg);
  49. });