From 4e6339392117076950d87664818bdc511111e47e Mon Sep 17 00:00:00 2001 From: Ayoub HADDAD Date: Thu, 14 Mar 2024 08:51:30 +0000 Subject: [PATCH] feat(@whook/whook): add prepareCommand function --- package.json | 5 +++++ packages/whook-example/ARCHITECTURE.md | 11 +++++++++++ packages/whook-example/src/index.ts | 16 ++++++++++++++++ packages/whook/bin/whook.js | 4 ++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 256b9290..073937ac 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,11 @@ "name": "Vincent Da Silva", "email": "dasilva.vincent.pro2@gmail.com", "url": "https://dasilvavincent.github.io/PortFolio/" + }, + { + "name": "Ayoub HAD-DAD", + "email": "aub.haddad@gmail.com", + "url": "https://github.com/AubHaddad" } ], "engines": { diff --git a/packages/whook-example/ARCHITECTURE.md b/packages/whook-example/ARCHITECTURE.md index 515eddc4..4287c9a2 100644 --- a/packages/whook-example/ARCHITECTURE.md +++ b/packages/whook-example/ARCHITECTURE.md @@ -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) @@ -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 diff --git a/packages/whook-example/src/index.ts b/packages/whook-example/src/index.ts index ff0ff56c..6759ad1d 100644 --- a/packages/whook-example/src/index.ts +++ b/packages/whook-example/src/index.ts @@ -205,3 +205,19 @@ export async function prepareEnvironment( 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( + innerPrepareEnvironment: ($?: T) => Promise = prepareEnvironment, + $: T = new Knifecycle() as T, +): Promise { + $ = await innerPrepareEnvironment($); + // you can add here any logic bound to the commands only + return $; +} diff --git a/packages/whook/bin/whook.js b/packages/whook/bin/whook.js index af04073d..882b507e 100755 --- a/packages/whook/bin/whook.js +++ b/packages/whook/bin/whook.js @@ -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);