Skip to content

Commit

Permalink
Merge pull request #10 from travis-w/beta
Browse files Browse the repository at this point in the history
0.4.0 Release
  • Loading branch information
travis-w committed Nov 9, 2021
2 parents 6a6fbf4 + fbeafd9 commit f21dda5
Show file tree
Hide file tree
Showing 91 changed files with 2,191 additions and 19,649 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1 +1,2 @@
test/coverage/*
lib/frontend/*
7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

14 changes: 14 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,14 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020
},
rules: {
'semi': [2, 'never'],
'no-console': 'off',
'quote-props': [2, 'consistent-as-needed'],
'linebreak-style': 'off',
'no-underscore-dangle': 'off',
'import/extensions': 'off'
},
}
83 changes: 83 additions & 0 deletions .github/workflows/workflow.yml
@@ -0,0 +1,83 @@
name: Testing and Release

# Run on push to all branches. But only PRs to master
on:
push:
branches:
- '*'

pull_request:
branches:
- 'master'

jobs:
test:
name: Test

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm i --legacy-peer-deps
- name: Build Project
run: npm run build
- name: Run Litning
run: npm run lint
- name: Run Tests
run: npm test
- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
path-to-lcov: './test/coverage/lcov.info'
parallel: true


coveralls:
name: Coveralls
needs: test

runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: './test/coverage/lcov.info'
parallel-finished: true


release:
name: Release
needs: test

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install Dependencies
run: npm i
- name: Build Project
run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm run semantic-release
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -4,6 +4,8 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
yarn.lock

# Runtime data
pids
Expand Down Expand Up @@ -59,3 +61,4 @@ typings/

hijacker.config.json
lib/frontend/*
storybook-static
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
@@ -1,4 +1,5 @@
# Hijacker
[![npm](https://img.shields.io/npm/v/hijacker.svg)](https://www.npmjs.com/package/hijacker)
[![Build Status](https://travis-ci.org/travis-w/hijacker.svg?branch=master)](https://travis-ci.org/travis-w/hijacker)
[![Coverage Status](https://coveralls.io/repos/github/travis-w/hijacker/badge.svg?branch=master)](https://coveralls.io/github/travis-w/hijacker?branch=master)

Expand Down
5 changes: 5 additions & 0 deletions babel.config.js
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
13 changes: 10 additions & 3 deletions bin/hijacker.js
@@ -1,24 +1,31 @@
#!/usr/bin/env node

const path = require('path')
const program = require('commander')
const { program } = require('commander')

const pkg = require('../package')
const Hijacker = require('../lib/hijacker')

// Define CLI
program
// .option('-c, --config <path>', 'set path to hijacker configuration')
.option('-c, --config <path>', 'set path to hijacker configuration', `${pkg.name}.config`)
.version(pkg.version)
.parse(process.argv)

const options = program.opts();

// TODO: Restructure to take in options as argument
let rc = {}

// TODO: Figure out a better way to read in rules (and watch?)
try {
let configPath = options.config;

if (!path.isAbsolute(options.config)) {
configPath = path.join(process.cwd(), configPath)
}
// eslint-disable-next-line
rc = require(path.join(process.cwd(), `${pkg.name}.config`))
rc = require(configPath)
} catch (e) {
// No config file. Create and start again
console.error('No config file found: Please set up a config file and start again')
Expand Down
4 changes: 4 additions & 0 deletions config/storybook/main.js
@@ -0,0 +1,4 @@
module.exports = {
stories: ['../../src/frontend/src/stories/*.stories.(js|jsx|ts|tsx|mdx)'],
addons: ['@storybook/addon-essentials']
}
1 change: 1 addition & 0 deletions config/storybook/preview.js
@@ -0,0 +1 @@
import './style.scss';
18 changes: 18 additions & 0 deletions config/storybook/style.scss
@@ -0,0 +1,18 @@
html, body {
font-family: 'Roboto', sans-serif;
color: #666;
}

input {
padding: 5px;
font-family: 'Roboto', sans-serif;
}

select {
padding: 5px 2px;
font-family: 'Roboto', sans-serif;
}

.center {
text-align: center !important;
}
24 changes: 13 additions & 11 deletions lib/hijacker.js
Expand Up @@ -3,7 +3,9 @@ const path = require('path')

const bodyParser = require('body-parser')
const express = require('express')
const xmlParser = require('express-xml-bodyparser')

const { initLogger } = require('./util/logger')
const config = require('./util/config')
const eventsMixin = require('./mixins/events')
const handlerMixin = require('./mixins/handler')
Expand All @@ -17,23 +19,23 @@ const util = require('./util/util')
* @type {Object} config - Hijacker configuration object
*/
class Hijacker {
constructor(configObj) {
constructor (configObj) {
// Set up server
this.app = express()
this.server = http.Server(this.app)
this.conf = config.read(configObj)
this.ruleList = configObj.rules.map(rules.read)
this._initEvents()

// Set application variables
this.app.set('ruleList', configObj.rules.map(rules.read))
this.app.set('conf', this.conf)
initLogger(this.conf.logger)

// Express setup
this.app.get('/favicon.ico', (req, res) => res.sendStatus(204))
this.app.use('/hijacker', express.static(path.join(__dirname, './frontend')))
this.app.use(bodyParser.json())
this.app.use(util.requestCount())
this.app.all('*', this._handleRoute)
this.app
.get('/favicon.ico', (req, res) => res.sendStatus(204))
.use('/hijacker', express.static(path.join(__dirname, './frontend')))
.use(bodyParser.json())
.use(xmlParser())
.use(util.requestCount())
.all('*', (req, res) => this._handleRoute(req, res))

// Start server
this.server.listen(this.conf.port, () => {
Expand All @@ -42,7 +44,7 @@ class Hijacker {
})
}

close() {
close () {
this.server.close()
}
}
Expand Down
12 changes: 7 additions & 5 deletions lib/mixins/events.js
@@ -1,23 +1,25 @@
/* eslint-disable no-param-reassign, func-names */

const EventEmitter = require('events')

module.exports = (Hijacker) => {
Hijacker.prototype._initEvents = function() {
Hijacker.prototype._initEvents = function () {
this._events = new EventEmitter()
}

Hijacker.prototype.on = function(eventName, cb) {
Hijacker.prototype.on = function (eventName, cb) {
this._events.on(eventName, cb)
}

Hijacker.prototype.once = function(eventName, cb) {
Hijacker.prototype.once = function (eventName, cb) {
this._events.once(eventName, cb)
}

Hijacker.prototype.off = function(eventName) {
Hijacker.prototype.off = function (eventName) {
this._events.off(eventName)
}

Hijacker.prototype._emit = function(eventName, val) {
Hijacker.prototype._emit = function (eventName, val) {
this._events.emit(eventName, val)
}
}

0 comments on commit f21dda5

Please sign in to comment.