Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
feat: first version of hooks library (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored May 14, 2020
1 parent ed34b1f commit ab057af
Show file tree
Hide file tree
Showing 12 changed files with 8,270 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
95 changes: 95 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
env:
node: true
es6: true

plugins:
- sonarjs

extends:
- plugin:sonarjs/recommended

parserOptions:
ecmaVersion: 2018

rules:
# Ignore Rules
strict: 0
no-underscore-dangle: 0
no-mixed-requires: 0
no-process-exit: 0
no-warning-comments: 0
curly: 0
no-multi-spaces: 0
no-alert: 0
consistent-return: 0
consistent-this: [0, self]
func-style: 0
max-nested-callbacks: 0

# Warnings
no-debugger: 1
no-empty: 1
no-invalid-regexp: 1
no-unused-expressions: 1
no-native-reassign: 1
no-fallthrough: 1
camelcase: 0

# Errors
eqeqeq: 2
no-undef: 2
no-dupe-keys: 2
no-empty-character-class: 2
no-self-compare: 2
valid-typeof: 2
no-unused-vars: [2, { "args": "none" }]
handle-callback-err: 2
no-shadow-restricted-names: 2
no-new-require: 2
no-mixed-spaces-and-tabs: 2
block-scoped-var: 2
no-else-return: 2
no-throw-literal: 2
no-void: 2
radix: 2
wrap-iife: [2, outside]
no-shadow: 0
no-use-before-define: [2, nofunc]
no-path-concat: 2
valid-jsdoc: [0, {requireReturn: false, requireParamDescription: false, requireReturnDescription: false}]

# stylistic errors
no-spaced-func: 2
semi-spacing: 2
quotes: [2, 'single']
key-spacing: [2, { beforeColon: false, afterColon: true }]
indent: [2, 2]
no-lonely-if: 2
no-floating-decimal: 2
brace-style: [2, 1tbs, { allowSingleLine: true }]
comma-style: [2, last]
no-multiple-empty-lines: [2, {max: 1}]
no-nested-ternary: 2
operator-assignment: [2, always]
padded-blocks: [2, never]
quote-props: [2, as-needed]
keyword-spacing: [2, {'before': true, 'after': true, 'overrides': {}}]
space-before-blocks: [2, always]
array-bracket-spacing: [2, never]
computed-property-spacing: [2, never]
space-in-parens: [2, never]
space-unary-ops: [2, {words: true, nonwords: false}]
wrap-regex: 2
linebreak-style: [2, unix]
semi: [2, always]
arrow-spacing: [2, {before: true, after: true}]
no-class-assign: 2
no-const-assign: 2
no-dupe-class-members: 2
no-this-before-super: 2
no-var: 2
object-shorthand: [2, always]
prefer-arrow-callback: 2
prefer-const: 2
prefer-spread: 2
prefer-template: 2
47 changes: 47 additions & 0 deletions .github/workflows/automerge-release-pr-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Automerge release bump PR

on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
- opened
- edited
- ready_for_review
- reopened
- unlocked
pull_request_review:
types:
- submitted
check_suite:
types:
- completed
status: {}

jobs:

autoapprove:
runs-on: ubuntu-latest
steps:
- name: Autoapproving
uses: hmarr/auto-approve-action@v2.0.0
if: github.actor == 'asyncapi-bot'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

automerge:
needs: [autoapprove]
runs-on: ubuntu-latest
steps:
- name: Automerging
uses: pascalgn/automerge-action@v0.7.5
if: github.actor == 'asyncapi-bot'
env:
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
GITHUB_LOGIN: asyncapi-bot
MERGE_LABELS: ""
MERGE_METHOD: "squash"
MERGE_COMMIT_MESSAGE: "pull-request-title"
MERGE_RETRIES: "10"
MERGE_RETRY_SLEEP: "10000"
22 changes: 22 additions & 0 deletions .github/workflows/pull-request-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull request testing

on:
pull_request

jobs:
release:
name: 'Run linter and tests'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 13
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
name: 'Release NPM, GitHub'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 13
- name: Install dependencies
run: npm ci
- name: Regenerate docs
run: npm run docs
- name: Run tests
run: npm test
- name: Lint code
run: npm run lint
- name: Get version from package.json before release step
id: initversion
run: echo "::set-output name=version::$(npm run get-version --silent)"
- name: Release to NPM and GitHub
id: release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_AUTHOR_NAME: asyncapi-bot
GIT_AUTHOR_EMAIL: info@asyncapi.io
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: info@asyncapi.io
run: npm run release
- name: Get version from package.json after release step
id: extractver
run: echo "::set-output name=version::$(npm run get-version --silent)"
- name: Create Pull Request with updated package files
if: steps.initversion.outputs.version != steps.extractver.outputs.version
uses: peter-evans/create-pull-request@v2.4.4
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: 'chore(release): ${{ steps.extractver.outputs.version }}'
committer: asyncapi-bot <info@asyncapi.io>
author: asyncapi-bot <info@asyncapi.io>
title: 'chore(release): ${{ steps.extractver.outputs.version }}'
body: 'Version bump in package.json and package-lock.json for release [${{ steps.extractver.outputs.version }}](https://github.com/${{github.repository}}/releases/tag/v${{ steps.extractver.outputs.version }})'
branch: version-bump/${{ steps.extractver.outputs.version }}
27 changes: 27 additions & 0 deletions .github/workflows/stale-issues-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Manage stale issues and PRs

on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1.1.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: |
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions :heart:
stale-pr-message: |
This pull request has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 30 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation.
Thank you for your contributions :heart:
days-before-stale: 60
days-before-close: 30
stale-issue-label: stale
stale-pr-label: stale
exempt-issue-label: keep-open
exempt-pr-label: keep-open
25 changes: 25 additions & 0 deletions .github/workflows/welcome-first-time-contrib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Welcome first time contributors

on:
pull_request:
types:
- opened
issues:
types:
- opened

jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: |
Welcome to AsyncAPI. Thanks a lot for reporting your first issue.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).
pr-message: |
Welcome to AsyncAPI. Thanks a lot for creating your first pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# generator-hooks
Library with reusable generator hooks that you can use in your templates
# Generator Hooks

This is a library with [generator](https://github.com/asyncapi/generator/) hooks that are used in more than one template. Use these hooks to not double your work. Read Generator documentation to understand how to configure your template to use external hooks.

This library consists of the following hooks:
|Hook name|Hook type|Description|
|---|---|---|
| `createAsyncapiFile` | `generate:after` | It creates AsyncAPI file with content of the spec file passed to the generator. By default it created the file in the root of the generation output directory. This hook also supports custom parameters that user can pass to template generation. Parameter called `asyncapiFileDir` allows user to specify the location where spec file should be created. To make your template users use this parameter, you need to add it to the configuration of your template like other parameters |



## Using Hooks library in custom template

1. Add `@asyncapi/generator-hooks` to `dependencies` of your template
```bash
npm install @asyncapi/generator-hooks --save
```
2. Configure your template what hooks you want to use in the template configuration file:
```json
{
"hooks": {
"@asyncapi/generator-hooks": "createAsyncapiFile"
}
}
```
3. (Optional) In case the hook that you want to use supports parameters, specify in the configuration what parameters users can specify:
```json
{
"parameters": {
"asyncapiFileDir": {
"description": "Custom location of the AsyncAPI file that you provided as an input in generation. By default it is located in the root of the output directory",
"required": false
}
},
"hooks": {
"@asyncapi/generator-hooks": "createAsyncapiFile"
}
}
```




Loading

0 comments on commit ab057af

Please sign in to comment.