Skip to content

Commit

Permalink
build: replace yarn with npm
Browse files Browse the repository at this point in the history
Changes documentation, commands, and procedures to work with `npm`
instead of `yarn`.  This should simplify our installation procedures and
remove an additional dependency that is no longer required.

Closes #7194.
  • Loading branch information
jniles committed May 24, 2024
1 parent cf15f00 commit d731271
Show file tree
Hide file tree
Showing 13 changed files with 20,651 additions and 10,275 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*~

# ignore lock file until it works with npm < version 5
package-lock.json
#package-lock.json

# ignore all compressed files
*.gz, *.xz, *.zip
Expand Down
8 changes: 4 additions & 4 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ The directions below assume you are working in a development environment based o
2. Do `git pull` to make sure it is up-to-date.
3. Create a new branch called `release-next` (for example) that is based on the upstream repo to do your release with. If one exists on upstream, remove it first. For example, if the main BHIMA githup repo is called `upstream` in your local development setup, do:
- `git checkout -b release-next upstream/master`
4. Run `yarn` to ensure you have the latest dependencies.
4. Run `npm install` to ensure you have the latest dependencies.
5. (Optional, best practice) Test the latest migration script on a production database. (See * below)
6. Build the application in production mode to make sure the build works correctly.
- `NODE_ENV=production yarn build`
- `NODE_ENV=production npm run build`
7. Determine the version number for the next version (eg, `v1.X.Y`)
8. Create a new folder in the `server/models/migrations/` directory to hold the migration file with the format `v1.A.B-v1.X.Y` where `1.A.B` is the current version and `v1.X.Y` is the next version.
9. Move the `server/models/migrations/next/migrate.sql` file to the directory created in the previous step.
Expand All @@ -23,15 +23,15 @@ The directions below assume you are working in a development environment based o
13. In github, convert your branch to a PR in the `IMA-WorldHealth/bhima` repository.
14. Make sure your personal GITHUB_TOKEN environment variable is defined
(assuming you have permissions to update the main BHIMA repository. [See Github instructions for this.](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
15. Run `yarn release` and follow the directions.
15. Run `npm run release` and follow the directions.
16. Verify the release was created and that the binary <version>.tar.gz file
is in the assets for the release.
17. Via the github interface, merge your `release-next` PR into `master`

(*) Optional, Best Practice: Test the latest database changes on a production database.

1. Change your `.env` so the `$DB_NAME` variable is the correct one for a production database.
2. Create your database migration script by running `yarn migrate`. This will create a release migration file `migration-$DB_NAME.sql`.
2. Create your database migration script by running `npm run migrate`. This will create a release migration file `migration-$DB_NAME.sql`.
3. Append the current migration file into the release migration file:
- `cat server/models/migrations/next/migrate.sql >> migration-$DB_NAME.sql`.
4. Build the migration script targetting your database.
Expand Down
4 changes: 2 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ These steps describe the typical deployment setup. We assume that the BHIMA sof
7. Copy the `.env` file from the current application into the `bhima-$RELEASE/bin/` folder and make any changes necessary to `.env`.
8. Copy the contents (but not sub-directories) from the `bhima-$RELEASE/bin/` folder into the `bhima-$RELEASE/` folder. This can be done with `cp $HOME/apps/bhima-$RELEASE/bin/* $HOME/apps/bhima-$RELEASE/bin/`
9. Change directory into the release directory with `cd $HOME/apps/bhima-$RELEASE/`
10. Install the `node_modules/` in the `bhima-$RELEASE/` folder with the command: `NODE_ENV=production yarn`
10. Install the `node_modules/` in the `bhima-$RELEASE/` folder with the command: `NODE_ENV=production npm install`

The BHIMA upgrade is not prepared.

Expand All @@ -35,7 +35,7 @@ Locally:
1. Download the latest production database from the BHIMA backups server for the site you are upgrading.
2. Build it locally.
3. Change the environmental variable `$DB_NAME` in the `.env` file in the bhima repository to the name of the site you are upgrading.
4. Run `yarn migrate` to create a migration script `migration-$DATABASE.sql`.
4. Run `npm run migrate` to create a migration script `migration-$DATABASE.sql`.
5. Copy in the migration files from up to the present version from the `server/models/migrations/` folder(s). You can use `cat` for this.
6. Test the database migration script: `mysql $DATABASE < migration-$DATABASE.sql`
7. If it works, copy the database over to the remote server with `scp`: `scp migration-$DATABASE.sql bhima@target.bhi.ma:~/`
Expand Down
9 changes: 2 additions & 7 deletions docs/cloud-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# BH_DATABASE_NAME - the name of the BHIMA database. Often tied to the domain name.
# BH_DATABASE_PASSWORD - the password of the database. Defaults to $(uuid).
# BH_DATABASE_USER - the name of the database user
#

packages:
- curl
Expand Down Expand Up @@ -159,10 +158,6 @@ runcmd:
- apt-get -qq update
- apt-get install -y nodejs

# install yarn
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- apt-get -qq update && apt-get install yarn --no-install-recommends

# clone and set up BHIMA repository
- cd /opt/
Expand All @@ -181,8 +176,8 @@ runcmd:
- echo "DB_NAME=$BH_DATABASE_NAME" >> .env

- bash ./sh/build-init-database.sh
- yarn --ignore-engines --frozen-lockfile
- NODE_ENV=production yarn build
- npm install
- NODE_ENV=production npm run build
- chown -R bhima:bhima .

# set up bhima to start on reboot
Expand Down
37 changes: 15 additions & 22 deletions docs/en/for-developers/installing-bhima.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Before you begin the installation process, please make sure you have all the bhi
2. [Redis](https://redis.io)
3. [curl](https://curl.haxx.se/)
4. [NodeJS](https://nodejs.org/en/) \(Note that we only test on stable and edge\).
5. [yarn](https://yarnpkg.com/)
6. [git](https://git-scm.com/downloads)
5. [git](https://git-scm.com/downloads)

### Detailed dependency installation instructions for Ubuntu

Expand Down Expand Up @@ -53,13 +52,8 @@ sudo apt-get install nodejs
# Verify that nodejs and npm are installed as expected
npm --version
node --version
```

```bash
# Installs yarn without re-installing NodeJS
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn --no-install-recommends
# Install chromium browser
# (On debian, you will also need to install 'chromium-driver' separately)
Expand Down Expand Up @@ -96,13 +90,12 @@ cd bhima

All our build scripts are found the `package.json` file. We use [gulpjs](http://www.gulpjs.com) internally, but you shouldn't ever need to call gulp explicitly.
To execute the build scripts, you can use either `yarn` or `npm`. We'll use `yarn` for the remainder of this guide. Note that using `npm` requires you to use `npm run` where it says `yarn` below.

To execute the build scripts, you can use either `yarn` or `npm`. We'll use `npm` below.
```bash
# Inside the bhima/ directory
# install all node modules
yarn install
npm run install
#If this command gives you an error (I.E. if you’re running Parallels), try running the following command:
git config -global url."https://".insteadOf git://
Expand Down Expand Up @@ -143,7 +136,7 @@ Then, build the app with
```bash
# build the application
NODE_ENV="development" yarn build
NODE_ENV="development" npm run build
```
### Creating a database
Expand Down Expand Up @@ -186,7 +179,7 @@ docker run --name redis -p 6379:6379 -d redis
If you have already a MySQL server running on port 3306 of your localhost, start docker without the port-forwarding (`-p 3306:3306`), use `docker inspect mysql` to find the IP of the container and use that IP in the `.env` file as `DB_HOST`.
The database structure is contained in the `server/models/*.sql` files. You can execute these one by one in the order below, or simply run `yarn build:db`.
The database structure is contained in the `server/models/*.sql` files. You can execute these one by one in the order below, or simply run `npm run build:db`.
1. `server/models/01-schema.sql`
2. `server/models/02-functions.sql`
Expand All @@ -201,7 +194,7 @@ This sets up the basic schema, routines, and triggers. The following scripts wil
2. `server/models/06-bhima.sql`
3. `test/data.sql`
You can run all this by using the following command: `yarn build:db` Alternatively, you might use the `./sh/build-database.sh` script, customized with your environmental variables as shown below:
You can run all this by using the following command: `npm run build:db` Alternatively, you might use the `./sh/build-database.sh` script, customized with your environmental variables as shown below:
```bash
# Install the database
Expand All @@ -211,13 +204,13 @@ DB_USER='me' DB_PASS='MyPassword' DB_NAME='bhima' ./sh/build-database.sh
If you are creating a fresh build for a new production site, you should probably start with:
```bash
yarn build:clean
npm run build:clean
```
And the databases to be loaded will need to be customized for that site.
### Running the Application
Running the application is super easy! Just type `yarn dev` in the application root directory.
Running the application is super easy! Just type `npm run dev` in the application root directory.
### Verify the Install
Expand All @@ -229,18 +222,18 @@ Navigate to [http://localhost:8080](http://localhost:8080) in the browser to ver
Our tests are broken into unit tests, end to end tests, and integration tests. There is more information on testing in the [wiki](https://github.com/IMA-WorldHealth/bhima/wiki).
1. **Integration Tests** - These test the server + database integration and generally our APIs. All reachable API endpoints should generally have an integration test associated with them. To run them, type `yarn test:integration`.
1. **Integration Tests** - These test the server + database integration and generally our APIs. All reachable API endpoints should generally have an integration test associated with them. To run them, type `npm run test:integration`.
2. **Server Unit Tests** - Server libraries are unit tested with mocha and chai, similar to the integration tests. To run them, type
`yarn test:server-unit.`
3. **Client Unit Tests** - Client components are unit tested with karma which you should have installed if you installed all dependencies. Karma launches a chrome browser to execute the tests. To run them, type `yarn test:client-unit`.
`npm run test:server-unit.`
3. **Client Unit Tests** - Client components are unit tested with karma which you should have installed if you installed all dependencies. Karma launches a chrome browser to execute the tests. To run them, type `npm run test:client-unit`.
4. **End to End Tests** - The entire stack is tested with end to end tests using [playwright](https://playwright.dev/). To enable the end-to-end tests, see [Running end-to-end tests](./end-to-end-tests.md).
You can run the end-to-end tests with
- `yarn test:e2e-account` _or_
- `yarn test:e2e-all` _or_
- `yarn test:e2e-?` _(where ? varies from 1 to 8)_.
- `npm run test:e2e-account` _or_
- `npm run test:e2e-all` _or_
- `npm run test:e2e-?` _(where ? varies from 1 to 8)_.
Note: test:e2e-3 includes test:e2e-account.
You can run all non-end-to-end tests by simply typing `yarn test`.
You can run all non-end-to-end tests by simply typing `npm run test`.
Enjoy using bhima!
8 changes: 4 additions & 4 deletions docs/en/for-developers/upgrading-bhima.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ When upgrading from an old version to a new version, it is important to run all

Changes to stored procedures, triggers, and functions are **not** tracked in migration scripts. This is because they are due to frequent change and are already stored in the `server/models` directory. Therefore, it is sufficient to simply rebuild them from source.

To help with this operation, BHIMA provides a [migration helper script](https://github.com/IMA-WorldHealth/bhima/blob/master/sh/setup-migration-script.sh) that can be invoked with `yarn migrate`. This script does several things:
To help with this operation, BHIMA provides a [migration helper script](https://github.com/IMA-WorldHealth/bhima/blob/master/sh/setup-migration-script.sh) that can be invoked with `npm run migrate`. This script does several things:

1. Drops all the triggers
2. Drops all routines
Expand All @@ -36,9 +36,9 @@ As mentioned above, releases are managed on Github. There are two ways to obtai
The basic steps to upgrade now are:

1. Obtain the latest release either by downloading and unzipping or checking out the tag with git.
2. Run `yarn` to upgrade dependencies.
3. Run `NODE_ENV=production yarn build` to compile the latest client-side code
4. Run `yarn migrate` to create the migration script.
2. Run `npm install` to upgrade dependencies.
3. Run `NODE_ENV=production npm run build` to compile the latest client-side code
4. Run `npm run migrate` to create the migration script.
5. Run `mysql $DATABASE < migration-$DATABASE.sql` as described above.
6. Restart any running BHIMA instances

Expand Down
1 change: 0 additions & 1 deletion docs/fr/for-developers/end-to-end-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ BHIMA dispose d'une large collection de tests de bout en bout utilisant le [Envi

2. Vérifiez que tout est cohérent. Les commandes suivantes doivent donner les mêmes numéros de version :
```bash
grep 'playwright/test' yarn.lock # si vous utilisez yarn
grep 'playwright/test' package.json
npx playwright --version
```
Expand Down
25 changes: 9 additions & 16 deletions docs/fr/for-developers/installing-bhima.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Avant de commencer le processus d'installation, assurez-vous que toutes les dép
2. [Redis](https://redis.io)
3. [curl](https://curl.haxx.se/)
4. [NodeJS](https://nodejs.org/en/) \(nous vous recommandons d’utiliser le [gestionnaire de version de node](https://github.com/creationix/nvm) sous Linux. Notez que nous ne testons que sur des versions stables. et bord \).
5. [yarn](https://yarnpkg.com)
6. [git](https://git-scm.com/downloads)
5. [git](https://git-scm.com/downloads)

### Instructions détaillées sur l'installation des dépendances pour Ubuntu \(vérifiées/installées spécifiquement avec VirtualBox\)

Expand All @@ -42,11 +41,6 @@ export NVM_DIR = "$ HOME/.nvm"
#Téléchargez NodeJS LTS
nvm install lts/*

#Installe yarn sans réinstaller NodeJS
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install fil --no-install-recommend

# Exécutez la commande suivante pour installer git:
sudo apt-get install git
Expand All @@ -65,13 +59,12 @@ cd bhima

Tous nos scripts de construction se trouvent dans le fichier `package.json`. Nous utilisons [gulpjs](http://www.gulpjs.com) en interne, mais vous ne devriez jamais avoir besoin d'appeler explicitement gulp.

Pour exécuter les scripts de construction, vous pouvez utiliser `yarn` ou` npm`. Nous utiliserons `fil 'pour le reste de ce guide. Notez que l'utilisation de `npm` peut nécessiter que vous utilisiez` npm run` où il est indiqué `yarn` ci-dessous.

Pour exécuter les scripts de construction, vous pouvez utiliser `yarn` ou` npm`. Nous utiliserons `npm` pour le reste de ce guide.
```bash
# Dans le répertoire bhima /
# installer tous les modules de noeuds

yarn install
npm run install

# Si cette commande vous donne une erreur (par exemple, si vous utilisez Parallels), essayez d’exécuter la commande suivante:
git config -global url. "https: //" .insteadOf git: //
Expand Down Expand Up @@ -106,7 +99,7 @@ Ensuite, construisez l'application avec
```bash
# construire l'application

NODE_ENV="development" yarn build
NODE_ENV="development" npm run build
```

### Création d'une base de données
Expand Down Expand Up @@ -141,7 +134,7 @@ docker run --name mysql -p 3306:3306 \
Il faut changer le fichier `.env` pour mettre `DB_HOST` a `127.0.0.1`.


La structure de la base de données est contenue dans les fichiers `server/models/*.sql`. Vous pouvez les exécuter un par un dans l'ordre ci-dessous ou simplement lancer `yarn build: db`.
La structure de la base de données est contenue dans les fichiers `server/models/*.sql`. Vous pouvez les exécuter un par un dans l'ordre ci-dessous ou simplement lancer `npm run build: db`.

1. `server/models/01-schema.sql`
2. `server/models/04-triggers.sql`
Expand All @@ -155,7 +148,7 @@ Ceci configure le schéma de base, les déclencheurs et les routines. Les script
2. `server/models/06-bhima.sql`
3. `test/data.sql`

Vous pouvez exécuter tout cela en utilisant la commande suivante: `yarn build:db` Vous pouvez également utiliser le script`./sh/build-database.sh`, personnalisé à l'aide de vos variables d'environnement, comme indiqué ci-dessous:
Vous pouvez exécuter tout cela en utilisant la commande suivante: `npm run build:db` Vous pouvez également utiliser le script`./sh/build-database.sh`, personnalisé à l'aide de vos variables d'environnement, comme indiqué ci-dessous:

```bash
# installer la base de données
Expand All @@ -164,7 +157,7 @@ DB_USER='moi' DB_PASS='MonPassword' DB_NAME='bhima' ./sh/build-database.sh

### Exécution de l'application

Exécuter l'application est super facile! Tapez simplement `yarn dev` dans le répertoire racine de l'application.
Exécuter l'application est super facile! Tapez simplement `npm run dev` dans le répertoire racine de l'application.

### Vérifier l'installation

Expand All @@ -180,8 +173,8 @@ Nos tests sont répartis en tests unitaires, tests de bout en bout et tests d'in
2. **Tests unitaires de serveur** - Les bibliothèques de serveur sont testées d'unité avec mocha et chai, de manière similaire aux tests d'intégration. Pour les exécuter, tapez
   `test de fil: unité-serveur.`
3. **Tests d'unité client** - Les composants client sont testés avec karma et doivent être installés si vous avez installé toutes les dépendances. Karma lance un navigateur chrome pour exécuter les tests. Pour les exécuter, tapez `test de fil: unité-client`.
4. **Tests de bout en bout** - L'ensemble de la pile est testée avec \(souvent flaky \) des tests de bout en bout à l'aide de [rapporteur](https://playwright.dev/). Les tests de bout en bout peuvent être exécutés avec `yarn test:e2e`.
4. **Tests de bout en bout** - L'ensemble de la pile est testée avec \(souvent flaky \) des tests de bout en bout à l'aide de [rapporteur](https://playwright.dev/). Les tests de bout en bout peuvent être exécutés avec `npm run test:e2e`.

Vous pouvez exécuter tous les tests en tapant simplement `yarn test`.
Vous pouvez exécuter tous les tests en tapant simplement `npm run test`.

Profitez de l'aide bhima!
8 changes: 4 additions & 4 deletions docs/fr/for-developers/upgrading-bhima.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Lors de la mise à niveau d'une ancienne version vers une nouvelle version, il e

Les modifications apportées aux procédures stockées, aux déclencheurs et aux fonctions ne sont **pas** suivies dans les scripts de migration. En effet, ils sont dus à des changements fréquents et sont déjà stockés dans le répertoire `server/models`. Il suffit donc simplement de les reconstruire à partir des sources.

Pour faciliter cette opération, BHIMA fournit un [script d'aide à la migration](https://github.com/IMA-WorldHealth/bhima/blob/master/sh/setup-migration-script.sh) qui peut être invoqué avec `yarn migrate`. Ce script fait plusieurs choses :
Pour faciliter cette opération, BHIMA fournit un [script d'aide à la migration](https://github.com/IMA-WorldHealth/bhima/blob/master/sh/setup-migration-script.sh) qui peut être invoqué avec `npm run migrate`. Ce script fait plusieurs choses :

1. Supprime tous les déclencheurs
2. Supprime toutes les routines
Expand All @@ -36,9 +36,9 @@ Comme mentionné ci-dessus, les versions sont gérées sur Github. Il existe deu
Les étapes de base pour mettre à niveau maintenant sont :

1. Obtenez la dernière version en téléchargeant et en décompressant ou en vérifiant la balise avec git.
2. Exécutez `yarn` pour mettre à niveau les dépendances.
3. Exécutez `NODE_ENV=production yarn build` pour compiler le dernier code côté client
4. Exécutez `yarn migrate` pour créer le script de migration.
2. Exécutez `npm install` pour mettre à niveau les dépendances.
3. Exécutez `NODE_ENV=production npm run build` pour compiler le dernier code côté client
4. Exécutez `npm run migrate` pour créer le script de migration.
5. Exécutez `mysql $DATABASE < migration-$DATABASE.sql` comme décrit ci-dessus.
6. Redémarrez toutes les instances BHIMA en cours d'exécution

Expand Down
Loading

0 comments on commit d731271

Please sign in to comment.