Skip to content

Commit

Permalink
Convert to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunoo authored Jul 27, 2020
1 parent 8a5cc45 commit 7fb21ee
Show file tree
Hide file tree
Showing 15 changed files with 2,973 additions and 472 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json'
},
rules: {
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
'@typescript-eslint/brace-style': 'error',
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/func-call-spacing': 'error',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/lines-between-class-members': ['error', {"exceptAfterSingleLine": true}],
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-parens': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': ['error', {"allowComparingNullableBooleansToTrue": false, "allowComparingNullableBooleansToFalse": false}],
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/quotes': ['error', 'single', {"allowTemplateLiterals": false}],
'@typescript-eslint/semi': ['error'],
'@typescript-eslint/space-before-function-paren': ['error', 'never'],
'@typescript-eslint/type-annotation-spacing': 'error',
'comma-dangle': 'error',
'no-confusing-arrow': 'error',
'no-lonely-if': 'error',
'no-trailing-spaces': 'error',
'no-unneeded-ternary': 'error',
'one-var': ['error', 'never']
}
}
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "10:00"
target-branch: "beta"
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
50 changes: 50 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: NodeJS

on:
push:
branches: '**'
pull_request:
release: # Run when release is created
types: [created]

jobs:
build:

strategy:
matrix:
node-version: [10.x, 12.x, 13.x, 14.x]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: npm install and build
run: |
npm ci
npm run build --if-present
env:
CI: true

publish-npm:
# publish only if we are on our own repo, event was 'release' (a tag was created) and the tag starts with "v" (aka version tag)
if: github.repository == 'Sunoo/homebridge-dafang-mqtt-republish' && github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')

needs: build # only run if build succeeds

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 10 # use the minimum required version
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
26 changes: 26 additions & 0 deletions .github/workflows/prerelease.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/env node

const fs = require('fs');
const semver = require('semver');
const child_process = require('child_process');

function getTagVersionFromNpm(tag) {
try {
return child_process.execSync(`npm info ${package.name} version --tag="${tag}"`).toString('utf8').trim();
} catch (e) {
return null;
}
}

// load package.json
const package = JSON.parse(fs.readFileSync('package.json', 'utf8'));

// work out the correct tag
const currentLatest = getTagVersionFromNpm('latest') || '0.0.0';
const currentBeta = getTagVersionFromNpm('beta') || '0.0.0';
const latestNpmTag = semver.gt(currentBeta, currentLatest, { includePrerelease: true }) ? currentBeta : currentLatest;
const publishTag = semver.gt(package.version, latestNpmTag, { includePrerelease: true }) ? package.version : latestNpmTag;

// save the package.json
package.version = publishTag;
fs.writeFileSync('package.json', JSON.stringify(package, null, 4));
41 changes: 41 additions & 0 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Beta

on:
workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
ref: beta
- uses: actions/[email protected]
with:
node-version: 10
- name: npm install and build
run: |
npm ci
npm run build --if-present
env:
CI: true

publish-npm:
if: github.repository == 'Sunoo/homebridge-dafang-mqtt-republish'

needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 10
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: node .github/workflows/prerelease.js
- run: npm --no-git-tag-version version prerelease --preid=beta
- run: npm publish --tag=beta
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
27 changes: 27 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Stale

on:
issues:
types: [reopened]
schedule:
- cron: "*/60 * * * *"

jobs:
stale:

runs-on: ubuntu-latest
env:
ACTIONS_STEP_DEBUG: true
steps:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
days-before-stale: 7
days-before-close: 2
exempt-issue-labels: 'long running,help wanted'
exempt-pr-labels: 'awaiting-approval,work-in-progress'
remove-stale-when-updated: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"line_length": false,
"no-duplicate-heading": false
}
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"pluginAlias": "dafangMqtt",
"pluginType": "platform",
"singular": true,
"headerDisplay": "Republishes MQTT Motion Messages from Dafang Hacks into a Format homebridge-camera-ffmpeg Understands",
"headerDisplay": "Routes Dafang Hacks Motion Messages to homebridge-camera-ffmpeg and Exposes Features to HomeKit",
"footerDisplay": "Raise [Issues](https://github.com/Sunoo/homebridge-dafang-mqtt-republish/issues) or submit [Pull Requests](https://github.com/Sunoo/homebridge-dafang-mqtt-republish/pulls) on [Project Page](https://github.com/Sunoo/homebridge-dafang-mqtt-republish).",
"schema": {
"type": "object",
Expand Down
Loading

0 comments on commit 7fb21ee

Please sign in to comment.