@brightbase/blocks 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +10 -4
  2. package/index.mjs +28 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,15 +8,21 @@ The package is **private** on npm. You need:
8
8
  1. An npm Pro/Teams account on the `@brightbase` org
9
9
  2. To be logged in: `npm login`
10
10
 
11
- Then in your consumer project, blocks install with:
11
+ Then add `BBAI_BLOCKS_TOKEN` to your consumer project's `.env.local` (same file you keep other Next.js env vars in):
12
+
13
+ ```
14
+ BBAI_BLOCKS_TOKEN=<your-token>
15
+ ```
16
+
17
+ Now blocks install with a clean command:
12
18
 
13
19
  ```bash
14
- BBAI_BLOCKS_TOKEN=<your-token> npx @brightbase/blocks add <slug>
20
+ npx @brightbase/blocks add <slug>
15
21
  ```
16
22
 
17
- The token also gates the catalog UI at https://bbai-blocks.vercel.app — same value for both.
23
+ The CLI auto-loads `.env.local` from the directory you run it in. The same token also gates the catalog UI at https://bbai-blocks.vercel.app.
18
24
 
19
- Tip: put `BBAI_BLOCKS_TOKEN` in your shell rc or `.env.local` and source it so you don't have to type it every install.
25
+ If you'd rather pass it explicitly, `--auth=<token>` and `BBAI_BLOCKS_TOKEN` env var both still work.
20
26
 
21
27
  ## What it does
22
28
 
package/index.mjs CHANGED
@@ -14,14 +14,37 @@
14
14
  */
15
15
 
16
16
  import { readFile, writeFile } from 'fs/promises'
17
+ import { readFileSync, existsSync } from 'fs'
17
18
  import { execSync } from 'child_process'
18
19
  import { join } from 'path'
19
20
 
21
+ // ── .env.local loader ────────────────────────────────────────────────────────
22
+ // Minimal parser: KEY=VALUE lines, quotes optional, # comments. Mirrors what
23
+ // users already do for Next.js env vars. Loaded once at startup from cwd.
24
+ function loadEnvLocal() {
25
+ const path = join(process.cwd(), '.env.local')
26
+ if (!existsSync(path)) return
27
+ const text = readFileSync(path, 'utf-8')
28
+ for (const line of text.split('\n')) {
29
+ const trimmed = line.trim()
30
+ if (!trimmed || trimmed.startsWith('#')) continue
31
+ const eq = trimmed.indexOf('=')
32
+ if (eq === -1) continue
33
+ const key = trimmed.slice(0, eq).trim()
34
+ let value = trimmed.slice(eq + 1).trim()
35
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
36
+ value = value.slice(1, -1)
37
+ }
38
+ if (key && !(key in process.env)) process.env[key] = value
39
+ }
40
+ }
41
+ loadEnvLocal()
42
+
20
43
  const REGISTRY_DEFAULT = 'https://bbai-blocks.vercel.app'
21
44
  const PREVIEW_REGISTRY_PATH = 'src/components/preview/preview-registry.ts'
22
45
  const MANIFEST_PATH = 'design/block-manifest.json'
23
46
 
24
- const VERSION = '0.1.0'
47
+ const VERSION = '0.1.1'
25
48
 
26
49
  // ── Arg parsing ──────────────────────────────────────────────────────────────
27
50
 
@@ -188,8 +211,9 @@ Options:
188
211
  --help, -h Print this help
189
212
 
190
213
  Env vars:
191
- BBAI_BLOCKS_TOKEN Used when --auth is not passed. Sent as Authorization:
192
- Bearer header (direct fetch) and ?token= query param
193
- (shadcn's fetch).
214
+ BBAI_BLOCKS_TOKEN Used when --auth is not passed. Auto-loaded from
215
+ .env.local in the current directory if present.
216
+ Sent as Authorization: Bearer header (direct fetch)
217
+ and ?token= query param (shadcn's fetch).
194
218
  `)
195
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightbase/blocks",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI for installing blocks from the bbai-blocks registry into a bbai project",
5
5
  "type": "module",
6
6
  "bin": {