diff --git a/.eslintrc b/.eslintrc index d3d2f9936..390d6d8ae 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,5 @@ { - "extends": "airbnb", + "extends": "airbnb-base", "rules": { "id-length": 0 } diff --git a/.nvmrc b/.nvmrc index 28cbf7c0a..7813681f5 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -5.0.0 \ No newline at end of file +5 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 26e1bcf9c..504e5fb0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/assets/release/README.md b/assets/release/README.md index b94797d78..38483a4c8 100644 --- a/assets/release/README.md +++ b/assets/release/README.md @@ -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. diff --git a/gulp/bundle.js b/gulp/bundle.js index 837af4e9c..70da9ddc2 100644 --- a/gulp/bundle.js +++ b/gulp/bundle.js @@ -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']); diff --git a/gulp/clean.js b/gulp/clean.js index 5d656f93c..d54a154be 100644 --- a/gulp/clean.js +++ b/gulp/clean.js @@ -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)); diff --git a/gulp/config.js b/gulp/config.js index 42660d26d..666d328a1 100644 --- a/gulp/config.js +++ b/gulp/config.js @@ -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')); @@ -9,16 +11,17 @@ 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/', }, @@ -26,3 +29,23 @@ module.exports.PATHS = { // 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, +}); diff --git a/gulp/connect.js b/gulp/connect.js index 34bfae73a..ee4ea754f 100644 --- a/gulp/connect.js +++ b/gulp/connect.js @@ -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, diff --git a/gulp/linting.js b/gulp/linting.js index 466ad081d..c54306186 100644 --- a/gulp/linting.js +++ b/gulp/linting.js @@ -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']); diff --git a/gulp/release.js b/gulp/release.js index c4c63e7a0..7c4baf6a2 100644 --- a/gulp/release.js +++ b/gulp/release.js @@ -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 @@ -35,7 +35,7 @@ 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 @@ -43,9 +43,10 @@ gulp.task('create-tag', function createTag(cb) { } 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(); }); }); diff --git a/gulp/scripts.js b/gulp/scripts.js index 5574b1558..863649484 100644 --- a/gulp/scripts.js +++ b/gulp/scripts.js @@ -4,21 +4,19 @@ const config = require('./config'); const merge = require('merge2'); const sourcemaps = require('gulp-sourcemaps'); -const banner = ['/**', - ' * <%= pkg.name %> - <%= pkg.description %>', - ' * @version v<%= pkg.version %>', - ' * @link <%= pkg.homepage %>', - ' * @license <%= pkg.license %>', - ' */', - ''].join('\n'); +function replaceSrcDir(path) { + path.dirname = path.dirname.replace(/^src/ig, ''); // eslint-disable-line no-param-reassign +} -gulp.task('scripts:ts', function scriptsTs() { - return gulp.src(config.PATHS.tsSrcFiles) - .pipe($.header(banner, { pkg: config.pkg } )) +gulp.task('scripts:ts', () => { + gulp.src(config.PATHS.tsSrcFiles) + .pipe($.header(config.banner, { + pkg: config.pkg, + })) .pipe(gulp.dest(config.PATHS.dist.ts)); }); -gulp.task('scripts:es6', function scriptsEs6() { +gulp.task('scripts:esm', () => { const taskConfig = $.typescript.createProject(config.PATHS.tsConfig, { module: 'ES6', target: 'ES6', @@ -29,54 +27,61 @@ gulp.task('scripts:es6', function scriptsEs6() { // todo: this emit errors right now because of duplicate ES6 declarations. // should be fixed when https://github.com/angular/angular/issues/4882 is included a new Angular2 version. const tsResult = gulp.src(config.PATHS.tsSrcFiles) - .pipe(sourcemaps.init()) + .pipe($.sourcemaps.init()) .pipe($.typescript(taskConfig, undefined, $.typescript.reporter.nullReporter())); - return tsResult.js.pipe(sourcemaps.write('.')) - .pipe($.header(banner, { pkg: config.pkg } )) - .pipe(gulp.dest(config.PATHS.dist.es6)); + return tsResult.js + .pipe($.header(config.banner, { + pkg: config.pkg, + })) + .pipe($.rename(replaceSrcDir)) + .pipe($.sourcemaps.write('.')) + .pipe(gulp.dest(config.PATHS.dist.esm)); }); -// we create the the tsConfig outside the task for fast incremential compilations during a watch. -const taskConfigCjs = $.typescript.createProject(config.PATHS.tsConfig, { - target: 'ES5', - 'module': 'commonjs', - moduleResolution: 'node', - declaration: true, - emitDecoratorMetadata: true, - experimentalDecorators: true, -}); -gulp.task('scripts:cjs', function scriptsEs5() { - const tsResult = gulp.src([config.PATHS.tsSrcFiles, 'typings/main.d.ts']) - .pipe(sourcemaps.init()) - .pipe($.typescript(taskConfigCjs)); +gulp.task('scripts:cjs', () => { + // todo: figure out why gulp-typescript don't write to the defined root dir (dist) + const tsResult = gulp.src([config.PATHS.tsSrcFiles, 'typings/index.d.ts']) + .pipe($.sourcemaps.init()) + .pipe($.typescript(config.tscConfigCjs)); return merge([ - tsResult.dts.pipe($.header(banner, { pkg: config.pkg } )).pipe(gulp.dest(config.PATHS.dist.cjs)), - tsResult.js.pipe($.header(banner, { pkg: config.pkg } )).pipe(sourcemaps.write('.')).pipe(gulp.dest(config.PATHS.dist.cjs)), + tsResult.dts.pipe($.header(config.banner, { + pkg: config.pkg, + })) + .pipe($.rename(replaceSrcDir)) + .pipe(gulp.dest(config.PATHS.dist.cjs)), + + tsResult.js.pipe($.header(config.banner, { + pkg: config.pkg, + })) + .pipe($.rename(replaceSrcDir)) + .pipe($.sourcemaps.write('.')) + .pipe(gulp.dest(config.PATHS.dist.cjs)), ]); }); -gulp.task('scripts:test', function scriptsEs5() { +gulp.task('scripts:test', () => { const tsResult = gulp.src(config.PATHS.tsTestFiles) .pipe(sourcemaps.init()) - .pipe($.typescript(taskConfigCjs)); + .pipe($.typescript(config.taskConfigCjs)); // todo: figure out why gulp-typescript don't write to the defined root dir (test-built) function replaceTestDir(path) { - path.dirname = path.dirname.replace('test/', ''); + path.dirname = path.dirname.replace('test/', ''); // eslint-disable-line no-param-reassign } return merge([ tsResult.dts - .pipe($.header(banner, { pkg: config.pkg } )) + .pipe($.header(config.banner, { + pkg: config.pkg, + })) .pipe($.rename(replaceTestDir)) .pipe(gulp.dest(config.PATHS.testBuilt)), tsResult.js .pipe($.rename(replaceTestDir)) - .pipe(sourcemaps.write('.')) + .pipe($.sourcemaps.write('.')) .pipe(gulp.dest(config.PATHS.testBuilt)), ]); }); - -gulp.task('scripts', ['scripts:cjs', 'scripts:es6', 'scripts:ts']); +gulp.task('scripts', ['scripts:cjs', 'scripts:esm', 'scripts:ts']); diff --git a/gulp/test.js b/gulp/test.js index ca67e37b7..a2f5e3d46 100644 --- a/gulp/test.js +++ b/gulp/test.js @@ -3,19 +3,17 @@ const karma = require('karma'); const path = require('path'); function createKarmaServer(singleRun, done) { - new karma.Server({ + return new karma.Server({ configFile: path.join(process.cwd(), 'karma.conf.js'), - singleRun: singleRun, + singleRun, }).start(done); } -gulp.task('karma:watch', function karmaStart(done) { - return createKarmaServer(false, done); -}); +gulp.task('karma:watch', (done) => createKarmaServer(false, done)); -gulp.task('karma', function karmaStart(done) { +gulp.task('karma', (done) => new karma.Server({ configFile: path.join(process.cwd(), 'karma.conf.js'), singleRun: true, - }).start(done); -}); + }).start(done) +); diff --git a/gulp/watch.js b/gulp/watch.js index 9626169d5..68ae7328b 100644 --- a/gulp/watch.js +++ b/gulp/watch.js @@ -1,10 +1,10 @@ const gulp = require('gulp'); const config = require('./config'); -gulp.task('watch:srcFiles', function watch() { +gulp.task('watch:srcFiles', () => { gulp.watch(config.PATHS.tsSrcFiles, ['scripts:cjs', 'bundle:cjs']); }); -gulp.task('watch:testfiles', function watch() { +gulp.task('watch:testfiles', () => { gulp.watch(config.PATHS.tsTestFiles, ['scripts:test']); }); diff --git a/gulpfile.js b/gulpfile.js index f30262857..9db1be9d5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,13 +4,19 @@ const gulp = require('gulp'); const runSequence = require('run-sequence'); // all grunt tasks, which are defined here, are intended for use via the CLI. -gulp.task('build', function build(done) { - runSequence('clean:dist', 'lint', ['copyReleaseAssets', 'scripts', 'bundle'], 'createPackageJson', done); +gulp.task('build', (done) => { + runSequence( + ['clean:dist', 'clean:tmp'], + 'lint', + ['copyReleaseAssets', 'scripts', 'bundle'], + 'createPackageJson', + done + ); }); gulp.task('serve', ['connect', 'watch:srcFiles']); -gulp.task('test', function testTask(done) { +gulp.task('test', (done) => { runSequence('clean:test', 'scripts:test', 'karma', done); }); diff --git a/package.json b/package.json index 814be2601..f17b49423 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "maps" ], "scripts": { - "postinstall": "typings install" + "postinstall": "typings install", + "ci": "gulp build && gulp test" }, "author": "Sebastian Müller ", "license": "MIT", @@ -34,38 +35,40 @@ "zone.js": "^0.6.12" }, "devDependencies": { - "babel-eslint": "4.1.8", + "babel-eslint": "6.0.4", + "clang-format": "1.0.39", "del": "2.2.0", - "eslint": "2.4.0", - "eslint-config-airbnb": "1.0.0", - "eslint-plugin-react": "4.2.1", + "eslint": "^2.10.2", + "eslint-config-airbnb-base": "^3.0.1", + "eslint-plugin-import": "^1.8.0", "gulp": "3.9.1", - "gulp-bump": "2.0.1", + "gulp-bump": "2.1.0", "gulp-clang-format": "1.0.23", - "gulp-connect": "3.2.0", - "gulp-conventional-changelog": "1.0.1", - "gulp-eslint": "1.1.1", - "gulp-git": "1.7.0", + "gulp-connect": "4.0.0", + "gulp-conventional-changelog": "1.1.0", + "gulp-eslint": "2.0.0", + "gulp-git": "1.7.2", "gulp-header": "^1.7.1", - "gulp-load-plugins": "1.1.0", + "gulp-load-plugins": "1.2.4", "gulp-rename": "1.2.2", + "gulp-shell": "0.5.2", "gulp-sourcemaps": "1.6.0", - "gulp-tslint": "4.3.3", - "gulp-typescript": "2.12.1", + "gulp-tslint": "5.0.0", + "gulp-typescript": "^2.13.4", "jasmine-core": "2.4.1", "karma": "0.13.22", - "karma-chrome-launcher": "0.2.2", - "karma-jasmine": "0.3.8", - "merge2": "1.0.1", + "karma-chrome-launcher": "1.0.1", + "karma-jasmine": "1.0.2", + "merge2": "1.0.2", "replace": "0.3.0", "require-dir": "0.3.0", - "run-sequence": "1.1.5", - "systemjs": "0.19.28", - "systemjs-builder": "0.15.17", - "tslint": "3.6.0", - "typescript": "1.8.9", - "typings": "0.7.7", - "watchify": "^3.7.0" + "rollup": "0.26.6", + "run-sequence": "1.2.1", + "systemjs": "0.19.29", + "tslint": "3.10.2", + "typescript": "1.8.10", + "typings": "1.0.4", + "watchify": "3.7.0" }, "jspm": { "jspmNodeConversion": false, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 000000000..339a393ca --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,17 @@ +export default { + entry: 'dist/esm/core.js', + dest: '.tmp/core.umd.js', + format: 'umd', + moduleName: 'ngmaps.core', + globals: { + '@angular/core': 'ng.core', + '@angular/common': 'ng.common', + '@angular/compiler': 'ng.compiler', + '@angular/platform-browser': 'ng.platformBrowser', + '@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic', + 'rxjs/Subject': 'Rx', + 'rxjs/observable/PromiseObservable': 'Rx', + 'rxjs/operator/toPromise': 'Rx.Observable.prototype', + 'rxjs/Observable': 'Rx' + } +} diff --git a/typings.json b/typings.json index 8597557ef..6712e2754 100644 --- a/typings.json +++ b/typings.json @@ -1,8 +1,6 @@ { "name": "angular2-google-maps", - "dependencies": {}, - "devDependencies": {}, - "ambientDevDependencies": { + "globalDevDependencies": { "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c", "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4" }