Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reading data from stdin #24

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,40 @@ A collection of email templates used by [WATcloud](https://cloud.watonomous.ca/)

## Development

### Emails

```sh
npm ci
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).
Expand Down
14 changes: 12 additions & 2 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
Expand Down
Loading