Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
Added Ionic ENV var support
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinyo committed Nov 16, 2017
1 parent a0360e4 commit 280aa93
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 93 deletions.
66 changes: 66 additions & 0 deletions .angular-cli.json
@@ -0,0 +1,66 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "BigTop"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "app/main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"codeCoverage": {
"exclude": [
"src/polyfills.ts",
"src/test.ts",
"src/mocks.ts",
"**/*.mock.ts",
"**/node_modules/**"
]
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
99 changes: 99 additions & 0 deletions README.md
Expand Up @@ -32,6 +32,10 @@ To launch the project:
For example:

ionic serve --platform=ios

You can preview all three supported Mobile platforms side by side:

ionic serve --lab

### Electron

Expand Down Expand Up @@ -65,6 +69,101 @@ To package the application:

If everything works as expected electron-builder will create a `/dist` directory.

## Build Management
* [Easy to use environment variables for Ionic 3](https://github.com/gshigeto/ionic-environment-variables)
* [Ionic CLI - Issue 1205 - Environment variable configuration](https://github.com/ionic-team/ionic-cli/issues/1205)

### Environment Variables

I followed these steps to add support for environment variables.

Update `package.json`:
```json
"config": {
"ionic_webpack": "./config/webpack.config.js"
}
```

Updated `tsconfig.json` in `compilerOptions`:
```json
"compilerOptions": {
...
"baseUrl": "./src",
"paths": {
"@app/env": [
"environments/environment"
]
}
},
```

Created `config/webpack.config.js`:
```javascript
var chalk = require("chalk");
var fs = require('fs');
var path = require('path');
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');

var env = process.env.IONIC_ENV;

if (env === 'prod' || env === 'dev') {
useDefaultConfig[env].resolve.alias = {
"@app/env": path.resolve(environmentPath())
};
} else {
// Default to dev config
useDefaultConfig[env] = useDefaultConfig.dev;
useDefaultConfig[env].resolve.alias = {
"@app/env": path.resolve(environmentPath())
};
}

function environmentPath() {
var filePath = './src/environments/environment' + (env === 'prod' ? '' : '.' + env) + '.ts';
if (!fs.existsSync(filePath)) {
console.log(chalk.red('\n' + filePath + ' does not exist!'));
} else {
return filePath;
}
}

module.exports = function () {
return useDefaultConfig;
};
```

Created `src/environments/environment.ts` that will be used for the **Production** environment:
```typescript
export const ENV = {
production: true,
isDebugMode: false
};
```

Created `src/environments/environment.dev.ts` that will be used for the **Development** environment:
```typescript
export const ENV = {
production: false,
isDebugMode: true
};
```
Import your environment variables:
```typescript
import { ENV } from '@app/env'
```
**Note:** Remember to ignore your environment files in your `.gitignore`
```
# Environment Variables
**/environment.*
!**/environment.model.ts
```

## Simple Logging Service

* [A simple logging service for Angular 4](https://robferguson.org/blog/2017/09/09/a-simple-logging-service-for-angular-4/)

Take a look at the .ts files in the `src/services/log4ts` directory.

## Scaffolding

The scaffolding for this project was generated using the [Ionic CLI](https://ionicframework.com/docs/cli/)
Expand Down
139 changes: 139 additions & 0 deletions TODO.md
@@ -0,0 +1,139 @@
## config.xml:

Update the package name:

<widget id="org.robferguson.BigTop" version="1.0.0"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

Then add and remove (supported) platforms:

ionic cordova platform rm android
ionic cordova platform add android

## Run in Emulator

Run:

ionic cordova emulate [<platform>] [options]

Print out console logs to terminal:

ionic cordova emulate android --consolelogs
ionic cordova emulate android --consolelogs --address=192.168.1.115

## Run on Device

* [Apache Cordova - Android Platform Support - Installing the Requirements](https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#installing-the-requirements)
* [Apache Cordova - iOS Platform Support - Installing the Requirements](https://cordova.apache.org/docs/en/latest/guide/platforms/ios/#installing-the-requirements)

Build:

ionic cordova build [<platform>] [options]

Run:

ionic cordova run [<platform>] [options]

Build and run on Android:

ionic cordova build android
ionic cordova run android --consolelogs

Build and run on iOS:

ionic cordova build ios
ionic cordova run ios --consolelogs --address=192.168.1.115


## Unit Testing and End-to-End (E2E) Testing

* [Testing an Angular project](https://angular.io/guide/testing)
* [Testing an Ionic project](http://lathonez.com/2017/ionic-2-unit-testing/)

Updated `tsconfig.ng-cli.json` in `compilerOptions`:
```json
"paths": {
"@app/env": [
"environments/environment"
]
}
```

### Jasmine

The [Jasmine test framework](https://jasmine.github.io/2.4/introduction.html) provides everything needed to write basic tests.

### Karma

The [Karma test runner](https://karma-runner.github.io/1.0/index.html) is ideal for writing and running unit tests while
developing an application. It can be an integral part of the project's development and continuous integration processes.

Run:

npm test

### Protractor

Use protractor to write and run end-to-end (e2e) tests. End-to-end tests explore the application as users experience it.
In e2e testing, one process runs the real application and a second process runs protractor tests that simulate user
behavior and assert that the application respond in the browser as expected.

Run:

ionic serve [--platform=ios]

Then (in a second terminal session):

npm e2e

### Test Coverage

Run:

npm test-coverage

In the `./coverage` folder open `index.html`:

<p align="center">
<img src="https://github.com/Robinyo/aus-id/blob/master/screen-shots/test-coverage.png">
</p>

## Documentation

To install Compodoc globally:

npm install -g @compodoc/compodoc

To add Compodoc to your project:

npm install --save-dev @compodoc/compodoc

Define script tasks for Compodoc in your `package.json`:

"scripts": {
"docs": "./node_modules/.bin/compodoc -d ./docs/ -p ./tsconfig.json --theme vagrant",
"serve-docs": "./node_modules/.bin/compodoc -s -d ./docs"
}

To generate documentation (using Compodoc):

npm run docs

To serve the generated documentation:

npm run serve-docs

Open your browser and navigate to:

http://localhost:8080

**Note:** You can exclude files from the generated documentation via `tsconfig.json`:

```
"exclude": [
"./node_modules",
"./temp/**/*.ts",
"./src/environments/*.ts",
"./src/services/**/*.ts",
"**/*.spec.ts"
]

0 comments on commit 280aa93

Please sign in to comment.