Re-indented some files I was missing.

I think that's it.
This commit is contained in:
David Diaz 2018-05-05 00:33:01 +00:00
parent 4bf7a60e9c
commit 3b8d66ffba
11 changed files with 7819 additions and 7814 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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