Skip to content

Commit

Permalink
fix(Build): Fix build and add a few dev docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 24, 2019
1 parent d533afb commit f15a8ad
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 64 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"cz-conventional-changelog": "^2.1.0",
"lerna": "^3.11.0",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.1"
"metapak-nfroidure": "9.6.0"
},
"contributors": [],
"engines": {
Expand Down
15 changes: 13 additions & 2 deletions packages/create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@
# @whook/create
> Kickstart a new Whook server
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/@whook/create/blob/master/LICENSE)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/whook/blob/master/packages/whook-create/LICENSE)
[![NPM version](https://badge.fury.io/js/@whook/create.svg)](https://npmjs.org/package/@whook/create)


[//]: # (::contents:start)

This module creates a basic `whook` server working out of the box.
This module creates a basic [`whook`](https://github.com/nfroidure/@whook)
server working out of the box.


## Usage

```
npm init @whook
```

## Dev

To test the create script:
```
npm run cli -- babel-node bin/create
```

[//]: # (::contents:end)

# Authors
Expand Down
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"jest": "^24.0.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.1",
"metapak-nfroidure": "9.6.0",
"prettier": "^1.16.3"
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/create/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import initAuthor from './services/author';
import initProject from './services/project';
import initCreateWhook from './services/createWhook';

// Required for babel builds to be set here
// Needed to avoid messing up babel builds 🤷
const _require = require;

export async function runCreateWhook() {
Expand Down
36 changes: 33 additions & 3 deletions packages/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,44 @@
# @whook/example
> A basic Whook server
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/@whook/example/blob/master/LICENSE)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/whook/blob/master/packages/whook-example/LICENSE)
[![NPM version](https://badge.fury.io/js/@whook/example.svg)](https://npmjs.org/package/@whook/example)


[//]: # (::contents:start)

This is a basic `whook` server demonstrating the various usages of
the Whook framework to build REST APIs.
This is a basic [`whook`]([`whook`](https://github.com/nfroidure/@whook))
server demonstrating the various usages of the Whook framework to build
REST APIs.

## Usage

```
npm it
npm start
```

## Dev

Start the dev server:
```
npm run dev
```

Execute a handler in isolation:
```
npm run whook -- handler --name putEcho --parameters '{"body": { "echo": "YOLO!" }}'
```

Debug `whook` internals:
```
DEBUG=whook npm run dev
```

Debug `knifecycle` internals (dependency injections issues):
```
DEBUG=metapak npm run dev
```

[//]: # (::contents:end)

Expand Down
2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"jest": "^24.0.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.1",
"metapak-nfroidure": "9.6.0",
"prettier": "^1.16.3"
},
"contributors": [],
Expand Down
3 changes: 3 additions & 0 deletions packages/example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export async function prepareEnvironment($ = new Knifecycle()) {
// transactions
$.register(constant('TRANSACTIONS', {}));

// Setup your own whook plugins or avoid whook default by leaving it empty
$.register(constant('WHOOK_PLUGINS', ['@whook/whook']));

// Add here any service/handler required to bootstrap
// the server env

Expand Down
6 changes: 3 additions & 3 deletions packages/whook-authorization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# @whook/authorization
> A wrapper to provide authorization support to a Whook server
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/@whook/authorization/blob/master/LICENSE)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/whook/blob/master/packages/whook-authorization/LICENSE)
[![NPM version](https://badge.fury.io/js/@whook/authorization.svg)](https://npmjs.org/package/@whook/authorization)


[//]: # (::contents:start)

To see how to add authorization support to your application, have a look
at the `create-whook` project, it will be well documented here
as soon as possible.
at the [`@whook/example`](https://github.com/nfroidure/whook/whook-example/)
project, it will be well documented here as soon as possible.

[//]: # (::contents:end)

Expand Down
2 changes: 1 addition & 1 deletion packages/whook-authorization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"jest": "^24.0.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.1",
"metapak-nfroidure": "9.6.0",
"prettier": "^1.16.3"
},
"contributors": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# @whook/cli
> The Whook server CLI
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/@whook/cli/blob/master/LICENSE)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/whook/blob/master/packages/whook-cli/LICENSE)
[![NPM version](https://badge.fury.io/js/@whook/cli.svg)](https://npmjs.org/package/@whook/cli)


Expand Down
2 changes: 1 addition & 1 deletion packages/whook-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"jest": "^24.0.0",
"jsdoc-to-markdown": "^4.0.1",
"metapak": "^3.1.5",
"metapak-nfroidure": "9.5.1",
"metapak-nfroidure": "9.6.0",
"prettier": "^1.16.3"
},
"contributors": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object {
],
"path": "mocked://service",
"requireCalls": Array [],
"resolveCalls": Array [],
"result": undefined,
}
`;
Expand All @@ -27,6 +28,10 @@ Object {
"debug",
"🤖 - Wrapping the whook autoloader.",
],
Array [
"debug",
"Plugin \\"@whook/whook\\" resolved to: /var/lib/node/node_modules/@whook/whook/src",
],
Array [
"warning",
"The handler seems to have no default export.",
Expand All @@ -38,6 +43,11 @@ Object {
"/home/whoiam/projects/my-whook-project/src/commands/handler",
],
],
"resolveCalls": Array [
Array [
"@whook/whook",
],
],
"result": undefined,
}
`;
Expand All @@ -50,13 +60,17 @@ Object {
"debug",
"🤖 - Wrapping the whook autoloader.",
],
Array [
"debug",
"Plugin \\"@whook/whook\\" resolved to: /var/lib/node/node_modules/@whook/whook/src",
],
Array [
"debug",
"Command \\"handler\\" not found in: /home/whoiam/projects/my-whook-project/src/commands/handler",
],
Array [
"debug",
"Command \\"handler\\" not found in: whook/commands/handler",
"Command \\"handler\\" not found in: /var/lib/node/node_modules/@whook/whook/src/commands/handler",
],
Array [
"warning",
Expand All @@ -69,7 +83,15 @@ Object {
"/home/whoiam/projects/my-whook-project/src/commands/handler",
],
Array [
"whook/commands/handler",
"/var/lib/node/node_modules/@whook/whook/src/commands/handler",
],
Array [
"/home/nfroidure/nfroidure/whook/packages/whook-cli/src/commands/handler",
],
],
"resolveCalls": Array [
Array [
"@whook/whook",
],
],
"result": undefined,
Expand All @@ -84,6 +106,10 @@ Object {
"debug",
"🤖 - Wrapping the whook autoloader.",
],
Array [
"debug",
"Plugin \\"@whook/whook\\" resolved to: /var/lib/node/node_modules/@whook/whook/src",
],
Array [
"warning",
"Command called!",
Expand All @@ -95,6 +121,11 @@ Object {
"/home/whoiam/projects/my-whook-project/src/commands/handler",
],
],
"resolveCalls": Array [
Array [
"@whook/whook",
],
],
"result": undefined,
}
`;
Expand All @@ -107,6 +138,10 @@ Object {
"debug",
"🤖 - Wrapping the whook autoloader.",
],
Array [
"debug",
"Plugin \\"@whook/whook\\" resolved to: /var/lib/node/node_modules/@whook/whook/src",
],
Array [
"debug",
"Command \\"handler\\" not found in: /home/whoiam/projects/my-whook-project/src/commands/handler",
Expand All @@ -122,7 +157,12 @@ Object {
"/home/whoiam/projects/my-whook-project/src/commands/handler",
],
Array [
"whook/commands/handler",
"/var/lib/node/node_modules/@whook/whook/src/commands/handler",
],
],
"resolveCalls": Array [
Array [
"@whook/whook",
],
],
"result": undefined,
Expand Down
49 changes: 35 additions & 14 deletions packages/whook-cli/src/services/_autoload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,58 @@ import path from 'path';
import initAutoloader from '@whook/whook/dist/services/_autoload';
import { wrapInitializer, alsoInject, service } from 'knifecycle';

// Needed to avoid messing up babel builds 🤷
const _require = require;
const _resolve = require.resolve;

export default alsoInject(
['PROJECT_SRC', 'WHOOK_PLUGINS', 'log'],
wrapInitializer(
async (
{ PROJECT_SRC, WHOOK_PLUGINS, log, require = _require },
{
PROJECT_SRC,
WHOOK_PLUGINS,
log,
require = _require,
resolve = _resolve,
},
$autoload,
) => {
log('debug', '🤖 - Wrapping the whook autoloader.');

return async serviceName => {
if (serviceName.endsWith('Command')) {
const commandName = serviceName.replace(/Command$/, '');
const pluginsPaths = WHOOK_PLUGINS.map(pluginName => {
// Here we resolve the main path to finally
// get the `main` exported file's directory
// which is assumed to contain the commands
// folder of the plugin
const modulePath = path.dirname(resolve(pluginName));

log('debug', `Plugin "${pluginName}" resolved to: ${modulePath}`);

return modulePath;
});

let commandModule;

[PROJECT_SRC, ...WHOOK_PLUGINS].some(basePath => {
const modulePath = path.join(basePath, 'commands', commandName);
[PROJECT_SRC, ...pluginsPaths, path.join(__dirname, '..')].some(
basePath => {
const finalPath = path.join(basePath, 'commands', commandName);

try {
commandModule = require(modulePath);
return true;
} catch (err) {
log(
'debug',
`Command "${commandName}" not found in: ${modulePath}`,
);
log('stack', err.stack);
}
});
try {
commandModule = require(finalPath);
return true;
} catch (err) {
log(
'debug',
`Command "${commandName}" not found in: ${finalPath}`,
);
log('stack', err.stack);
}
},
);
let commandInitializer;

if (!commandModule) {
Expand Down
Loading

0 comments on commit f15a8ad

Please sign in to comment.