Re-indented some files I was missing. (#19)

I think that's it.
This commit is contained in:
Sergio Díaz 2018-05-04 22:00:54 -06:00 committed by GitHub
parent 4bf7a60e9c
commit 56d536a509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 7819 additions and 7814 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
require('@oclif/command') require('@oclif/command')
.run() .run()
.catch(require('@oclif/errors/handle')); .catch(require('@oclif/errors/handle'));

View File

@ -6,36 +6,36 @@ const { Command, flags } = require('@oclif/command');
const Beau = require('../../src/beau'); const Beau = require('../../src/beau');
class Base extends Command { class Base extends Command {
openConfigFile(configFile) { openConfigFile(configFile) {
if (!fs.existsSync(configFile)) { if (!fs.existsSync(configFile)) {
this.error(`The config file, ${configFile} was not found.`); this.error(`The config file, ${configFile} was not found.`);
this.exit(1); this.exit(1);
} }
return yaml.safeLoad(fs.readFileSync(configFile, 'utf-8')); return yaml.safeLoad(fs.readFileSync(configFile, 'utf-8'));
} }
loadConfig(configFile) { loadConfig(configFile) {
const config = this.openConfigFile(configFile); const config = this.openConfigFile(configFile);
const env = dotenv.config().parsed || {}; const env = dotenv.config().parsed || {};
return new Beau(config, env); return new Beau(config, env);
} }
} }
Base.flags = { Base.flags = {
config: flags.string({ config: flags.string({
char: 'c', char: 'c',
description: 'The configuration file to be used.', description: 'The configuration file to be used.',
default: 'beau.yml' default: 'beau.yml'
}), }),
verbose: flags.boolean({ verbose: flags.boolean({
char: 'V', char: 'V',
description: 'Show all additional information available for a command.' description: 'Show all additional information available for a command.'
}), }),
'no-format': flags.boolean({ 'no-format': flags.boolean({
description: `Disables color formatting for usage on external tools.` description: `Disables color formatting for usage on external tools.`
}) })
}; };
module.exports = Base; module.exports = Base;

View File

@ -5,45 +5,45 @@ const { flags } = require('@oclif/command');
const Base = require('../base'); const Base = require('../base');
class ListCommand extends Base { class ListCommand extends Base {
async run() { async run() {
const { flags } = this.parse(ListCommand); const { flags } = this.parse(ListCommand);
const Beau = this.loadConfig(flags.config); const Beau = this.loadConfig(flags.config);
if (flags['no-format']) { if (flags['no-format']) {
return Beau.requests.list.forEach( return Beau.requests.list.forEach(
({ VERB, ALIAS, ENDPOINT, PATH }) => ({ VERB, ALIAS, ENDPOINT, PATH }) =>
this.log( this.log(
VERB + VERB +
`\t` + `\t` +
ALIAS + ALIAS +
`\t` + `\t` +
ENDPOINT.replace(/\/$/, '') + ENDPOINT.replace(/\/$/, '') +
`/` + `/` +
PATH.replace(/^\//, '') PATH.replace(/^\//, '')
) )
); );
} }
new Line() new Line()
.padding(2) .padding(2)
.column('HTTP Verb', 20, [clc.cyan]) .column('HTTP Verb', 20, [clc.cyan])
.column('Alias', 30, [clc.cyan]) .column('Alias', 30, [clc.cyan])
.column('Endpoint', 20, [clc.cyan]) .column('Endpoint', 20, [clc.cyan])
.output(); .output();
Beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) => Beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) =>
new Line() new Line()
.padding(2) .padding(2)
.column(VERB, 20, [clc.yellow]) .column(VERB, 20, [clc.yellow])
.column(ALIAS, 30, [clc.yellow]) .column(ALIAS, 30, [clc.yellow])
.column( .column(
ENDPOINT.replace(/\/$/, '') + '/' + PATH.replace(/^\//, '') ENDPOINT.replace(/\/$/, '') + '/' + PATH.replace(/^\//, '')
) )
.output() .output()
); );
new Line().output(); new Line().output();
} }
} }
ListCommand.description = `Lists all available requests in the config file.`; ListCommand.description = `Lists all available requests in the config file.`;

View File

