diff --git a/README.md b/README.md index 429f20e..839551c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ A collection of email templates used by [WATcloud](https://cloud.watonomous.ca/) ## Development +### Emails + ```sh npm ci npm run dev @@ -20,12 +22,31 @@ npm run dev Open [localhost:3000](http://localhost:3000) with your browser to see email previews. -Run the following to use the CLI: +### CLI ```sh +npm run build node ./dist/cli/index.js ``` +#### Packaging the CLI + +```sh +npm run build +npm version --no-git-tag-version 0.0.0-dev +npm pack --pack-destination . +``` + +A `watonomous-watcloud-emails-0.0.0-dev.tgz` file will be created in the current directory. +Use it as follows: + +```sh +npx watonomous-watcloud-emails-0.0.0-dev.tgz --help +# or +npm install -g watonomous-watcloud-emails-0.0.0-dev.tgz +watcloud-emails --help +``` + ## Releasing Releases are manually created from the [Releases page](https://github.com/WATonomous/watcloud-emails/releases). diff --git a/cli/index.ts b/cli/index.ts index 15f2af2..947c0ac 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -32,7 +32,12 @@ program .action(async (template_name, options) => { let data = {}; if (options.data) { - data = JSON.parse(options.data); + if (options.data === '-') { + // Read from stdin + data = JSON.parse(fs.readFileSync(0, 'utf-8')); + } else { + data = JSON.parse(options.data); + } } const template = await getTemplate(template_name, [data]); @@ -57,7 +62,12 @@ program .action(async (template_name, options) => { let data = []; if (options.data) { - data = JSON.parse(options.data); + if (options.data === '-') { + // Read from stdin + data = JSON.parse(fs.readFileSync(0, 'utf-8')); + } else { + data = JSON.parse(options.data); + } } const template = await getTemplate(template_name, data);