Skip to content

Web prototype for automated generation of individual explanations from Catala programs

License

Notifications You must be signed in to change notification settings

CatalaLang/catala-dsfr

Repository files navigation

Catala DFSR

Report BugWebsite

Source code for the web demo about automated generation of individual explanations of Catala programs hosted at https://code.gouv.fr/demos/catala.


This project is built on top of the following libraries:

Local dev

# Install dependencies
yarn

# Start a local dev server
yarn dev

Warning

When adding modifications to the Rescript files, if you start seeing errors like that in your yarn dev output:

14:28:30 [vite] hmr invalidate /src/components/Form.bs.js Could not Fast Refresh.

That means that the fast reload isn't working properly. To avoid that, each ReScript file must export only one React component. You can hide internal code by providing an interface file that only exports the component you want to use.

Generally, you should always have an inteface file (.resi) for each implementation file (.res) to speed up incremental build.

Using local packages

If you want to use one of the @catala-lang packages from your local machine instead of the published version, you can use yarn link to link them to this project.

# In the library you want to link
yarn link

# In this project
yarn link @catala-lang/<library-name>

Important

But then some shenanigans will appear. First, there might be duplicate dependencies between catala-dsfr and the linked dependencies. These duplicates will show as error messages so you know which they are. To remove the dependency duplication, you should link the version of the duplicate dependency in catala-dsfr/node_modules/<duplicate-library-name> and make sure @catala-lang/<library-name> uses it with yarn link <duplicate-library-name> in the local folder of @catala-lang/<library-name>.

Now that the links are OK, you have to tell vite to watch for the changes in the dependencies to have reloading work. For that, follow the instructions to modify vite.config.ts in catala-dsfr here. At last, don't forget to run yarn watch in the local folder of @catala-lang/<library-name>, so that the modifications in the Rescript files are watched and compiled to modifications to JS files that vite can pick up.

Versioned assets

Multiple versions of @catala-lang/catala-web-assets and @catala-lang/french-law are used in this project.

In the assets-versions.json file is defined the list of versions available. Each version is defined by a pair of versions for each package (one for the web assets and one for the french law library) and named with the corresponding date.

To add a new version

To add a new version of the assets, you need to use the yarn aliases:

# For @catala-lang/catala-web-assets
yarn add @catala-lang/catala-web-assets-<latest-version>@npm:@catala-lang/catala-web-assets@<latest-version>

# For @catala-lang/french-law
yarn add @catala-lang/french-law-<latest-version>@npm:@catala-lang/french-law@<latest-version>

Tip

The latest version of the @catala-lang/catala-web-assets package and the @catala-lang/french-law package are automatically updated with the ./update-assets.sh (yarn assets) script run before yarn build and yarn dev. Consequently, you don't need to manually update the version of the packages in the package.json file.

Important

For now, if a new version of one of the packages is added, you need to manually update the assets-versions.json file with the new version.

{
  "available": [
+   {
+    "name": "<date>",
+    "french-law": "<latest-version>"
+    "catala-web-assets": "<latest-version>",
+  },
  ]
}

Using local assets

If you want to use @catala-lang/french-law (resp. @catala-lang/catala-web-assets) from your local machine instead of the published version, you can use yarn link to link them to this project.

Important

See the Using local packages section for more information about how to link local packages.

Then, add the new version in assets-versions.json with the local version.

{
  "available": [
+   {
+     "name": "local", # or whatever name you want to give to the version
+     "french-law": "local"
+     "catala-web-assets": "<latest-version>", 
+   },
  ]
}

Build for production and deploy

To test before deploy

# Build for production
yarn build

# Locally preview the production build
yarn serve

To deploy

# Build for production and rsync files to the <destination> (could be a ssh address)
yarn deploy <destination>

Sponsors

This library has been developed during a research project funded by the mission logiciels libres et communs numériques of the direction interministérielle du numérique in collaboration with the Catala project.