Skip to content

Commit

Permalink
chore(build): added systemjs bundles, fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Jan 25, 2016
1 parent 63f4618 commit 93d0173
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"yoda": [2, "never"],

// Strict Mode
"strict": [2, "global"],
"strict": [0],

// Variables
"no-catch-shadow": 2,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ npm-debug.log
# ignore build and dist for now
/build
/dist
/bundles

# ignore incline compiling
/demo/**/*.js
Expand Down
7 changes: 4 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ gulp.paths = {
tssrc: [
'**/*.ts',
'!node_modules/**/*',
'!dist/**/*',
'!bundles/**/*',
'!typings/**/*',
'!**/*.{ts,coffee}.js'],
jssrc: [
'*.js',
'gulp-tasks/*.js',
'!bundles/*.js',
'!ng2-bootstrap.js',
'!node_modules',
'!node_modules/**/*',
'!**/*.{ts,coffee}.js']
};

require('require-dir')('./gulp-tasks');

var clean = require('gulp-clean');
gulp.task('clean', function () {
return gulp.src('dist', {read: false})
return gulp.src('bundles', {read: false})
.pipe(clean());
});

Expand Down
95 changes: 95 additions & 0 deletions make.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node
/*eslint no-console: 0, no-sync: 0*/
'use strict';

// System.js bundler
// simple and yet reusable system.js bundler
// bundles, minifies and gzips

const fs = require('fs');
const del = require('del');
const path = require('path');
const zlib = require('zlib');
const async = require('async');
const Builder = require('systemjs-builder');

const pkg = require('./package.json');
const name = pkg.name;
const targetFolder = 'bundles';

async.waterfall([
cleanBundlesFolder,
getSystemJsBundleConfig,
buildSystemJs({}),
getSystemJsBundleConfig,
buildSystemJs({minify: true, sourceMaps: true}),
gzipSystemJsBundle
], function (err) {
if (err) {
throw err;
}
});

function getSystemJsBundleConfig(cb) {
let config = {
baseURL: '..',
transpiler: 'typescript',
typescriptOptions: {
module: 'cjs'
},
map: {
typescript: path.resolve('node_modules/typescript/lib/typescript.js'),
angular2: path.resolve('node_modules/angular2'),
rxjs: path.resolve('node_modules/rxjs')
},
paths: {
'*': '*.js'
}
};

config.meta = ['angular2', 'rxjs'].reduce((memo, currentValue) => {
memo[`${name}/node_modules/${currentValue}/*`] = {build: false};
return memo;
}, {});
return cb(null, config);
}

function cleanBundlesFolder(cb) {
return del(targetFolder)
.then((paths) => {
console.log('Deleted files and folders:\n', paths.join('\n'));
cb();
});
}

function buildSystemJs(options) {
return function (config, cb) {
let fileName = name + (options && options.minify ? '.min' : '') + '.js';
let dest = path.resolve(__dirname, targetFolder, fileName);
console.log('Bundling system.js file:', fileName, options);

let builder = new Builder();
builder.config(config);
return builder
.bundle([name, name].join('/'), dest, options)
.then(()=>cb()).catch(cb);
};
}

function gzipSystemJsBundle(cb) {
var files = fs.readdirSync(path.resolve(targetFolder))
.map(file => path.resolve(targetFolder, file))
.filter(file => fs.statSync(file).isFile())
.filter(file => path.extname(file) !== 'gz');
return async.eachLimit(files, 1, (file, gzipcb)=> {
process.nextTick(()=> {
console.log('Gzipping ', file);
const gzip = zlib.createGzip({level: 9});
let inp = fs.createReadStream(file);
let out = fs.createWriteStream(file + '.gz');
inp.on('end', ()=>gzipcb());
inp.on('error', err => gzipcb(err));
return inp.pipe(gzip).pipe(out);
});
}, cb);
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.1-beta.1",
"description": "angular2 bootstrap components",
"scripts": {
"prepublish": "gulp clean && tsc",
"deploy": "NODE_ENV=production webpack -p --progress --color --optimize-minimize --optimize-dedupe --optimize-occurence-order",
"dev": "webpack-dev-server --hot --inline --colors --display-error-details --display-cached",
"prepublish": "gulp clean && ./node_modules/.bin/tsc && ./make.js",
"build:prod": "NODE_ENV=production webpack -p --progress --color --optimize-minimize --optimize-dedupe --optimize-occurence-order",
"build:dev": "webpack-dev-server --hot --inline --colors --display-error-details --display-cached",
"start": "npm run dev",
"test": "gulp lint"
},
Expand All @@ -30,10 +30,12 @@
"dependencies": {},
"devDependencies": {
"angular2": "2.0.0-beta.1",
"async": "1.5.2",
"balanced-match": "0.3.0",
"bootstrap": "3.3.6",
"clean-webpack-plugin": "0.1.6",
"compression-webpack-plugin": "0.2.0",
"compression-webpack-plugin": "0.3.0",
"del": "2.2.0",
"es6-shim": "0.33.3",
"eslint": "1.10.3",
"exports-loader": "0.6.2",
Expand All @@ -42,7 +44,6 @@
"gulp-clean": "0.3.1",
"gulp-eslint": "1.1.1",
"gulp-size": "2.0.0",
"gulp-tsc": "1.1.4",
"gulp-tslint": "4.3.1",
"html-loader": "0.4.0",
"markdown-loader": "0.1.7",
Expand All @@ -55,10 +56,11 @@
"reflect-metadata": "0.1.2",
"require-dir": "0.3.0",
"rxjs": "5.0.0-beta.0",
"systemjs-builder": "0.15.4",
"ts-loader": "0.8.0",
"tslint": "3.2.2",
"tslint": "3.3.0",
"typescript": "1.7.5",
"webpack": "1.12.11",
"webpack": "1.12.12",
"webpack-dev-server": "1.14.1",
"zone.js": "0.5.10"
}
Expand Down

0 comments on commit 93d0173

Please sign in to comment.