-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Move the cht-conf README file to a new section on the Contributor Handbook cht-conf #620 --------- Co-authored-by: mariachana_moturi <[email protected]>
- Loading branch information
1 parent
54d3297
commit 15d06ea
Showing
4 changed files
with
334 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
--- | ||
title: "CHT App Configurer" | ||
linkTitle: "CHT Conf" | ||
weight: 10 | ||
description: > | ||
CHT Conf is a command-line interface tool to manage and configure apps built using the [Core Framework](https://github.com/medic/cht-core) of the [Community Health Toolkit](https://communityhealthtoolkit.org/). | ||
--- | ||
|
||
## Requirements | ||
- nodejs 18 or later | ||
- python 3 | ||
- Docker(optional) | ||
|
||
## Installation | ||
|
||
### Operating System Specific | ||
|
||
{{< tabpane persistLang=false lang=shell >}} | ||
{{< tab header="Linux (Ubuntu)" >}} | ||
npm install -g cht-conf | ||
sudo python -m pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic | ||
{{< /tab >}} | ||
{{< tab header="macOS" >}} | ||
npm install -g cht-conf | ||
pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic | ||
{{< /tab >}} | ||
{{< tab header="Windows (WSL2)" >}} | ||
# As Administrator: | ||
npm install -g cht-conf | ||
python -m pip install git+https://github.com/medic/[email protected]#egg=pyxform-medic --upgrade | ||
{{< /tab >}} | ||
{{< /tabpane >}} | ||
|
||
### Using Docker | ||
CHT Conf can also be run from within a Docker container. This is useful if you are already familiar with Docker and do not wish to configure the various dependencies required for developing CHT apps on your local machine. The necessary dependencies are pre-packaged in the Docker image. | ||
|
||
#### Using the image | ||
The Docker image can be used as a [VS Code Development Container](https://code.visualstudio.com/docs/devcontainers/containers) (easiest) or as a standalone Docker utility. | ||
|
||
Install [Docker](https://www.docker.com/). If you are using Windows, you also need to enable the [Windows Subsystem for Linux (WSL2)](https://learn.microsoft.com/en-us/windows/wsl/install) to perform the following steps. | ||
|
||
##### VS Code Development Container | ||
If you want to develop CHT apps with VS Code, you can use the Docker image as a Development Container. This will allow you to use the `cht-conf` utility and its associated tech stack from within VS Code (without needing to install dependencies like NodeJS on your host system). | ||
|
||
Look through [Developing with VS Code Dev Container Documentation](https://docs.communityhealthtoolkit.org/apps/tutorials/local-setup/#developing-with-vs-code-dev-container) to get more information . | ||
|
||
##### Standalone Docker utility | ||
If you are not using VS Code, you can use the Docker image as a standalone utility from the command line. Instead of using the `cht ...` command, you can run `docker run -it --rm -v "$PWD":/workdir medicmobile/cht-app-ide ....` This will create an ephemeral container with access to your current directory that will run the given cht command. (Do not include the `cht` part of the command, just your desired actions/parameters.) | ||
|
||
Run the following command inside the project directory to bootstrap your new CHT project: | ||
```shell | ||
docker run -it --rm -v "$PWD":/workdir medicmobile/cht-app-ide initialise-project-layout | ||
``` | ||
|
||
#### Note on connecting to a local CHT instance | ||
When using `cht-conf` within a Docker container to connect to a CHT instance that is running on your local machine (e.g. a development instance), you cannot use the `--local` flag or `localhost` in your `--url` parameter (since these will be interpreted as "local to the container"). | ||
|
||
It is recommended to run a local CHT instance using the [CHT Docker Helper script](https://docs.communityhealthtoolkit.org/apps/guides/hosting/4.x/app-developer/). You can connect to the resulting `...my.local-ip.co` URL from the Docker container (or the VS Code terminal). Ensure the port your CHT instance is hosted on is not blocked by your firewall. | ||
|
||
### Bash completion | ||
To enable tab completion in bash, add the following to your `.bashrc`/`.bash_profile`: | ||
```shell | ||
eval "$(cht-conf --shell-completion=bash)" | ||
``` | ||
|
||
### Upgrading | ||
To upgrade to the latest version, run the command below. To view changes made to CHT Conf, view the [CHANGELOG](https://docs.communityhealthtoolkit.org/apps/guides/updates/preparing-for-4/#cht-conf). | ||
```shell | ||
npm update -g cht-conf | ||
``` | ||
|
||
## Usage | ||
`cht` will upload the configuration **from your current directory**. | ||
|
||
### Specifying the server to configure | ||
If you are using the default actionset, or performing any actions that require a CHT instance to function (e.g. `upload-xyz` or `backup-xyz` actions) you must specify the server you'd like to function against. | ||
|
||
#### localhost | ||
For developers, this is the instance defined in your `COUCH_URL` environment variable. | ||
```shell | ||
cht --local | ||
``` | ||
|
||
#### A specific Medic-hosted instance | ||
For configuring Medic-hosted instances. | ||
```shell | ||
cht --instance=instance-name.dev | ||
``` | ||
|
||
Username `admin` is used. A prompt is shown for entering password. | ||
If a different username is required, add the `--user` switch: | ||
```shell | ||
--user user-name --instance=instance-name.dev | ||
``` | ||
|
||
#### An arbitrary URL | ||
```shell | ||
cht --url=https://username:[email protected]:12345 | ||
``` | ||
**NB** - When specifying the URL with `--url`, be sure not to specify the CouchDB database name in the URL. The CHT API will find the correct database. | ||
|
||
#### Using a session token for authentication | ||
CHT Conf supports authentication using a session token by adding `--session-token` parameter: | ||
```shell | ||
cht --url=https://example.com:12345 --session-token=*my_token* | ||
``` | ||
|
||
#### Into an archive to be uploaded later | ||
```shell | ||
cht --archive | ||
``` | ||
The resulting archive is consumable by CHT API >v3.7 to create default configurations. | ||
|
||
### Perform specific action(s) | ||
```shell | ||
cht <--archive|--local|--instance=instance-name|--url=url> <...action> | ||
``` | ||
The list of available actions can be seen via `cht --help`. | ||
|
||
### Perform actions for specific forms | ||
```shell | ||
cht <--local|--instance=instance-name|--url=url> <...action> -- <...form> | ||
``` | ||
|
||
### Protecting against configuration overwriting | ||
_Added in v3.2.0_ | ||
In order to avoid overwriting someone else's configuration cht-conf records the last uploaded configuration snapshot in the `.snapshots` directory. The `remote.json` file should be committed to your repository along with the associated configuration change. When uploading future configuration if cht-conf detects the snapshot doesn't match the configuration on the server you will be prompted to overwrite or cancel. | ||
|
||
## Development | ||
To develop a new command that is part of cht-conf, or improve an existing one. For more information check ["Actions" doc](https://github.com/medic/cht-conf/blob/main/src/fn/README.md). | ||
|
||
|
||
### Testing | ||
|
||
#### Unit tests | ||
Execute `npm test` to run static analysis checks and the test suite. Requires Docker to run integration tests against a CouchDB instance. | ||
|
||
#### End-to-end tests | ||
Run `npm run test-e2e` to run the end-to-end test suite against an actual CHT instance locally. These tests rely on [CHT Docker Helper](https://docs.communityhealthtoolkit.org/hosting/4.x/app-developer/#cht-docker-helper-for-4x) to spin up and tear down an instance locally. | ||
|
||
The code interfacing with CHT Docker Helper lives in [`test/e2e/cht-docker-utils.js`](https://github.com/medic/cht-conf/blob/main/test/e2e/cht-docker-utils.js). You should rely on the API exposed by this file to orchestrate CHT instances for testing purposes. It is preferable to keep the number of CHT instances orchestrated in E2E tests low as it takes a non-negligible amount of time to spin up an instance and can quickly lead to timeouts. | ||
|
||
### Executing your local branch | ||
1. Clone the project locally | ||
2. Make changes to cht-conf or checkout a branch for testing | ||
3. Test changes | ||
1. To test CLI changes locally you can run `node <project_dir>/src/bin/index.js`. This will run as if you installed via npm. | ||
2. To test changes that are imported in code run `npm install <project_dir>` to use the local version of cht-conf. | ||
|
||
### Releasing | ||
1. Create a pull request with prep for the new release. | ||
2. Get the pull request reviewed and approved. | ||
3. When doing the squash and merge, make sure that your commit message is clear and readable and follows the strict format described in the commit format section below. If the commit message does not comply, automatic release will fail. | ||
4. In case you are planning to merge the pull request with a merge commit, make sure that every commit in your branch respects the format. | ||
|
||
#### Commit format | ||
The commit format should follow this [conventional-changelog angular preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular). Examples are provided below. | ||
|
||
| Type | Example commit message | Release type | | ||
|-------------|-----------------------------------------------------------------------------------------------------|--------------| | ||
| Bug fixes | fix(#123): infinite spinner when clicking contacts tab twice | patch | | ||
| Performance | perf(#789): lazily loaded angular modules | patch | | ||
| Features | feat(#456): add home tab | minor | | ||
| Non-code | chore(#123): update README | none | | ||
| Breaking | perf(#2): remove reporting rates feature <br/> BREAKING CHANGE: reporting rates no longer supported | major | | ||
|
||
#### Releasing betas | ||
1. Checkout the default branch, for example `main` | ||
2. Run `npm version --no-git-tag-version <major>.<minor>.<patch>-beta.1`. This will only update the versions in `package.json` and `package-lock.json`. It will not create a git tag and not create an associated commit. | ||
3. Run `npm publish --tag beta`. This will publish your beta tag to npm's beta channel. | ||
|
||
To install from the beta channel, run `npm install cht-conf@beta`. | ||
|
||
### Build status | ||
Builds brought to you courtesy of GitHub actions. | ||
{{< figure src="build-status.png" link="build-status.png" class=" center col-4 col-lg-4" >}} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
--- | ||
title: "CHT App Configurer" | ||
linkTitle: "CHT Conf Code" | ||
weight: 2 | ||
description: > | ||
CHT Conf is a command-line interface tool to manage and configure apps built using the [Core Framework](https://github.com/medic/cht-core) of the [Community Health Toolkit](https://communityhealthtoolkit.org/). | ||
--- | ||
|
||
## Installation | ||
|
||
Read more about setting up [CHT Conf]({{< relref "contribute/code/cht-conf" >}}). | ||
|
||
## Currently Supported | ||
The different items that are supported by CHT Conf include: | ||
### Settings | ||
* Compile app settings from: | ||
- tasks | ||
- rules | ||
- schedules | ||
- contact-summary | ||
- purge | ||
* App settings can also be defined in a more modular way by having the following files in app_settings folder: | ||
- base_settings.json | ||
- forms.json | ||
- schedules.json | ||
* Backup app settings from server | ||
* Upload app settings to server | ||
* Upload resources to server | ||
* Upload custom translations to the server | ||
* Upload privacy policies to server | ||
* Upload branding to server | ||
* Upload partners to server | ||
|
||
### Forms | ||
* Fetch from Google Drive and save locally as `.xlsx` | ||
* Backup from server | ||
* Delete all forms from server | ||
* Delete specific form from server | ||
* Upload all app or contact forms to server | ||
* Upload specified app or contact forms to server | ||
|
||
### Managing data and images | ||
* Convert CSV files with contacts and reports to JSON docs | ||
* Move contacts by downloading and making the changes locally first | ||
* Upload JSON files as docs on instance | ||
* Compress PNGs and SVGs in the current directory and its subdirectories | ||
|
||
### Editing contacts across the hierarchy. | ||
To edit existing couchdb documents, create a CSV file that contains the ids of the document you wish to update, and the columns of the document attribute(s) you wish to add/edit. By default, values are parsed as strings. To parse a CSV column as a JSON type. | ||
|
||
| Parameter | Description | Required | | ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------| | ||
| column(s) | Comma delimited list of columns you wish to add/edit. If this is not specified all columns will be added. | No | | ||
| docDirectoryPath | This action outputs files to local disk at this destination | No. Default `json-docs` | | ||
| file(s) | Comma delimited list of files you wish to process using edit-contacts. By default, contact.csv is searched for in the current directory and processed. | No. | | ||
| updateOfflineDocs | If passed, this updates the docs already in the docDirectoryPath instead of downloading from the server. | No. | | ||
|
||
#### Example | ||
1. Create a contact.csv file with your columns in the csv folder in your current path. The documentID column is a requirement. The documentID column contains the document IDs to be fetched from couchdb. | ||
|
||
| documentID | is_in_emnch:bool | | ||
|-------------|------------------| | ||
| documentID1 | false | | ||
| documentID2 | false | | ||
| documentID3 | true | | ||
|
||
2. Use the following command to download and edit the documents: | ||
``` | ||
cht --instance=*instance* edit-contacts -- --column=*is_in_emnch* --docDirectoryPath=*my_folder* | ||
``` | ||
or this one to update already downloaded docs | ||
``` | ||
cht --instance=*instance* edit-contacts -- --column=*is_in_emnch* --docDirectoryPath=*my_folder* --updateOfflineDocs | ||
``` | ||
|
||
3. Then upload the edited documents using the _**upload-docs**_ command. | ||
``` | ||
cht --instance=*instance* --upload-docs | ||
``` | ||
|
||
## Project layout | ||
|
||
This tool expects a project to be structured as follows: | ||
``` | ||
example-project/ | ||
.eslintrc | ||
app_settings.json | ||
contact-summary.js | ||
privacy-policies.json | ||
privacy-policies/ | ||
language1.html | ||
… | ||
purge.js | ||
resources.json | ||
resources/ | ||
icon-one.png | ||
… | ||
targets.js | ||
tasks.js | ||
task-schedules.json | ||
forms/ | ||
app/ | ||
my_project_form.xlsx | ||
my_project_form.xml | ||
my_project_form.properties.json | ||
my_project_form-media/ | ||
[extra files] | ||
… | ||
contact/ | ||
person-create.xlsx | ||
person-create.xml | ||
person-create-media/ | ||
[extra files] | ||
… | ||
… | ||
… | ||
translations/ | ||
messages-xx.properties | ||
… | ||
``` | ||
|
||
If you are starting from scratch you can initialise the file layout using the initialise-project-layout action: | ||
``` | ||
cht initialise-project-layout | ||
``` | ||
|
||
### Derived configs | ||
|
||
Configuration can be inherited from another project, and then modified. This allows the `app_settings.json` and contained files (`task-schedules.json`, `targets.json` etc.) to be imported, and then modified. | ||
|
||
To achieve this, create a file called `settings.inherit.json` in your project's root directory with the following format: | ||
``` | ||
{ | ||
"inherit": "../path/to/other/project", | ||
"replace": { | ||
"keys.to.replace": "value-to-replace-it-with" | ||
}, | ||
"merge": { | ||
"complex.objects": { | ||
"will_be_merged": true | ||
} | ||
}, | ||
"delete": [ | ||
"all.keys.listed.here", | ||
"will.be.deleted" | ||
], | ||
"filter": { | ||
"object.at.this.key": [ | ||
"will", | ||
"keep", | ||
"only", | ||
"these", | ||
"properties" | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters