Last active
October 31, 2015 13:27
-
-
Save andrewconnell/41743b62f4b83252c144 to your computer and use it in GitHub Desktop.
Example gulp task... this compiles all TypeScript to JavaScript in a project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| import {BaseGulpTask} from '../BaseGulpTask'; | |
| import * as gulp from 'gulp'; | |
| import {Utils} from '../utils'; | |
| import * as yargs from 'yargs'; | |
| let $: any = require('gulp-load-plugins')({ lazy: true }); | |
| /** | |
| * Builds all TypeScript as JavaScript as the gulp task 'build-ts'. | |
| * | |
| * @class | |
| */ | |
| export class GulpTask extends BaseGulpTask { | |
| /** | |
| * @property {string} description - Help description for the task. | |
| */ | |
| public static description: string = 'Builds all TypeScript as JavaScript'; | |
| /** | |
| * @property {string[]} aliases - Different options to run the task. | |
| */ | |
| public static aliases: string[] = ['b']; | |
| /** | |
| * @property {Object} options - Any command line flags that can be passed to the task. | |
| */ | |
| public static options: any = { | |
| 'verbose': 'Output all TypeScript files being built' | |
| }; | |
| /** | |
| * @property {commandLineArgs} args - Command line arguments; | |
| */ | |
| private _args: ICommandLineArgs = yargs.argv; | |
| /** @constructor */ | |
| constructor() { | |
| super(); | |
| Utils.log('Transpiling app TypeScript files to JavaScript'); | |
| // use the TypeScript project config file for all settings | |
| let tsProject: any = $.typescript.createProject('tsconfig.json'); | |
| // compile all TypeScript files, including sourcemaps inline in the generated JavaScript | |
| let result: any = tsProject.src() | |
| .pipe($.if(this._args.verbose, $.print())) | |
| .pipe($.sourcemaps.init()) | |
| .pipe($.typescript(tsProject)); | |
| return result.js | |
| .pipe($.sourcemaps.write()) | |
| .pipe(gulp.dest('')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment