diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bc61fe4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "prettier.printWidth": 100, + "prettier.singleQuote": true, + "editor.formatOnSave": true +} diff --git a/README.md b/README.md index 094f5f0..b2b76a5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Mandatory Update for Ionic 2 +# Mandatory Update for Ionic 2+ [![Build Status](https://travis-ci.org/NextFaze/ionic-manup.svg?branch=master)](https://travis-ci.org/NextFaze/ionic-manup) @@ -34,23 +34,28 @@ Mandatory Update (manup) works like this: ## Requirements - * Ionic 2 - * Angular 2.x - * `ionic-native` (needed to get the app version and name) + * Ionic >2 + * Angular >2 * `@ionic/storage` (used for caching) - * `cordova-plugin-app-version` to get the installed app name and version + * `@ionic-native/app-version` + * `cordova-plugin-app-version` + * `@ionic-native/in-app-browser` * `cordova-plugin-inappbrowser` to launch the link to the app/play store + In your ionic project root: ```sh -npm install --save @ionic/storage ionic-native +npm install --save @ionic/storage @ionic-native/app-version @ionic-native/in-app-browser ionic plugin add cordova-plugin-app-version ionic plugin add cordova-plugin-inappbrowser ``` Manup assumes you are using Semantic Versioning for your app. + ### Optional + * `@ngx-translate/core` Needed to handle translations + ## Installation ```sh @@ -126,26 +131,45 @@ export class MyApp { ## Internationalisation Support -The service uses [ng2-translate](https://www.npmjs.com/package/ng2-translate) to support languages other than English. This package is the way [recommended](https://ionicframework.com/docs/v2/resources/ng2-translate/) by the Ionic developers. +The service uses [ngx-translate](https://www.npmjs.com/package/ng2-translate) to support languages other than English. This package is the way [recommended](https://ionicframework.com/docs/v2/resources/ng2-translate/) by the Ionic developers. ### With Built in translations -To make life easy for app developers, the service includes its own translation strings. All you need to do is add `ng2-translate` to your Ionic app and set the active language. +To make life easy for app developers, the service includes its own translation strings. All you need to do is add `ngx-translate` to your Ionic app and set the active language. Due to the way AOT works, you also need to provide a `TRANSLATE_SERVICE` for ManUp to use. Languages supported are currently limited to English and a Google Translated Spanish. We would love pull requests for new languages. -#### Boostrap ng2-translate with your app! +#### Boostrap ngx-translate with your app! ```ts - import { ManUpModule } from 'ionic-manup'; - import { TranslateModule } from 'ng2-translate'; - - // in your module's import array - TranslateModule.forRoot(), - ManUpModule.forRoot({url: 'https://example.com/manup.json'}) + import { ManUpModule, ManUpService, TRANSLATE_SERVICE } from 'ionic-manup'; + import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core'; + + + @NgModule({ + declarations: [MyApp, HomePage], + imports: [ + ... + ManUpModule.forRoot({ + url: 'https://example.com/manup.json', + externalTranslations: true + }), + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useFactory: translateLoader, + deps: [HttpClient] + } + }) + ], + providers: [ + { provide: TRANSLATE_SERVICE, useClass: TranslateService }, + ManUpService, + ], + }) ``` -Note: This is an absolute bare minimum example of loading the module. Follow the instructions linked to above for how to use `ng2-translate` in your app. +Note: This is an absolute bare minimum example of loading the module. Follow the instructions linked to above for how to use `ngx-translate` in your app. ### With your own strings @@ -153,7 +177,7 @@ If you want to further customise the messages, you can provide your own translat #### Setup your language files -Follow the instructions for setting up `ng2-translate` with your Ionic 2 app, and add the following tree to your language files: +Follow the instructions for setting up `ngx-translate` with your Ionic 2 app, and add the following tree to your language files: ```json @@ -194,7 +218,7 @@ You need to tell ManUp to use external translations. Modify your Bootstrap like ## Demonstration App -A demonstration app is in the `manup-demo` folder. This is the default Ionic 2 tabs starter app, with Manup added. +A demonstration app is in the `manup-demo` folder. This is the default Ionic 2 starter app, with ManUp added. ```sh cd manup-demo diff --git a/angular-cli.json b/angular-cli.json deleted file mode 100644 index 1ed7f0a..0000000 --- a/angular-cli.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "project": { - "version": "1.0.0-beta.22-1", - "name": "ionic2-tdd" - }, - "apps": [ - { - "root": "src", - "outDir": "dist", - "index": "index.html", - "main": "main.ts", - "test": "test.ts", - "tsconfig": "tsconfig.test.json", - "prefix": "", - "mobile": false, - "styles": [ - "styles.css" - ], - "scripts": [], - "environments": { - "source": "environments/environment.ts", - "dev": "environments/environment.ts", - "prod": "environments/environment.prod.ts" - } - } - ], - "addons": [], - "packages": [], - "test": { - "karma": { - "config": "./karma.conf.js" - } - }, - "defaults": { - "styleExt": "css", - "prefixInterfaces": false, - "inline": { - "style": false, - "template": false - }, - "spec": { - "class": false, - "component": true, - "directive": true, - "module": false, - "pipe": true, - "service": true - } - } -} diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index a1cd69e..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,45 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/0.13/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', 'angular-cli'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-phantomjs-launcher'), - require('karma-remap-istanbul'), - require('karma-mocha-reporter'), - require('angular-cli/plugins/karma') - ], - files: [ - { pattern: './src/test.ts', watched: false } - ], - preprocessors: { - './src/test.ts': ['angular-cli'] - }, - mime: { - 'text/x-typescript': ['ts','tsx'] - }, - remapIstanbulReporter: { - reports: { - html: 'coverage', - lcovonly: './coverage/coverage.lcov' - } - }, - angularCli: { - config: './angular-cli.json', - environment: 'dev' - }, - reporters: config.angularCli && config.angularCli.codeCoverage - ? ['mocha', 'karma-remap-istanbul'] - : ['mocha'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['PhantomJS'], - singleRun: false - }); -}; diff --git a/manup-demo/.gitignore b/manup-demo/.gitignore index c558400..faf0575 100644 --- a/manup-demo/.gitignore +++ b/manup-demo/.gitignore @@ -13,6 +13,7 @@ log.txt npm-debug.log* .idea/ +.sourcemaps/ .sass-cache/ .tmp/ .versions/ diff --git a/manup-demo/README.md b/manup-demo/README.md new file mode 100644 index 0000000..3797ce1 --- /dev/null +++ b/manup-demo/README.md @@ -0,0 +1,26 @@ +This is a starter template for [Ionic](http://ionicframework.com/docs/) projects. + +## How to use this template + +*This template does not work on its own*. The shared files for each starter are found in the [ionic2-app-base repo](https://github.com/ionic-team/ionic2-app-base). + +To use this template, either create a new ionic project using the ionic node.js utility, or copy the files from this repository into the [Starter App Base](https://github.com/ionic-team/ionic2-app-base). + +### With the Ionic CLI: + +Take the name after `ionic2-starter-`, and that is the name of the template to be used when using the `ionic start` command below: + +```bash +$ sudo npm install -g ionic cordova +$ ionic start myBlank blank +``` + +Then, to run it, cd into `myBlank` and run: + +```bash +$ ionic cordova platform add ios +$ ionic cordova run ios +``` + +Substitute ios for android if not on a Mac. + diff --git a/manup-demo/config.xml b/manup-demo/config.xml index c98217b..e8b1011 100644 --- a/manup-demo/config.xml +++ b/manup-demo/config.xml @@ -1,40 +1,87 @@ - - - Manup Demo - Demonstration of how to use Ionic Manup. - Ionic Framework Team - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + MyApp + An awesome Ionic/Cordova app. + Ionic Framework Team + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/manup-demo/ionic.config.json b/manup-demo/ionic.config.json index 2d12178..85dfdf5 100644 --- a/manup-demo/ionic.config.json +++ b/manup-demo/ionic.config.json @@ -1,6 +1,8 @@ { "name": "manup-demo", "app_id": "", - "v2": true, - "typescript": true + "type": "ionic-angular", + "integrations": { + "cordova": {} + } } diff --git a/manup-demo/package.json b/manup-demo/package.json index 9939964..1ddfa0f 100644 --- a/manup-demo/package.json +++ b/manup-demo/package.json @@ -1,53 +1,65 @@ { - "name": "ionic-hello-world", + "name": "manup-demo", + "version": "0.0.1", "author": "Ionic Framework", "homepage": "http://ionicframework.com/", "private": true, "scripts": { "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts build", + "lint": "ionic-app-scripts lint", "ionic:build": "ionic-app-scripts build", "ionic:serve": "ionic-app-scripts serve" }, "dependencies": { - "@angular/common": "2.2.1", - "@angular/compiler": "2.2.1", - "@angular/compiler-cli": "2.2.1", - "@angular/core": "2.2.1", - "@angular/forms": "2.2.1", - "@angular/http": "2.2.1", - "@angular/platform-browser": "2.2.1", - "@angular/platform-browser-dynamic": "2.2.1", - "@angular/platform-server": "2.2.1", - "@ionic/storage": "1.1.7", - "ionic-angular": "2.0.0", - "ionic-manup": "^0.1.0", - "ionic-native": "2.4.1", + "@angular/common": "4.4.3", + "@angular/compiler": "4.4.3", + "@angular/compiler-cli": "4.4.3", + "@angular/core": "4.4.3", + "@angular/forms": "4.4.3", + "@angular/http": "4.4.3", + "@angular/platform-browser": "4.4.3", + "@angular/platform-browser-dynamic": "4.4.3", + "@ionic-native/app-version": "^4.3.1", + "@ionic-native/core": "4.3.0", + "@ionic-native/in-app-browser": "^4.3.1", + "@ionic-native/splash-screen": "4.3.0", + "@ionic-native/status-bar": "4.3.0", + "@ionic/storage": "^2.0.1", + "@ngx-translate/core": "^8.0.0", + "@ngx-translate/http-loader": "^2.0.0", + "cordova-ios": "^4.5.1", + "cordova-plugin-app-version": "^0.1.9", + "cordova-plugin-device": "^1.1.4", + "cordova-plugin-inappbrowser": "^1.7.1", + "cordova-plugin-ionic-webview": "^1.1.14", + "cordova-plugin-splashscreen": "^4.0.3", + "cordova-plugin-statusbar": "git+https://github.com/apache/cordova-plugin-statusbar.git", + "cordova-plugin-whitelist": "^1.3.1", + "ionic-angular": "3.7.1", + "ionic-manup": "file:../ionic-manup-0.2.1.tgz", + "ionic-plugin-keyboard": "^2.2.1", "ionicons": "3.0.0", - "ng2-translate": "^5.0.0", - "rxjs": "5.0.0-beta.12", - "sw-toolbox": "3.4.0", - "zone.js": "0.6.26" + "rxjs": "5.4.3", + "sw-toolbox": "3.6.0", + "zone.js": "0.8.18" }, "devDependencies": { - "@ionic/app-scripts": "1.0.0", - "typescript": "^2.0.9" + "@ionic/app-scripts": "3.0.0", + "typescript": "2.3.4" }, - "cordovaPlugins": [ - "cordova-plugin-whitelist", - "cordova-plugin-statusbar", - "cordova-plugin-console", - "cordova-plugin-device", - "cordova-plugin-splashscreen", - "ionic-plugin-keyboard" - ], - "cordovaPlatforms": [ - "ios", - { - "platform": "ios", - "version": "", - "locator": "ios" - } - ], - "description": "manup-demo: An Ionic project" + "description": "An Ionic project", + "cordova": { + "plugins": { + "cordova-plugin-app-version": {}, + "cordova-plugin-inappbrowser": {}, + "cordova-plugin-device": {}, + "cordova-plugin-ionic-webview": {}, + "cordova-plugin-splashscreen": {}, + "cordova-plugin-statusbar": {}, + "cordova-plugin-whitelist": {}, + "ionic-plugin-keyboard": {} + }, + "platforms": ["ios"] + } } diff --git a/manup-demo/resources/ios/icon/icon-40.png b/manup-demo/resources/ios/icon/icon-40.png index 76cc53c..7f94466 100644 Binary files a/manup-demo/resources/ios/icon/icon-40.png and b/manup-demo/resources/ios/icon/icon-40.png differ diff --git a/manup-demo/resources/ios/icon/icon-40@2x.png b/manup-demo/resources/ios/icon/icon-40@2x.png index 64b4906..b110f89 100644 Binary files a/manup-demo/resources/ios/icon/icon-40@2x.png and b/manup-demo/resources/ios/icon/icon-40@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-40@3x.png b/manup-demo/resources/ios/icon/icon-40@3x.png index 1291a2f..ea9a9c7 100644 Binary files a/manup-demo/resources/ios/icon/icon-40@3x.png and b/manup-demo/resources/ios/icon/icon-40@3x.png differ diff --git a/manup-demo/resources/ios/icon/icon-50.png b/manup-demo/resources/ios/icon/icon-50.png index 8bd51df..71b51a2 100644 Binary files a/manup-demo/resources/ios/icon/icon-50.png and b/manup-demo/resources/ios/icon/icon-50.png differ diff --git a/manup-demo/resources/ios/icon/icon-50@2x.png b/manup-demo/resources/ios/icon/icon-50@2x.png index 2676f8f..40a2995 100644 Binary files a/manup-demo/resources/ios/icon/icon-50@2x.png and b/manup-demo/resources/ios/icon/icon-50@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-60.png b/manup-demo/resources/ios/icon/icon-60.png index 11f3912..bdbccd3 100644 Binary files a/manup-demo/resources/ios/icon/icon-60.png and b/manup-demo/resources/ios/icon/icon-60.png differ diff --git a/manup-demo/resources/ios/icon/icon-60@2x.png b/manup-demo/resources/ios/icon/icon-60@2x.png index b521048..b97133c 100644 Binary files a/manup-demo/resources/ios/icon/icon-60@2x.png and b/manup-demo/resources/ios/icon/icon-60@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-60@3x.png b/manup-demo/resources/ios/icon/icon-60@3x.png index dbc8303..b1e024b 100644 Binary files a/manup-demo/resources/ios/icon/icon-60@3x.png and b/manup-demo/resources/ios/icon/icon-60@3x.png differ diff --git a/manup-demo/resources/ios/icon/icon-72.png b/manup-demo/resources/ios/icon/icon-72.png index 4e5a827..539576b 100644 Binary files a/manup-demo/resources/ios/icon/icon-72.png and b/manup-demo/resources/ios/icon/icon-72.png differ diff --git a/manup-demo/resources/ios/icon/icon-72@2x.png b/manup-demo/resources/ios/icon/icon-72@2x.png index 56fb29e..5b6e551 100644 Binary files a/manup-demo/resources/ios/icon/icon-72@2x.png and b/manup-demo/resources/ios/icon/icon-72@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-76.png b/manup-demo/resources/ios/icon/icon-76.png index e66a90e..54d533d 100644 Binary files a/manup-demo/resources/ios/icon/icon-76.png and b/manup-demo/resources/ios/icon/icon-76.png differ diff --git a/manup-demo/resources/ios/icon/icon-76@2x.png b/manup-demo/resources/ios/icon/icon-76@2x.png index 3f5c942..555ade4 100644 Binary files a/manup-demo/resources/ios/icon/icon-76@2x.png and b/manup-demo/resources/ios/icon/icon-76@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-83.5@2x.png b/manup-demo/resources/ios/icon/icon-83.5@2x.png index 1dca548..e836805 100644 Binary files a/manup-demo/resources/ios/icon/icon-83.5@2x.png and b/manup-demo/resources/ios/icon/icon-83.5@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-small.png b/manup-demo/resources/ios/icon/icon-small.png index de3146d..5e8c658 100644 Binary files a/manup-demo/resources/ios/icon/icon-small.png and b/manup-demo/resources/ios/icon/icon-small.png differ diff --git a/manup-demo/resources/ios/icon/icon-small@2x.png b/manup-demo/resources/ios/icon/icon-small@2x.png index 916a02e..4c5c488 100644 Binary files a/manup-demo/resources/ios/icon/icon-small@2x.png and b/manup-demo/resources/ios/icon/icon-small@2x.png differ diff --git a/manup-demo/resources/ios/icon/icon-small@3x.png b/manup-demo/resources/ios/icon/icon-small@3x.png index 0efa99d..cfe92c8 100644 Binary files a/manup-demo/resources/ios/icon/icon-small@3x.png and b/manup-demo/resources/ios/icon/icon-small@3x.png differ diff --git a/manup-demo/resources/ios/icon/icon.png b/manup-demo/resources/ios/icon/icon.png index 89f8c00..c66ca8f 100644 Binary files a/manup-demo/resources/ios/icon/icon.png and b/manup-demo/resources/ios/icon/icon.png differ diff --git a/manup-demo/resources/ios/icon/icon@2x.png b/manup-demo/resources/ios/icon/icon@2x.png index a6687a1..fdd3b72 100644 Binary files a/manup-demo/resources/ios/icon/icon@2x.png and b/manup-demo/resources/ios/icon/icon@2x.png differ diff --git a/manup-demo/resources/ios/splash/Default-568h@2x~iphone.png b/manup-demo/resources/ios/splash/Default-568h@2x~iphone.png index d2128a6..ed5f447 100644 Binary files a/manup-demo/resources/ios/splash/Default-568h@2x~iphone.png and b/manup-demo/resources/ios/splash/Default-568h@2x~iphone.png differ diff --git a/manup-demo/resources/ios/splash/Default-667h.png b/manup-demo/resources/ios/splash/Default-667h.png index fc23e64..b5176d8 100644 Binary files a/manup-demo/resources/ios/splash/Default-667h.png and b/manup-demo/resources/ios/splash/Default-667h.png differ diff --git a/manup-demo/resources/ios/splash/Default-736h.png b/manup-demo/resources/ios/splash/Default-736h.png index 71b16ca..4a26f63 100644 Binary files a/manup-demo/resources/ios/splash/Default-736h.png and b/manup-demo/resources/ios/splash/Default-736h.png differ diff --git a/manup-demo/resources/ios/splash/Default-Landscape-736h.png b/manup-demo/resources/ios/splash/Default-Landscape-736h.png index aaff74a..70056dd 100644 Binary files a/manup-demo/resources/ios/splash/Default-Landscape-736h.png and b/manup-demo/resources/ios/splash/Default-Landscape-736h.png differ diff --git a/manup-demo/resources/ios/splash/Default-Landscape@2x~ipad.png b/manup-demo/resources/ios/splash/Default-Landscape@2x~ipad.png index 19770a2..567cd21 100644 Binary files a/manup-demo/resources/ios/splash/Default-Landscape@2x~ipad.png and b/manup-demo/resources/ios/splash/Default-Landscape@2x~ipad.png differ diff --git a/manup-demo/resources/ios/splash/Default-Landscape@~ipadpro.png b/manup-demo/resources/ios/splash/Default-Landscape@~ipadpro.png new file mode 100644 index 0000000..976fad1 Binary files /dev/null and b/manup-demo/resources/ios/splash/Default-Landscape@~ipadpro.png differ diff --git a/manup-demo/resources/ios/splash/Default-Landscape~ipad.png b/manup-demo/resources/ios/splash/Default-Landscape~ipad.png index 6fe8925..716bc1e 100644 Binary files a/manup-demo/resources/ios/splash/Default-Landscape~ipad.png and b/manup-demo/resources/ios/splash/Default-Landscape~ipad.png differ diff --git a/manup-demo/resources/ios/splash/Default-Portrait@2x~ipad.png b/manup-demo/resources/ios/splash/Default-Portrait@2x~ipad.png index 3d06d86..ffa5d1b 100644 Binary files a/manup-demo/resources/ios/splash/Default-Portrait@2x~ipad.png and b/manup-demo/resources/ios/splash/Default-Portrait@2x~ipad.png differ diff --git a/manup-demo/resources/ios/splash/Default-Portrait@~ipadpro.png b/manup-demo/resources/ios/splash/Default-Portrait@~ipadpro.png new file mode 100644 index 0000000..85b3e77 Binary files /dev/null and b/manup-demo/resources/ios/splash/Default-Portrait@~ipadpro.png differ diff --git a/manup-demo/resources/ios/splash/Default-Portrait~ipad.png b/manup-demo/resources/ios/splash/Default-Portrait~ipad.png index 53ad4c4..361e780 100644 Binary files a/manup-demo/resources/ios/splash/Default-Portrait~ipad.png and b/manup-demo/resources/ios/splash/Default-Portrait~ipad.png differ diff --git a/manup-demo/resources/ios/splash/Default@2x~iphone.png b/manup-demo/resources/ios/splash/Default@2x~iphone.png index 6a13316..aba85db 100644 Binary files a/manup-demo/resources/ios/splash/Default@2x~iphone.png and b/manup-demo/resources/ios/splash/Default@2x~iphone.png differ diff --git a/manup-demo/resources/ios/splash/Default@2x~universal~anyany.png b/manup-demo/resources/ios/splash/Default@2x~universal~anyany.png new file mode 100644 index 0000000..0f7f6ef Binary files /dev/null and b/manup-demo/resources/ios/splash/Default@2x~universal~anyany.png differ diff --git a/manup-demo/resources/ios/splash/Default~iphone.png b/manup-demo/resources/ios/splash/Default~iphone.png index 0aaad62..65fa805 100644 Binary files a/manup-demo/resources/ios/splash/Default~iphone.png and b/manup-demo/resources/ios/splash/Default~iphone.png differ diff --git a/manup-demo/resources/splash.png b/manup-demo/resources/splash.png index cbddba0..37e8ee7 100644 Binary files a/manup-demo/resources/splash.png and b/manup-demo/resources/splash.png differ diff --git a/manup-demo/src/app/app.component.ts b/manup-demo/src/app/app.component.ts index 689052a..1197ad4 100644 --- a/manup-demo/src/app/app.component.ts +++ b/manup-demo/src/app/app.component.ts @@ -1,28 +1,34 @@ import { Component } from '@angular/core'; +import { SplashScreen } from '@ionic-native/splash-screen'; +import { StatusBar } from '@ionic-native/status-bar'; +import { TranslateService } from '@ngx-translate/core'; import { Platform } from 'ionic-angular'; -import { StatusBar, Splashscreen } from 'ionic-native'; - -import { TabsPage } from '../pages/tabs/tabs'; - import { ManUpService } from 'ionic-manup'; -import { TranslateService } from 'ng2-translate' + +import { HomePage } from '../pages/home/home'; @Component({ templateUrl: 'app.html' }) export class MyApp { - rootPage = TabsPage; + rootPage: any = HomePage; - constructor(platform: Platform, private manup: ManUpService, private translate: TranslateService) { - translate.setDefaultLang('es'); + constructor( + platform: Platform, + statusBar: StatusBar, + splashScreen: SplashScreen, + manup: ManUpService, + translate: TranslateService + ) { platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. - StatusBar.styleDefault(); - Splashscreen.hide(); + translate.setDefaultLang('es'); manup.validate(); + statusBar.styleDefault(); + splashScreen.hide(); }); } } diff --git a/manup-demo/src/app/app.module.ts b/manup-demo/src/app/app.module.ts index db808e3..85bb62e 100644 --- a/manup-demo/src/app/app.module.ts +++ b/manup-demo/src/app/app.module.ts @@ -1,46 +1,51 @@ -import { NgModule, ErrorHandler } from '@angular/core'; -import { Http } from '@angular/http'; -import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; -import { MyApp } from './app.component'; -import { AboutPage } from '../pages/about/about'; -import { ContactPage } from '../pages/contact/contact'; -import { HomePage } from '../pages/home/home'; -import { TabsPage } from '../pages/tabs/tabs'; -import { ManUpModule, ManUpService } from 'ionic-manup'; -import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate'; +import { HttpClient, HttpClientModule } from '@angular/common/http'; +import { ErrorHandler, NgModule } from '@angular/core'; +import { HttpModule } from '@angular/http'; +import { BrowserModule } from '@angular/platform-browser'; +import { AppVersion } from '@ionic-native/app-version'; +import { InAppBrowser } from '@ionic-native/in-app-browser'; +import { SplashScreen } from '@ionic-native/splash-screen'; +import { StatusBar } from '@ionic-native/status-bar'; +import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core'; +import { TranslateHttpLoader } from '@ngx-translate/http-loader'; +import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; +import { ManUpModule, ManUpService, TRANSLATE_SERVICE } from 'ionic-manup'; +import { HomePage } from '../pages/home/home'; +import { MyApp } from './app.component'; -export function translateLoader(http: Http) { - return new TranslateStaticLoader(http, 'assets/i18n', '.json'); +export function translateLoader(http: HttpClient) { + return new TranslateHttpLoader(http, 'assets/i18n/', '.json'); } - @NgModule({ - declarations: [ - MyApp, - AboutPage, - ContactPage, - HomePage, - TabsPage - ], + declarations: [MyApp, HomePage], imports: [ + BrowserModule, IonicModule.forRoot(MyApp), - ManUpModule.forRoot({url: 'https://raw.githubusercontent.com/NextFaze/ionic-manup/master/manup-demo/manup.json', externalTranslations: true}), + HttpModule, + HttpClientModule, + ManUpModule.forRoot({ + url: 'https://raw.githubusercontent.com/NextFaze/ionic-manup/master/manup-demo/manup.json', + externalTranslations: true + }), TranslateModule.forRoot({ - provide: TranslateLoader, - useFactory: (translateLoader), - deps: [Http] + loader: { + provide: TranslateLoader, + useFactory: translateLoader, + deps: [HttpClient] + } }) ], bootstrap: [IonicApp], - entryComponents: [ - MyApp, - AboutPage, - ContactPage, - HomePage, - TabsPage + providers: [ + AppVersion, + { provide: ErrorHandler, useClass: IonicErrorHandler }, + { provide: TRANSLATE_SERVICE, useClass: TranslateService }, + ManUpService, + SplashScreen, + InAppBrowser, + StatusBar ], - providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, - ManUpService - ] + entryComponents: [MyApp, HomePage] }) export class AppModule {} diff --git a/manup-demo/src/index.html b/manup-demo/src/index.html index e6106b1..9585b8a 100644 --- a/manup-demo/src/index.html +++ b/manup-demo/src/index.html @@ -3,7 +3,7 @@ Ionic App - + @@ -11,6 +11,10 @@ + + + + @@ -19,7 +23,7 @@ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service-worker.js') .then(() => console.log('service worker installed')) - .catch(err => console.log('Error', err)); + .catch(err => console.error('Error', err)); } --> @@ -34,7 +38,11 @@ - + + + + diff --git a/manup-demo/src/pages/about/about.html b/manup-demo/src/pages/about/about.html deleted file mode 100644 index 2763c93..0000000 --- a/manup-demo/src/pages/about/about.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - About - - - - - - - diff --git a/manup-demo/src/pages/about/about.scss b/manup-demo/src/pages/about/about.scss deleted file mode 100644 index 639956d..0000000 --- a/manup-demo/src/pages/about/about.scss +++ /dev/null @@ -1,3 +0,0 @@ -page-about { - -} diff --git a/manup-demo/src/pages/about/about.ts b/manup-demo/src/pages/about/about.ts deleted file mode 100644 index 1b4c5ad..0000000 --- a/manup-demo/src/pages/about/about.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component } from '@angular/core'; - -import { NavController } from 'ionic-angular'; - -@Component({ - selector: 'page-about', - templateUrl: 'about.html' -}) -export class AboutPage { - - constructor(public navCtrl: NavController) { - - } - -} diff --git a/manup-demo/src/pages/contact/contact.html b/manup-demo/src/pages/contact/contact.html deleted file mode 100644 index c6ce324..0000000 --- a/manup-demo/src/pages/contact/contact.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - Contact - - - - - - - Follow us on Twitter - - - @ionicframework - - - diff --git a/manup-demo/src/pages/contact/contact.scss b/manup-demo/src/pages/contact/contact.scss deleted file mode 100644 index 13d4440..0000000 --- a/manup-demo/src/pages/contact/contact.scss +++ /dev/null @@ -1,3 +0,0 @@ -page-contact { - -} diff --git a/manup-demo/src/pages/contact/contact.ts b/manup-demo/src/pages/contact/contact.ts deleted file mode 100644 index a344720..0000000 --- a/manup-demo/src/pages/contact/contact.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component } from '@angular/core'; - -import { NavController } from 'ionic-angular'; - -@Component({ - selector: 'page-contact', - templateUrl: 'contact.html' -}) -export class ContactPage { - - constructor(public navCtrl: NavController) { - - } - -} diff --git a/manup-demo/src/pages/home/home.html b/manup-demo/src/pages/home/home.html index 485991e..bbe6e77 100644 --- a/manup-demo/src/pages/home/home.html +++ b/manup-demo/src/pages/home/home.html @@ -1,17 +1,14 @@ - Home + + Ionic Blank + -

Welcome to Ionic!

+ The world is your oyster.

- This starter project comes with simple tabs-based layout for apps - that are going to primarily use a Tabbed UI. -

-

- Take a look at the src/pages/ directory to add or change tabs, - update any existing page or create new pages. + If you get lost, the docs will be your guide.

diff --git a/manup-demo/src/pages/home/home.ts b/manup-demo/src/pages/home/home.ts index e9f7e6a..1d510dd 100644 --- a/manup-demo/src/pages/home/home.ts +++ b/manup-demo/src/pages/home/home.ts @@ -1,5 +1,4 @@ import { Component } from '@angular/core'; - import { NavController } from 'ionic-angular'; @Component({ diff --git a/manup-demo/src/pages/tabs/tabs.html b/manup-demo/src/pages/tabs/tabs.html deleted file mode 100644 index fa3921a..0000000 --- a/manup-demo/src/pages/tabs/tabs.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/manup-demo/src/pages/tabs/tabs.ts b/manup-demo/src/pages/tabs/tabs.ts deleted file mode 100644 index a95cdf4..0000000 --- a/manup-demo/src/pages/tabs/tabs.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Component } from '@angular/core'; - -import { HomePage } from '../home/home'; -import { AboutPage } from '../about/about'; -import { ContactPage } from '../contact/contact'; - -@Component({ - templateUrl: 'tabs.html' -}) -export class TabsPage { - // this tells the tabs component which Pages - // should be each tab's root Page - tab1Root: any = HomePage; - tab2Root: any = AboutPage; - tab3Root: any = ContactPage; - - constructor() { - - } -} diff --git a/manup-demo/src/theme/variables.scss b/manup-demo/src/theme/variables.scss index 12c82d5..18276a4 100644 --- a/manup-demo/src/theme/variables.scss +++ b/manup-demo/src/theme/variables.scss @@ -1,7 +1,17 @@ // Ionic Variables and Theming. For more info, please see: -// http://ionicframework.com/docs/v2/theming/ +// http://ionicframework.com/docs/theming/ + +// Font path is used to include ionicons, +// roboto, and noto sans fonts $font-path: "../assets/fonts"; + +// The app direction is used to include +// rtl styles in your app. For more info, please see: +// http://ionicframework.com/docs/theming/rtl-support/ +$app-direction: ltr; + + @import "ionic.globals"; @@ -10,7 +20,7 @@ $font-path: "../assets/fonts"; // To customize the look and feel of this app, you can override // the Sass variables found in Ionic's source scss files. // To view all the possible Ionic variables, see: -// http://ionicframework.com/docs/v2/theming/overriding-ionic-variables/ +// http://ionicframework.com/docs/theming/overriding-ionic-variables/ @@ -24,7 +34,7 @@ $font-path: "../assets/fonts"; // The "primary" color is the only required color in the map. $colors: ( - primary: #387ef5, + primary: #488aff, secondary: #32db64, danger: #f53d3d, light: #f4f4f4, @@ -66,7 +76,7 @@ $colors: ( // Ionicons // -------------------------------------------------- // The premium icon font for Ionic. For more info, please see: -// http://ionicframework.com/docs/v2/ionicons/ +// http://ionicframework.com/docs/ionicons/ @import "ionic.ionicons"; diff --git a/manup-demo/tsconfig.json b/manup-demo/tsconfig.json index df50ddf..2e450f9 100644 --- a/manup-demo/tsconfig.json +++ b/manup-demo/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "allowSyntheticDefaultImports": true, - "declaration": true, + "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ @@ -23,4 +23,4 @@ "atom": { "rewriteTsconfig": false } -} +} \ No newline at end of file diff --git a/package.json b/package.json index d73ddd6..0f3dc9d 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,14 @@ "scripts": { "clean": "rm -rf lib", "mocha": "node_modules/.bin/mocha", - "test": "ng test --single-run --code-coverage", "posttest": "npm run coveralls", "tsc": "node_modules/.bin/tsc", "ngc": "node_modules/.bin/ngc", "build": "npm run ngc", "prebuild": "npm run clean", "prepublish": "npm run build", - "coveralls": "./node_modules/coveralls/bin/coveralls.js < coverage/coverage.lcov" + "coveralls": "./node_modules/coveralls/bin/coveralls.js < coverage/lcov.info", + "test": "karma start ./test-config/karma.conf.js --single-run --coverage" }, "repository": { "type": "git", @@ -28,36 +28,45 @@ "author": "Michael Marner ", "license": "MIT", "devDependencies": { - "@angular/common": "^2.2.1", - "@angular/compiler": "^2.2.1", - "@angular/compiler-cli": "^2.2.1", - "@angular/core": "^2.2.1", - "@angular/forms": "^2.2.1", - "@angular/http": "^2.2.1", - "@angular/platform-browser": "^2.2.1", - "@angular/platform-browser-dynamic": "^2.2.1", - "@angular/platform-server": "^2.2.1", + "@angular/common": "^4.4.3", + "@angular/compiler": "^4.4.3", + "@angular/compiler-cli": "^4.4.3", + "@angular/core": "^4.4.3", + "@angular/forms": "^4.4.3", + "@angular/http": "^4.4.3", + "@angular/platform-browser": "^4.4.3", + "@angular/platform-browser-dynamic": "^4.4.3", + "@angular/platform-server": "^4.4.3", + "@ionic-native/app-version": "^4.3.1", + "@ionic-native/core": "^4.3.1", + "@ionic-native/in-app-browser": "^4.3.1", "@ionic/storage": "^1.1.9", "@ngx-translate/core": "^7.0.0", "@types/jasmine": "^2.5.41", "@types/node": "^7.0.5", "@types/semver": "^5.3.30", - "angular-cli": "^1.0.0-beta.28.3", + "angular2-template-loader": "^0.6.2", "codecov": "^1.0.1", "coveralls": "^2.11.16", "ionic-angular": "^2.0.0", - "ionic-native": "^2.4.1", + "istanbul-instrumenter-loader": "^3.0.0", "jasmine-core": "^2.5.2", "jasmine-spec-reporter": "^3.2.0", "karma": "^1.4.1", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", + "karma-coverage": "^1.1.1", + "karma-coverage-istanbul-reporter": "^1.3.0", "karma-jasmine": "^1.1.0", + "karma-jasmine-html-reporter": "^0.2.2", "karma-mocha-reporter": "^2.2.2", - "karma-phantomjs-launcher": "^1.0.2", "karma-remap-istanbul": "^0.6.0", + "karma-sourcemap-loader": "^0.3.7", + "karma-typescript": "^3.0.7", + "karma-webpack": "^2.0.4", "mocha": "^3.2.0", "rxjs": "^5.0.0-beta.12", + "ts-loader": "^2.3.7", "ts-node": "^2.1.0", "tslint": "^4.4.2", "tslint-eslint-rules": "^3.3.0", @@ -68,6 +77,10 @@ "peerDependencies": { "@angular/common": "^2.0.0", "@angular/core": "^2.0.0", + "@ionic/storage": "^1.1.9", + "@ionic-native/app-version": "^4.3.1", + "@ionic-native/core": "^4.3.1", + "@ionic-native/in-app-browser": "^4.3.1", "rxjs": "^5.0.0-beta.12", "zone.js": "^0.6.26" }, diff --git a/src/manup.service.ts b/src/manup.service.ts index 9f64934..5f8b120 100644 --- a/src/manup.service.ts +++ b/src/manup.service.ts @@ -1,174 +1,172 @@ -import { TranslateService } from '@ngx-translate/core'; -import { ManUpConfig } from './manup.config'; -import { AlertController, Platform } from 'ionic-angular'; +import 'rxjs/add/observable/fromPromise'; +import 'rxjs/add/operator/map'; + +import { Inject, Injectable, InjectionToken, Optional } from '@angular/core'; import { Http } from '@angular/http'; -import { Injectable, Optional } from '@angular/core'; -import { AppVersion, InAppBrowser } from 'ionic-native'; -import { Observable } from 'rxjs'; +import { AppVersion } from '@ionic-native/app-version'; +import { InAppBrowser } from '@ionic-native/in-app-browser'; import { Storage } from '@ionic/storage'; +import { AlertController, Platform } from 'ionic-angular'; +import { Observable } from 'rxjs'; +import * as semver from 'semver'; import { i18n } from './i18n'; +import { ManUpConfig } from './manup.config'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/observable/fromPromise'; - -import * as semver from 'semver'; +/** + * DI InjectionToken for optional ngx-translate + */ +export const TRANSLATE_SERVICE: any = new InjectionToken('manup:translate'); -const STORAGE_KEY='com.nextfaze.ionic-manup'; +const STORAGE_KEY = 'com.nextfaze.ionic-manup'; /** * The types of alerts we may present */ export enum AlertType { - /** + /** * A mandatory update is required */ - MANDATORY, + MANDATORY, - /** + /** * An optional update is available */ - OPTIONAL, + OPTIONAL, - /** + /** * The app is disabled */ - MAINTENANCE, + MAINTENANCE, - /** + /** * Nothing to see here */ - NOP + NOP } export interface PlatformData { - minimum: string, - latest: string, - url: string, - enabled: boolean + minimum: string; + latest: string; + url: string; + enabled: boolean; } /** * What the metadata object should look like */ export interface ManUpData { - ios?: PlatformData; - android?: PlatformData; - windows?: PlatformData; + ios?: PlatformData; + android?: PlatformData; + windows?: PlatformData; } @Injectable() export class ManUpService { - /** - * A local reference to Ionic Native's AppVersion class. - * Stored locally so mocks can be injected in for testing. - * - * @type {*} - * @memberOf ManUpService - */ - public AppVersion: any = AppVersion; - - public constructor(private config: ManUpConfig, - private http: Http, - private alert: AlertController, - private platform: Platform, - @Optional() private translate: TranslateService, - @Optional() private storage: Storage) { - - // load the translations unless we've been told not to - if (this.translate && !this.config.externalTranslations) { - for (let lang of i18n) { - this.translate.setTranslation(lang.lang, lang.translations, true); - } - } + public constructor( + private config: ManUpConfig, + private http: Http, + private alert: AlertController, + private platform: Platform, + private iab: InAppBrowser, + private AppVersion: AppVersion, + @Optional() + @Inject(TRANSLATE_SERVICE) + private translate: any, + @Optional() private storage: Storage + ) { + // load the translations unless we've been told not to + if (this.translate && !this.config.externalTranslations) { + for (let lang of i18n) { + this.translate.setTranslation(lang.lang, lang.translations, true); + } } + } - /** + /** * True if there is an alert already displayed. Used to prevent multiple alerts * being presented on top of one another */ - private inProgress: boolean = false; + private inProgress: boolean = false; - /** + /** * A reference to the current unresolved promise */ - private currentPromise: Promise; + private currentPromise: Promise; - /** + /** * Begins the manup check process. * * @Returns a promise that resolves if the app is able to continue. */ - public validate(): Promise { - - if (!this.inProgress) { - this.inProgress = true; - this.currentPromise = new Promise( (resolve, reject) => { - this.platform.ready() - .then( () => { - this.metadata() - .map(response => this.getPlatformData(response)) - .subscribe(metadata => { - this.evaluate(metadata).then(alert => { - switch (alert) { - case AlertType.NOP: - resolve(); - break; - default: - return this.presentAlert(alert, metadata); - } - }, - error => resolve()); - }); - }) + public validate(): Promise { + if (!this.inProgress) { + this.inProgress = true; + this.currentPromise = new Promise((resolve, reject) => { + this.platform.ready().then(() => { + this.metadata() + .map(response => this.getPlatformData(response)) + .subscribe(metadata => { + this.evaluate(metadata).then( + alert => { + switch (alert) { + case AlertType.NOP: + resolve(); + break; + default: + return this.presentAlert(alert, metadata); + } + }, + error => resolve() + ); }); - } - return this.currentPromise; - } - - /** - * Evaluates what kind of update is required, if any. - * - * Returns a promise that resolves with an alert type. - */ - public evaluate(metadata: PlatformData): Promise { - if (!metadata.enabled) { - return Promise.resolve(AlertType.MAINTENANCE); - } - return this.AppVersion.getVersionNumber().then((version:string) => { - - if (semver.lt(version, metadata.minimum)) { - return AlertType.MANDATORY; - } - else if (semver.lt(version, metadata.latest)) { - return AlertType.OPTIONAL; - } - return AlertType.NOP; }); + }); } - - - /** - * Fetches the remote metadata and returns an observable with the json - */ - public metadata(): Observable { - return this.http.get(this.config.url).map(response => response.json()) - .map(response => { - if (this.storage) { - this.saveMetadata(response).catch( () => {}); - } - return response; - }) - .catch(err => { - if (this.storage) { - return this.metadataFromStorage(); - } - return err; - }); + return this.currentPromise; + } + + /** + * Evaluates what kind of update is required, if any. + * + * Returns a promise that resolves with an alert type. + */ + public evaluate(metadata: PlatformData): Promise { + if (!metadata.enabled) { + return Promise.resolve(AlertType.MAINTENANCE); } + return this.AppVersion.getVersionNumber().then((version: string) => { + if (semver.lt(version, metadata.minimum)) { + return AlertType.MANDATORY; + } else if (semver.lt(version, metadata.latest)) { + return AlertType.OPTIONAL; + } + return AlertType.NOP; + }); + } + + /** + * Fetches the remote metadata and returns an observable with the json + */ + public metadata(): Observable { + return this.http + .get(this.config.url) + .map(response => response.json()) + .map(response => { + if (this.storage) { + this.saveMetadata(response).catch(() => {}); + } + return response; + }) + .catch(err => { + if (this.storage) { + return this.metadataFromStorage(); + } + return err; + }); + } - - /** + /** * Gets the version metadata from storage, if available. * * @private @@ -177,16 +175,17 @@ export class ManUpService { * * @memberOf ManUpService */ - metadataFromStorage(): Observable { - if (this.storage) { - return Observable.fromPromise((> this.storage.get(STORAGE_KEY + '.manup'))).map(v=> JSON.parse(v)); - } - else { - throw new Error('Storage not configured'); - } + metadataFromStorage(): Observable { + if (this.storage) { + return Observable.fromPromise(>this.storage.get( + STORAGE_KEY + '.manup' + )).map(v => JSON.parse(v)); + } else { + throw new Error('Storage not configured'); } + } - /** + /** * * Saves the metadata to storage. * @@ -197,33 +196,31 @@ export class ManUpService { * * @memberOf ManUpService */ - public saveMetadata(metadata: ManUpData): Promise { - if (this.storage) { - return this.storage.set(STORAGE_KEY + '.manup', JSON.stringify(metadata)); - } - else { - throw new Error('Storage not configured'); - } + public saveMetadata(metadata: ManUpData): Promise { + if (this.storage) { + return this.storage.set(STORAGE_KEY + '.manup', JSON.stringify(metadata)); + } else { + throw new Error('Storage not configured'); } + } - /** + /** * Returns the branch of the metadata relevant to this platform */ - public getPlatformData(metadata: ManUpData): PlatformData { - if (this.platform.is('ios')) { - return metadata.ios; - } - if (this.platform.is('android')) { - return metadata.android; - } - if (this.platform.is('windows')) { - return metadata.windows; - } - throw new Error('Unknown platform'); + public getPlatformData(metadata: ManUpData): PlatformData { + if (this.platform.is('ios')) { + return metadata.ios; } + if (this.platform.is('android')) { + return metadata.android; + } + if (this.platform.is('windows')) { + return metadata.windows; + } + throw new Error('Unknown platform'); + } - - /** + /** * Presents an update alert. * * @param type The type of alert to show @@ -231,94 +228,106 @@ export class ManUpService { * * @returns A promise that resolves when this whole thing is over. */ - private presentAlert(type: AlertType, platformData: any): Promise { - switch (type) { - case AlertType.MANDATORY: - return this.presentMandatoryUpdate(platformData); + private presentAlert(type: AlertType, platformData: any): Promise { + switch (type) { + case AlertType.MANDATORY: + return this.presentMandatoryUpdate(platformData); - case AlertType.OPTIONAL: - return this.presentOptionalUpdate(platformData); + case AlertType.OPTIONAL: + return this.presentOptionalUpdate(platformData); - case AlertType.MAINTENANCE: - return this.presentMaintenanceMode(); - } + case AlertType.MAINTENANCE: + return this.presentMaintenanceMode(); } + } - /** + /** * Displays a maintenance mode alert. * * @returns a promise that will never resolve, because the app should not continue */ - presentMaintenanceMode(): Promise { - return this.AppVersion.getAppName().then( (name:string) => { - return new Promise((resolve, reject) => { - let alert = this.alert.create({ - enableBackdropDismiss: false, - title: (this.translate) ? this.translate.instant('manup.maintenance.title', {app: name}) : `${name} Unavailable`, - subTitle: (this.translate) ? this.translate.instant('manup.maintenance.text', {app: name}) : `${name} is currently unavailable. Please check back later`, - }) - alert.present(); - }); - }) - } + presentMaintenanceMode(): Promise { + return this.AppVersion.getAppName().then((name: string) => { + return new Promise((resolve, reject) => { + let alert = this.alert.create({ + enableBackdropDismiss: false, + title: this.translate + ? this.translate.instant('manup.maintenance.title', { app: name }) + : `${name} Unavailable`, + subTitle: this.translate + ? this.translate.instant('manup.maintenance.text', { app: name }) + : `${name} is currently unavailable. Please check back later` + }); + alert.present(); + }); + }); + } - /** + /** * Displays a mandatory update alert. * * @returns a promise that will never resolve, because the app should not continue */ - presentMandatoryUpdate(platformData: any): Promise { - return this.AppVersion.getAppName().then( (name:string) => { - return new Promise((resolve, reject) => { - let alert = this.alert.create({ - enableBackdropDismiss: false, - title: (this.translate) ? this.translate.instant('manup.mandatory.title', {app: name}) : "Update Required", - subTitle: (this.translate) ? this.translate.instant('manup.mandatory.text', {app: name}) : `An update to ${name} is required to continue.`, - buttons: [ - { - text: (this.translate) ? this.translate.instant('manup.buttons.update') : 'Update', - handler: () => { - new InAppBrowser(platformData.url, '_system'); - return false; - } - } - ] - }) - alert.present(); - }); + presentMandatoryUpdate(platformData: any): Promise { + return this.AppVersion.getAppName().then((name: string) => { + return new Promise((resolve, reject) => { + let alert = this.alert.create({ + enableBackdropDismiss: false, + title: this.translate + ? this.translate.instant('manup.mandatory.title', { app: name }) + : 'Update Required', + subTitle: this.translate + ? this.translate.instant('manup.mandatory.text', { app: name }) + : `An update to ${name} is required to continue.`, + buttons: [ + { + text: this.translate ? this.translate.instant('manup.buttons.update') : 'Update', + handler: () => { + this.iab.create(platformData.url, '_system'); + return false; + } + } + ] }); - } + alert.present(); + }); + }); + } - /** + /** * Displays an optional update alert. * * @returns a promise that will resolves if the user selects 'not now' */ - presentOptionalUpdate(platformData: any): Promise { - return this.AppVersion.getAppName().then( (name:string) => { - return new Promise((resolve, reject) => { - let alert = this.alert.create({ - enableBackdropDismiss: false, - title: (this.translate) ? this.translate.instant('manup.optional.title', {app: name}) : "Update Available", - subTitle: (this.translate) ? this.translate.instant('manup.optional.text', {app: name}) : `An update to ${name} is available. Would you like to update?`, - buttons: [ - { - text: (this.translate) ? this.translate.instant('manup.buttons.later') : 'Not Now', - handler: () => { - resolve(); - } - }, - { - text: (this.translate) ? this.translate.instant('manup.buttons.update') : 'Update', - handler: () => { - new InAppBrowser(platformData.url, '_system'); - return false; - } - } - ] - }) - alert.present(); - }); + presentOptionalUpdate(platformData: any): Promise { + return this.AppVersion.getAppName().then((name: string) => { + return new Promise((resolve, reject) => { + let alert = this.alert.create({ + enableBackdropDismiss: false, + title: this.translate + ? this.translate.instant('manup.optional.title', { app: name }) + : 'Update Available', + subTitle: this.translate + ? this.translate.instant('manup.optional.text', { app: name }) + : `An update to ${name} is available. Would you like to update?`, + buttons: [ + { + text: this.translate ? this.translate.instant('manup.buttons.later') : 'Not Now', + handler: () => { + resolve(); + } + }, + { + text: this.translate ? this.translate.instant('manup.buttons.update') : 'Update', + handler: () => { + this.iab.create(platformData.url, '_system'); + return false; + } + } + ] }); - } + alert.present(); + }); + }); + } } diff --git a/src/manup.spec.ts b/src/manup.spec.ts index 5549637..38b5670 100644 --- a/src/manup.spec.ts +++ b/src/manup.spec.ts @@ -1,368 +1,409 @@ -import { error } from 'util'; +import 'rxjs/add/observable/of'; + import { Observable } from 'rxjs/Rx'; -import { AlertType, ManUpService } from './manup.service'; -import { ManUpConfig} from './manup.config'; +import { error } from 'util'; -import 'rxjs/add/observable/of'; +import { ManUpConfig } from './manup.config'; +import { AlertType, ManUpService } from './manup.service'; class MockAppVersion { - public static getVersionNumber() { - return Promise.resolve("2.3.4"); - } + public static getVersionNumber() { + return Promise.resolve('2.3.4'); + } } describe('Manup Spec', function() { - - describe('evaluate', function() { - it('Should return maintenance mode if json says disabled', function(done) { - let json = { - minimum: "2.3.4", - latest: "2.3.4", - url: "http://example.com", - enabled: false - }; - - let manup = new ManUpService(null, null, null, null, null,null); - manup.AppVersion = MockAppVersion; - - manup.evaluate(json).then(function(alert) { - expect(alert).toEqual(AlertType.MAINTENANCE); - done(); - }); - }); - it('Should return mandatory update if app version less than minimum', function(done) { - let json = { - minimum: "4.3.4", - latest: "6.3.4", - url: "http://example.com", - enabled: true - }; - - let manup = new ManUpService(null, null, null, null, null,null); - manup.AppVersion = MockAppVersion; - - manup.evaluate(json).then(function(alert) { - expect(alert).toEqual(AlertType.MANDATORY); - done(); - }); - }); - it('Should return optional update if app version less than latest', function(done) { - let json = { - minimum: "2.3.4", - latest: "6.3.4", - url: "http://example.com", - enabled: true - }; - - let manup = new ManUpService(null, null, null, null, null,null); - manup.AppVersion = MockAppVersion; - - manup.evaluate(json).then(function(alert) { - expect(alert).toEqual(AlertType.OPTIONAL); - done(); - }); - }); - it('Should return nop if app version latest', function(done) { - let json = { - minimum: "2.3.4", - latest: "2.3.4", - url: "http://example.com", - enabled: true - }; - - let manup = new ManUpService(null, null, null, null, null,null); - manup.AppVersion = MockAppVersion; - - manup.evaluate(json).then(function(alert) { - expect(alert).toEqual(AlertType.NOP); - done(); - }); - }); + describe('evaluate', function() { + it('Should return maintenance mode if json says disabled', function(done) { + let json = { + minimum: '2.3.4', + latest: '2.3.4', + url: 'http://example.com', + enabled: false + }; + + let manup = new ManUpService(null, null, null, null, null, MockAppVersion, null, null); + + manup.evaluate(json).then(function(alert) { + expect(alert).toEqual(AlertType.MAINTENANCE); + done(); + }); }); - - describe('metadata', function() { - - let config: ManUpConfig = { - url: 'test.example.com' - } - - describe('Http route, no storage configured', () => { - let mockHttp = { - get: function(url: string):Observable { - return Observable.of({ - json: function(): Object { - return { - ios: { - minimum: "1.0.0", - latest: "2.4.5", - enabled: true, - url: "http://http.example.com" - } - } - } - }); + it('Should return mandatory update if app version less than minimum', function(done) { + let json = { + minimum: '4.3.4', + latest: '6.3.4', + url: 'http://example.com', + enabled: true + }; + + let manup = new ManUpService(null, null, null, null, null, MockAppVersion, null, null); + + manup.evaluate(json).then(function(alert) { + expect(alert).toEqual(AlertType.MANDATORY); + done(); + }); + }); + it('Should return optional update if app version less than latest', function(done) { + let json = { + minimum: '2.3.4', + latest: '6.3.4', + url: 'http://example.com', + enabled: true + }; + + let manup = new ManUpService(null, null, null, null, null, MockAppVersion, null, null); + + manup.evaluate(json).then(function(alert) { + expect(alert).toEqual(AlertType.OPTIONAL); + done(); + }); + }); + it('Should return nop if app version latest', function(done) { + let json = { + minimum: '2.3.4', + latest: '2.3.4', + url: 'http://example.com', + enabled: true + }; + + let manup = new ManUpService(null, null, null, null, null, MockAppVersion, null, null); + + manup.evaluate(json).then(function(alert) { + expect(alert).toEqual(AlertType.NOP); + done(); + }); + }); + }); + + describe('metadata', function() { + let config: ManUpConfig = { + url: 'test.example.com' + }; + + describe('Http route, no storage configured', () => { + let mockHttp = { + get: function(url: string): Observable { + return Observable.of({ + json: function(): Object { + return { + ios: { + minimum: '1.0.0', + latest: '2.4.5', + enabled: true, + url: 'http://http.example.com' } - }; - it('Should make an http request', function(done) { - spyOn(mockHttp, 'get').and.callThrough(); - let manup = new ManUpService(config, mockHttp, null, null, null,null); - manup.metadata().subscribe(data => { - expect(mockHttp.get).toHaveBeenCalled(); - done(); - }) - }) - it('Should return json', function(done) { - let manup = new ManUpService(config, mockHttp, null, null, null,null); - manup.metadata().subscribe(data => { - expect(data.ios).toBeDefined(); - expect(data.ios.url).toBe('http://http.example.com'); - done(); - }) - }) + }; + } + }); + } + }; + it('Should make an http request', function(done) { + spyOn(mockHttp, 'get').and.callThrough(); + let manup = new ManUpService(config, mockHttp, null, null, null, null, null, null); + manup.metadata().subscribe(data => { + expect(mockHttp.get).toHaveBeenCalled(); + done(); + }); + }); + it('Should return json', function(done) { + let manup = new ManUpService(config, mockHttp, null, null, null, null, null, null); + manup.metadata().subscribe(data => { + expect(data.ios).toBeDefined(); + expect(data.ios.url).toBe('http://http.example.com'); + done(); }); + }); + }); - describe('Http route, with storage', () => { - let mockHttp = { - get: function(url: string):Observable { - return Observable.of({ - json: function(): Object { - return { - ios: { - minimum: "1.0.0", - latest: "2.4.5", - enabled: true, - url: "http://http.example.com" - } - } - } - }); - } - }; - let mockStorage = { - set(key: string, value: string) { - return Promise.resolve(); + describe('Http route, with storage', () => { + let mockHttp = { + get: function(url: string): Observable { + return Observable.of({ + json: function(): Object { + return { + ios: { + minimum: '1.0.0', + latest: '2.4.5', + enabled: true, + url: 'http://http.example.com' } + }; } - let response: any; - let manup: any; - - beforeAll( done => { - manup = new ManUpService(config, mockHttp, null, null, null, mockStorage); - spyOn(mockHttp, 'get').and.callThrough(); - spyOn(manup, 'saveMetadata').and.callThrough(); - manup.metadata().subscribe( (data:any) => { - response = data; - done(); - }); - }) - it('Should make an http request', () => { - expect(mockHttp.get).toHaveBeenCalled(); - }) - it('Should store the result to storage', () => { - expect(manup.saveMetadata).toHaveBeenCalled(); - }) - it('Should return json', () => { - expect(response.ios).toBeDefined(); - expect(response.ios.url).toBe('http://http.example.com'); - }) + }); + } + }; + let mockStorage = { + set(key: string, value: string) { + return Promise.resolve(); + } + }; + let response: any; + let manup: any; + + beforeAll(done => { + manup = new ManUpService( + config, + mockHttp, + null, + null, + null, + null, + null, + mockStorage + ); + spyOn(mockHttp, 'get').and.callThrough(); + spyOn(manup, 'saveMetadata').and.callThrough(); + manup.metadata().subscribe((data: any) => { + response = data; + done(); }); + }); + it('Should make an http request', () => { + expect(mockHttp.get).toHaveBeenCalled(); + }); + it('Should store the result to storage', () => { + expect(manup.saveMetadata).toHaveBeenCalled(); + }); + it('Should return json', () => { + expect(response.ios).toBeDefined(); + expect(response.ios.url).toBe('http://http.example.com'); + }); + }); - describe('Fallback to storage', () => { - let mockHttp: any; - let mockStorage: any; - - beforeEach( () => { - mockHttp = { - get: function(url: string):Observable { - return Observable.throw(new Error('HTTP Failed')); - } - }; - mockStorage = { - get(key: string) { - return Promise.resolve(JSON.stringify({ - ios: { - minimum: "1.0.0", - latest: "2.4.5", - enabled: true, - url: "http://storage.example.com" - } - })); - }, - set(key: string, value: string) { - return Promise.resolve(); - } + describe('Fallback to storage', () => { + let mockHttp: any; + let mockStorage: any; + + beforeEach(() => { + mockHttp = { + get: function(url: string): Observable { + return Observable.throw(new Error('HTTP Failed')); + } + }; + mockStorage = { + get(key: string) { + return Promise.resolve( + JSON.stringify({ + ios: { + minimum: '1.0.0', + latest: '2.4.5', + enabled: true, + url: 'http://storage.example.com' } - spyOn(mockHttp, 'get').and.callThrough(); - spyOn(mockStorage, 'get').and.callThrough(); - spyOn(mockStorage, 'set').and.callThrough(); - }) - - it('Should make an http request', function(done) { - let manup = new ManUpService(config, mockHttp, null, null, null, mockStorage); - manup.metadata().subscribe(data => { - expect(mockHttp.get).toHaveBeenCalled(); - done(); - }) - }) - it('Should fallback to storage', function(done) { - let manup = new ManUpService(config, mockHttp, null, null, null, mockStorage); - manup.metadata().subscribe(data => { - expect(mockStorage.get).toHaveBeenCalled(); - done(); - }) - }) - it('Should return json', function(done) { - let manup = new ManUpService(config, mockHttp, null, null, null, mockStorage); - manup.metadata().subscribe(data => { - expect(data.ios).toBeDefined(); - expect(data.ios.url).toBe('http://storage.example.com'); - done(); - }) - }) + }) + ); + }, + set(key: string, value: string) { + return Promise.resolve(); + } + }; + spyOn(mockHttp, 'get').and.callThrough(); + spyOn(mockStorage, 'get').and.callThrough(); + spyOn(mockStorage, 'set').and.callThrough(); + }); + + it('Should make an http request', function(done) { + let manup = new ManUpService( + config, + mockHttp, + null, + null, + null, + null, + null, + mockStorage + ); + manup.metadata().subscribe(data => { + expect(mockHttp.get).toHaveBeenCalled(); + done(); }); - - }) - - describe('metadataFromStorage', function() { - - it('Should return data from storage, if it exists', done => { - let metadata = {ios: {minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com'}}; - let mockStorage = { - get(key: string) { - return Promise.resolve(JSON.stringify(metadata)); - } - } - spyOn(mockStorage, 'get').and.callThrough(); - let manup = new ManUpService(null, null, null, null, null, mockStorage); - manup.metadataFromStorage() - .subscribe( (data) => { - expect(mockStorage.get).toHaveBeenCalledWith('com.nextfaze.ionic-manup.manup'); - expect(data).toEqual(metadata); - done(); - }) - }) - - it('Should error if data is not stored ', function(done) { - let mockStorage = { - get(key: string) { - return Promise.reject(new Error('not found')); - } - } - spyOn(mockStorage, 'get').and.callThrough(); - let manup = new ManUpService(null, null, null, null, null, mockStorage); - manup.metadataFromStorage() - .subscribe( - data => { - expect(data).toBe(false); - }, - error => { - expect(error).toBeDefined(); - done(); - } - ) - }) - it('Should throw an exception if storage not configured', done => { - let manup = new ManUpService(null, null, null, null, null, null); - expect(() => {manup.metadataFromStorage()}).toThrowError(); - done(); - }) + }); + it('Should fallback to storage', function(done) { + let manup = new ManUpService( + config, + mockHttp, + null, + null, + null, + null, + null, + mockStorage + ); + manup.metadata().subscribe(data => { + expect(mockStorage.get).toHaveBeenCalled(); + done(); + }); + }); + it('Should return json', function(done) { + let manup = new ManUpService( + config, + mockHttp, + null, + null, + null, + null, + null, + mockStorage + ); + manup.metadata().subscribe(data => { + expect(data.ios).toBeDefined(); + expect(data.ios.url).toBe('http://storage.example.com'); + done(); + }); + }); }); - - describe('saveMetaData', function() { - let mockStorage = { - set(key: string, value: string) { - return Promise.resolve(); - } + }); + + describe('metadataFromStorage', function() { + it('Should return data from storage, if it exists', done => { + let metadata = { + ios: { minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com' } + }; + let mockStorage = { + get(key: string) { + return Promise.resolve(JSON.stringify(metadata)); } + }; + spyOn(mockStorage, 'get').and.callThrough(); + let manup = new ManUpService(null, null, null, null, null, null, null, mockStorage); + manup.metadataFromStorage().subscribe(data => { + expect(mockStorage.get).toHaveBeenCalledWith('com.nextfaze.ionic-manup.manup'); + expect(data).toEqual(metadata); + done(); + }); + }); - it('Should save the item if storage configured', done => { - spyOn(mockStorage, 'set').and.callThrough(); - let manup = new ManUpService(null, null, null, null, null, mockStorage); - let metadata = {ios: {minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com'}}; - manup.saveMetadata(metadata) - .then( () => { - expect(mockStorage.set).toHaveBeenCalledWith('com.nextfaze.ionic-manup.manup', JSON.stringify(metadata)) - done(); - }) - }); - - it('Should throw an exception if storage not configured', done => { - let metadata = {ios: {minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com'}}; - let manup = new ManUpService(null, null, null, null, null, null); - expect(() => {manup.saveMetadata(metadata)}).toThrowError(); - done(); - }) - }) - - describe('getPlatformData', function() { - let json = { - ios: { - minimum: "1.0.0", - latest: "2.4.5", - enabled: true, - url: "http://example.com" - }, - android: { - minimum: "4.0.1", - latest: "6.2.1", - enabled: true, - url: "http://example.com" - }, - windows: { - minimum: "1.0.0", - latest: "1.0.1", - enabled: false, - url: "http://example.com" - }, + it('Should error if data is not stored ', function(done) { + let mockStorage = { + get(key: string) { + return Promise.reject(new Error('not found')); } + }; + spyOn(mockStorage, 'get').and.callThrough(); + let manup = new ManUpService(null, null, null, null, null, null, null, mockStorage); + manup.metadataFromStorage().subscribe( + data => { + expect(true).toBe(false); + }, + error => { + expect(error).toBeDefined(); + done(); + } + ); + }); + it('Should throw an exception if storage not configured', done => { + let manup = new ManUpService(null, null, null, null, null, null, null, null); + expect(() => { + manup.metadataFromStorage(); + }).toThrowError(); + done(); + }); + }); + + describe('saveMetaData', function() { + let mockStorage = { + set(key: string, value: string) { + return Promise.resolve(); + } + }; + + it('Should save the item if storage configured', done => { + spyOn(mockStorage, 'set').and.callThrough(); + let manup = new ManUpService(null, null, null, null, null, null, null, mockStorage); + let metadata = { + ios: { minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com' } + }; + manup.saveMetadata(metadata).then(() => { + expect(mockStorage.set).toHaveBeenCalledWith( + 'com.nextfaze.ionic-manup.manup', + JSON.stringify(metadata) + ); + done(); + }); + }); - it('should return IOS metadata if platform is ios', function() { - let mockPlatform = { - is: function(v: String) { - return v === 'ios' - } - }; - let manup = new ManUpService(null, null, null, mockPlatform, null,null); - - let result = manup.getPlatformData(json); - expect(result).toEqual(json.ios); - }) - - it('should return android metadata if platform is android', function() { - let mockPlatform = { - is: function(v: String) { - return v === 'android' - } - }; - let manup = new ManUpService(null, null, null, mockPlatform, null,null); + it('Should throw an exception if storage not configured', done => { + let metadata = { + ios: { minimum: '1.0.0', latest: '2.0.0', enabled: true, url: 'test.example.com' } + }; + let manup = new ManUpService(null, null, null, null, null, null, null, null); + expect(() => { + manup.saveMetadata(metadata); + }).toThrowError(); + done(); + }); + }); + + describe('getPlatformData', function() { + let json = { + ios: { + minimum: '1.0.0', + latest: '2.4.5', + enabled: true, + url: 'http://example.com' + }, + android: { + minimum: '4.0.1', + latest: '6.2.1', + enabled: true, + url: 'http://example.com' + }, + windows: { + minimum: '1.0.0', + latest: '1.0.1', + enabled: false, + url: 'http://example.com' + } + }; + + it('should return IOS metadata if platform is ios', function() { + let mockPlatform = { + is: function(v: String) { + return v === 'ios'; + } + }; + let manup = new ManUpService(null, null, null, mockPlatform, null, null, null, null); - let result = manup.getPlatformData(json); - expect(result).toEqual(json.android); - }) + let result = manup.getPlatformData(json); + expect(result).toEqual(json.ios); + }); - it('should return windows metadata if platform is windows', function() { - let mockPlatform = { - is: function(v: String) { - return v === 'windows' - } - }; - let manup = new ManUpService(null, null, null, mockPlatform, null,null); + it('should return android metadata if platform is android', function() { + let mockPlatform = { + is: function(v: String) { + return v === 'android'; + } + }; + let manup = new ManUpService(null, null, null, mockPlatform, null, null, null, null); - let result = manup.getPlatformData(json); - expect(result).toEqual(json.windows); - }) + let result = manup.getPlatformData(json); + expect(result).toEqual(json.android); + }); - it('should throw and error if the platform is unsupported', function() { - let mockPlatform = { - is: function(v: String) { - return false; - } - }; - let manup = new ManUpService(null, null, null, mockPlatform, null,null); + it('should return windows metadata if platform is windows', function() { + let mockPlatform = { + is: function(v: String) { + return v === 'windows'; + } + }; + let manup = new ManUpService(null, null, null, mockPlatform, null, null, null, null); - expect( () => {manup.getPlatformData(json)}).toThrow(); - }) + let result = manup.getPlatformData(json); + expect(result).toEqual(json.windows); + }); - }) + it('should throw and error if the platform is unsupported', function() { + let mockPlatform = { + is: function(v: String) { + return false; + } + }; + let manup = new ManUpService(null, null, null, mockPlatform, null, null, null, null); -}) + expect(() => { + manup.getPlatformData(json); + }).toThrow(); + }); + }); +}); diff --git a/src/test.ts b/src/test.ts deleted file mode 100644 index a5ad762..0000000 --- a/src/test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import './polyfills.ts'; - -import 'zone.js/dist/long-stack-trace-zone'; -import 'zone.js/dist/proxy.js'; -import 'zone.js/dist/sync-test'; -import 'zone.js/dist/jasmine-patch'; -import 'zone.js/dist/async-test'; -import 'zone.js/dist/fake-async-test'; - -import { getTestBed, TestBed } from '@angular/core/testing'; -import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; - -// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. -declare var __karma__: any; -declare var require: any; - -// Prevent Karma from running prematurely. -__karma__.loaded = function (): void { - // noop -}; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting(), -); - -// Then we find all the tests. -let context: any = require.context('./', true, /\.spec\.ts/); - -// And load the modules. -context.keys().map(context); - -// Finally, start Karma to run the tests. -__karma__.start(); diff --git a/test-config/karma-test-shim.js b/test-config/karma-test-shim.js new file mode 100644 index 0000000..c3a48f4 --- /dev/null +++ b/test-config/karma-test-shim.js @@ -0,0 +1,24 @@ +Error.stackTraceLimit = Infinity; + +require('core-js/es6'); +require('core-js/es7/reflect'); + +require('zone.js/dist/zone'); +require('zone.js/dist/long-stack-trace-zone'); +require('zone.js/dist/proxy'); +require('zone.js/dist/sync-test'); +require('zone.js/dist/jasmine-patch'); +require('zone.js/dist/async-test'); +require('zone.js/dist/fake-async-test'); + +var appContext = require.context('../src', true, /\.spec\.ts/); + +appContext.keys().forEach(appContext); + +var testing = require('@angular/core/testing'); +var browser = require('@angular/platform-browser-dynamic/testing'); + +testing.TestBed.initTestEnvironment( + browser.BrowserDynamicTestingModule, + browser.platformBrowserDynamicTesting() +); diff --git a/test-config/karma.conf.js b/test-config/karma.conf.js new file mode 100644 index 0000000..e6c27af --- /dev/null +++ b/test-config/karma.conf.js @@ -0,0 +1,62 @@ +var webpackConfig = require('./webpack.test.js'); + +module.exports = function(config) { + var _config = { + basePath: '../', + + frameworks: ['jasmine'], + + files: [ + { + pattern: './test-config/karma-test-shim.js', + watched: true + }, + { + pattern: './src/assets/**/*', + watched: false, + included: false, + served: true, + nocache: false + } + ], + + proxies: { + '/assets/': '/base/src/assets/' + }, + + preprocessors: { + './test-config/karma-test-shim.js': ['webpack', 'sourcemap'] + }, + + webpack: webpackConfig, + + webpackMiddleware: { + stats: 'errors-only' + }, + + webpackServer: { + noInfo: true + }, + + browserConsoleLogOptions: { + level: 'log', + format: '%b %T: %m', + terminal: true + }, + + coverageIstanbulReporter: { + reports: ['html', 'lcovonly'], + fixWebpackSourcePaths: true + }, + + reporters: config.coverage ? ['kjhtml', 'mocha', 'coverage-istanbul'] : ['kjhtml', 'mocha'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['ChromeHeadless'], + singleRun: false + }; + + config.set(_config); +}; diff --git a/test-config/mocks-ionic.ts b/test-config/mocks-ionic.ts new file mode 100644 index 0000000..6e730bc --- /dev/null +++ b/test-config/mocks-ionic.ts @@ -0,0 +1,96 @@ +export class PlatformMock { + public ready(): Promise { + return new Promise(resolve => { + resolve('READY'); + }); + } + + public getQueryParam() { + return true; + } + + public registerBackButtonAction(fn: Function, priority?: number): Function { + return () => true; + } + + public hasFocus(ele: HTMLElement): boolean { + return true; + } + + public doc(): HTMLDocument { + return document; + } + + public is(): boolean { + return true; + } + + public getElementComputedStyle(container: any): any { + return { + paddingLeft: '10', + paddingTop: '10', + paddingRight: '10', + paddingBottom: '10' + }; + } + + public onResize(callback: any) { + return callback; + } + + public registerListener(ele: any, eventName: string, callback: any): Function { + return () => true; + } + + public win(): Window { + return window; + } + + public raf(callback: any): number { + return 1; + } + + public timeout(callback: any, timer: number): any { + return setTimeout(callback, timer); + } + + public cancelTimeout(id: any) { + // do nothing + } + + public getActiveElement(): any { + return document['activeElement']; + } +} + +export class NavMock { + public pop(): any { + return new Promise(function(resolve: Function): void { + resolve(); + }); + } + + public push(): any { + return new Promise(function(resolve: Function): void { + resolve(); + }); + } + + public getActive(): any { + return { + instance: { + model: 'something' + } + }; + } + + public setRoot(): any { + return true; + } + + public registerChildNav(nav: any): void { + return; + } +} + +export class DeepLinkerMock {} diff --git a/test-config/webpack.test.js b/test-config/webpack.test.js new file mode 100644 index 0000000..e9c7d01 --- /dev/null +++ b/test-config/webpack.test.js @@ -0,0 +1,54 @@ +var webpack = require('webpack'); +var path = require('path'); + +module.exports = { + devtool: 'inline-source-map', + + resolve: { + extensions: ['.ts', '.js'] + }, + + module: { + rules: [ + { + test: /\.ts$/, + loaders: [ + { + loader: 'ts-loader' + }, + 'angular2-template-loader' + ] + }, + { + test: /.+\.ts$/, + exclude: /(index.ts|mocks.ts|\.spec\.ts$)/, + loader: 'istanbul-instrumenter-loader', + enforce: 'post', + query: { + esModules: true + } + }, + { + test: /\.html$/, + loader: 'html-loader?attrs=false' + }, + { + test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/, + loader: 'null-loader' + } + ] + }, + + plugins: [ + new webpack.ContextReplacementPlugin( + // The (\\|\/) piece accounts for path separators in *nix and Windows + /(ionic-angular)|(angular(\\|\/)core(\\|\/)@angular)/, + root('./src'), // location of your src + {} // a map of your routes + ) + ] +}; + +function root(localPath) { + return path.resolve(__dirname, localPath); +} diff --git a/tsconfig.json b/tsconfig.json index f806273..b961edc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,20 +7,15 @@ "declaration": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "lib": [ "es2015", "dom" ], + "lib": ["es2015", "dom"], "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "outDir": "lib", "rootDir": "src" }, - "exclude": [ - "node_modules", - "manup-demo", - "lib", - "src/test.ts" - ], + "include": ["src/**/*.ts"], + "exclude": ["node_modules", "manup-demo", "lib"], "angularCompilerOptions": { - "genDir": "lib" + "genDir": "lib" } - }