| 1 |
--- |
| 2 |
subtitle: Application Development |
| 3 |
--- |
| 4 |
|
| 5 |
The [Quick Start](quickstart.md) tutorial introduces how to setup a new application project, |
| 6 |
and [Application Design](application.md) draw a high-level view of how it works. |
| 7 |
This tutorial goes into more details about the development environment provided by the **Dome** |
| 8 |
framework. |
| 9 |
|
| 10 |
|
| 11 |
## HTML & JavaScript Environment |
| 12 |
|
| 13 |
The Web environment for designing your application is based on the following |
| 14 |
framework: |
| 15 |
|
| 16 |
- **Electron** [v5.0+](https://electronjs.org) runtime environment (packaging Chrome and Node) |
| 17 |
- **Node** [v12.0+](https://nodejs.org/dist/latest-v12.x/docs/api) provided by Electron |
| 18 |
- **Chromium** [v73.0+](https://www.chromium.org/Home) HTML rendering engine provided by Electron |
| 19 |
|
| 20 |
You will write your application in a an environment setup with the following |
| 21 |
JavaScript features: |
| 22 |
|
| 23 |
- **Webpack** for packaging the application from sources |
| 24 |
- **Babel** to parse language extensions |
| 25 |
- **Babel Presets Env** to use ECMA modules and JavaScript strict mode |
| 26 |
- **Babel Presets React** to use JSX react notation in all your `*.js` files |
| 27 |
- **Babel Object Rest Spread** to use object spread syntax `{ ...props }` |
| 28 |
- **React v16** with its latest features (including Hooks) |
| 29 |
- **React Hot Loader** for [live-editing](hotreload.md) your application |
| 30 |
- **CSS Loader** to load and install `*.css` files |
| 31 |
|
| 32 |
## Available Packages |
| 33 |
|
| 34 |
The implementation and internals of the **Dome** framework rely on |
| 35 |
high-quality and mature popular packages. They are automatically packed |
| 36 |
into your dependencies by the provided template makefile. We list them here |
| 37 |
since you may re-use them for your own purpose: |
| 38 |
|
| 39 |
- [**Lodash**](https://lodash.com) convenient JavaScript utilities |
| 40 |
- [**React-Virtualized**](http://bvaughn.github.io/react-virtualized) |
| 41 |
for layout of large data set in list, tables and grids |
| 42 |
- [**React-Draggable**](https://github.com/mzabriskie/react-draggable) |
| 43 |
for straightforward drag-and-drop features |
| 44 |
- [**CodeMirror**](https://codemirror.net) for rich text capabilities and edition |
| 45 |
that scales on large document |
| 46 |
|
| 47 |
## Project Files Organization |
| 48 |
|
| 49 |
The main directory holding your application project with **Dome** consists of |
| 50 |
several files and directories. Each is created and/or managed by various |
| 51 |
entities : yourself the **Developer**, the **Dome** template makefile, the |
| 52 |
**Yarn** JavaScript package manager and the **Electron** suite of |
| 53 |
utilities. Parts of those files are generated and updated on demand and shall or |
| 54 |
shall _not_ be tracked in your source version control system, be it based on `git`, |
| 55 |
`svn` or anything else. |
| 56 |
|
| 57 |
Most files are actually created and used by **Dome**, **Electron** and **Yarn**. |
| 58 |
However, that are _in fine_ under the responsibility of the **Developer** |
| 59 |
since you can edit and extend them to fit your needs. |
| 60 |
Those generated files generally contains comments to indicate how you |
| 61 |
can extend them. You shall put those files under version control only if you edit them. |
| 62 |
|
| 63 |
As depicted in the [Quick Start](quickstart.md) tutorial, the only file you |
| 64 |
need to create by yourself is the main `Makefile`, with a minimal content |
| 65 |
limited to: |
| 66 |
|
| 67 |
```makefile |
| 68 |
DOME="..." ;; path to your dome installation |
| 69 |
include $(DOME)/template/makefile |
| 70 |
``` |
| 71 |
|
| 72 |
The following table lists the main files and directories of your project, with |
| 73 |
the associated entity responsible for it, and whether they should be tracked by |
| 74 |
your source version control system (VCS). |
| 75 |
|
| 76 |
Optional files are tagged with « (Opt.) » in the corresponding `Entity` column, |
| 77 |
and are _not_ generated by default. Similarly, files mainly used by the system |
| 78 |
but that can still be configured by the developer are tagged with « (+Dev) ». |
| 79 |
Files are tagged with « ✓(*) » in the `VCS` column shall be tracked only if you |
| 80 |
actually modified them. |
| 81 |
|
| 82 |
| File or Directory | Description | Entity | VCS | |
| 83 |
|:------------------|:------------|:-------:|:---:| |
| 84 |
| `./Makefile` | Drives the build system | **Developer** | ✓ | |
| 85 |
| `./src/main/` | Sources for the main process | **Developer** | ✓ | |
| 86 |
| `./src/main/index.js` | Main process entry point | **Electron** (+Dev) | ✓ | |
| 87 |
| `./src/renderer/` | Sources for the renderer process | **Developer** | ✓ | |
| 88 |
| `./src/renderer/index.js` | Renderer process entry point | **Electron** (+Dev) | ✓ | |
| 89 |
| `./src/renderer/Application.js` | Top React component of the main application window | **Developer** | ✓ | |
| 90 |
| `./src/renderer/Preferences.js` | Top React component of the user preferences window | **Developer** | ✓ | |
| 91 |
| `./src/common/` | Sources for _both_ processes | **Developer** (Opt.) | ✓ | |
| 92 |
| `./static/` | Static resources | **Developer** (Opt.) | ✓ | |
| 93 |
| `./package.json` | JavaScript packages configuration | **Yarn** (+Dev) | ✓ | |
| 94 |
| `./node_modules` | Downloaded packages | **Yarn** | 𐄂 | |
| 95 |
| `./yarn.lock` | Packages versions stamps | **Yarn** | ✓ | |
| 96 |
| `./electron-webpack.json` | Electron configuration | **Electron** (+Dev) | ✓(*) | |
| 97 |
| `./babelrc` | Babel configuration | **Electron** (+Dev) | ✓(*) | |
| 98 |
| `./webpack.main.json` | Webpack main process config. | **Electron** (+Dev) | ✓(*) | |
| 99 |
| `./webpack.renderer.json` | Webpack renderer process config. | **Electron** (+Dev) | ✓(*) | |
| 100 |
| `./.dome-*` | Dome makefile stamps | **Dome** | 𐄂 | |
| 101 |
| `$(DOME)/*` | Dome framework clone | **Dome** | (var.) | |
| 102 |
| `./dist/` | Packaged application | **Dome** | 𐄂 | |
| 103 |
| `./bin/` | Local command-lines | **Dome** | 𐄂 | |
| 104 |
|
| 105 |
The main entry points of the two **Electron** processes running your application, |
| 106 |
`src/main/index.js` and `src/renderer/index.js` shall be modified with extreme care, |
| 107 |
since they are in charge with the correct bootstrap of your application. |
| 108 |
The generated files from **Dome** templates contains explicit comments and guidelines. |
| 109 |
|
| 110 |
You may want to modify the name of your application top-level **React** components, |
| 111 |
namely `src/renderer/Application.js` and `src/render/Preferences.js` by default. |
| 112 |
To do this, you shall hook into the |
| 113 |
`src/renderer/index.js` file and follow the provided comments and guidelines, |
| 114 |
and set the `DOME_CUSTOM_ENTRIES` variable into your own `./Makefile` to make |
| 115 |
**Dome** aware about this. |
| 116 |
|
| 117 |
If you need static resource files to be packed with your application, put them in the `static` directory. |
| 118 |
You can then access to their actual path from your code by using the `System.getStatic(<path>)` utility function. |
| 119 |
|
| 120 |
The location of the **Dome** resources actually depends on the developer |
| 121 |
profile, as explained in more detailed in the [Live Editing](hotreload.md) tutorial. |
| 122 |
To summarize: |
| 123 |
- for normal developers, it can be a local copy of the dome framework, for instance in your `/usr/local/lib/dome` directory; |
| 124 |
- for developers working with a specific or modified version of the dome framework, it can be in the local |
| 125 |
`./dome/` directory of your project, with or without versioning control; |
| 126 |
- for **Dome** developers, it is also possible to clone the Git repository inside the `./src/dome/` sub-directory of your |
| 127 |
project, hence also enabling live-editing of **Dome** itself; |
| 128 |
- for **Dome** maintainers, it is even possible to use the root of the **Dome** development repository as an application project |
| 129 |
in itself, for demos, examples or testing purposes. |
| 130 |
|
| 131 |
Most of the **Electron** configuration files depends on the definition of the |
| 132 |
`DOME` environment variable to find the necessary resources for your application |
| 133 |
during development. Commands initiated by **Dome** from `$(DOME)/template/makefile` |
| 134 |
will explicitly copy the `$(DOME)` makefile variable into the `$DOME` shell environment |
| 135 |
variable when calling the **Electron** builder utilities, and might use it to generate static |
| 136 |
files from templates, if necessary. |
| 137 |
|
| 138 |
If you ever _move_ the place where **Dome** is installed, you |
| 139 |
probably have to inspect the generated files that you have modified to check |
| 140 |
if they still behave as expected. |
| 141 |
|
| 142 |
Notice, however, that distributed versions of |
| 143 |
the application (those accessible from the `./dist/` directory) are |
| 144 |
self-contained: they are _not_ tied to your local installation of **Dome**. |
| 145 |
|
| 146 |
The command-line version of the application is accessible to the developer from the `./bin` directory. |
| 147 |
|
| 148 |
# Common Development Tasks |
| 149 |
|
| 150 |
Most development tasks shall be accessible from your `./Makefile`, and simply delegate to the |
| 151 |
predefined **Dome** targets in `$(DOME)/template/makefile` ; however, for very specific needs, |
| 152 |
you can borrow the content of the template makefile into your own one and modify it at your |
| 153 |
convenience. The **Dome** environment will not target this template makefile explicitly. |
| 154 |
|
| 155 |
The top target of the **Dome** template makefile is `make dome-help`, |
| 156 |
which is thus activated by default unless you put your own targets _before_ |
| 157 |
its inclusion. The `dome-help` target simply echoes a short list of all the |
| 158 |
`dome-xxx` predefined targets in the template. It also reports on |
| 159 |
actual values of makefile variables used by the template. |
| 160 |
|
| 161 |
``` |
| 162 |
$ make dome-help |
| 163 |
|
| 164 |
[Dome] Builtin Targets: |
| 165 |
make dome-help This help |
| 166 |
make dome-dev Run application in development mode |
| 167 |
make dome-app Compile application |
| 168 |
make dome-dist Package application for production |
| 169 |
make dome-doc Generate Dome documentation |
| 170 |
make dome-api Generate Application documentation |
| 171 |
make dome-pkg Install development packages |
| 172 |
make dome-templ Update templates |
| 173 |
make dome-reboot Rebuild templates from scratch |
| 174 |
make dome-clean Remove dome temporary files |
| 175 |
make dome-plugins Package plugins for distribution |
| 176 |
|
| 177 |
[Dome] Development: |
| 178 |
… (environment variables) |
| 179 |
|
| 180 |
[Dome] Documentation: |
| 181 |
… (environment variables) |
| 182 |
|
| 183 |
``` |
| 184 |
|
| 185 |
As depicted above, the **Dome** template also provides two extensible targets `help::` and `clean::`. |
| 186 |
By default, the `make clean` would only remove the **Dome** stamp files, not the actually generated files, |
| 187 |
since they can have been modified when developing the application. This can cause, however, an _update_ of |
| 188 |
configuration files that can be managed incrementally, typically for the `package.json` and the installed |
| 189 |
JavaScript packages. |
| 190 |
|
| 191 |
The **Dome** framework can generate its own documentation locally, hence you may consult it offline. It |
| 192 |
is also capable of generating internal **JSDoc** documentation of the application itself. The application |
| 193 |
documentation does _not_ contain the framework documentation, though. |
| 194 |
|
| 195 |
The environment variable can be redefined _via_ your own Makefile before the **Dome** template inclusion. |