Skip to content

Commit

Permalink
Merge pull request nfroidure#32 from nfroidure/refactor/commands
Browse files Browse the repository at this point in the history
Refactor/commands
  • Loading branch information
nfroidure authored Mar 10, 2019
2 parents 32f6cbb + 441d639 commit 17325fb
Show file tree
Hide file tree
Showing 47 changed files with 1,543 additions and 414 deletions.
4 changes: 2 additions & 2 deletions packages/whook-authorization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"homepage": "https://github.com/nfroidure/whook",
"dependencies": {
"knifecycle": "^5.3.0",
"http-auth-utils": "^2.2.0"
"http-auth-utils": "^2.2.0",
"knifecycle": "^5.3.0"
},
"peerDependencies": {
"@whook/whook": "^3.1.3"
Expand Down
6 changes: 5 additions & 1 deletion packages/whook-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ This is the Whook server CLI tool. To create new commands, you simply
have to create new files in the `src/commands` folder of your Whook
project.

By setting `@whook/cli` in the `WHOOK_PLUGINS` constant, you will
benefit of the commands
[embedded in this plugin](https://github.com/nfroidure/whook/tree/master/packages/whook-cli/src/commands).

See the [Whook example server commands](https://github.com/nfroidure/whook/tree/master/packages/whook-example/src/commands)
for simple examples.
for simple examples on creating your own commands in a `whook` project.

## Dev

Expand Down
3 changes: 2 additions & 1 deletion packages/whook-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"homepage": "https://github.com/nfroidure/whook",
"dependencies": {
"@whook/whook": "^3.1.3",
"knifecycle": "^5.3.0"
"knifecycle": "^5.3.0",
"miniquery": "^1.1.2"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
Expand Down
100 changes: 100 additions & 0 deletions packages/whook-cli/src/commands/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`configCommand should fail with no result 1`] = `
Object {
"errorCode": "E_NO_RESULT",
"errorParams": Array [
"MYSQL",
"nothing_here",
],
"logCalls": Array [
Array [
"error",
"Could not find any results for nothing_here",
],
],
}
`;

exports[`configCommand should fail with unexisting config name 1`] = `
Object {
"errorCode": "E_NO_CONFIG",
"errorParams": Array [
"DOES_NOT_EXIST",
],
"logCalls": Array [
Array [
"error",
"No config found for DOES_NOT_EXIST",
],
],
}
`;

exports[`configCommand should work with an unexisting config but a default value 1`] = `
Object {
"logCalls": Array [
Array [
"error",
"No config found for DOES_NOT_EXIST",
],
Array [
"info",
"undefined",
],
],
"result": undefined,
}
`;

exports[`configCommand should work with no query at all 1`] = `
Object {
"logCalls": Array [
Array [
"info",
"{\\"auth\\":{\\"username\\":\\"root\\"},\\"version\\":\\"2.1.1\\"}",
],
],
"result": undefined,
}
`;

exports[`configCommand should work with no result but a default value 1`] = `
Object {
"logCalls": Array [
Array [
"error",
"Could not find any results for nothing_here",
],
Array [
"info",
"\\"v8\\"",
],
],
"result": undefined,
}
`;

exports[`configCommand should work with one value 1`] = `
Object {
"logCalls": Array [
Array [
"info",
"\\"root\\"",
],
],
"result": undefined,
}
`;

exports[`configCommand should work with several values 1`] = `
Object {
"logCalls": Array [
Array [
"info",
"\\"root\\"",
],
],
"result": undefined,
}
`;
35 changes: 35 additions & 0 deletions packages/whook-cli/src/commands/__snapshots__/env.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`envCommand should fail with no value 1`] = `
Object {
"errorCode": "E_NO_ENV_VALUE",
"errorParams": Array [
"NODE_ENV",
],
"logCalls": Array [],
}
`;

exports[`envCommand should work 1`] = `
Object {
"logCalls": Array [
Array [
"info",
"test",
],
],
"result": undefined,
}
`;

exports[`envCommand should work with a default value 1`] = `
Object {
"logCalls": Array [
Array [
"info",
"lol",
],
],
"result": undefined,
}
`;
114 changes: 114 additions & 0 deletions packages/whook-cli/src/commands/__snapshots__/handler.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`handlerCommand should fail with a failing handler 1`] = `
Object {
"errorCode": "E_UNEXPECTED_SUCCESS",
"errorParams": Array [],
"injectorCalls": Array [
Array [
Array [
"putEcho",
],
],
],
"logCalls": Array [
Array [
"debug",
"handler",
"putEcho",
],
Array [
"debug",
"parameters",
Object {
"body": Object {
"echo": "YOLO!",
},
},
],
Array [
"error",
"Got an error while running the handler.",
],
],
}
`;

exports[`handlerCommand should fail with non JSON parameters 1`] = `
Object {
"errorCode": "E_BAD_PARAMETERS",
"errorParams": Array [
"{\\"body: {\\"echo\\": \\"YOLO!\\"} }",
"Unexpected token e in JSON at position 10",
],
"injectorCalls": Array [],
"logCalls": Array [],
}
`;

exports[`handlerCommand should work with all parameters 1`] = `
Object {
"injectorCalls": Array [
Array [
Array [
"putEcho",
],
],
],
"logCalls": Array [
Array [
"debug",
"handler",
"putEcho",
],
Array [
"debug",
"parameters",
Object {
"body": Object {
"echo": "YOLO!",
},
},
],
Array [
"info",
"{
\\"status\\": 200,
\\"body\\": {
\\"echo\\": \\"YOLO!\\"
}
}",
],
],
}
`;

exports[`handlerCommand should work with handler only 1`] = `
Object {
"injectorCalls": Array [
Array [
Array [
"getPing",
],
],
],
"logCalls": Array [
Array [
"debug",
"handler",
"getPing",
],
Array [
"debug",
"parameters",
Object {},
],
Array [
"info",
"{
\\"status\\": 200
}",
],
],
}
`;
110 changes: 110 additions & 0 deletions packages/whook-cli/src/commands/__snapshots__/ls.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lsCommand should work with no plugin 1`] = `
Object {
"logCalls": Array [],
"readDirCalls": Array [],
"requireCalls": Array [],
"result": undefined,
}
`;

exports[`lsCommand should work with some plugins 1`] = `
Object {
"logCalls": Array [
Array [
"debug",
"✅ - No commands folder found at path \${pluginPath}",
],
Array [
"info",
"
# Provided by \\"@whook/cli\\": 2 commands",
],
Array [
"info",
"- ls: Print available commands",
],
Array [
"info",
"- env: A command printing env values",
],
Array [
"info",
"
# Provided by \\"@whook/whook\\": none",
],
],
"readDirCalls": Array [
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands",
],
Array [
"/var/lib/node/node_modules/@whook/lol/dist/commands",
],
],
"requireCalls": Array [
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands/ls",
],
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands/env",
],
],
}
`;

exports[`lsCommand should work with some plugins and a verbose output 1`] = `
Object {
"logCalls": Array [
Array [
"debug",
"✅ - No commands folder found at path \${pluginPath}",
],
Array [
"info",
"
# Provided by \\"@whook/cli\\": 2 commands
",
],
Array [
"info",
"- ls: Print available commands
$ whook ls
",
],
Array [
"info",
"- env: A command printing env values
$ whook env --name NODE_ENV --default \\"default value\\"
",
],
Array [
"info",
"
# Provided by \\"@whook/whook\\": none
",
],
],
"readDirCalls": Array [
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands",
],
Array [
"/var/lib/node/node_modules/@whook/lol/dist/commands",
],
],
"requireCalls": Array [
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands/ls",
],
Array [
"/var/lib/node/node_modules/@whook/cli/dist/commands/env",
],
],
}
`;
Loading

0 comments on commit 17325fb

Please # to comment.