|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var gulp = require('gulp'); |
| 4 | +var clangFormat = require('clang-format'); |
| 5 | +var gulpFormat = require('gulp-clang-format'); |
| 6 | +var runSequence = require('run-sequence'); |
| 7 | +var spawn = require('child_process').spawn; |
| 8 | + |
| 9 | +var runSpawn = function(done, task, opt_arg) { |
| 10 | + opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : []; |
| 11 | + var child = spawn(task, opt_arg, {stdio: 'inherit'}); |
| 12 | + var running = false; |
| 13 | + child.on('close', function() { |
| 14 | + if (!running) { |
| 15 | + running = true; |
| 16 | + done(); |
| 17 | + } |
| 18 | + }); |
| 19 | + child.on('error', function() { |
| 20 | + if (!running) { |
| 21 | + console.error('gulp encountered a child error'); |
| 22 | + running = true; |
| 23 | + done(); |
| 24 | + } |
| 25 | + }); |
| 26 | +}; |
| 27 | + |
| 28 | +gulp.task('copy', function() { |
| 29 | + return gulp.src(['config.json', 'package.json']) |
| 30 | + .pipe(gulp.dest('built/')); |
| 31 | +}); |
| 32 | + |
| 33 | +gulp.task('clang', function() { |
| 34 | + return gulp.src(['src/**/*.ts']) |
| 35 | + .pipe(gulpFormat.checkFormat('file', clangFormat)) |
| 36 | + .on('warning', function(e) { |
| 37 | + console.log(e); |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
| 41 | +gulp.task('typings', function(done) { |
| 42 | + runSpawn(done, 'node', ['node_modules/typings/dist/bin.js', 'install']); |
| 43 | +}); |
| 44 | + |
| 45 | +gulp.task('tsc', function(done) { |
| 46 | + runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']); |
| 47 | +}); |
| 48 | + |
| 49 | +gulp.task('prepublish', function(done) { |
| 50 | + runSequence(['typings', 'clang'], 'tsc', 'copy', done); |
| 51 | +}); |
| 52 | + |
| 53 | +gulp.task('default',['prepublish']); |
| 54 | +gulp.task('build',['prepublish']); |
| 55 | + |
| 56 | +gulp.task('test', ['build'], function(done) { |
| 57 | + var opt_arg = []; |
| 58 | + opt_arg.push('node_modules/jasmine/bin/jasmine.js'); |
| 59 | + runSpawn(done, 'node', opt_arg); |
| 60 | +}); |
0 commit comments