Commit f5d5b3fe authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] add typescript support

parent 5794fc02
......@@ -21,11 +21,11 @@ function setUpCompiler() {
switch (config.js.compiler) {
case 'es6':
compiler = new require('./js-compilers/es6')();
break;
plugins.util.log(plugins.util.colors.blue('Using ES6 compiler'));
return new require('./js-compilers/es6')();
case 'typescript':
compiler = new require('./js-compilers/typescript')();
break;
plugins.util.log(plugins.util.colors.blue('Using Typescript compiler'));
return new require('./js-compilers/typescript')();
default:
plugins.util.log(plugins.util.colors.red('The specified JavaScript compiler "' + config.js.compiler + '" could not be found'));
done();
......@@ -40,14 +40,14 @@ gulp.task('js:qa', function() {
});
gulp.task('js:compile', function(done) {
setUpCompiler(done);
compiler = setUpCompiler(done);
glob(`${settings.getPath()}/${config.directories.javascriptSrc}/*${compiler.getFileExtension()}`, function(err, files) {
return compiler.compile(files, done, argv.production);
});
});
gulp.task('js:compileAndSync', function(done) {
setUpCompiler(done);
compiler = setUpCompiler(done);
glob(`${settings.getPath()}/${config.directories.javascriptSrc}/*${compiler.getFileExtension()}`, function(err, files) {
return compiler.compile(files, done, argv.production)
.pipe(plugins.browserSync.stream());
......@@ -55,3 +55,5 @@ gulp.task('js:compileAndSync', function(done) {
});
gulp.task('js', gulp.series('js:qa', 'js:compile'));
module.exports.setUpCompiler = setUpCompiler;
......@@ -4,12 +4,62 @@ module.exports = function() {
var typescript = {},
gulp = require('gulp'),
settings = require('../settings'),
config = settings.getConfig(),
eventStream = require('event-stream'),
rename = require('gulp-rename'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
tsify = require('tsify'),
plugins = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'browser-sync']
pattern: ['gulp-*', 'gulp.*', 'browserify', 'browser-sync']
});
typescript.compile = function(files, done, _productionMode) {
var tasks = files.map(function(file) {
var browserify = plugins.browserify({
entries: [file],
paths: config.js.libraryPaths,
debug: true
});
if (_productionMode) {
return browserify
.plugin(tsify, {noImplicitAny: true})
.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(plugins.uglify())
.on('error', console.log)
.pipe(rename({
extname: '.bundled.min.js',
dirname: ''
}))
.pipe(plugins.checkFilesize({
enableGzip: true
}))
.pipe(gulp.dest(settings.getPath() + '/' + config.directories.javascriptDest));
} else {
return browserify
.plugin(tsify, {noImplicitAny: true})
.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(plugins.sourcemaps.init({loadMaps: true}))
.pipe(plugins.uglify())
.on('error', console.log)
.pipe(rename({
extname: '.bundled.min.js',
dirname: ''
}))
.pipe(plugins.checkFilesize({
enableGzip: true
}))
.pipe(plugins.sourcemaps.write('../SourceMaps'))
.pipe(gulp.dest(settings.getPath() + '/' + config.directories.javascriptDest));
}
});
return eventStream.merge(tasks).on('end', done);
};
typescript.getFileExtension = function() {
......
......@@ -15,16 +15,18 @@ var gulp = require('gulp'),
gulp.registry(hub);
gulp.task('watch', function() {
let jsFileExtension = require('./gulp/javascript').setUpCompiler().getFileExtension();
for (var extension in config.extensions) {
gulp.watch([
config.directories.basePath + config.extensions[extension] + '/' + config.directories.sass + '/**/*.scss',
`${config.directories.basePath}${config.extensions[extension]}/${config.directories.sass}/**/*.scss`,
'!**/_sprite.scss',
'!**/_svg.scss',
'!**/*scsslint_tmp*.scss'
], gulp.series('css:compileAndSync')).on('change', setCurrentExtensionName);
gulp.watch([
config.directories.basePath + config.extensions[extension] + '/' + config.directories.javascriptSrc + '/**/*.js',
`${config.directories.basePath}${config.extensions[extension]}/${config.directories.javascriptSrc}/**/*${jsFileExtension}`,
'!**/*.min.js'
], gulp.series('js:qa', 'js:compileAndSync')).on('change', setCurrentExtensionName);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment