diff --git a/Dockerfile b/Dockerfile index 434d372..b371da9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,9 @@ RUN npm ci # https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user USER node -ARG INSTANCE_COUCH_URL -ENV COUCH_URL=INSTANCE_COUCH_URL +ENV FILE="" +ENV COUCH_URL="" VOLUME /app/test-data -ARG FILE -ENTRYPOINT ["npm", "run", "generate", "test-data/$FILE"] + +ENTRYPOINT npm run generate test-data/$FILE diff --git a/README.md b/README.md index f69f8cf..fbe5384 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Design the test data that fit your project hierarchy and reports. The tool will ## Minimum System Requirements -- npm >= 8.0.0 -- node >= 16.0.0 +- npm >= 10.2.4 +- node >= 20.11.0 ## Setup and Getting Started @@ -28,10 +28,21 @@ Instructions on setting up the project and getting it running on a local machine - Set the `COUCH_URL` environment variable to point your test instance, for example it is something similar to this: `http://[user]:[pass]@[host]:[port]/medic` - Double-check your CHT test instance is running -- Clone or fork the repository -- Install the project globally by running `npm install -g`. +- Clone or fork the test data generator repository +- Install and build the project by running `npm ci` in the project root folder - Design the test data in a custom JavaScript file. See section [Designing Test Data](#designing-test-data). -- Build, generate data and upload by running `test-data-generator *path_to_your_custom_design_file*` +- Build, generate data and upload by running `npm run generate *path_to_your_custom_design_file*` + +### Install it globally +Another option is to install the tool globally: +- Build the project `npm run build` +- Run `npm install -g` in the project root folder +- Build, generate and upload data by running `test-data-generator `. + +### Use it with Docker +The tool is also available in Docker: +- Create the image `docker build -t test-data-generator .` +- Run the container `docker run --rm -it -v :/app/test-data -e COUCH_URL= -e FILE= test-data-generator` ## Designing Test Data @@ -39,7 +50,7 @@ Steps to design the test data: 1. Create a custom JavaScript file that exports a `default` function. This function should match the [`DocDesign` type](./src/doc-design.ts). 2. Your custom function should return an array of [`DesignSpec`](./src/doc-design.ts) objects that define the structure of your data to create. -3. Generate and upload data `test-data-generator *path_to_your_custom_design_file*`. That's all! You can check the data in the CHT's CouchDB. +3. Generate and upload data `npm run generate *path_to_your_custom_design_file*`. That's all! You can check the data in the CHT's CouchDB. Note that `getDoc` function should return an object with at least a `type: string`. Remember that `type` is a `data_record` for reports, but when it comes to contacts, use the `contact_types` defined in your CHT project's `app-settings.json`. diff --git a/package.json b/package.json index 32fba64..af61161 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "npm": ">=10.2.4" }, "scripts": { + "postinstall": "npm run build", "test": "mocha", "lint": "eslint .", "build": "npm run lint && tsc", - "generate": "npm run build && echo 'Processing, please wait.' && node built/." + "generate": "node built/." }, "bin": { "test-data-generator": "built/index.js"