|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -let build = require('./lib/index'); |
4 | | - |
5 | | -// Use the build tools to build the build tools. |
6 | | -build.initializeTasks( |
7 | | - require('gulp'), |
8 | | - { |
9 | | - build: { |
10 | | - paths: { |
11 | | - lessMatch: null, |
12 | | - staticsMatch: null, |
13 | | - htmlMatch: null |
14 | | - }, |
15 | | - isLintingEnabled: true |
| 3 | +let gulp = require('gulp'); |
| 4 | +let config = { |
| 5 | + paths: { |
| 6 | + libFolder: 'lib', |
| 7 | + sourceMatch: [ |
| 8 | + 'src/**/*.ts', |
| 9 | + 'typings/tsd.d.ts' |
| 10 | + ], |
| 11 | + testMatch: [ |
| 12 | + 'lib/**/*.test.js' |
| 13 | + ] |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +gulp.task('build', () => { |
| 18 | + let ts = require('gulp-typescript'); |
| 19 | + let plumber = require('gulp-plumber'); |
| 20 | + let merge = require('merge2'); |
| 21 | + let lint = require('gulp-tslint'); |
| 22 | + let tsConfig = require('./tsconfig.json'); |
| 23 | + let paths = config.paths; |
| 24 | + let errorCount = 0; |
| 25 | + let allStreams = []; |
| 26 | + let tsProject = ts.createProject(tsConfig.compilerOptions); |
| 27 | + let gutil = require('gulp-util'); |
| 28 | + let chalk = require('chalk'); |
| 29 | + let sourceStream = gulp.src(paths.sourceMatch); |
| 30 | + |
| 31 | + sourceStream |
| 32 | + .pipe(lint({ |
| 33 | + configuration: require('./tslint.json') |
| 34 | + })) |
| 35 | + .pipe(lint.report('full', { |
| 36 | + emitError: false |
| 37 | + })); |
| 38 | + |
| 39 | + let tsResult = sourceStream |
| 40 | + .pipe(plumber({ |
| 41 | + errorHandler: function(error) { |
| 42 | + // console.log(error); |
| 43 | + errorCount++; |
| 44 | + } |
| 45 | + })) |
| 46 | + .pipe(ts(tsProject, undefined, ts.reporter.longReporter())); |
| 47 | + |
| 48 | + allStreams.push(tsResult.js.pipe(gulp.dest(paths.libFolder))); |
| 49 | + allStreams.push(tsResult.dts.pipe(gulp.dest(paths.libFolder))); |
| 50 | + |
| 51 | + let mergedStream = merge(allStreams); |
| 52 | + |
| 53 | + mergedStream.on('queueDrain', function() { |
| 54 | + if (errorCount) { |
| 55 | +// throw new gutil.PluginError('msg', `[gulp-typescript] TypeScript error(s): ${ chalk.red(errorCount) }`, { showStack: false }); |
16 | 56 | } |
17 | 57 | }); |
18 | 58 |
|
| 59 | + return mergedStream; |
| 60 | +}); |
| 61 | + |
| 62 | +gulp.task('test', ['build'], () => { |
| 63 | + let mocha = require('gulp-mocha'); |
| 64 | + |
| 65 | + return gulp.src(config.paths.testMatch, { read: false }) |
| 66 | + .pipe(mocha()); |
| 67 | +}); |
| 68 | + |
| 69 | +gulp.task('default', ['build']); |
0 commit comments