@stjoseph/prumo 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/generate.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { spawnSync } from 'node:child_process';
2
+ import { randomBytes } from 'node:crypto';
2
3
  import { existsSync } from 'node:fs';
3
4
  import { readdir, readFile, writeFile } from 'node:fs/promises';
4
5
  import { join } from 'node:path';
@@ -20,6 +21,23 @@ async function nameMobileApp(app, name) {
20
21
  return setJsonc(result, ['expo', 'scheme'], schemeFor(name));
21
22
  });
22
23
  }
24
+ const SECRET_LINE = /^BETTER_AUTH_SECRET=.*$/m;
25
+ // `.env` stays out of git, so the example is the committed truth and a fresh project gets a copy it can start with.
26
+ // Only the secret differs: a sample value is public, so every generated API draws its own.
27
+ async function writeLocalEnv(app, type) {
28
+ const example = join(app, '.env.example');
29
+ if (!existsSync(example)) {
30
+ return;
31
+ }
32
+ let env = await readFile(example, 'utf8');
33
+ if (type === 'api') {
34
+ if (!SECRET_LINE.test(env)) {
35
+ throw new Error(`${example} no longer carries a BETTER_AUTH_SECRET line`);
36
+ }
37
+ env = env.replace(SECRET_LINE, `BETTER_AUTH_SECRET=${randomBytes(32).toString('base64url')}`);
38
+ }
39
+ await writeFile(join(app, '.env'), env);
40
+ }
23
41
  function run(command, args, cwd) {
24
42
  const result = spawnSync(command, args, { cwd, stdio: 'inherit' });
25
43
  if (result.status !== 0) {
@@ -34,6 +52,7 @@ export async function generate({ templates, knowledge, target, answers, install,
34
52
  if (answers.architecture === 'alone' && only !== undefined) {
35
53
  await copyTemplate(join(templates, only), target);
36
54
  await nameProject(target, answers.name);
55
+ await writeLocalEnv(target, only);
37
56
  if (only === 'mobile') {
38
57
  await nameMobileApp(target, answers.name);
39
58
  }
@@ -46,6 +65,9 @@ export async function generate({ templates, knowledge, target, answers, install,
46
65
  mobileScheme: schemeFor(answers.name),
47
66
  });
48
67
  await nameProject(target, answers.name);
68
+ for (const type of answers.types) {
69
+ await writeLocalEnv(join(target, 'apps', type), type);
70
+ }
49
71
  if (answers.types.includes('mobile')) {
50
72
  await nameMobileApp(join(target, 'apps', 'mobile'), answers.name);
51
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stjoseph/prumo",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Scaffolds a TypeScript project and ships it the conventions it follows, in a .prumo/ folder any AI assistant reads.",
5
5
  "keywords": [
6
6
  "scaffolding",
@@ -8,12 +8,14 @@ Node 22.17 or later, pnpm, and Docker.
8
8
 
9
9
  ```sh
10
10
  pnpm install
11
- cp .env.example .env # then replace BETTER_AUTH_SECRET with 32 or more random characters
12
11
  docker compose up -d --wait
13
12
  pnpm db:migrate
14
13
  pnpm dev
15
14
  ```
16
15
 
16
+ `.env` comes with the generated project, copied from `.env.example` with a random `BETTER_AUTH_SECRET`. It is not
17
+ committed, so on a fresh clone run `cp .env.example .env` and replace the secret with 32 or more random characters.
18
+
17
19
  The API listens on `http://localhost:3000`. Outside production, its documentation is at `/api/docs`.
18
20
 
19
21
  `pnpm db:migrate` builds first, then runs Better Auth's migrations and then the application's. Before
@@ -9,10 +9,12 @@ to open the app.
9
9
 
10
10
  ```sh
11
11
  pnpm install
12
- cp .env.example .env # EXPO_PUBLIC_API_URL points at the API
13
12
  pnpm dev
14
13
  ```
15
14
 
15
+ `.env` comes with the generated project, copied from `.env.example`; `EXPO_PUBLIC_API_URL` points at the API. It is
16
+ not committed, so on a fresh clone run `cp .env.example .env`.
17
+
16
18
  On an Android emulator `localhost` is the emulator itself; point `EXPO_PUBLIC_API_URL` at your machine's address.
17
19
 
18
20
  ## Everyday commands
@@ -8,10 +8,12 @@ Node 22.17 or later, pnpm, and the API running.
8
8
 
9
9
  ```sh
10
10
  pnpm install
11
- cp .env.example .env # VITE_API_URL points at the API
12
11
  pnpm dev
13
12
  ```
14
13
 
14
+ `.env` comes with the generated project, copied from `.env.example`; `VITE_API_URL` points at the API. It is not
15
+ committed, so on a fresh clone run `cp .env.example .env`.
16
+
15
17
  The app runs on `http://localhost:5173`, which is the origin the API trusts by default (`WEB_ORIGIN`).
16
18
 
17
19
  Open it and you are sent to sign in, because everything but the sign-in and sign-up pages needs a session. Follow