Skip to content

Commit

Permalink
Tools: Improve and simplify how to build the apps (laurent22#2538)
Browse files Browse the repository at this point in the history
* Improving CLI build

* Improving CLI build

* Remove requirement to build the tools

* Moved Electron app one level down

* Clean up Electron build

* Moved tools to sub-dir

* Updated root script

* update root

* update root

* update root

* update root

* update root

* update root

* Updated build

* Added doc

* Update CI config

* Should not lint index.js

* Fixing jetify

* Fixed linter errors

* Fixed pod build

* Fixed Windows build
  • Loading branch information
laurent22 authored Feb 20, 2020
1 parent 2dfe693 commit 3407a31
Show file tree
Hide file tree
Showing 196 changed files with 7,450 additions and 975 deletions.
28 changes: 17 additions & 11 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _releases/
Assets/
CliClient/build
CliClient/locales
CliClient/locales-build
CliClient/node_modules
CliClient/tests-build
CliClient/tests/enex_to_md
Expand All @@ -22,12 +23,12 @@ Clipper/joplin-webclipper/icons
Clipper/joplin-webclipper/popup/build
Clipper/joplin-webclipper/popup/node_modules
docs/
ElectronClient/app/dist
ElectronClient/app/lib
ElectronClient/app/lib/vendor/sjcl-rn.js
ElectronClient/app/lib/vendor/sjcl.js
ElectronClient/app/locales
ElectronClient/app/node_modules
ElectronClient/dist
ElectronClient/lib
ElectronClient/lib/vendor/sjcl-rn.js
ElectronClient/lib/vendor/sjcl.js
ElectronClient/locales
ElectronClient/node_modules
highlight.pack.js
node_modules/
ReactNativeClient/android
Expand All @@ -45,17 +46,22 @@ Server/docs/
Server/dist/
Server/bin/
Server/node_modules/
ElectronClient/app/packageInfo.js
ElectronClient/packageInfo.js
ReactNativeClient/pluginAssets/
ReactNativeClient/lib/joplin-renderer/vendor/fountain.min.js
ReactNativeClient/lib/joplin-renderer/assets/
ReactNativeClient/lib/rnInjectedJs/

# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
ElectronClient/app/gui/ShareNoteDialog.js
ReactNativeClient/PluginAssetsLoader.js
ReactNativeClient/lib/JoplinServerApi.js
CliClient/tests-build/lib/JoplinServerApi.js
ElectronClient/app/lib/joplin-renderer/MdToHtml/rules/mermaid.js
ElectronClient/app/lib/joplin-renderer/MdToHtml/rules/sanitize_html.js
ElectronClient/app/lib/JoplinServerApi.js
ElectronClient/gui/ResourceScreen.js
ElectronClient/gui/ShareNoteDialog.js
ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.js
ElectronClient/app/gui/ResourceScreen.js
ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/sanitize_html.js
ReactNativeClient/lib/JoplinServerApi.js
ReactNativeClient/PluginAssetsLoader.js
ReactNativeClient/setUpQuickActions.js
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ Tools/github_oauth_token.txt
_releases
ReactNativeClient/lib/csstojs/
ReactNativeClient/lib/rnInjectedJs/
ElectronClient/app/gui/note-viewer/fonts/
ElectronClient/app/gui/note-viewer/lib.js
ElectronClient/gui/note-viewer/fonts/
ElectronClient/gui/note-viewer/lib.js
Tools/commit_hook.txt
.vscode/*
*.map

# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
ElectronClient/app/gui/ShareNoteDialog.js
ReactNativeClient/PluginAssetsLoader.js
ReactNativeClient/lib/JoplinServerApi.js
CliClient/tests-build/lib/JoplinServerApi.js
ElectronClient/app/lib/joplin-renderer/MdToHtml/rules/mermaid.js
ElectronClient/app/lib/joplin-renderer/MdToHtml/rules/sanitize_html.js
ElectronClient/app/lib/JoplinServerApi.js
ElectronClient/gui/ResourceScreen.js
ElectronClient/gui/ShareNoteDialog.js
ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/mermaid.js
ElectronClient/app/gui/ResourceScreen.js
ReactNativeClient/lib/joplin-renderer/MdToHtml/rules/sanitize_html.js
ReactNativeClient/lib/JoplinServerApi.js
ReactNativeClient/PluginAssetsLoader.js
ReactNativeClient/setUpQuickActions.js
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ before_install:
script:
- |
# Copy lib
rsync -aP --delete ReactNativeClient/lib/ ElectronClient/app/lib/
# Install tools
npm install
npm run tsc
cd Tools
npm install
cd ..
Expand All @@ -70,7 +66,6 @@ script:
# and that would break the desktop release.
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
cd CliClient
npm install
./run_test.sh
testResult=$?
if [ $testResult -ne 0 ]; then
Expand Down Expand Up @@ -113,5 +108,5 @@ script:
fi
# Prepare the Electron app and build it
cd ElectronClient/app
npm install && USE_HARD_LINKS=false yarn dist
cd ElectronClient
USE_HARD_LINKS=false yarn dist
97 changes: 37 additions & 60 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,71 @@

# General information

- All the applications share the same library, which, for historical reasons, is in ReactNativeClient/lib. This library is copied to the relevant directories when building each app.
- All the applications share the same library, which, for historical reasons, is in `ReactNativeClient/lib`. This library is copied to the relevant directories when building each app.
- In general, most of the backend (anything to do with the database, synchronisation, data import or export, etc.) is shared across all the apps, so when making a change please consider how it will affect all the apps.

# TypeScript
## TypeScript

Most of the application is written in JavaScript, however new classes and files should generally be written in [TypeScript](https://www.typescriptlang.org/). Even if you don't write TypeScript code, you will need to build the existing .ts and .tsx files. This is done from the root of the project, by running `npm run tsc`.
Most of the application is written in JavaScript, however new classes and files should generally be written in [TypeScript](https://www.typescriptlang.org/). Even if you don't write TypeScript code, you will need to build the existing .ts and .tsx files. This is done from the root of the project, by running `npm run build`.

If you are modifying TypeScript code, the best is to have the compiler watch for changes from a terminal. To do so, run `npm run tsc-watch`.
If you are modifying TypeScript code, the best is to have the compiler watch for changes from a terminal. To do so, run `npm run watch`.

All TypeScript files are generated next to the .ts or .tsx file. So for example, if there's a file "lib/MyClass.ts", there will be a generated "lib/MyClass.js" next to it. If you create a new TypeScript file, make sure you add the generated .js file to .gitignore. It is implemented that way as it requires minimal changes to integrate TypeScript in the existing JavaScript code base.

## macOS dependencies

brew install yarn node
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

## Linux and Windows (WSL) dependencies
## Required dependencies

- Install yarn - https://yarnpkg.com/lang/en/docs/install/
- Install node v10.x (check with `node --version`) - https://nodejs.org/en/
- If you get a node-gyp related error you might need to manually install it: `npm install -g node-gyp`

# Building the tools
# Building the desktop application

Before building any of the applications, you need to build the tools and pre-commit hooks:
```
npm install
cd ElectronClient
npm run start
```

# Building the Terminal application

```
npm install && cd Tools && npm install && cd ..
npm install
cd CliClient
npm run start
```

# Building the Electron application
# Building the Mobile application

First you need to setup React Native to build projects with native code. For this, follow the instructions on the [Get Started](https://facebook.github.io/react-native/docs/getting-started.html) tutorial, in the "React Native CLI Quickstart" tab.

## Linux and macOS
Then:

```
npm run copyLib
npm run tsc
cd ElectronClient/app
npm install
yarn dist
cd ReactNativeClient
react-native run-ios
# Or: react-native run-android
```

If there's an error `while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory`, run `sudo apt-get install libgconf-2-4`
To run the iOS application, it might be easier to open the file `ios/Joplin.xcworkspace` on XCode and the app from there.

If you get a node-gyp related error you might need to manually install it: `npm install -g node-gyp`.
On iOS you might also need to install the Podfiles:

If you get the error `libtool: unrecognized option '-static'`, follow the instructions [in this post](https://stackoverflow.com/a/38552393/561309) to use the correct libtool version.
```
cd ReactNativeClient/ios
pod install
```

That will create the executable file in the `dist` directory.
# Troubleshooting desktop application

From `/ElectronClient` you can also run `run.sh` to run the app for testing.
## On Linux and macOS

## Windows
If there's an error `while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory`, run `sudo apt-get install libgconf-2-4`

Run the following commands on Windows Command prompt running as Administrator:
If you get a node-gyp related error you might need to manually install it: `npm install -g node-gyp`.

```
xcopy /C /I /H /R /Y /S ReactNativeClient\lib ElectronClient\app\lib
npm run tsc
cd ElectronClient\app
npm install
yarn dist
```
If you get the error `libtool: unrecognized option '-static'`, follow the instructions [in this post](https://stackoverflow.com/a/38552393/561309) to use the correct libtool version.

## On Windows

If node-gyp does not works (MSBUILD: error MSB3428: Could not load the Visual C++ component "VCBuild.exe"), you might need to install the `windows-build-tools` using `npm install --global windows-build-tools`.

Expand All @@ -75,7 +76,7 @@ If you get an `error MSB8020: The build tools for v140 cannot be found.` try to

The [building\_win32\_tips on this page](./readme/building_win32_tips.md) might be helpful.

## Troubleshooting desktop application
## Other issues

> The application window doesn't open or is white
Expand All @@ -91,27 +92,3 @@ This is an indication that there's an early initialisation error. Try this:
You should not use WSL at all because this is a GUI app that lives outside of WSL, and the WSL layer can cause all kind of very hard to debug issues. It can also lock files in node_modules that cannot be unlocked when the app crashes (you need to restart your computer). Likewise, don't run the TypeScript watch command from WSL.

So everything should be done from a Windows Command prompt running as Administrator. You can use `run.bat` to run the app in dev mode.

# Building the Mobile application

First you need to setup React Native to build projects with native code. For this, follow the instructions on the [Get Started](https://facebook.github.io/react-native/docs/getting-started.html) tutorial, in the "React Native CLI Quickstart" tab.

Then:

```
npm run tsc
cd ReactNativeClient
npm install
react-native run-ios
# Or: react-native run-android
```

# Building the Terminal application

```
cd CliClient
npm install
./build.sh
```

Run `run.sh` to start the application for testing.
5 changes: 2 additions & 3 deletions CliClient/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
build/*
!build/locales
node_modules/
app/src
tests-build/
Expand All @@ -21,4 +19,5 @@ tests/sync
out.txt
linkToLocal.sh
yarn-error.log
tests/support/dropbox-auth.txt
tests/support/dropbox-auth.txt
build/
15 changes: 0 additions & 15 deletions CliClient/build.sh

This file was deleted.

22 changes: 22 additions & 0 deletions CliClient/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const gulp = require('gulp');
const fs = require('fs-extra');
const utils = require('../Tools/gulp/utils');
const tasks = {
copyLib: require('../Tools/gulp/tasks/copyLib'),
};

const buildDir = `${__dirname}/build`;

tasks.build = {
fn: async () => {
await utils.copyDir(`${__dirname}/app`, buildDir, {
excluded: ['node_modules'],
});
await utils.copyDir(`${__dirname}/locales-build`, `${buildDir}/locales`);
await tasks.copyLib.fn();
await utils.copyFile(`${__dirname}/package.json`, `${buildDir}/package.json`);
fs.chmodSync(`${buildDir}/main.js`, 0o755);
},
};

gulp.task('build', tasks.build.fn);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,39 @@ locales['sv'] = require('./sv.json');
locales['tr_TR'] = require('./tr_TR.json');
locales['zh_CN'] = require('./zh_CN.json');
locales['zh_TW'] = require('./zh_TW.json');
stats['ar'] = {"percentDone":94};
stats['eu'] = {"percentDone":40};
stats['bs_BA'] = {"percentDone":88};
stats['bg_BG'] = {"percentDone":79};
stats['ca'] = {"percentDone":62};
stats['hr_HR'] = {"percentDone":33};
stats['cs_CZ'] = {"percentDone":97};
stats['da_DK'] = {"percentDone":87};
stats['de_DE'] = {"percentDone":98};
stats['et_EE'] = {"percentDone":78};
stats['en_GB'] = {"percentDone":100};
stats['en_US'] = {"percentDone":100};
stats['es_ES'] = {"percentDone":97};
stats['eo'] = {"percentDone":45};
stats['fr_FR'] = {"percentDone":98};
stats['gl_ES'] = {"percentDone":51};
stats['it_IT'] = {"percentDone":93};
stats['nl_NL'] = {"percentDone":89};
stats['nl_BE'] = {"percentDone":40};
stats['nb_NO'] = {"percentDone":91};
stats['fa'] = {"percentDone":39};
stats['pl_PL'] = {"percentDone":77};
stats['pt_PT'] = {"percentDone":93};
stats['pt_BR'] = {"percentDone":90};
stats['ro'] = {"percentDone":40};
stats['sl_SI'] = {"percentDone":51};
stats['sv'] = {"percentDone":69};
stats['tr_TR'] = {"percentDone":94};
stats['el_GR'] = {"percentDone":96};
stats['ru_RU'] = {"percentDone":98};
stats['sr_RS'] = {"percentDone":77};
stats['zh_CN'] = {"percentDone":97};
stats['zh_TW'] = {"percentDone":94};
stats['ja_JP'] = {"percentDone":98};
stats['ko'] = {"percentDone":92};
module.exports = { locales: locales, stats: stats };
stats['ar'] = { 'percentDone': 94 };
stats['eu'] = { 'percentDone': 40 };
stats['bs_BA'] = { 'percentDone': 88 };
stats['bg_BG'] = { 'percentDone': 79 };
stats['ca'] = { 'percentDone': 62 };
stats['hr_HR'] = { 'percentDone': 33 };
stats['cs_CZ'] = { 'percentDone': 97 };
stats['da_DK'] = { 'percentDone': 87 };
stats['de_DE'] = { 'percentDone': 98 };
stats['et_EE'] = { 'percentDone': 78 };
stats['en_GB'] = { 'percentDone': 100 };
stats['en_US'] = { 'percentDone': 100 };
stats['es_ES'] = { 'percentDone': 97 };
stats['eo'] = { 'percentDone': 45 };
stats['fr_FR'] = { 'percentDone': 98 };
stats['gl_ES'] = { 'percentDone': 51 };
stats['it_IT'] = { 'percentDone': 93 };
stats['nl_NL'] = { 'percentDone': 89 };
stats['nl_BE'] = { 'percentDone': 40 };
stats['nb_NO'] = { 'percentDone': 91 };
stats['fa'] = { 'percentDone': 39 };
stats['pl_PL'] = { 'percentDone': 77 };
stats['pt_PT'] = { 'percentDone': 93 };
stats['pt_BR'] = { 'percentDone': 90 };
stats['ro'] = { 'percentDone': 40 };
stats['sl_SI'] = { 'percentDone': 51 };
stats['sv'] = { 'percentDone': 69 };
stats['tr_TR'] = { 'percentDone': 94 };
stats['el_GR'] = { 'percentDone': 96 };
stats['ru_RU'] = { 'percentDone': 98 };
stats['sr_RS'] = { 'percentDone': 77 };
stats['zh_CN'] = { 'percentDone': 97 };
stats['zh_TW'] = { 'percentDone': 94 };
stats['ja_JP'] = { 'percentDone': 98 };
stats['ko'] = { 'percentDone': 92 };
module.exports = { locales: locales, stats: stats };
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3407a31

Please sign in to comment.