Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(project): bundle into single file
Browse files Browse the repository at this point in the history
BREAKING CHANGE: all imports need to use 'aurelia-authenticaton'
  • Loading branch information
doktordirk committed Apr 8, 2016
1 parent 814a34f commit 6984c59
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
70 changes: 42 additions & 28 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var compilerOptions = require('../babel-options');
var assign = Object.assign || require('object.assign');
var through2 = require('through2');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var rename = require('gulp-rename');
var tools = require('aurelia-tools');
var del = require('del');
Expand All @@ -15,62 +14,76 @@ var vinylPaths = require('vinyl-paths');
// merged output file name. a folder of paths.packageName is temporarly created in build-dts
var jsName = paths.packageName + '.js';


// concats submodules into one file, compiles d.ts file and copies them to the dist folders
gulp.task('build-dts', function() {
var importsToAdd = []; // stores extracted imports

return gulp.src(paths.tsSource)
.pipe(tools.sortFiles())
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
if (file) {
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
}
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(jsName)) // concat all selected files to jsName (now without their imports)
.pipe(to5(assign({}, compilerOptions.dts()))); // compile to d.ts from file jsName. d.ts file is in folder paths.packageName
.pipe(concat(jsName))
.pipe(to5(assign({}, compilerOptions.dts())));
});

gulp.task('build-es2015', ['build-html-es2015'], function() {
gulp.task('copy-dts', function() {
var tdsPath = paths.packageName + '/' + paths.packageName + '.d.ts';
return gulp.src(tdsPath)
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es2015'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('remove-dts-folder', function() {
var tdsFolder = paths.packageName;
return gulp.src([tdsFolder])
.pipe(vinylPaths(del));
});

// concats modules into one file
gulp.task('concat-modules', function() {
var importsToAdd = []; // stores extracted imports

return gulp.src(paths.source)
.pipe(tools.sortFiles())
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(jsName))
.pipe(gulp.dest(paths.output));
});

gulp.task('build-es2015', ['build-html-es2015'], function() {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.es2015())))
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-commonjs', ['build-html-commonjs'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.commonjs())))
.pipe(gulp.dest(paths.output + 'commonjs'));
});

gulp.task('build-amd', ['build-html-amd'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.amd())))
.pipe(gulp.dest(paths.output + 'amd'));
});

gulp.task('build-system', ['build-html-system'], function() {
return gulp.src(paths.source)
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.system())))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('copy-dts', function() {
var tdsPath = paths.packageName + '/' + paths.packageName + '.d.ts';
return gulp.src(tdsPath)
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es2015'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('remove-dts-folder', function() {
var tdsFolder = paths.packageName;
return gulp.src([tdsFolder])
.pipe(vinylPaths(del));
});

gulp.task('build-html-es2015', function() {
return gulp.src(paths.html)
Expand All @@ -95,10 +108,11 @@ gulp.task('build-html-system', function() {
gulp.task('build', function(callback) {
return runSequence(
'clean',
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
'copy-dts',
'remove-dts-folder',
'concat-modules',
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
callback
);
});
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"gulp-concat": "^2.6.0",
"gulp-eslint": "^1.1.1",
"gulp-remark": "^1.1.5",
"gulp-insert": "^0.5.0",
"gulp-rename": "^1.2.2",
"gulp-typedoc": "^1.2.1",
"gulp-typedoc-extractor": "0.0.8",
Expand Down

0 comments on commit 6984c59

Please sign in to comment.