From 7fbe3397514ef801589e08362a36e70e1faa4408 Mon Sep 17 00:00:00 2001 From: Dmitriy Shekhovtsov Date: Wed, 18 May 2016 18:48:21 +0300 Subject: [PATCH] fix(package): updated code style\fixed ng2 imports --- .config/bundle-system.js | 12 +++-- .eslintignore | 28 ---------- .travis.yml | 14 +++-- components/select/select-pipes.spec.ts | 12 +++++ components/select/select-pipes.ts | 8 ++- components/select/select.spec.ts | 17 ------ demo/components/select-section.ts | 9 ++-- demo/index.ts | 4 +- gulp-tasks/lint.js | 9 ++-- gulpfile.js | 9 ---- karma.conf.js | 55 +++----------------- ng2-select.ts | 2 +- package.json | 62 +++++++++++----------- test.bundle.js | 72 +++++++++++++------------- tsconfig.json | 17 ++---- typings.json | 11 ++-- webpack.config.js | 10 ++-- 17 files changed, 128 insertions(+), 223 deletions(-) delete mode 100644 .eslintignore create mode 100644 components/select/select-pipes.spec.ts delete mode 100644 components/select/select.spec.ts diff --git a/.config/bundle-system.js b/.config/bundle-system.js index 1894fa21..9c8cc53c 100755 --- a/.config/bundle-system.js +++ b/.config/bundle-system.js @@ -17,7 +17,7 @@ const Builder = require('systemjs-builder'); const pkg = require('../package.json'); const name = pkg.name; const targetFolder = path.resolve('./bundles'); -console.log(targetFolder) + async.waterfall([ cleanBundlesFolder, getSystemJsBundleConfig, @@ -40,7 +40,11 @@ function getSystemJsBundleConfig(cb) { }, map: { typescript: path.resolve('node_modules/typescript/lib/typescript.js'), - angular2: path.resolve('node_modules/angular2'), + '@angular/core': path.resolve('node_modules/@angular/core/index.js'), + '@angular/common': path.resolve('node_modules/@angular/common/index.js'), + '@angular/compiler': path.resolve('node_modules/@angular/compiler/index.js'), + '@angular/platform-browser': path.resolve('node_modules/@angular/platform-browser/index.js'), + '@angular/platform-browser-dynamic': path.resolve('node_modules/@angular/platform-browser-dynamic/'), rxjs: path.resolve('node_modules/rxjs') }, paths: { @@ -48,12 +52,12 @@ function getSystemJsBundleConfig(cb) { } }; - config.meta = ['angular2', 'rxjs'].reduce((memo, currentValue) => { + config.meta = ['@angular/common','@angular/compiler','@angular/core', + '@angular/platform-browser','@angular/platform-browser-dynamic', 'rxjs'].reduce((memo, currentValue) => { memo[path.resolve(`node_modules/${currentValue}/*`)] = {build: false}; return memo; }, {}); config.meta.moment = {build: false}; - console.log(config.meta) return cb(null, config); } diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 41d8b2bd..00000000 --- a/.eslintignore +++ /dev/null @@ -1,28 +0,0 @@ -test.bundle.js -karma.conf.js -gulpfile.js - -.idea/ -gulp-tasks/ -logs/ - -# typings -typings/ -node_modules/ - -# testing -karma.conf.js -test.bundle.js -coverage/ - -demo/ -demo-build/ - -/demo/**/*.js -/components/**/*.js -ng2-select.js - -logs/ -bundles/ - - diff --git a/.travis.yml b/.travis.yml index 2bd1ce1f..56eb9da3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,13 @@ language: node_js node_js: - - "5" - - "4" - -before_install: -- npm install -g npm@latest + - "6" script: -- npm run flow.install:typings -- npm test -- ./node_modules/.bin/codecov + - npm run flow.install:typings + - npm test + +after_success: + - ./node_modules/.bin/codecov addons: # sauce labs tunel connector (read more https://docs.travis-ci.com/user/sauce-connect/ ) diff --git a/components/select/select-pipes.spec.ts b/components/select/select-pipes.spec.ts new file mode 100644 index 00000000..11a720e3 --- /dev/null +++ b/components/select/select-pipes.spec.ts @@ -0,0 +1,12 @@ +import {it, expect, describe, inject, beforeEachProviders} from '@angular/core/testing'; +import {ComponentFixture} from '@angular/compiler/testing'; +import {HighlightPipe} from './select-pipes'; + +describe('Component: HighlightPipe', () => { + beforeEachProviders(() => [ + HighlightPipe + ]); + it('should be fine', inject([HighlightPipe], (fixture:ComponentFixture) => { + expect(fixture).not.toBeNull(); + })); +}); diff --git a/components/select/select-pipes.ts b/components/select/select-pipes.ts index 33458b10..c536eae5 100644 --- a/components/select/select-pipes.ts +++ b/components/select/select-pipes.ts @@ -1,9 +1,7 @@ import {Pipe, PipeTransform} from '@angular/core'; import {escapeRegexp} from './common'; -@Pipe({ - name: 'highlight' -}) +@Pipe({name: 'highlight'}) export class HighlightPipe implements PipeTransform { public transform(value:string, args:any[]):any { if (args.length < 1) { @@ -31,7 +29,7 @@ export class HighlightPipe implements PipeTransform { } export function stripTags(input:string):string { - let tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, - commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; + let tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi; + let commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; return input.replace(commentsAndPhpTags, '').replace(tags, ''); } diff --git a/components/select/select.spec.ts b/components/select/select.spec.ts deleted file mode 100644 index afbd0f57..00000000 --- a/components/select/select.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {it, expect} from 'angular2/testing'; - -describe('TEST', () => { - it('true is true', () => { - expect(true).toBe(true); - }); - describe('Load TestComponentBuilder', () => { - // beforeEach(injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { - // return tcb.createAsync(Select) - // .then((componentFixture:ComponentFixture) => { - // }); - // })); - it('true is true', () => { - expect(true).toBe(true); - }); - }); -}); diff --git a/demo/components/select-section.ts b/demo/components/select-section.ts index 760c3cd4..55ccdb4b 100644 --- a/demo/components/select-section.ts +++ b/demo/components/select-section.ts @@ -38,11 +38,10 @@ let tabDesc:Array = [ let tabsContent:string = ``; tabDesc.forEach((desc:any) => { tabsContent += ` -
- <${desc.heading.toLowerCase()}-demo> - -
-
{{ currentHeading }}
+
+ <${desc.heading.toLowerCase()}-demo> + +

diff --git a/demo/index.ts b/demo/index.ts index 1d75084c..872f27c6 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -1,4 +1,4 @@ -import {bootstrapStatic} from '@angular/platform-browser'; +import {bootstrap} from '@angular/platform-browser-dynamic'; import {Component} from '@angular/core'; import {NgClass} from '@angular/common'; @@ -41,4 +41,4 @@ let gettingStarted = require('./getting-started.md'); export class DemoComponent { } -bootstrapStatic(DemoComponent); +bootstrap(DemoComponent); diff --git a/gulp-tasks/lint.js b/gulp-tasks/lint.js index 8d7e794b..62c7806a 100644 --- a/gulp-tasks/lint.js +++ b/gulp-tasks/lint.js @@ -2,13 +2,14 @@ const gulp = require('gulp'); const tslint = require('gulp-tslint'); -const paths = gulp.paths; -const tslintConf = require('../tslint.json'); +const gitignore = require('gitignore-to-glob')(); + +gitignore.push('**/*.ts'); gulp.task('tslint', () => gulp - .src(paths.tssrc) - .pipe(tslint(tslintConf)) + .src(gitignore) + .pipe(tslint()) .pipe(tslint.report('prose', { emitError: true, summarizeFailureOutput: true, diff --git a/gulpfile.js b/gulpfile.js index a902fca6..3d44e09d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,15 +2,6 @@ const gulp = require('gulp'); -gulp.paths = { - tssrc: [ - '**/*.ts', - '!**/*.d.ts', - '!node_modules/**/*', - '!bundles/**/*', - '!typings/**/*'] -}; - require('require-dir')('./gulp-tasks'); gulp.task('default', () => { diff --git a/karma.conf.js b/karma.conf.js index 01c6cd9a..31fec667 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -3,7 +3,7 @@ const path = require('path'); const cwd = process.cwd(); -module.exports = function (config) { +module.exports = config => { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', @@ -27,41 +27,14 @@ module.exports = function (config) { }, webpack: { - // Do not change, leave as is or it wont work. - // See: https://github.com/webpack/karma-webpack#source-maps - devtool: 'inline-source-map', resolve: { - root: [root('components')], + root: [path.resolve(cwd)], + modulesDirectories: ['node_modules', 'demo', 'components', 'test', '.'], extensions: ['', '.ts', '.js', '.css'] }, module: { - preLoaders: [ - { - test: /\.ts$/, - loader: 'tslint-loader', - exclude: [ - root('node_modules') - ] - }, - { - test: /\.js$/, - loader: 'source-map-loader', - exclude: [ - root('node_modules/rxjs') - ] - } - ], loaders: [ - { - test: /\.ts$/, - loader: 'awesome-typescript-loader', - query: { - 'compilerOptions': { - 'removeComments': true, - } - }, - exclude: [/\.e2e\.ts$/] - } + {test: /\.ts$/, loader: 'ts-loader', exclude: [/node_modules/]} ], postLoaders: [ // instrument only testing sources with Istanbul @@ -76,25 +49,10 @@ module.exports = function (config) { } ] }, - tslint: { - emitErrors: false, - failOnHint: false, - resourcePath: 'components' - }, stats: { colors: true, reasons: true }, - - node: { - global: 'window', - process: false, - crypto: 'empty', - module: false, - clearImmediate: false, - setImmediate: false - }, - watch: true, debug: true }, @@ -138,7 +96,6 @@ module.exports = function (config) { }); }; -function root(args) { - args = Array.prototype.slice.call(arguments, 0); - return path.join.apply(path, [__dirname].concat(args)); +function root(partialPath) { + return path.join(__dirname, partialPath); } diff --git a/ng2-select.ts b/ng2-select.ts index 21216aff..10271758 100644 --- a/ng2-select.ts +++ b/ng2-select.ts @@ -7,4 +7,4 @@ export default { directives: [ SELECT_DIRECTIVES ] -} +}; diff --git a/package.json b/package.json index 5422f886..f66a2f7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-select", - "version": "1.0.1-beta.0", + "version": "1.0.2", "description": "Angular2 based replacement for select boxes", "scripts": { "flow.install:typings": "./node_modules/.bin/typings install", @@ -10,11 +10,11 @@ "flow.copy:src": "./node_modules/.bin/cpy ng2-select.ts \"components/*.ts\" ts --parents", "flow.clean": "./node_modules/.bin/del bundles coverage demo-build typings \"components/**/*.+(js|d.ts|js.map)\" dist \"ng2-select.+(js|d.ts|js.map)\"", "flow.deploy:gh-pages": "npm run flow.build:prod && ./node_modules/.bin/gh-pages -d demo-build", - "flow.eslint": "./node_modules/.bin/eslint --ignore-path .eslintignore --ext js --fix . .config", + "flow.eslint": "./node_modules/.bin/eslint --ignore-path .gitignore --ext js --fix . .config", "flow.tslint": "./node_modules/.bin/gulp lint", "flow.lint": "npm run flow.eslint && npm run flow.tslint", "flow.changelog": "./node_modules/.bin/conventional-changelog -i CHANGELOG.md -s -p angular -v", - "flow.github-release": "conventional-github-releaser -p angular", + "flow.github-release": "./node_modules/.bin/conventional-github-releaser -p angular", "flow.build:prod": "NODE_ENV=production ./node_modules/.bin/webpack --progress --color", "flow.build:dev": "./node_modules/.bin/webpack --progress --color", "flow.serve:dev": "./node_modules/.bin/webpack-dev-server --hot --inline --colors --display-error-details --display-cached", @@ -49,65 +49,65 @@ "peerDependencies": { "@angular/common": "^2.0.0-rc.1", "@angular/compiler": "^2.0.0-rc.1", - "@angular/core": "^2.0.0-rc.1", - "@angular/platform-browser": "^2.0.0-rc.1", - "@angular/platform-browser-dynamic": "^2.0.0-rc.1" - }, + "@angular/core": "^2.0.0-rc.1" + }, "dependencies": {}, "devDependencies": { - "angular2": "2.0.0-beta.15", + "@angular/common": "^2.0.0-rc.1", + "@angular/compiler": "^2.0.0-rc.1", + "@angular/core": "^2.0.0-rc.1", + "@angular/platform-browser": "^2.0.0-rc.1", + "@angular/platform-browser-dynamic": "^2.0.0-rc.1", + "async": "1.5.2", "awesome-typescript-loader": "^0.17.0-rc.6", "bootstrap": "3.3.6", - "clean-webpack-plugin": "0.1.9", "codecov": "1.0.1", "compression-webpack-plugin": "0.3.1", - "conventional-changelog-cli": "1.1.1", + "conventional-changelog-cli": "1.2.0", "conventional-github-releaser": "1.1.2", - "copy-webpack-plugin": "2.1.1", - "core-js": "^2.1.5", + "copy-webpack-plugin": "3.0.0", "cpy-cli": "1.0.0", "del-cli": "0.2.0", - "es6-promise": "3.1.2", - "es6-shim": "0.35.0", + "es6-promise": "3.2.1", + "es6-shim": "0.35.1", "es7-reflect-metadata": "1.6.0", - "eslint-config-valorsoft": "0.0.10", + "eslint-config-valorsoft": "0.0.13", "exports-loader": "0.6.3", "file-loader": "0.8.5", "gh-pages": "0.11.0", + "gitignore-to-glob": "0.2.1", "gulp": "3.9.1", "gulp-size": "2.1.0", - "gulp-tslint": "github:valorkin/gulp-tslint", + "gulp-tslint": "5.0.0", "html-loader": "0.4.3", - "html-webpack-plugin": "2.16.0", + "html-webpack-plugin": "2.17.0", "istanbul-instrumenter-loader": "0.2.0", "jasmine": "2.4.1", "karma": "0.13.22", - "karma-chrome-launcher": "0.2.3", - "karma-coverage": "0.5.5", - "karma-jasmine": "0.3.8", + "karma-chrome-launcher": "1.0.1", + "karma-coverage": "1.0.0", + "karma-jasmine": "1.0.2", "karma-phantomjs-launcher": "1.0.0", "karma-sourcemap-loader": "0.3.7", "karma-spec-reporter": "0.0.26", "karma-webpack": "1.7.0", + "lite-server": "2.2.0", "markdown-loader": "0.1.7", "marked": "0.3.5", - "moment": "2.13.0", - "ng2-bootstrap": "1.0.13", + "ng2-bootstrap": "1.0.16", "phantomjs-polyfill": "0.0.2", "phantomjs-prebuilt": "2.1.7", - "pre-commit": "1.1.2", - "prismjs": "valorkin/prism", - "prismjs-loader": "0.0.2", + "pre-commit": "1.1.3", + "prismjs": "1.5.0", + "prismjs-loader": "0.0.3", "raw-loader": "0.5.1", "reflect-metadata": "0.1.2", "require-dir": "0.3.0", - "rxjs": "5.0.0-beta.2", - "source-map-loader": "^0.1.5", - "systemjs-builder": "0.15.15", - "ts-helpers": "^1.1.0", + "rxjs": "5.0.0-beta.6", + "source-map-loader": "0.1.5", + "systemjs-builder": "0.15.16", "ts-loader": "0.8.2", - "tslint-config-valorsoft": "1.0.2", - "tslint-loader": "2.1.3", + "tslint-config-valorsoft": "1.0.3", "typescript": "1.8.10", "typings": "0.8.1", "webpack": "1.13.0", diff --git a/test.bundle.js b/test.bundle.js index 5a5482fc..9ade8579 100644 --- a/test.bundle.js +++ b/test.bundle.js @@ -1,47 +1,47 @@ +'use strict'; +/* eslint vars-on-top:0 no-var:0 */ +// @AngularClass +/* + * When testing with webpack and ES6, we have to do some extra + * things get testing to work right. Because we are gonna write test + * in ES6 to, we have to compile those as well. That's handled in + * karma.conf.js with the karma-webpack plugin. This is the entry + * file for webpack test. Just like webpack will create a bundle.js + * file for our client, when we run test, it well compile and bundle them + * all here! Crazy huh. So we need to do some setup + */ Error.stackTraceLimit = Infinity; +require('phantomjs-polyfill'); +require('es6-promise'); +require('es6-shim'); +require('es7-reflect-metadata/dist/browser'); -require('core-js'); - -// Typescript emit helpers polyfill -require('ts-helpers'); - -require('zone.js/dist/zone'); -require('zone.js/dist/long-stack-trace-zone'); -require('zone.js/dist/jasmine-patch'); - -// RxJS -require('rxjs/Rx'); +// require('zone.js'); +require('zone.js/dist/zone.js'); +require('zone.js/dist/long-stack-trace-zone.js'); +require('zone.js/dist/jasmine-patch.js'); +require('zone.js/dist/async-test.js'); -var testing = require('angular2/testing'); -var browser = require('angular2/platform/testing/browser'); +var testing = require('@angular/core/testing'); +var browser = require('@angular/platform-browser-dynamic/testing'); testing.setBaseTestProviders( - browser.TEST_BROWSER_PLATFORM_PROVIDERS, - browser.TEST_BROWSER_APPLICATION_PROVIDERS -); - -Object.assign(global, testing); + browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, + browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); /* - * Ok, this is kinda crazy. We can use the the context method on - * require that webpack created in order to tell webpack - * what files we actually want to require or import. - * Below, context will be an function/object with file names as keys. - * using that regex we are saying look in ./src/app and ./test then find - * any file that ends with spec.js and get its path. By passing in true - * we say do this recursively + Ok, this is kinda crazy. We can use the the context method on + require that webpack created in order to tell webpack + what files we actually want to require or import. + Below, context will be an function/object with file names as keys. + using that regex we are saying look in ./src/app and ./test then find + any file that ends with spec.js and get its path. By passing in true + we say do this recursively */ var testContext = require.context('./components', true, /\.spec\.ts/); -/* - * get all the files, for each file, call the context function - * that will require the file and load it up here. Context will - * loop and require those spec files here - */ -function requireAll(requireContext) { - return requireContext.keys().map(requireContext); -} - -// requires and returns all modules that match -var modules = requireAll(testContext); +// get all the files, for each file, call the context function +// that will require the file and load it up here. Context will +// loop and require those spec files here +testContext.keys().forEach(testContext); diff --git a/tsconfig.json b/tsconfig.json index d9454eb9..8028f548 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,6 @@ "module": "commonjs", "moduleResolution": "node", "sourceMap": false, - "noEmitHelpers": true, "declaration": true, "removeComments": false, "emitDecoratorMetadata": true, @@ -14,20 +13,12 @@ "noLib": false }, "exclude": [ - "node_modules", - "typings/main.d.ts", - "typings/main" + "node_modules" ], - "filesGlob": [ - "./components/**/*.spec.ts", - "!./node_modules/**/*.ts", - "./ng2-select.ts", - "typings/browser.d.ts" + "files": [ + "./typings/browser.d.ts", + "./ng2-select.ts" ], - "awesomeTypescriptLoaderOptions": { - "resolveGlobs": true, - "forkChecker": true - }, "compileOnSave": false, "buildOnSave": false, "atom": { "rewriteTsconfig": false } diff --git a/typings.json b/typings.json index 605e9106..592b524e 100644 --- a/typings.json +++ b/typings.json @@ -1,13 +1,12 @@ { "dependencies": { - "zone.js": "github:gdi2290/typed-zone.js#66ea8a3451542bb7798369306840e46be1d6ec89", - "moment": "github:typed-typings/npm-moment#a4075cd50e63efbedd850f654594f293ab81a385" + "moment": "registry:npm/moment#2.10.5+20160211003958", + "webpack": "registry:npm/webpack#1.12.9+20160219013405" }, "devDependencies": {}, "ambientDependencies": { - "core-js": "registry:dt/core-js#0.0.0+20160317120654", - "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#4b36b94d5910aa8a4d20bdcd5bd1f9ae6ad18d3c", - "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#8cf8164641be73e8f1e652c2a5b967c7210b6729", - "webpack": "github:DefinitelyTyped/DefinitelyTyped/webpack/webpack.d.ts#95c02169ba8fa58ac1092422efbd2e3174a206f4" + "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654", + "jasmine": "registry:dt/jasmine#2.2.0+20160317120654", + "require": "registry:dt/require#2.1.20+20160316155526" } } diff --git a/webpack.config.js b/webpack.config.js index 2efe62dc..2d04b081 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -48,12 +48,12 @@ const config = { entry: { angular2: [ // Angular 2 Deps - 'core-js/es6', - 'core-js/es7/reflect', + 'es6-shim', + 'es6-promise', 'zone.js', - 'angular2/common', - 'angular2/core', - 'ts-helpers' + 'reflect-metadata', + '@angular/common', + '@angular/core' ], 'angular2-select': ['ng2-select'], 'angular2-select-demo': 'demo'