Skip to content

Commit

Permalink
feat(*): provide an UMD bundle
Browse files Browse the repository at this point in the history
From now on angular2-google-maps ships an UMD bundle named
`core.umd.js`.

BREAKING CHANGES

The SystemJS based bundle located in the `bundles/` dir is gone!
Please use the new UMD bundle.

SystemJS example:

```js
SystemJS.config({
	packages: {
		'angular2-google-maps/core': { main:  'core.umd.js', defaultExtension: 'js' }
	}
})
```
  • Loading branch information
sebholstein committed Jun 5, 2016
1 parent 00f4f2d commit 531110d
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "airbnb",
"extends": "airbnb-base",
"rules": {
"id-length": 0
}
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ install:
- npm install

script:
- node_modules/.bin/gulp build
- node_modules/.bin/gulp test
- npm run ci

after_success:
- ./scripts/npm-publish.sh
5 changes: 2 additions & 3 deletions assets/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ The sources for this package are in the [angular2-google-maps](https://github.co
This package contains different sources for different users:

1. The files located in the root dir are ES5 compatible files that can be consumed using CommonJS.
2. The files under `/es6` are ES6 compatible files that can be transpiled to E5 using any transpiler.
2. The files under `/esm` are ES6 compatible files that can be transpiled to E5 using any transpiler.
3. The files under `/ts` are the TypeScript source files.
4. The `/bundles` directory contains the following files:
* `angular2-google-maps.js` and `angular2-google-maps.min.js` are bundles that can be consumed using SystemJS.
4. Files with the name pattern *.umd.js are UMD bundled modules for fast load times during development.

License: See LICENSE file in this folder.
54 changes: 8 additions & 46 deletions gulp/bundle.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,17 @@
const gulp = require('gulp');
const config = require('./config');
const path = require('path');
const $ = require('gulp-load-plugins')();
const Builder = require('systemjs-builder');

const bundleConfig = {
baseURL: config.PATHS.dist.cjs,
defaultJSExtensions: true,
paths: {
'angular2-google-maps/*': '*',
'@angular/*': './node_modules/@angular/*',
'rxjs/*': './node_modules/rxjs/*',
},
packages: {
'@angular/core': { main: 'index.js', defaultExtension: 'js' },
'@angular/common': { main: 'index.js', defaultExtension: 'js' },
'@angular/compiler': { main: 'index.js', defaultExtension: 'js' },
},
map: {
'@angular': '@angular',
},
};
const tsCmd = `./node_modules/.bin/tsc --out ${config.PATHS.dist.cjs}core.umd.js ` +
`--target es5 --allowJs ${config.PATHS.tmp}core.umd.js`;

function bundle(moduleName, moduleBundleName, minify, done) {
const outputConfig = {
sourceMaps: true,
minify: minify,
};
const builder = new Builder();
builder.config(bundleConfig);
const outputFile = path.join(config.PATHS.dist.bundles, moduleBundleName + (minify ? '.min' : '') + '.js');
// todo: newest systemjs-builder version requires to explicitly exclude .d.ts files - probably a systemjs-builder bug.
const bundlePromise = builder.bundle(moduleName + ' - @angular/core/*.ts - @angular/core/*.js - rxjs/*.ts - rxjs/*.js', outputFile, outputConfig);
gulp.task('rollup:umd', ['scripts:esm'],
$.shell.task('./node_modules/.bin/rollup -c rollup.config.js'));

if (!minify) {
bundlePromise.then(() => {
gulp.src(outputFile)
.pipe($.connect.reload());
});
}
return bundlePromise.then(() => {
done();
});
}
gulp.task('bundle:umd', ['rollup:umd'], $.shell.task(tsCmd, { ignoreErrors: true }));

gulp.task('bundle:cjs', ['scripts:cjs'], function bundleCjs(done) {
bundle('angular2-google-maps/core', 'angular2-google-maps', false, done);
gulp.task('bundle:umd:min', ['bundle:umd'], (done) => {
done();
});

gulp.task('bundle:cjs:min', ['scripts:cjs'], function bundleCjsMin(done) {
bundle('angular2-google-maps/core', 'angular2-google-maps', true, done);
});

gulp.task('bundle', ['bundle:cjs', 'bundle:cjs:min']);
gulp.task('bundle', ['bundle:umd', 'bundle:umd:min']);
10 changes: 4 additions & 6 deletions gulp/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ const gulp = require('gulp');
const del = require('del');
const config = require('./config');

gulp.task('clean:dist', function cleanDist(done) {
return del([config.PATHS.dist.base], done);
});
gulp.task('clean:dist', (done) => del(config.PATHS.dist.base, done));

gulp.task('clean:test', function cleanTest(done) {
return del([config.PATHS.testBuilt], done);
});
gulp.task('clean:test', (done) => del(config.PATHS.testBuilt, done));

gulp.task('clean:tmp', (done) => del(config.PATHS.tmp, done));
27 changes: 25 additions & 2 deletions gulp/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const path = require('path');
const ts = require('typescript');
const $ = require('gulp-load-plugins')();

// package.json as JS object
module.exports.pkg = require(path.join(__dirname, '../package.json'));
Expand All @@ -9,20 +11,41 @@ module.exports.PATHS = {
tsSrcFiles: 'src/**/*.ts',
tsTestFiles: [
'test/**/*.ts',
'typings/main.d.ts',
'typings/index.d.ts',
],
releaseAssets: ['assets/release/**/*', 'LICENSE'],
exampleFiles: 'examples/**/*',
jsFiles: ['gulpfile.js', 'gulp/*.js'],
tsConfig: path.join(__dirname, '../tsconfig.json'),
tmp: '.tmp/',
dist: {
base: 'dist/',
cjs: 'dist/',
es6: 'dist/es6/',
esm: 'dist/esm/',
ts: 'dist/ts/',
bundles: 'dist/bundles/',
},
// todo: figure out why `..` is needed here to write compiled test files to test-build/ dir
// instead of test-built/test/ dir.
testBuilt: 'test-built/',
};

module.exports.banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');

// we create the the tsConfig outside the task for fast incremential compilations during a watch.
module.exports.tscConfigCjs = $.typescript.createProject(module.exports.PATHS.tsConfig, {
target: 'ES5',
module: 'commonjs',
moduleResolution: 'node',
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
typescript: ts,
allowJs: true,
});
2 changes: 1 addition & 1 deletion gulp/connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();

gulp.task('connect', function connect() {
gulp.task('connect', () => {
$.connect.server({
root: '.',
livereload: true,
Expand Down
38 changes: 21 additions & 17 deletions gulp/linting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@ const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const config = require('./config');
const path = require('path');
const tslint = require('../tslint.json');

gulp.task('tslint', () => {
return gulp.src(config.PATHS.tsSrcFiles)
gulp.task('tslint', () =>
gulp.src(config.PATHS.tsSrcFiles)
.pipe($.tslint({
configuration: require('../tslint.json'),
configuration: tslint,
}))
.pipe($.tslint.report('verbose'));
});
.pipe($.tslint.report('verbose'))
);

gulp.task('eslint', () => {
return gulp.src(config.PATHS.jsFiles)
gulp.task('eslint', () =>
gulp.src(config.PATHS.jsFiles)
.pipe($.eslint({
rulePaths: [path.join(__dirname, '../')],
}))
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});
.pipe($.eslint.failAfterError())
);

gulp.task('clang:check', () => {
return gulp.src(config.PATHS.tsSrcFiles)
.pipe($.clangFormat.checkFormat('file', undefined, {verbose: true, fail: true}));
});
gulp.task('clang:check', () =>
gulp.src(config.PATHS.tsSrcFiles)
.pipe($.clangFormat.checkFormat('file', undefined, {
verbose: true,
fail: true,
}))
);

gulp.task('clang:format', () => {
return gulp.src(config.PATHS.tsSrcFiles)
gulp.task('clang:format', () =>
gulp.src(config.PATHS.tsSrcFiles)
.pipe($.clangFormat.format('file'))
.pipe(gulp.dest(config.PATHS.srcDir));
});
.pipe(gulp.dest(config.PATHS.srcDir))
);

gulp.task('lint', ['clang:check', 'tslint', 'eslint']);
23 changes: 12 additions & 11 deletions gulp/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const config = require('./config');
const fs = require('fs');
const path = require('path');

gulp.task('copyReleaseAssets', function copyReleaseAssets() {
return gulp.src(config.PATHS.releaseAssets)
.pipe(gulp.dest(config.PATHS.dist.base));
});
gulp.task('copyReleaseAssets', () =>
gulp.src(config.PATHS.releaseAssets)
.pipe(gulp.dest(config.PATHS.dist.base))
);

gulp.task('changelog', function changelog() {
return gulp.src('CHANGELOG.md', {
gulp.task('changelog', () =>
gulp.src('CHANGELOG.md', {
buffer: false,
})
.pipe($.conventionalChangelog({
preset: 'angular',
}))
.pipe(gulp.dest('.'));
});
.pipe(gulp.dest('.'))
);

gulp.task('createPackageJson', function createPackageJson() {
gulp.task('createPackageJson', () => {
const basePkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));

// remove scripts
Expand All @@ -35,17 +35,18 @@ gulp.task('createPackageJson', function createPackageJson() {
fs.writeFileSync(filepath, JSON.stringify(basePkgJson, null, 2), 'utf-8');
});

gulp.task('create-tag', function createTag(cb) {
gulp.task('create-tag', (cb) => {
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}

const version = getPackageJsonVersion();
$.git.tag(version, 'chore(version): ' + version, function createGitTag(error) {
return $.git.tag(version, `chore(version): ${version}`, (error) => {
if (error) {
return cb(error);
}
return cb();
});
});
Loading

0 comments on commit 531110d

Please sign in to comment.