Skip to content

Commit 62f2de8

Browse files
authored
Add prompts to AdonisJS configure hook (#117)
* Add prompts to AdonisJS configure hook * Update README
1 parent ae2c375 commit 62f2de8

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ _Note:_ Apitally only works with H3 v2 and currently doesn't support nested apps
205205

206206
### AdonisJS
207207

208-
You can use the built-in Ace command to configure Apitally in your AdonisJS application:
208+
You can use the below Ace command to configure Apitally in your AdonisJS application:
209209

210210
```bash
211211
node ace configure apitally/adonisjs
@@ -216,12 +216,7 @@ This command will automatically:
216216
- Create a config file at `config/apitally.ts`
217217
- Register the Apitally provider in `adonisrc.ts`
218218
- Add the Apitally middleware to `start/kernel.ts`
219-
- Add environment variables to `.env` and `start/env.ts`
220-
221-
After running the command, you'll need to:
222-
223-
- Set your `APITALLY_CLIENT_ID` in the `.env` file
224-
- Modify your exception handler in `app/exceptions/handler.ts` to capture validation and server errors
219+
- Add required environment variables to `.env` and `start/env.ts`
225220

226221
For further instructions, see our
227222
[setup guide for AdonisJS](https://docs.apitally.io/frameworks/adonisjs).

src/adonisjs/configure.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,33 @@
55
import type Configure from "@adonisjs/core/commands/configure";
66
import { fileURLToPath } from "url";
77

8+
import { isValidClientId, isValidEnv } from "../common/paramValidation.js";
9+
810
const STUBS_ROOT = fileURLToPath(new URL("./stubs/", import.meta.url));
911

1012
export async function configure(command: Configure) {
13+
const clientId = await command.prompt.ask("Apitally client ID", {
14+
result(value) {
15+
return value.trim().toLowerCase();
16+
},
17+
validate(value) {
18+
return isValidClientId(value);
19+
},
20+
});
21+
const env = await command.prompt.ask("Environment name", {
22+
default: "dev",
23+
result(value) {
24+
return value
25+
.trim()
26+
.toLowerCase()
27+
.replaceAll("_", "-")
28+
.replaceAll(" ", "-");
29+
},
30+
validate(value) {
31+
return isValidEnv(value);
32+
},
33+
});
34+
1135
const codemods = await command.createCodemods();
1236

1337
await codemods.makeUsingStub(STUBS_ROOT, "config/apitally.stub", {});
@@ -23,8 +47,8 @@ export async function configure(command: Configure) {
2347
});
2448

2549
await codemods.defineEnvVariables({
26-
APITALLY_CLIENT_ID: "",
27-
APITALLY_ENV: "dev",
50+
APITALLY_CLIENT_ID: clientId,
51+
APITALLY_ENV: env,
2852
});
2953

3054
await codemods.defineEnvValidations({

0 commit comments

Comments
 (0)