Skip to content

Commit 68cf442

Browse files
committed
Merge branch 'feature/fix-test-cordova' into develop
2 parents edfb929 + 9dee844 commit 68cf442

File tree

9 files changed

+66
-49
lines changed

9 files changed

+66
-49
lines changed

README.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ Integration tests are performed with [Protractor](http://angular.github.io/protr
171171

172172
## Environment confugration
173173
There is a configuration management in place. Three standart environments are already set (devlopment, test and production).
174-
You can also add more environments with ```--env <env-name>``` but there is a catch: You have to add ```--``` for each npm command you
174+
You can also add more environments with ```--env.target <env-name>``` but there is a catch: You have to add ```--``` for each npm command you
175175
run throw so if your like to set the evnirnment for ```npm start``` you have to do this like so:
176176

177177
```shell
178-
npm start -- -- --env <json-file-name-without-extension>
178+
npm start -- -- --env.target <json-file-name-without-extension>
179179
```
180180

181-
This because ```npm start``` runs ```npm run server:dev``` and then the target command, so we have to to pass the ```--env``` by providing two times ```--```.
181+
This because ```npm start``` runs ```npm run server:dev``` and then the target command, so we have to to pass the ```--env.target``` by providing two times ```--```.
182182
You can find the configurations in ```<root>/environment```.
183183

184184
## HTML5 pushState routing
@@ -191,26 +191,7 @@ extra confuration to enable this.
191191
Initiate cordova with the following commands:
192192
```shell
193193
npm install -g cordova
194-
npm run cordova:init
195-
```
196-
197-
Finally add the following code just before the ```</body>``` closing tag:
198-
```
199-
<!-- Cordova -->
200-
<script src="cordova.js"></script>
201-
```
202-
203-
Cordova has a issue in the way they serve the source code files to the WebView in the platforms. So we have to remove/alter the following code
204-
to make sure everything works in cordova.
205-
206-
Remove the following line in src/index.ejs
207-
```
208-
12: <base href="<%= htmlWebpackPlugin.options.baseUrl %>">
209-
```
210-
211-
Remove the following line in src/app/app.ts
212-
```
213-
8: config.options.pushState = true;
194+
npm run mobile:setup
214195
```
215196

216197
### Run and build
@@ -235,10 +216,10 @@ So make sure you run for example ```npm run build``` first before runing/buildin
235216
- [X] add i18n
236217
- [ ] add materialize.css
237218
- [ ] Add all important libs like moment, lodash ...
238-
- [ ] Add cordova
219+
- [X] Add cordova
239220
- [X] Add travis
240221
- [ ] Add greenkeeper
241-
- [ ] polyfill ES6 promises for tests => replaced phantom with firefox
222+
- [X] polyfill ES6 promises for tests => replaced phantom with firefox
242223
- [ ] Add electron
243224
- [ ] Add wallaby.js
244225
- [ ] Add typedocs

config/config-environment.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
"use strict";
22

33
const webpack = require('webpack');
4-
const minimist = require('minimist')(process.argv.slice(2));
54

65
/**
76
* Environment Config
87
*/
98
const configEnv = function (options) {
109
return {
1110
plugins: [
12-
new webpack.DefinePlugin(getDefinitions(options.env, options.name, options.version))
11+
new webpack.DefinePlugin(getDefinitions(options.env, options.name, options.version, options.platform))
1312
]
1413
};
1514
};
1615

17-
function getDefinitions(env, name, version) {
18-
const environment = minimist.env || env;
16+
function getDefinitions(env, name, version, platform) {
1917
return {
2018
NAME: JSON.stringify(name),
2119
VERSION: JSON.stringify(version),
22-
CONFIG: JSON.stringify(require(process.cwd() + `/environment/${environment}.json`))
20+
PLATFORM: JSON.stringify(platform),
21+
CONFIG: JSON.stringify(require(process.cwd() + `/environment/${env}.json`))
2322
};
2423

2524
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
"webpack": "cross-env ./node_modules/.bin/webpack",
3434
"webpack-dev-server": "cross-env ./node_modules/.bin/webpack-dev-server",
3535
"server:coverage": "http-server ./test/coverage --cors",
36-
"cordova:init": "node ./config/init-cordova.js"
36+
"mobile:setup": "node ./config/setup-mobile.js",
37+
"mobile:build": "npm run build:dev -- --env.platform mobile",
38+
"mobile:release": "npm run build:prod -- --env.platform mobile"
39+
3740
},
3841
"repository": {
3942
"type": "git",

src/app/app-config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Gets and defines the environment configruation
3+
*/
4+
declare var NAME: string;
5+
declare var VERSION: string;
6+
declare var ENV: string;
7+
declare var PLATFORM: string;
8+
declare var CONFIG: AppConfig.IAppConfigEnv;
9+
10+
const AppConfig: AppConfig.IAppConfig = {
11+
NAME: NAME,
12+
VERSION: VERSION,
13+
ENV: ENV,
14+
PLATFORM: PLATFORM,
15+
CONFIG: CONFIG
16+
};
17+
18+
export default AppConfig;

src/app/main.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
/**
2-
* Gets and defines the environment configruation
2+
* Import the main sass file for all the styles
33
*/
4-
declare var NAME: string;
5-
declare var VERSION: string;
6-
declare var CONFIG: AppConfig.IAppConfigEnv;
7-
8-
const AppConfig: AppConfig.IAppConfig = {
9-
NAME: NAME,
10-
VERSION: VERSION,
11-
CONFIG: CONFIG
12-
};
4+
import '../scss/main.scss';
135

146
/**
15-
* Import the main sass file for all the styles
7+
* App configuration import
168
*/
17-
import '../scss/main.scss';
9+
import AppConfig from './app-config';
1810

1911
/**
2012
* Aurelia imports

test/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function(config) {
3838
'spec-bundle.js': ['coverage', 'webpack', 'sourcemap']
3939
},
4040

41-
webpack: require('../webpack.config'),
41+
webpack: require('../webpack.config')(),
4242

4343
coverageReporter: {
4444
reporters: [{

test/unit/app.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import '../lib/setup';
22
import { App } from '../../src/app/app';
3+
import { I18N } from 'aurelia-i18n';
4+
import {BindingSignaler} from 'aurelia-templating-resources';
5+
import {EventAggregator} from 'aurelia-event-aggregator';
6+
import EnglishTranslation from '../../src/locales/en.json';
7+
import AppConfig from '../../src/app/app-config';
38

49
class RouterStub {
510
public routes;
11+
public options = {
12+
pushState: undefined
13+
};
614

715
public configure(handler): void {
816
handler(this);
@@ -19,7 +27,21 @@ describe('the App module', () => {
1927

2028
beforeEach(() => {
2129
mockedRouter = new RouterStub();
22-
sut = new App();
30+
31+
// Translation setup
32+
sut = new I18N(new EventAggregator(), new BindingSignaler());
33+
sut.setup({
34+
resources: {
35+
en: {
36+
translation: EnglishTranslation
37+
}
38+
},
39+
lng: 'en',
40+
fallbackLng: 'en',
41+
debug: false
42+
});
43+
44+
sut = new App(sut, AppConfig);
2345
sut.configureRouter(mockedRouter, mockedRouter);
2446
});
2547

@@ -28,7 +50,7 @@ describe('the App module', () => {
2850
});
2951

3052
it('configures the router title', () => {
31-
expect(sut.router.title).toEqual('Aurelia');
53+
expect(sut.router.title).toEqual('Transaltion Title');
3254
});
3355

3456
it('should have a welcome route', () => {

typings_custom/app-config.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ declare namespace AppConfig {
66

77
export interface IAppConfig {
88
NAME: string;
9-
VERSION: string;
10-
CONFIG: IAppConfigEnv;
9+
VERSION: string;
10+
ENV: string;
11+
PLATFORM: string;
12+
CONFIG: IAppConfigEnv;
1113
}
1214
}

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function (envArguments) {
1515
const ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || 'development';
1616
const pkg = require(path.join(process.cwd(), 'package.json'));
1717
let PLATFORM = 'web';
18-
let TARGET = 'development';
18+
let TARGET = ENV;
1919
if (envArguments) {
2020
PLATFORM = envArguments.platform || PLATFORM;
2121
TARGET = envArguments.target || TARGET;

0 commit comments

Comments
 (0)