Last active
February 12, 2016 20:19
-
-
Save atsu85/84c776a874f1c8e4fd84 to your computer and use it in GitHub Desktop.
example, how to create separate gulp tasks for compilling main or e2e-test typescript sources to javascript
This file contains 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
// contains just a gulp task that compiles main application TypeScript code to Javascript | |
var paths = require('../paths'); | |
var typeScript = require('../typeScript.js'); | |
gulp.task('build-typescript', function() { | |
// exclude test typescript sources from paths defined in tsconfig.json | |
return typeScript.builder({}, paths.output, [], paths.testTsSourceFilesGlob); | |
}); |
This file contains 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
// contains just a gulp task that compiles e2e-test TypeScript code to Javascript | |
var paths = require('../paths'); | |
var typeScript = require('../typeScript.js'); | |
gulp.task('build-e2e', function() { | |
const extraIncludeTsSourceFilesGlobs = [paths.e2eSpecsSrc]; | |
const excludeTsSourceFilesGlobs = [ | |
paths.source, // e2e tests don't use application main sources | |
paths.unitTestsSrc, // e2e tests don't use unit test sources | |
"./typings/jquery/jquery.d.ts", // <-------------- excluding this file, because it declares var $ just like aurelia-protractor, that is used for testing | |
]; | |
const tsconfigJsonSettingsOverride = { | |
module: 'commonjs' | |
}; | |
return typeScript.builder(tsconfigJsonSettingsOverride, paths.e2eSpecsDist, extraIncludeTsSourceFilesGlobs, excludeTsSourceFilesGlobs); | |
}); |
This file contains 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
// contains constants for directories and file globs | |
var appRoot = 'src/'; | |
var outputRoot = 'dist/'; | |
module.exports = { | |
source: appRoot + '**/*.ts', | |
output: outputRoot, | |
e2eSpecsSrc: 'test/e2e/src/*.ts', | |
unitTestsSrc: 'test/unit/**/*.ts', | |
testTsSourceFilesGlob: [ | |
"./test/**/*.ts", | |
"./typings/angular-protractor/angular-protractor.d.ts", | |
"./typings/aurelia-protractor.d.ts", | |
] | |
} |
This file contains 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
Show hidden characters
{ | |
"version": "1.7.3", | |
"compileOnSave": false, | |
"compilerOptions": { | |
"rootDir": "src/", | |
"sourceMap": true, | |
"target": "es5", | |
"module": "amd", | |
"moduleResolution": "classic", | |
"declaration": false, | |
"noImplicitAny": false, | |
"noResolve": true, | |
"removeComments": true, | |
"noLib": false, | |
"noEmitOnError": true, | |
"newLine": "LF", | |
"emitDecoratorMetadata": true, | |
"experimentalDecorators": true | |
}, | |
"filesGlob": [ | |
"./src/**/*.ts", | |
"./test/**/*.ts", | |
"./typings/**/*.d.ts", | |
"./jspm_packages/**/*.d.ts" | |
], | |
"exclude": [ | |
"node_modules" | |
], | |
"atom": { | |
"rewriteTsconfig": false | |
} | |
} |
This file contains 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
// this file contains helper functions to be used by Gulp tasks that compile TypeScript to javascript | |
const gulp = require('gulp'); | |
const plumber = require('gulp-plumber'); | |
const sourcemaps = require('gulp-sourcemaps'); | |
const extend = require('extend'); | |
const typescript = require('gulp-typescript'); | |
const tsc = require('typescript'); | |
const tsconfig = require('../tsconfig.json'); | |
function createProject(tsconfigJsonSettingsOverride) { | |
const gulpTsDefaultSettings = { | |
typescript: tsc | |
}; | |
const tsconfigSettings = extend(false, {}, gulpTsDefaultSettings, tsconfigJsonSettingsOverride); | |
return typescript.createProject('./tsconfig.json', tsconfigSettings); | |
} | |
function builder(tsconfigJsonSettingsOverride, outputPath, extraIncludeTsSourceFilesGlobs, excludeTsSourceFilesGlobs) { | |
const tsProject = createProject(tsconfigJsonSettingsOverride); | |
const mainTsSourceFilesGlob = clone(tsconfig.filesGlob).concat(extraIncludeTsSourceFilesGlobs); | |
excludeTsSourceFilesGlobs.forEach((globElem, index, array) => { | |
mainTsSourceFilesGlob.push('!' + globElem); | |
}); | |
return gulp.src(tsconfig.filesGlob.concat(mainTsSourceFilesGlob)) | |
.pipe(plumber()) | |
.pipe(sourcemaps.init({loadMaps: true})) | |
.pipe(typescript(tsProject)) | |
.pipe(sourcemaps.write({includeContent: true})) | |
.pipe(gulp.dest(outputPath)); | |
} | |
function clone(o) { | |
return JSON.parse(JSON.stringify(o)); | |
} | |
module.exports = { | |
"createProject": createProject, | |
"builder": builder, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment