From 5ad2978760186ffd3f6c548d3c024d5c815eca9f Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Fri, 19 Oct 2018 16:41:52 +0200 Subject: [PATCH] Load all commands statically; fixes #158 --- lib/Command.js | 54 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/lib/Command.js b/lib/Command.js index fd7fa70..7896ab9 100644 --- a/lib/Command.js +++ b/lib/Command.js @@ -1,11 +1,46 @@ 'use strict'; -var Data = require('./Data.js'), - URL = require('url'), - fs = require('fs'), - qs = require('querystring'), - formFunctions = require('./Form.js'), - cmdDir = __dirname + '/commands/'; +var Data = require('./Data.js'), + URL = require('url'), + qs = require('querystring'), + formFunctions = require('./Form.js'); + +var commands = { + 'click': require('./commands/click.js'), + 'config': require('./commands/config.js'), + 'contains': require('./commands/contains.js'), + 'cookie': require('./commands/cookie.js'), + 'data': require('./commands/data.js'), + 'delay': require('./commands/delay.js'), + 'do': require('./commands/do.js'), + 'done': require('./commands/done.js'), + 'fail': require('./commands/fail.js'), + 'filter': require('./commands/filter.js'), + 'find': require('./commands/find.js'), + 'follow': require('./commands/follow.js'), + 'get': require('./commands/get.js'), + 'header': require('./commands/header.js'), + 'headers': require('./commands/headers.js'), + 'if': require('./commands/if.js'), + 'learn': require('./commands/learn.js'), + 'login': require('./commands/login.js'), + 'match': require('./commands/match.js'), + 'paginate': require('./commands/paginate.js'), + 'parse': require('./commands/parse.js'), + 'pause': require('./commands/pause.js'), + 'proxy': require('./commands/proxy.js'), + 'resume': require('./commands/resume.js'), + 'rewrite': require('./commands/rewrite.js'), + 'set': require('./commands/set.js'), + 'stop': require('./commands/stop.js'), + 'submit': require('./commands/submit.js'), + 'success': require('./commands/success.js'), + 'then': require('./commands/then.js'), + 'train': require('./commands/train.js'), + 'trigger': require('./commands/trigger.js'), + 'use': require('./commands/use.js'), + 'using': require('./commands/using.js'), +}; /** * An Osmosis command. @@ -538,15 +573,14 @@ Command.prototype.findCommandArg = function (obj) { return obj; }; -fs.readdirSync(cmdDir).forEach(function (file) { - var command = require(cmdDir + file); - +Object.keys(commands).forEach(function (file) { + var command = commands[file]; if (typeof command === 'object') { Object.keys(command).forEach(function (name) { contextCommand(name, command[name]); }); } else { - runtimeCommand(file.substr(0, file.length - 3), command); + runtimeCommand(file, command); } });