diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..c889eb8 --- /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..035a400 --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,7 @@ +env: + node: true + es6: true + mocha: true + es2022: true + +extends: ['@haraka'] 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..5ccd7ed --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,13 @@ +Changes proposed in this pull request: + +- +- + +Fixes # + +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..df04b68 --- /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: 'monthly' + allow: + - dependency-type: production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3d01042 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: [push, pull_request] + +env: + CI: true + +jobs: + lint: + uses: haraka/.github/.github/workflows/lint.yml@master + + # coverage: + # uses: haraka/.github/.github/workflows/coverage.yml@master + # secrets: inherit + + ubuntu: + needs: [lint] + uses: haraka/.github/.github/workflows/ubuntu.yml@master + + windows: + needs: [lint] + uses: haraka/.github/.github/workflows/windows.yml@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..816e8c3 --- /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..e81c15f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,16 @@ +name: publish + +on: + push: + branches: + - master + paths: + - package.json + +env: + CI: true + +jobs: + publish: + uses: haraka/.github/.github/workflows/publish.yml@master + secrets: inherit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..625981f --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# 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 +bower_components +# Optional npm cache directory +.npmrc +.idea +.DS_Store +haraka-update.sh \ No newline at end of file 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/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8ded5e0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,2 @@ +singleQuote: true +semi: false diff --git a/.release b/.release new file mode 160000 index 0000000..7cd5707 --- /dev/null +++ b/.release @@ -0,0 +1 @@ +Subproject commit 7cd5707f7d69f8d4dca1ec407ada911890e59d0a diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7c9ea33 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,47 @@ +# Changelog + +The format is based on [Keep a Changelog](https://keepachangelog.com/). + +### Unreleased + +### [1.0.6] - 2024-04-08 + +- dep: eslint-plugin-haraka -> @haraka/eslint-config +- lint: remove duplicate / stale rules from .eslintrc +- populate [files] in package.json. Delete .npmignore. +- doc: Changes.md -> CHANGELOG.md +- test: switch to node --test + +### 1.0.5 - 2023-12-12 + +- ci: run tests on PR +- ci(publish): add on.release trigger +- deps(dev\*): pin versions + +### [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 + +- ci: replace hard coded node vers with node-lts-versions +- ci(publish): add secrets: inherit +- ci: use reusable workflows (#18) +- packaging updates + +### [1.0.1] - 2021-02-04 + +- test: added example tests that set up conn/txn +- ci: add automated package publishing +- ci(GHA): consolidate \*nix & win tests + +### 1.0.0 - 2017-02-02 + +- initial release + +[1.0.1]: https://github.com/haraka/haraka-plugin-template/releases/tag/1.0.1 +[1.0.2]: https://github.com/haraka/haraka-plugin-template/releases/tag/1.0.2 +[1.0.3]: https://github.com/haraka/haraka-plugin-template/releases/tag/1.0.3 +[1.0.6]: https://github.com/haraka/haraka-plugin-template/releases/tag/v1.0.6 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..e330d90 --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +[![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 [template repo's main page](https://github.com/haraka/haraka-plugin-template), click the _Use this template_ button and create your new repository. 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/$MY_PLUGIN_NAME.git +cd $MY_PLUGIN_NAME +``` + +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..e4bd2f5 --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +'use strict' + +exports.register = function () { + this.load_template_ini() + + // register hooks here. More info at https://haraka.github.io/core/Plugins/ + // this.register_hook('data_post', 'do_stuff_with_message') +} + +exports.load_template_ini = function () { + this.cfg = this.config.get( + 'template.ini', + { + booleans: [ + '+enabled', // this.cfg.main.enabled=true + '-disabled', // this.cfg.main.disabled=false + '+feature_section.yes', // this.cfg.feature_section.yes=true + ], + }, + () => { + this.load_template_ini() + }, + ) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..52c3363 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "haraka-plugin-template", + "version": "1.0.6", + "description": "Haraka plugin that...CHANGE THIS", + "main": "index.js", + "files": [ + "CHANGELOG.md", + "config" + ], + "scripts": { + "format": "npm run prettier:fix && npm run lint:fix", + "lint": "npx eslint@^8 *.js test", + "lint:fix": "npx eslint@^8 *.js test --fix", + "prettier": "npx prettier . --check", + "prettier:fix": "npx prettier . --write --log-level=warn", + "test": "node --test", + "versions": "npx dependency-version-checker check", + "versions:fix": "npx dependency-version-checker update" + }, + "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": { + "@haraka/eslint-config": "1.1.3", + "haraka-test-fixtures": "1.3.5" + } +} diff --git a/redress.sh b/redress.sh new file mode 100755 index 0000000..1add457 --- /dev/null +++ b/redress.sh @@ -0,0 +1,44 @@ +#!/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 < { + this.plugin = new fixtures.plugin('template') +}) + +describe('template', () => { + it('loads', () => { + assert.ok(this.plugin) + }) +}) + +describe('load_template_ini', () => { + it('loads template.ini from config/template.ini', () => { + this.plugin.load_template_ini() + assert.ok(this.plugin.cfg) + }) + + it('initializes enabled boolean', () => { + this.plugin.load_template_ini() + assert.equal(this.plugin.cfg.main.enabled, true, this.plugin.cfg) + }) +}) + +describe('uses text fixtures', () => { + it('sets up a connection', () => { + this.connection = fixtures.connection.createConnection({}) + assert.ok(this.connection.server) + }) + + it('sets up a transaction', () => { + this.connection = fixtures.connection.createConnection({}) + this.connection.init_transaction() + assert.ok(this.connection.transaction.header) + }) +})