All issues, PRs, suggestions welcome. Feel free to log issues here, or find me on the Elm Slack.
The main entry point is at index.js
. This parses the command line arguments using
Commander.js, then executes the code generation process. This process is defined
in code-gen.js
(the function exported from this module). The process has the following steps:
- Read the source JSON file.
- Build an in-memory model of the source, defining the modules/functions/parameters that should be created. Here is
where all validation and sanitisation of the source occurs. This is defined in
model-builder.js
. - Build the actual Elm code for the model created above. This is defined in
code-builder.js
. - Write the generated Elm code to disk. This is defined in
file-writer.js
.
There is a test file for every module (with the same name as the module, with .spec
added). For most modules this
contains low-level unit tests focused purely on what that module does. In some cases, however, the module under test is
a higher-level component (e.g. index.js
and code-gen.js
) so the tests here are higher-level, acting more like
integration tests, ensuring various other modules all interoperate correctly.
There are also some integration tests that run the whole process and validate its output using
elm-format and elm-test. These are
defined in package.json
in these scripts: generate-sample-translations
, elm-format-validate
, and elm-test-validate
.
The purpose of these tests is to make sure that the generated Elm code is properly formatted and works as expected.
When first opening the project, you might see some warnings about unresolved variables in node-specific code:
To get round this go to Settings --> Languages & Frameworks --> Node.js and NPM and tick the Coding assistance for Node.js checkbox:
Then, when prompted, select the elm-i18next-gen
module: