Skip to content

Commit 7a562d4

Browse files
Evgeny BarabanovEvgeny Barabanov
authored andcommitted
docs: add information about development process, testing and application structure. Closes #28.
1 parent b271451 commit 7a562d4

File tree

3 files changed

+73
-15
lines changed

3 files changed

+73
-15
lines changed

README.md

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Native code is supported in two different ways:
2626
- Native libraries support (using [node-ffi](https://github.com/node-ffi/node-ffi) 2.2.0)
2727
- Hot reload for development
2828

29-
## To Use
29+
## Getting ready
3030

31-
1. To clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer.
31+
1. In order to clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer.
3232
* **Node 9 is not supported yet** due to a [node-ffi issue](https://github.com/node-ffi/node-ffi/issues/438)
3333
* **bash command line is required (use git-bash for windows)**
3434
2. Clone the repository
@@ -50,7 +50,7 @@ Native code is supported in two different ways:
5050
cd electron-angular-native
5151
```
5252
53-
3. Install and run
53+
3. Prepare the environment
5454

5555
* If you're behind a corporate firewall configure `npm` proxy:
5656
@@ -99,13 +99,73 @@ Native code is supported in two different ways:
9999
* From your bash (git-bash or similar) command line:
100100
101101
```bash
102-
# Install dependencies and run the app
103-
npm install && npm start
102+
# Install dependencies
103+
npm install
104104
```
105105
106-
`npm start` runs application in debug mode while watching the .ts files (hot reload)
107-
108-
## To distribute
106+
## Application structure
107+
108+
- All the source code resides in `src/` directory
109+
- All the native source code resides in `src/native/` directory (a new native source code shall be put there as well)
110+
- Precompiled binaries (`simplelib`) are fetched from [another git repository](https://github.com/meltedspark/electron-angular-native-simplelib-bin) as git submodule and can be found in `native-artifacts/precompiled-libraries` directory.
111+
If you have any precompiled binaries you'd like to use in your project just put them inside this directory, while keeping platform and architecture subdirectories same to the `simplelib`.
112+
- Native artifacts that were compiled from the source code as part of the build can be found in `native-artifacts/native-addons` directory (first time compiled on `npm install`)
113+
114+
## Application info
115+
You can define application name, version, author and runtime node dependencies in `app.package.js`
116+
117+
## Development
118+
119+
- **Running application in debug mode:**
120+
121+
```bash
122+
npm start
123+
```
124+
125+
This will run your Electron Angular application in watch mode, i.e. if you change any `.ts` file the application will reload the changes automatically.
126+
The application starts with debug tools open so that you can place breakpoints and debug your Typescript code.
127+
128+
**Note** *that first time you run `npm start` the application might open with console error saying "Not allowed to load local resource: file:///.../electron-angular-native/serve/index.html".
129+
The reason for that is that webpack compilation and electron serve run simultaneously and the application starts before the code is ready.
130+
All you need to do is wait - once the compilation is complete the application will reload with the compiled code.*
131+
132+
- **Compiling native code:**
133+
134+
Native code is not compiled on every `npm start` (it's only compiled on `npm install` and before the distribution), but if you want to recompile it, run the following command from your *bash* command line:
135+
136+
```bash
137+
npm run compile:native
138+
```
139+
140+
- **Running end to end tests with Spectron:**
141+
142+
To run end to end tests use the following command:
143+
144+
```bash
145+
npm run e2e
146+
```
147+
This will run all the tests in `e2e` directory (the tests extension must be `.e2e-spec.ts`).
148+
For your convenience there is a helper class `SpectronUtils` which can be used for tests definition and two test examples:
149+
150+
- `native-links.e2e-spec.ts` verifies that the links that loaded from native modules present upon the application start
151+
- `sanity.e2e-spec.ts` verifies that the application starts
152+
153+
- **AoT build:**
154+
155+
Sometimes you want to make sure your code compiles with AoT compiler during the development.
156+
In order to do that use the following command:
157+
158+
```bash
159+
npm run build
160+
```
161+
162+
If you want to *run* the application in product mode (built with AoT) use this:
163+
164+
```bash
165+
npm run start:prod
166+
```
167+
168+
## Distribution
109169

110170
- Run the following from the root folder to create a distribution for:
111171

@@ -138,12 +198,7 @@ Native code is supported in two different ways:
138198
If for some reason you want it in dev mode (JIT), run `npm run dist:dev`
139199
- Build artifact can be found in build-artifacts folder
140200
141-
## Application info
142-
You can define application name, version author and runtime node dependencies in `app.package.js`
143-
144201
## Useful links
145202
- [Electron documentation](http://electron.atom.io/docs/latest)
146203
- [Using native modules in Electron](https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md)
147-
- [Node.js module lookup mechanism with System.js](http://stackoverflow.com/questions/38747445/node-js-module-lookup-in-electronangular-2-typescript-application)
148204
- [Running binding.gyp in all subdirectories](http://stackoverflow.com/questions/38693619/node-gyp-run-binding-gyp-in-all-subdirectories)
149-
- [System.js plugin-node-binary](https://github.com/systemjs/plugin-node-binary)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function containsString(app: Application, text: string, url: string) {
1717
});
1818
}
1919

20-
SpectronUtils.describe('Native strings', app => {
20+
SpectronUtils.describe('Native links', app => {
2121
containsString(app, 'The link is provided by Node addon (using nan)', 'https://github.com/nodejs/nan');
2222
containsString(app, 'The link is provided by precompiled native library (using ffi)', 'https://github.com/node-ffi/node-ffi');
2323
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
"version": "2.0.1",
44
"license": "Apache 2.0",
55
"scripts": {
6-
"postinstall": "electron-rebuild && rimraf build bin",
6+
"postinstall": "npm run compile:native",
77
"ng": "ng",
88
"test": "karma start ./karma.conf.js",
99
"start": "npm run serve",
10+
"start:prod": "npm run build && electron . --dist",
11+
"build": "npm run webpack:build:prod",
1012
"lint": "ng lint",
1113
"e2e": "cross-env TS_NODE_PROJECT=e2e/tsconfig.e2e.json mocha -r ts-node/register e2e/**/*.e2e-spec.ts",
14+
"compile:native": "electron-rebuild && rimraf build bin",
1215
"compile:main:serve": "tsc src/main.electron.ts --outDir serve",
1316
"compile:main:dist": "tsc src/main.electron.ts --outDir dist",
1417
"serve": "rimraf serve && npm run compile:main:serve && concurrently \"npm run webpack:dev:watch\" \"electron . --serve\"",

0 commit comments

Comments
 (0)