Skip to content

Commit

Permalink
feat(#18,#19): Make tool global installable (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
latin-panda authored Jun 24, 2024
1 parent 83261ba commit 6edf540
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:20-slim

RUN apt update && apt install --no-install-recommends -y build-essential

WORKDIR /app

COPY . .

RUN npm ci

# Using the 1000:1000 user is recommended for VSCode dev containers
# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
USER node

ENV FILE=""
ENV COUCH_URL=""

ENTRYPOINT npm run generate test-data/$FILE
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ 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

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 something similar to this: `http://[user]:[pass]@[host]:[port]/medic`
- 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
- Install the project by running `npm ci`
- 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 `npm run generate *path_to_your_custom_design_file*`

### Install it globally
Another option is to install the tool globally:
- Install package dependencies and build the project `npm ci`
- Run `npm install -g` in the project root folder
- Build, generate and upload data by running `tdg <path_to_your_custom_design_file>`.

### 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 <folder_path_of_your_design_file>:/app/test-data -e COUCH_URL=<test_instance_CouchDB_URL> -e FILE=<your_design_file> test-data-generator`

## Designing Test Data

Steps to design the test data:
Expand Down
14 changes: 9 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-data-generator",
"version": "0.2.0",
"version": "1.0.0",
"description": "Tool to upload test data into CHT test instances.",
"type": "module",
"main": "built/index.js",
Expand All @@ -9,17 +9,21 @@
"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": {
"tdg": "built/index.js"
},
"keywords": [
"CHT",
"test data"
],
"author": "latin-panda",
"license": "GNU GPLv3",
"author": "",
"license": "AGPL-3.0-only",
"dependencies": {
"@faker-js/faker": "^8.3.1",
"axios": "^1.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getInputFilePath = () => {
const args = process.argv.slice(2);
if (!args?.length) {
throw new Error(
'No path to the design file provided. Expected: npm run generate *path_to_your_custom_design_file*'
'No path to the design file provided.'
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { cli } from './cli.js';
import { Docs } from './docs.js';
import { DocDesign } from './doc-design.js';
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('cli', () => {
assert.fail('Should have thrown an error');
} catch (error) {
expect(error?.message).to.equal(
'No path to the design file provided. Expected: npm run generate *path_to_your_custom_design_file*'
'No path to the design file provided.'
);
}
});
Expand Down

0 comments on commit 6edf540

Please sign in to comment.