@ -6,78 +6,78 @@ const { flags } = require('@oclif/command');
const Base = require('../base'); const Base = require('../base');
class RequestCommand extends Base { class RequestCommand extends Base {
prettyOutput(res, verbose = false) { prettyOutput(res, verbose = false) {
let { status, body } = res.response; let { status, body } = res.response;
this.spinner.stop(); this.spinner.stop();
status = status.toString().startsWith(2) status = status.toString().startsWith(2)
? clc.green(status) ? clc.green(status)
: clc.red(status); : clc.red(status);
new Line() new Line()
.padding(2) .padding(2)
.column('Status', 20, [clc.cyan]) .column('Status', 20, [clc.cyan])
.column('Endpoint', 20, [clc.cyan]) .column('Endpoint', 20, [clc.cyan])
.output(); .output();
new Line() new Line()
.padding(2) .padding(2)
.column(status, 20) .column(status, 20)
.column(res.request.endpoint) .column(res.request.endpoint)
.output(); .output();
new Line().output(); new Line().output();
jsome((verbose ? res : body) || null); jsome((verbose ? res : body) || null);
} }
async run() { async run() {
const { flags, args } = this.parse(RequestCommand); const { flags, args } = this.parse(RequestCommand);
const Beau = this.loadConfig(flags.config); const Beau = this.loadConfig(flags.config);
this.spinner = new Spinner(clc.yellow(`Requesting: ${args.alias}`), [ this.spinner = new Spinner(clc.yellow(`Requesting: ${args.alias}`), [
'⣾', '⣾',
'⣽', '⣽',
'⣻', '⣻',
'⢿', '⢿',
'⡿', '⡿',
'⣟', '⣟',
'⣯', '⣯',
'⣷' '⣷'
]); ]);
try { try {
if (!flags['no-format']) { if (!flags['no-format']) {
this.spinner.start(); this.spinner.start();
} }
let res = await Beau.requests.execByAlias(args.alias); let res = await Beau.requests.execByAlias(args.alias);
if (flags['no-format']) { if (flags['no-format']) {
this.log(res.response.status); this.log(res.response.status);
this.log(res.request.endpoint); this.log(res.request.endpoint);
this.log(JSON.stringify(res.response.headers)); this.log(JSON.stringify(res.response.headers));
this.log(JSON.stringify(res.response.body)); this.log(JSON.stringify(res.response.body));
} else { } else {
this.prettyOutput(res, flags.verbose); this.prettyOutput(res, flags.verbose);
} }
} catch (err) { } catch (err) {
new Line().output(); new Line().output();
this.spinner.stop(); this.spinner.stop();
this.error(err.message); this.error(err.message);
} }
} }
} }
RequestCommand.description = `Executes a request by name.`; RequestCommand.description = `Executes a request by name.`;
RequestCommand.flags = { ...Base.flags }; RequestCommand.flags = { ...Base.flags };
RequestCommand.args = [ RequestCommand.args = [
{ {
name: 'alias', name: 'alias',
required: true, required: true,
description: `The alias of the request to execute.` description: `The alias of the request to execute.`
} }
]; ];
module.exports = RequestCommand; module.exports = RequestCommand;

View File

@ -7,28 +7,28 @@ const Base = require('../base');
const { validate } = require('../../../src/schema.js'); const { validate } = require('../../../src/schema.js');
class ValidateCommand extends Base { class ValidateCommand extends Base {
async run() { async run() {
const { flags, args } = this.parse(ValidateCommand); const { flags, args } = this.parse(ValidateCommand);
const configFile = args.alias || flags.config; const configFile = args.alias || flags.config;
const config = this.openConfigFile(configFile); const config = this.openConfigFile(configFile);
let result = await validate(config); let result = await validate(config);
if (result.valid) { if (result.valid) {
this.log(`${configFile} is valid.`); this.log(`${configFile} is valid.`);
} else { } else {
this.error(result.message); this.error(result.message);
} }
} }
} }
ValidateCommand.description = `Validates the given configuration file against Beau's configuration schema.`; ValidateCommand.description = `Validates the given configuration file against Beau's configuration schema.`;
ValidateCommand.flags = { ...Base.flags }; ValidateCommand.flags = { ...Base.flags };
ValidateCommand.args = [ ValidateCommand.args = [
{ {
name: 'alias', name: 'alias',
required: false, required: false,
description: `The configuration file to validate.` description: `The configuration file to validate.`
} }
]; ];
module.exports = ValidateCommand; module.exports = ValidateCommand;

View File

@ -17,3 +17,9 @@ GET /cookies/set:
GET /status/418: GET /status/418:
alias: teapot alias: teapot
POST /post:
alias: post
formdata:
file: $[createReadStream('./github.yml')]

15240
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +1,52 @@
{ {
"name": "beau", "name": "beau",
"version": "0.8.0", "version": "0.8.0",
"description": "Testing APIs made easy.", "description": "Testing APIs made easy.",
"main": "./src/beau.js", "main": "./src/beau.js",
"author": "Sergio Diaz <seich@martianwabbit.com>", "author": "Sergio Diaz <seich@martianwabbit.com>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "jest", "test": "jest",
"test:coverage": "jest --coverage" "test:coverage": "jest --coverage"
}, },
"dependencies": { "dependencies": {
"@oclif/command": "^1.4.16", "@oclif/command": "^1.4.16",
"@oclif/config": "^1.6.13", "@oclif/config": "^1.6.13",
"@oclif/plugin-help": "^1.2.5", "@oclif/plugin-help": "^1.2.5",
"@oclif/plugin-warn-if-update-available": "^1.3.6", "@oclif/plugin-warn-if-update-available": "^1.3.6",
"cli-color": "^1.1.0", "cli-color": "^1.1.0",
"clui": "^0.3.1", "clui": "^0.3.1",
"deepmerge": "^2.1.0", "deepmerge": "^2.1.0",
"dotenv": "^5.0.1", "dotenv": "^5.0.1",
"joi": "^13.2.0", "joi": "^13.2.0",
"globby": "^8.0.1", "globby": "^8.0.1",
"is-plain-object": "^2.0.4", "is-plain-object": "^2.0.4",
"js-yaml": "^3.11.0", "js-yaml": "^3.11.0",
"jsome": "^2.5.0", "jsome": "^2.5.0",
"request": "^2.85.0", "request": "^2.85.0",
"request-promise-native": "^1.0.5", "request-promise-native": "^1.0.5",
"requireg": "^0.1.6" "requireg": "^0.1.6"
}, },
"repository": "git@github.com:Seich/Beau.git", "repository": "git@github.com:Seich/Beau.git",
"devDependencies": { "devDependencies": {
"jest": "^22.4.0" "jest": "^22.4.0"
}, },
"oclif": { "oclif": {
"commands": "./bin/cli/commands", "commands": "./bin/cli/commands",
"bin": "beau", "bin": "beau",
"plugins": [ "plugins": [
"@oclif/plugin-help", "@oclif/plugin-help",
"@oclif/plugin-warn-if-update-available" "@oclif/plugin-warn-if-update-available"
] ]
}, },
"jest": { "jest": {
"testEnvironment": "node", "testEnvironment": "node",
"notify": true "notify": true
}, },
"bin": { "bin": {
"beau": "./bin/beau" "beau": "./bin/beau"
}, },
"engines": { "engines": {
"node": ">=8.9.3" "node": ">=8.9.3"
} }
} }

View File

@ -1,7 +1,7 @@
class BeauStd { class BeauStd {
constructor(registry, settings) { constructor(registry, settings) {
registry.defineDynamicValue('createReadStream', () => {}); registry.defineDynamicValue('createReadStream', () => {});
} }
} }
module.exports = BeauStd; module.exports = BeauStd;

View File

@ -1,15 +1,15 @@
function requireg(name) { function requireg(name) {
return require(name); return require(name);
} }
requireg.std_resolving = false; requireg.std_resolving = false;
requireg.resolve = function(name) { requireg.resolve = function(name) {
if (requireg.std_resolving) { if (requireg.std_resolving) {
return ''; return '';
} else { } else {
throw new Error(`Failed to resolve.`); throw new Error(`Failed to resolve.`);
} }
}; };
module.exports = requireg; module.exports = requireg;

View File

@ -53,6 +53,7 @@ class Plugins {
} }
replaceDynamicValues(obj) { replaceDynamicValues(obj) {
vm.createContext(this.context);
return replaceInObject(obj, val => { return replaceInObject(obj, val => {
let valIsEmpty = val.trim().length === 0; let valIsEmpty = val.trim().length === 0;
@ -93,8 +94,6 @@ class Plugins {
defineDynamicValue(name, fn) { defineDynamicValue(name, fn) {
this.registry.dynamicValues.push({ name, fn }); this.registry.dynamicValues.push({ name, fn });
this.context[name] = fn; this.context[name] = fn;
vm.createContext(this.context);
} }
} }