Skip to content

Commit

Permalink
feat!: restructure code as an npm library
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgengrimnes committed Jan 1, 2022
1 parent 6958d54 commit f05d950
Show file tree
Hide file tree
Showing 90 changed files with 14,641 additions and 22,772 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
182 changes: 182 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020, // Allows for the parsing of modern ECMAScript features.
"sourceType": "module", // Allows for the use of imports.
"project": "./tsconfig.json"
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"plugins": [
"sort-imports-es6-autofix"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
// Disallows calls to methods of the console object.
"no-console": "warn",
// Require semi colon.
"semi": "error",
// Enforces a consistent indentation style.
"indent": [
"error",
2
],
// Enforces consistent line endings independent of operating system, VCS, or editor used across your codebase.
"linebreak-style": [
"error",
"unix"
],
// Enforces the consistent use double quotes.
"quotes": [
"error",
"double"
],
// Enforces parentheses around arrow function parameters, as needed.
"arrow-parens": [
"error",
"as-needed"
],
// Enforces at least one newline (or absence thereof) at the end of non-empty files.
"eol-last": [
"error"
],
// Enforce consistent spacing before function parentheses and as such.
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "never"
}
],
// Create space before/after the arrow function's arrow.
"arrow-spacing": [
"error",
{
"before": true,
"after": true
}
],
// Ensuring there are spaces around infix operators.
"space-infix-ops": [
"error",
{
"int32Hint": false
}
],
// Enforce consistency of spacing before blocks.
"space-before-blocks": [
"warn",
"always"
],
// Enforces consistent line breaks inside braces of object literals or destructuring assignments.
"object-curly-newline": [
"warn",
{
"multiline": true,
"minProperties": 4
}
],
// Enforces consistent spacing inside braces of object literals, destructuring assignments, and import/export specifiers.
"object-curly-spacing": [
"warn",
"always"
],
// Enforces consistent brace style for blocks.
"brace-style": [
"warn",
"stroustrup"
],
// Checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by the first member or alias name.
"sort-imports-es6-autofix/sort-imports-es6": [
"warn",
{
"ignoreCase": true,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": [
"none",
"all",
"multiple",
"single"
]
}
],
// Enforce consistent spacing directly inside of parentheses, by disallowing or requiring one or more spaces to the right of ( and to the left of ).
"space-in-parens": [
"error",
"never"
],
// Enforce consistency of spacing after the start of a comment // or /*.
"spaced-comment": [
"error",
"always",
{
"exceptions": [
"-",
"+"
]
}
],
// Enforces consistent spacing between keys and values in object literal properties.
"key-spacing": [
"error",
{
"afterColon": true
}
],
// Disallow multiple whitespace around logical expressions, conditional expressions, declarations, array elements, object properties, sequences and function parameters.
"no-multi-spaces": [
"error"
],
// Declare variables first, rather than having ES6 hoisting them to the top of the scope
"no-use-before-define": [
"error",
{
"functions": false,
"classes": false
}
],
// Do not recreate variables with existing/identical names
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
// Remove trailing whitespaces immediately, rather than possibly having unnecessary one-line changes in git later
"no-trailing-spaces": "warn",
// Require trailing commas on multiline array and objects
"comma-dangle": [
"warn",
{
"arrays": "only-multiline",
"objects": "only-multiline"
}
],
// Do not include spacing in object property lookups like object["somekey"]
"computed-property-spacing": [
"warn",
"never"
],
// Require spacing after comma, forbid before
"comma-spacing": "warn",
// Require use of 'let' and 'const'
"no-var": "error",
// Add an additional set of parathesis around iife functions to hint the reader about the iife
"wrap-iife": [
"warn",
"outside"
],
// Require triple equals. The behavior of double equals might not behave as the coder expects
"eqeqeq": "error",
// Prefer dot notation referencing in object notation. Eg: object["somekey"] => object.somekey
"dot-notation": "warn",
// Require curly brackets on all if/else/for statements
"curly": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
]
}
}
94 changes: 94 additions & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build and release master

on:
push:
branches: [ master ]
paths-ignore:
- 'CHANGELOG.md'
- docs
- example
workflow_dispatch:

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Use Node.js 17
uses: actions/setup-node@v2
with:
node-version: 17
- name: Install packages
run: npm ci && npm run postinstall --if-present
- name: Transpile with Typescript
run: npm run dist --if-present
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Run tests
run: npm run test --if-present

echoPendingChangelog:
name: Render pending changelog
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v2
- name: Generate standard version changelog
run: |
npm ci
npx standard-version --skip.commit --skip.tag
UPDATED_VERSION=$(jq '.version' --raw-output package.json)
npx changelog-parser | jq --raw-output --arg UPDATED_VERSION "$UPDATED_VERSION" '.versions[] | select(.version==$UPDATED_VERSION).body | if . != "" then . else "[[empty]]" end'
release:
needs: build
name: Create release
runs-on: ubuntu-latest
environment:
name: publishing
defaults:
run:
shell: bash
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v2
- name: Install packages
run: npm ci && npm run postinstall --if-present
- name: Tag release and push to Github
run: |
set -e
git config --local user.name "Github Actions"
git config --local user.email "github-actions@example.com"
git pull origin master
npm run release
npm run generate-docs
git add -A
git commit -q -m "chore: updated typedocs"
git push --tags origin master
- name: Publish to NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Pull request

on:
pull_request:

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Use Node.js 17
uses: actions/setup-node@v2
with:
node-version: 17
- name: Install packages
run: npm ci && npm run postinstall --if-present
- name: Transpile with Typescript
run: npm run dist --if-present
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Run tests
run: npm run test --if-present

11 changes: 11 additions & 0 deletions .renovaterc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
"config:base"
],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
}
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Jørgen Grimnes
Copyright (c) 2022 Jørgen Grimnes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit f05d950

Please sign in to comment.