Skip to content

Commit

Permalink
busywork, do it now rather than later
Browse files Browse the repository at this point in the history
  • Loading branch information
robotmayo committed Sep 21, 2016
1 parent 298db73 commit 3e5aeeb
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 196 deletions.
243 changes: 243 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"node": true,
"es6" : true
},
"rules": {
"no-cond-assign": 2,
"no-console": 0,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty": 2,
"no-ex-assign": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-inner-declarations": 1,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-obj-calls": 2,
"no-prototype-builtins": 2,
"no-regex-spaces": 2,
"no-sparse-arrays": 2,
"no-template-curly-in-string": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-unsafe-finally": 2,
"no-unsafe-negation": 2,
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"accessor-pairs": 2,
"array-callback-return": 2,
"block-scoped-var" : 2,
"class-methods-use-this" : 0,
"complexity" : 0,
"consistent-return" : 2,
"curly" : 0,
"default-case" : 2,
"dot-location" : [2, "property"],
"dot-notation" : 2,
"eqeqeq" : [2, "smart"],
"guard-for-in" : 2,
"no-alert" : 2,
"no-caller" : 2,
"no-case-declarations" : 2,
"no-div-regex" : 2,
"no-else-return" : 2,
"no-empty-function" : 2,
"no-empty-pattern" : 2,
"no-eq-null" : 0,
"no-eval" : 2,
"no-extend-native" : 2,
"no-extra-bind" : 2,
"no-extra-label": 2,
"no-fallthrough" : 2,
"no-floating-decimal" : 2,
"no-global-assign" : [2, {"exceptions" : ["Promise"]}],
"no-implicit-coercion" : 2,
"no-implicit-globals" : 2,
"no-implied-eval" : 2,
"no-invalid-this" : 2,
"no-iterator" : 2,
"no-labels" : [2, {"allowLoop" : true}],
"no-lone-blocks" : 2,
"no-loop-func" : 2,
"no-magic-numbers" : 0,
"no-multi-spaces" : 2,
"no-multi-str" : 2,
"no-new-func" : 2,
"no-new-wrappers" : 2,
"no-new" : 2,
"no-octal-escape" : 2,
"no-octal" : 2,
"no-param-reassign" : 2,
"no-proto" : 2,
"no-redeclare" : 2,
"no-return-assign" : 2,
"no-script-url" : 2,
"no-self-assign" : 2,
"no-self-compare" : 2,
"no-sequences" : 2,
"no-throw-literal" : 2,
"no-unmodified-loop-condition" : 2,
"no-unused-expressions" : 2,
"no-unused-labels" : 2,
"no-useless-call" : 2,
"no-useless-concat" : 2,
"no-useless-escape" : 2,
"no-void" : 2,
"no-warning-comments" : 1,
"no-with" : 2,
"radix" : 2,
"vars-on-top" : 2,
"wrap-iife" : 2,
"yoda" : 2,
"strict" : 2,
"init-declarations" : 0,

"no-catch-shadow" : 2,
"no-delete-var": 2,
"no-label-var" : 2,
"no-restricted-globals" : 0,
"no-shadow-restricted-names" : 0,
"no-shadow" : 2,
"no-undef-init" : 2,
"no-undef" : 2,
"no-undefined" : 2,
"no-unused-vars" : 2,
"no-use-before-define" : 2,

"callback-return" : 1,
"global-require" : 2,
"handle-callback-err" : 2,
"no-mixed-requires" : 0,
"no-new-require" : 2,
"no-path-concat" : 2,
"no-process-env" : 0,
"no-process-exit" : 1,
"no-restricted-modules" : 0,
"no-restricted-properties" : 0,
"no-sync" : 0,

"array-bracket-spacing" : 2,
"block-spacing" : 2,
"brace-style" : 2,
"camelcase" : 2,
"comma-dangle" : 2,
"comma-spacing" : 2,
"comma-style" : 2,
"computed-property-spacing" : 2,
"consistent-this" : [2, "self"],
"eol-last" : 2,
"func-call-spacing" : 2,
"func-names" : 0,
"func-style" : 0,
"id-blacklist" : [2, "flavorTown"],
"id-length" : 0,
"id-match" : 0,
"indent" : [2, 2],
"jsx-quotes" : 2,
"key-spacing": 2,
"keyword-spacing" : 2,
"line-comment-position" : 0,
"linebreak-style" : 2,
"lines-around-comment" : 0,
"lines-around-directive" : 2,
"max-depth" : [2, 5],
"max-len" : [2, {"code" : 120, "tabWidth" : 2}],
"max-lines" : [2, {"max" : 600, "skipBlankLines" : true, "skipComments" : true}],
"max-nested-callbacks" : [2, 5],
"max-params" : 0,
"max-statements-per-line" : 0,
"max-statements" : 0,
"multiline-ternary" : 0,
"new-cap" : 0,
"new-parens" : 2,
"newline-after-var" : 0,
"newline-before-return" : 0,
"newline-per-chained-call" : 0,
"no-array-constructor" : 2,
"no-bitwise" : 1,
"no-continue" : 1,
"no-inline-comments" : 0,
"no-lonely-if" : 2,
"no-mixed-operators" : 2,
"no-mixed-spaces-and-tabs" : 2,
"no-multiple-empty-lines" : 0,
"no-negated-condition" : 0,
"no-nested-ternary" : 2,
"no-new-object" : 2,
"no-plusplus": 0,
"no-restricted-syntax" : 0,
"no-tabs" : 0,
"no-ternary" : 0,
"no-trailing-spaces" : 0,
"no-underscore-dangle" : 0,
"no-unneeded-ternary" : 2,
"no-whitespace-before-property" : 2,
"object-curly-newline" : 0,
"object-curly-spacing" : 2,
"object-property-newline" : 0,
"one-var-declaration-per-line" : 2,
"one-var" : 0,
"operator-assignment" : 0,
"operator-linebreak" : 2,
"padded-block" : 0,
"quote-props" : 0,
"quotes" : [2, "single", { "allowTemplateLiterals": true }],
"require-jsdoc" : 2,
"semi-spacing" : 2,
"semi" : 2,
"sort-keys" : 0,
"sort-vars" : 0,
"space-before-blocks" : 0,
"space-before-function-paren" : 0,
"space-in-parens" : 0,
"space-infix-ops" : 2,
"space-unary-ops" : 0,
"spaced-comment" : 0,
"unicode-bom" : 0,
"wrap-regex" : 2,
"arrow-body-style" : 0,
"arrow-parens" : 0,
"arrow-spacing" : 0,
"constructor-super" : 2,
"generator-star-spacing" : [2, {"before" : false, "after" : true}],
"no-class-assign" : 2,
"no-confusing-arrow" : 0,
"no-const-assign" : 2,
"no-dupe-class-members" : 2,
"no-duplicate-imports" : 2,
"no-new-symbol" : 2,
"no-restricted-imports" : 0,
"no-this-before-super" : 2,
"no-useless-computed-key" : 2,
"no-useless-constructor" : 2,
"no-useless-rename" : 2,
"no-var" : 2,
"object-shorthand" : 0,
"prefer-arrow-callback" : 0,
"prefer-const" : 2,
"prefer-numeric-literals" : 0,
"prefer-reflect" : 0,
"prefer-rest-params" : 2,
"prefer-spread" : 2,
"prefer-template" : 2,
"require-yield" : 2,
"rest-spread-spacing" : 0,
"sort-imports" : 0,
"symbol-description" : 2,
"template-curly-spacing" : 0,
"yield-star-spacing" : 2
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
docs/
docs/
.vscode/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "6"
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
"author": "robotmayo",
"license": "GPL-3.0",
"dependencies": {
"bluebird": "^3.4.6",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"express-hbs": "^1.0.3",
"express-session": "^1.14.1",
"logbro": "^1.2.0",
"passport": "^0.3.2",
"passport-local": "^1.0.0"
"bluebird": "3.4.6",
"body-parser": "1.15.2",
"express": "4.14.0",
"express-hbs": "1.0.3",
"express-session": "1.14.1",
"logbro": "1.2.0",
"passport": "0.3.2",
"passport-local": "1.0.0"
},
"devDependencies": {
"ava": "^0.16.0",
"documentation": "^4.0.0-beta10"
"ava": "0.16.0",
"documentation": "4.0.0-beta10",
"eslint": "^3.5.0"
}
}
55 changes: 28 additions & 27 deletions src/plugins/hook.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const Promise = require('bluebird');
const log = require('logbro');

