Permalink
Browse files

feat(project): bundle into single file

BREAKING CHANGE: all imports but components need to use 'aurelia-orm'
  • Loading branch information...
doktordirk committed Apr 3, 2016
1 parent a081f36 commit 915814436235a27270249006309654b019a4904f
Showing with 51 additions and 27 deletions.
  1. +4 −3 build/dts-builder-options.js
  2. +1 −0 build/paths.js
  3. +46 −24 build/tasks/build.js
@@ -1,3 +1,4 @@
module.exports = {
extraImports: ['import {ValidationRule} from "aurelia-validation"']
};
// external imports to add to the d.ts file
module.exports = {
extraImports: ["import {ValidationRule} from 'aurelia-validation'"]
};
@@ -14,6 +14,7 @@ module.exports = {
appRoot + '**/*.js', // list files to parse for d.ts
'!' + appRoot + entryFileName // exclude entry file
],
components: 'component/*.js', // relative to root, components can not that easily be bundled into a single file (due to naming conventions)
html: appRoot + '**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
@@ -16,13 +16,13 @@ var dtsOptions = require('../dts-builder-options.js');
// 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() {
return gulp.src(paths.tsSource)
//.pipe(tools.sortFiles()) // sort fails with subdirectories!
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
var dummyImports = [];
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), dummyImports));
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
var extractedImports = [];
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), extractedImports));
this.push(file);
return callback();
}))
@@ -33,45 +33,66 @@ gulp.task('build-dts', function() {
.pipe(to5(assign({}, compilerOptions.dts()))); // compile to d.ts from file jsName. d.ts file is in folder paths.packageName
});
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('copy-components', function() {
return gulp.src(paths.root + paths.components, {base: paths.root})
.pipe(gulp.dest(paths.output));
});
// concats modules into one file
gulp.task('concat-modules', ['copy-components'], function() {
var importsToAdd = []; // stores extracted imports
return gulp.src([paths.source, '!' + paths.root + paths.components])
//.pipe(tools.sortFiles()) // sort fails with subdirectories!
.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.source)
return gulp.src([paths.output + jsName, paths.output + paths.components], {base: paths.output})
.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, paths.output + paths.components], {base: paths.output})
.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, paths.output + paths.components], {base: paths.output})
.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, paths.output + paths.components], {base: paths.output})
.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)
@@ -96,10 +117,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
);
});

0 comments on commit 9158144

Please sign in to comment.