diff --git a/docs/Ake.md b/docs/Ake.md index e6004dd..37fdb8a 100644 --- a/docs/Ake.md +++ b/docs/Ake.md @@ -98,6 +98,12 @@ ake greetings # finds ../ake and runs it in the project directory The working directory is automatically set to the project directory (where the ake file lives), so `$` commands always run relative to the project root. +## Global Variables + +```ts +PROJECT_DIR // absolute path to the project dir +``` + ## Multiple Ake Files Any file named `ake` or `ake.ts` is supported. diff --git a/docs/Global Commands.md b/docs/Global Commands.md index d87b645..505730a 100644 --- a/docs/Global Commands.md +++ b/docs/Global Commands.md @@ -76,6 +76,7 @@ $`cat ${files}` // cat a.txt b.txt ## Global Variables ```ts -app // Command instance for defining CLI metadata and commands -$ // Shell command tagged template +app // Command instance for defining CLI metadata and commands +$ // Shell command tagged template +PROJECT_DIR // ake only: absolute path to the project dir (where the ake file lives) ``` diff --git a/src/Command.ts b/src/Command.ts index 8865b19..1117c5c 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -132,6 +132,7 @@ export class Command { } const projectDir = getProjectDir(scriptPath) process.chdir(projectDir) + ;(globalThis as any).PROJECT_DIR = projectDir } async parse(argv: string[]): Promise { diff --git a/src/globals.d.ts b/src/globals.d.ts index 0c5e4f6..2f2a719 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -4,4 +4,5 @@ import type { $ as Shell } from './spawn' declare global { var app: Command var $: typeof Shell + var PROJECT_DIR: string }