const HOOK_TYPES = require('./constants').HOOK_TYPES;
const HOOK_TYPES_ARR = [HOOK_TYPES.FILTER, HOOK_TYPES.STATIC, HOOK_TYPES.ACTION];
const DEFAULT_PRIORITY = 5;

module.exports = function hookInit(Plugins) {
/**
Expand Down Expand Up @@ -37,31 +36,13 @@ module.exports = function hookInit(Plugins) {
if (!opts.hook || typeof opts.hook !== 'string') throw new Error('Hook is required');
if (!opts.fn || typeof opts.fn !== 'function') throw new Error('fn is required');
const data = Object.assign({}, opts);
data.priority = typeof data.priority === 'number' ? data.priority : 5;
data.priority = typeof data.priority === 'number' ? data.priority : DEFAULT_PRIORITY;
data.id = pluginID;
if (!Plugins.hookMap.has(data.hook)) Plugins.hookMap.set(data.hook, []);
Plugins.hookMap.get(data.hook).push(data);
}
Plugins.addHook = addHook;

/**
*
* @memberof Plugins
* @param {string} hook
* @param {object} context
* @returns {Promise<Any|Error>}
*/
function fireHook(hook, context) {
const hookType = hook.split('::')[0];
if (HOOK_TYPES.indexOf(hookType) === -1) return Promise.reject(new Error('Invalid hooktype'));
const hooks = Plugins.hookMap.get(hook);
if (!hooks) return Promise.resolve(context);
if (hookType === HOOK_TYPES.FILTER) return fireFilterHook(hooks, context);
else if (hookType === HOOK_TYPES.STATIC) return fireStaticHook(hooks, context);
else if (hookType === HOOK_TYPES.ACTION) return fireActionHook(hooks, context);
}
Plugins.fireHook = fireHook;


/**
*
Expand All @@ -71,7 +52,7 @@ module.exports = function hookInit(Plugins) {
* @returns {Promise<Any|Error>}
*/
function fireFilterHook(hooks, context) {
return Promise.reduce(hooks, function (accum, data) {
return Promise.reduce(hooks, function filterHookReduce(accum, data) {
return data.fn(accum);
}, context);
}
Expand All @@ -85,15 +66,15 @@ module.exports = function hookInit(Plugins) {
* @returns {Promise<Any|Error>}
*/
function fireStaticHook(hooks, context) {
return Promise.each(hooks, function (data) {
return Promise.each(hooks, function staticHookEach(data) {
return data.fn(context)
.timeout(5000)
.catch(Promise.TimeoutError, function (err) {
log.error('Plugin failed to finish in time');
log.error(`Plugin failed to finish in time ${err.stack}`);
})
.catch(function (err) {
log.error('Plugin failure');
})
log.error(`Plugin failure ${err.stack}`);
});
});
}
Plugins.fireStaticHook = fireStaticHook;
Expand All @@ -109,7 +90,27 @@ module.exports = function hookInit(Plugins) {
return Promise.all(hooks.map(d => d.fn(context)));
}
Plugins.fireActionHook = fireActionHook;

/**
*
* @memberof Plugins
* @param {string} hook
* @param {object} context
* @returns {Promise<Any|Error>}
*/
function fireHook(hook, context) {
const hookType = hook.split('::')[0];
if (HOOK_TYPES_ARR.indexOf(hookType) === -1) return Promise.reject(new Error('Invalid hooktype'));
const hooks = Plugins.hookMap.get(hook);
if (!hooks) return Promise.resolve(context);
if (hookType === HOOK_TYPES.FILTER) return fireFilterHook(hooks, context);
else if (hookType === HOOK_TYPES.STATIC) return fireStaticHook(hooks, context);
else if (hookType === HOOK_TYPES.ACTION) return fireActionHook(hooks, context);
return Promise.reject(new Error('Invalid hooktype'));
}
Plugins.fireHook = fireHook;

return Plugins;

}
};

3 changes: 1 addition & 2 deletions src/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
/**
* @namespace Plugins
*/
const Plugins = {};
module.exports = require('./hook')(Plugins);
module.exports = require('./hook')(Plugins);
Loading

0 comments on commit 3e5aeeb

Please sign in to comment.