Skip to content

Commit

Permalink
feat(@whook/whook): add prepareCommand function
Browse files Browse the repository at this point in the history
  • Loading branch information
AubHaddad committed Mar 14, 2024
1 parent be477f1 commit 4e63393
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"name": "Vincent Da Silva",
"email": "[email protected]",
"url": "https://dasilvavincent.github.io/PortFolio/"
},
{
"name": "Ayoub HAD-DAD",
"email": "[email protected]",
"url": "https://github.com/AubHaddad"
}
],
"engines": {
Expand Down
11 changes: 11 additions & 0 deletions packages/whook-example/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
3. [MAIN_FILE_URL](#1133-main_file_url)
3. [TRANSACTIONS](#1133-transactions)
4. [WHOOK_PLUGINS](#1134-whook_plugins)
4. [prepareCommand](#114-preparecommand)
2. [The build file](#12-the-build-file)
1. [The `runBuild` function](#121-the-`runbuild`-function)
2. [The `prepareBuildEnvironment` function](#122-the-`preparebuildenvironment`-function)
Expand Down Expand Up @@ -208,6 +209,16 @@ You can also avoid Whook defaults by leaving it empty.



#### 1.1.4. prepareCommand

The `prepareCommand` function is intended to prepare the commands
environment. It relies on the main environment but will be
used only by the commands, not the server or build scripts.

[See in context](./src/index.ts#L209-L214)



### 1.2. The build file

Per convention a Whook server build file must export
Expand Down
16 changes: 16 additions & 0 deletions packages/whook-example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,19 @@ export async function prepareEnvironment<T extends Knifecycle>(

return $;
}

/* Architecture Note #1.1.4: prepareCommand
The `prepareCommand` function is intended to prepare the commands
environment. It relies on the main environment but will be
used only by the commands, not the server or build scripts.
*/

export async function prepareCommand<T extends Knifecycle>(
innerPrepareEnvironment: ($?: T) => Promise<T> = prepareEnvironment,
$: T = new Knifecycle() as T,
): Promise<T> {
$ = await innerPrepareEnvironment($);
// you can add here any logic bound to the commands only
return $;
}
4 changes: 2 additions & 2 deletions packages/whook/bin/whook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import path from 'path';
import runCLI from '../dist/cli.js';

const { prepareEnvironment } = await import(
const { prepareCommand } = await import(
path.join(process.cwd(), 'dist', 'index.js')
);

await runCLI(prepareEnvironment);
await runCLI(prepareCommand);

0 comments on commit 4e63393

Please sign in to comment.