From c6e4da5a7f1756be35561f8ec7ca10bccf1be31b Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 17 Jun 2022 01:46:13 -0700 Subject: [PATCH] Initial commit --- .codeclimate.yml | 10 +++++ .eslintrc.yaml | 25 +++++++++++ .github/ISSUE_TEMPLATE.md | 11 +++++ .github/PULL_REQUEST_TEMPLATE.md | 11 +++++ .github/dependabot.yml | 10 +++++ .github/workflows/ci.yml | 41 +++++++++++++++++ .github/workflows/codeql.yml | 13 ++++++ .github/workflows/publish.yml | 14 ++++++ .gitignore | 39 ++++++++++++++++ .gitmodules | 3 ++ .npmignore | 14 ++++++ .release | 1 + Changes.md | 27 ++++++++++++ LICENSE | 21 +++++++++ README.md | 76 ++++++++++++++++++++++++++++++++ config/template.ini | 2 + index.js | 20 +++++++++ package.json | 33 ++++++++++++++ redress.sh | 39 ++++++++++++++++ test/index.js | 52 ++++++++++++++++++++++ 20 files changed, 462 insertions(+) create mode 100644 .codeclimate.yml create mode 100644 .eslintrc.yaml create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 .npmignore create mode 160000 .release create mode 100644 Changes.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config/template.ini create mode 100644 index.js create mode 100644 package.json create mode 100755 redress.sh create mode 100644 test/index.js diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..0e443ca --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,10 @@ +engines: + eslint: + enabled: true + channel: "eslint-8" + config: + config: ".eslintrc.yaml" + +ratings: + paths: + - "**.js" diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 0000000..fe947ea --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,25 @@ +env: + node: true + es6: true + mocha: true + es2020: true + +plugins: + - haraka + +extends: + - eslint:recommended + - plugin:haraka/recommended + +rules: + indent: [2, 2, {"SwitchCase": 1}] + +root: true + +globals: + OK: true + CONT: true + DENY: true + DENYSOFT: true + DENYDISCONNECT: true + DENYSOFTDISCONNECT: true diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..0dccc85 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,11 @@ +### system info + +Please report your OS, Node version, and Haraka version by running this shell script on your Haraka server and replacing this section with the output. + +echo "Haraka | $(haraka -v)"; echo " --- | :--- "; echo "Node | $(node -v)"; echo "OS | $(uname -a)"; echo "openssl | $(openssl version)" + +### Expected behavior + +### Observed behavior + +### Steps to reproduce diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..afafec5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +Fixes # + +Changes proposed in this pull request: +- +- + +Checklist: +- [ ] docs updated +- [ ] tests updated +- [ ] Changes.md updated +- [ ] package.json.version bumped diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0449e4a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "weekly" + allow: + - dependency-type: production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d768329 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: [ push ] + +env: + CI: true + +jobs: + + lint: + uses: haraka/.github/.github/workflows/lint.yml@master + + # coverage: + # uses: haraka/.github/.github/workflows/coverage.yml@master + # secrets: inherit + + test: + needs: [ lint, get-lts ] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + node-version: ${{ fromJson(needs.get-lts.outputs.active) }} + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + + get-lts: + runs-on: ubuntu-latest + steps: + - id: get + uses: msimerson/node-lts-versions@v1 + outputs: + active: ${{ steps.get.outputs.active }} + lts: ${{ steps.get.outputs.lts }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..383aca2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,13 @@ +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: '18 7 * * 4' + +jobs: + codeql: + uses: haraka/.github/.github/workflows/codeql.yml@master diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..42a9bb9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,14 @@ +name: publish + +on: + push: + branches: + - master + +env: + CI: true + +jobs: + publish: + uses: haraka/.github/.github/workflows/publish.yml@master + secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8faa6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +package-lock.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a8e94cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".release"] + path = .release + url = git@github.com:msimerson/.release.git diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..54329c7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,14 @@ +.github +.DS_Store +.editorconfig +.gitignore +.gitmodules +.lgtm.yml +appveyor.yml +.travis.yml +.eslintrc.yaml +.eslintrc.json +.nyc_output +coverage +.codeclimate.yml +codecov.yml diff --git a/.release b/.release new file mode 160000 index 0000000..20e8e5d --- /dev/null +++ b/.release @@ -0,0 +1 @@ +Subproject commit 20e8e5dbcf634c2f568d973966be42c4504db480 diff --git a/Changes.md b/Changes.md new file mode 100644 index 0000000..27ff6bf --- /dev/null +++ b/Changes.md @@ -0,0 +1,27 @@ + +### Unreleased + + +### [1.0.3] - 2022-06-05 + +- ci: replace hard coded vers with node-lts-versions +- * ci(publish): add secrets: inherit +- ci: use reusable workflows (#18) + + +### 1.0.2 - 2022-05-23 + +- packaging updates + + +### 1.0.1 - 2021-02-04 + +- added example tests that set up conn/txn +- add automated package publishing +- GH actions: consolidate \*nix & win tests + + +### 1.0.0 - 2017-02-02 + +- initial release +[1.0.3]: https://github.com/haraka/haraka-plugin-template/releases/tag/1.0.3 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..29f9810 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Haraka + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..036ed60 --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +[![CI Test Status][ci-img]][ci-url] +[![Code Climate][clim-img]][clim-url] +[![NPM][npm-img]][npm-url] + +# haraka-plugin-template + +Clone me, to create a new Haraka plugin! + +# Template Instructions + +These instructions will not self-destruct after use. Use and destroy. + +See also, [How to Write a Plugin](https://github.com/haraka/Haraka/wiki/Write-a-Plugin) and [Plugins.md](https://github.com/haraka/Haraka/blob/master/docs/Plugins.md) for additional plugin writing information. + +## Create a new repo for your plugin + +Haraka plugins are named like `haraka-plugin-something`. All the namespace after `haraka-plugin-` is yours for the taking. Please check the [Plugins](https://github.com/haraka/Haraka/blob/master/Plugins.md) page and a Google search to see what plugins already exist. + +Once you've settled on a name, create the GitHub repo. On the repo's main page, click the _Clone or download_ button and copy the URL. Then paste that URL into a local ENV variable with a command like this: + +```sh +export MY_GITHUB_ORG=haraka +export MY_PLUGIN_NAME=haraka-plugin-SOMETHING +``` + +Clone and rename the template repo: + +```sh +git clone git@github.com:haraka/haraka-plugin-template.git +mv haraka-plugin-template $MY_PLUGIN_NAME +cd $MY_PLUGIN_NAME +git remote rm origin +git remote add origin "git@github.com:$MY_GITHUB_ORG/$MY_PLUGIN_NAME.git" +``` + +Now you'll have a local git repo to begin authoring your plugin + +## rename boilerplate + +Replaces all uses of the word `template` with your plugin's name. + +./redress.sh [something] + +You'll then be prompted to update package.json and then force push this repo onto the GitHub repo you've created earlier. + + +# Add your content here + +## INSTALL + +```sh +cd /path/to/local/haraka +npm install haraka-plugin-template +echo "template" >> config/plugins +service haraka restart +``` + +### Configuration + +If the default configuration is not sufficient, copy the config file from the distribution into your haraka config dir and then modify it: + +```sh +cp node_modules/haraka-plugin-template/config/template.ini config/template.ini +$EDITOR config/template.ini +``` + +## USAGE + + + +[ci-img]: https://github.com/haraka/haraka-plugin-template/actions/workflows/ci.yml/badge.svg +[ci-url]: https://github.com/haraka/haraka-plugin-template/actions/workflows/ci.yml +[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-template/badges/gpa.svg +[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-template +[npm-img]: https://nodei.co/npm/haraka-plugin-template.png +[npm-url]: https://www.npmjs.com/package/haraka-plugin-template diff --git a/config/template.ini b/config/template.ini new file mode 100644 index 0000000..2a92888 --- /dev/null +++ b/config/template.ini @@ -0,0 +1,2 @@ + +[main] diff --git a/index.js b/index.js new file mode 100644 index 0000000..7c1b269 --- /dev/null +++ b/index.js @@ -0,0 +1,20 @@ +'use strict' + +exports.register = function () { + this.load_template_ini() +} + +exports.load_template_ini = function () { + const plugin = this + + plugin.cfg = plugin.config.get('template.ini', { + booleans: [ + '+enabled', // plugin.cfg.main.enabled=true + '-disabled', // plugin.cfg.main.disabled=false + '+feature_section.yes' // plugin.cfg.feature_section.yes=true + ] + }, + function () { + plugin.load_example_ini() + }) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee96bb1 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "haraka-plugin-template", + "version": "1.0.3", + "description": "Haraka plugin that frobnicates email connections", + "main": "index.js", + "scripts": { + "lint": "npx eslint *.js test/*.js", + "lintfix": "npx eslint --fix *.js test/*.js", + "versions": "npx dependency-version-checker check", + "test": "npx mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/haraka/haraka-plugin-template.git" + }, + "keywords": [ + "haraka", + "plugin", + "template" + ], + "author": "Welcome Member ", + "license": "MIT", + "bugs": { + "url": "https://github.com/haraka/haraka-plugin-template/issues" + }, + "homepage": "https://github.com/haraka/haraka-plugin-template#readme", + "devDependencies": { + "eslint": "8", + "eslint-plugin-haraka": "*", + "haraka-test-fixtures": "*", + "mocha": "9" + } +} diff --git a/redress.sh b/redress.sh new file mode 100755 index 0000000..ebcf134 --- /dev/null +++ b/redress.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "$0 something" + exit +fi + +sed -i '' -e "s/template/${1}/g" README.md + +sed -i '' \ + -e "s/template/${1}/g" \ + -e "s/template\.ini/$1.ini/" \ + test/index.js + +sed -i '' -e "s/template/${1}/g" package.json +sed -i '' \ + -e "s/_template/_${1}/g" \ + -e "s/template\.ini/$1.ini/" \ + index.js + +tee Changes.md <