Skip to content

Commit

Permalink
Automate updating the README's usage section
Browse files Browse the repository at this point in the history
  • Loading branch information
djfarrelly committed Mar 29, 2020
1 parent 7ef2e07 commit 6d0b5e2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 52 deletions.
80 changes: 29 additions & 51 deletions README.md
Expand Up @@ -24,58 +24,36 @@ For a guide for usage with Docker,
For convenient use with Grunt, try [grunt-maildev](https://github.com/xavierpriour/grunt-maildev).

## Usage
```
Usage: maildev [options]
```

maildev [options]

-h, --help output usage information
-V, --version output the version number
-s, --smtp <port> SMTP port to catch emails [1025]
-w, --web <port> Port to run the Web GUI [1080]
--ip <ip address> IP Address to bind SMTP service to
--outgoing-host <host> SMTP host for outgoing emails
--outgoing-port <port> SMTP port for outgoing emails
--outgoing-user <user> SMTP user for outgoing emails
--outgoing-pass <password> SMTP password for outgoing emails
--outgoing-secure Use SMTP SSL for outgoing emails
--auto-relay [email] Use auto-relay mode. Optional relay email address
--auto-relay-rules <file> Filter rules for auto relay mode
--incoming-user <user> SMTP user for incoming emails
--incoming-pass <pass> SMTP password for incoming emails
--web-ip <ip address> IP Address to bind HTTP service to, defaults to --ip
--web-user <user> HTTP user for GUI
--web-pass <password> HTTP password for GUI
--https Switch from http to https protocol
--https-key <file> The file path to the ssl private key
--https-cert <file> The file path to the ssl cert file
--base-pathname <path> base path for URLs
--disable-web Disable the use of the web interface. Useful for unit testing
--hide-extensions <extensions> Comma separated list of SMTP extensions to NOT advertise
(SMTPUTF8, PIPELINING, 8BITMIME)
-o, --open Open the Web GUI after startup
-v, --verbose
--silent

## Environment variables

MailDev can be configured using the following environment variables:

MAILDEV_SMTP_PORT
MAILDEV_WEB_PORT
MAILDEV_IP
MAILDEV_OUTGOING_HOST
MAILDEV_OUTGOING_PORT
MAILDEV_OUTGOING_USER
MAILDEV_OUTGOING_PASS
MAILDEV_OUTGOING_SECURE
MAILDEV_AUTO_RELAY
MAILDEV_AUTO_RELAY_RULES
MAILDEV_INCOMING_USER
MAILDEV_INCOMING_PASS
MAILDEV_WEB_IP
MAILDEV_WEB_USER
MAILDEV_WEB_PASS
MAILDEV_BASE_PATHNAME
MAILDEV_DISABLE_WEB
|Options|Environment variable|Description|
|---|---|---|
|`-s, --smtp <port>`|`MAILDEV_SMTP_PORT`|SMTP port to catch emails|
|`-w, --web <port>`|`MAILDEV_WEB_PORT`|Port to run the Web GUI|
|`--https`|`MAILDEV_HTTPS`|Switch from http to https protocol|
|`--https-key <file>`|`MAILDEV_HTTPS_KEY`|The file path to the ssl private key|
|`--https-cert <file>`|`MAILDEV_HTTPS_CERT`|The file path to the ssl cert file|
|`--ip <ip address>`|`MAILDEV_IP`|IP Address to bind SMTP service to|
|`--outgoing-host <host>`|`MAILDEV_OUTGOING_HOST`|SMTP host for outgoing emails|
|`--outgoing-port <port>`|`MAILDEV_OUTGOING_PORT`|SMTP port for outgoing emails|
|`--outgoing-user <user>`|`MAILDEV_OUTGOING_USER`|SMTP user for outgoing emails|
|`--outgoing-pass <password>`|`MAILDEV_OUTGOING_PASS`|SMTP password for outgoing emails|
|`--outgoing-secure`|`MAILDEV_OUTGOING_SECURE`|Use SMTP SSL for outgoing emails|
|`--auto-relay <email>`|`MAILDEV_AUTO_RELAY`|Use auto-relay mode. Optional relay email address|
|`--auto-relay-rules <file>`|`MAILDEV_AUTO_RELAY_RULES`|Filter rules for auto relay mode|
|`--incoming-user <user>`|`MAILDEV_INCOMING_USER`|SMTP user for incoming emails|
|`--incoming-pass <pass>`|`MAILDEV_INCOMING_PASS`|SMTP password for incoming emails|
|`--web-ip <ip address>`|`MAILDEV_WEB_IP`|IP Address to bind HTTP service to, defaults to --ip|
|`--web-user <user>`|`MAILDEV_WEB_USER`|HTTP user for GUI|
|`--web-pass <password>`|`MAILDEV_WEB_PASS`|HTTP password for GUI|
|`--base-pathname <path>`|`MAILDEV_BASE_PATHNAME`|base path for URLs|
|`--disable-web`|`MAILDEV_DISABLE_WEB`|Disable the use of the web interface. Useful for unit testing|
|`--hide-extensions <extensions>`|`MAILDEV_HIDE_EXTENSIONS`|Comma separated list of SMTP extensions to NOT advertise (SMTPUTF8, PIPELINING, 8BITMIME)|
|`-o, --open`||Open the Web GUI after startup|
|`-v, --verbose`|||
|`--silent`|||

## API

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -33,7 +33,8 @@
"css-watch": "node-sass -wr --output-style compressed -o app/styles assets/styles/style.scss",
"docker-build": "docker build -t maildev/maildev:$npm_package_version . && docker tag maildev/maildev:$npm_package_version maildev/maildev:latest",
"docker-run": "docker run --rm -p 1080:1080 -p 1025:1025 maildev/maildev:$npm_package_version",
"docker-push": "docker push maildev/maildev:$npm_package_version && docker push maildev/maildev:latest"
"docker-push": "docker push maildev/maildev:$npm_package_version && docker push maildev/maildev:latest",
"update-readme": "node ./scripts/updateUsageREADME.js"
},
"main": "./index.js",
"bin": {
Expand Down
31 changes: 31 additions & 0 deletions scripts/updateUsageREADME.js
@@ -0,0 +1,31 @@
const fs = require('fs')
const path = require('path')
const { options } = require('../lib/options')

const generateMarkdown = (options) => {
const tableRows = options.map((option) => {
const env = option[1] ? `\`${option[1] || ''}\`` : ''
return `|\`${option[0]}\`|${env}|${option[2] || ''}|`
})
return [
`|Options|Environment variable|Description|`,
`|---|---|---|`
].concat(tableRows).join('\n')
}

const readmeFilename = path.join(__dirname, '../README.md')
const README = fs.readFileSync(readmeFilename).toString()

const updatedText = `
\`\`\`
Usage: maildev [options]
\`\`\`
${generateMarkdown(options)}
`

const updatedREADME = README.replace(/(## Usage)(.|\n)+(\n## API)/, `$1${updatedText}$3`)

fs.writeFileSync(readmeFilename, updatedREADME)

console.log(`Successfully updated ${readmeFilename}`)

0 comments on commit 6d0b5e2

Please sign in to comment.