diff --git a/.eslintrc b/.eslintrc index 1025ddc1fc..186c8e9115 100644 --- a/.eslintrc +++ b/.eslintrc @@ -103,7 +103,7 @@ "yoda": [2, "never"], // Strict Mode - "strict": [2, "global"], + "strict": [0], // Variables "no-catch-shadow": 2, diff --git a/.gitignore b/.gitignore index aec866cfeb..69ae1278d9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ npm-debug.log # ignore build and dist for now /build /dist +/bundles # ignore incline compiling /demo/**/*.js diff --git a/gulpfile.js b/gulpfile.js index 1832603717..be227d2198 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,14 +4,15 @@ 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'] }; @@ -19,7 +20,7 @@ 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()); }); diff --git a/make.js b/make.js new file mode 100755 index 0000000000..0672902779 --- /dev/null +++ b/make.js @@ -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); +} diff --git a/package.json b/package.json index 7ea8b5a4f8..bda34714a5 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", @@ -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", @@ -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" }