From 6edf5400067c1bfc8b1c9e9ccce5bb31295459d2 Mon Sep 17 00:00:00 2001 From: Jennifer Q <66472237+latin-panda@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:45:05 +0700 Subject: [PATCH] feat(#18,#19): Make tool global installable (#20) --- Dockerfile | 18 ++++++++++++++++++ README.md | 20 ++++++++++++++++---- package-lock.json | 14 +++++++++----- package.json | 12 ++++++++---- src/cli.ts | 2 +- src/index.ts | 2 ++ tests/cli.spec.ts | 2 +- 7 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a119724 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 97bd53d..b2dd3ec 100644 --- a/README.md +++ b/README.md @@ -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 `. + +### 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 Steps to design the test data: diff --git a/package-lock.json b/package-lock.json index 343fb60..822a7e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,22 @@ { "name": "test-data-generator", - "version": "0.2.0", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "test-data-generator", - "version": "0.2.0", - "license": "GNU GPLv3", + "version": "1.0.0", + "hasInstallScript": true, + "license": "AGPL-3.0-only", "dependencies": { "@faker-js/faker": "^8.3.1", "axios": "^1.6.2", "uuid": "^9.0.1" }, + "bin": { + "tdg": "built/index.js" + }, "devDependencies": { "@medic/eslint-config": "^1.1.0", "@types/chai": "^4.3.11", @@ -29,8 +33,8 @@ "typescript": "^5.3.3" }, "engines": { - "node": ">=16.0.0", - "npm": ">=8.0.0" + "node": ">=20.11.0", + "npm": ">=10.2.4" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 684ff4f..f5dc462 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/cli.ts b/src/cli.ts index 6a580ac..6c59dc0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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.' ); } diff --git a/src/index.ts b/src/index.ts index 97d6a74..7098dc2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { cli } from './cli.js'; import { Docs } from './docs.js'; import { DocDesign } from './doc-design.js'; diff --git a/tests/cli.spec.ts b/tests/cli.spec.ts index 0317f57..81ca038 100644 --- a/tests/cli.spec.ts +++ b/tests/cli.spec.ts @@ -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.' ); } });