@brightbase/blocks 0.1.0 → 0.1.2

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 +49 -6
  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
 
@@ -127,9 +150,28 @@ async function wirePreviewRegistry(slug, exportName, installPath) {
127
150
 
128
151
  const entry = ` '${slug}': () => import('${importPath}').then(m => m.${exportName}),\n`
129
152
 
130
- const closingBrace = source.lastIndexOf('}')
153
+ // Find `previewRegistry`'s opening, then match its closing `}` with a
154
+ // brace-depth scan. `lastIndexOf('}')` would grab the closing brace of
155
+ // whichever const happens to be declared last in the file (typically
156
+ // `samplePropsRegistry`), leaving the new entry in the wrong export.
157
+ const declMatch = source.match(/export\s+const\s+previewRegistry\b[^{]*\{/)
158
+ if (!declMatch) {
159
+ console.error(' Could not find `export const previewRegistry` — add entry manually')
160
+ return
161
+ }
162
+ const openBraceIdx = declMatch.index + declMatch[0].length - 1
163
+ let depth = 1
164
+ let closingBrace = -1
165
+ for (let i = openBraceIdx + 1; i < source.length; i++) {
166
+ const c = source[i]
167
+ if (c === '{') depth++
168
+ else if (c === '}') {
169
+ depth--
170
+ if (depth === 0) { closingBrace = i; break }
171
+ }
172
+ }
131
173
  if (closingBrace === -1) {
132
- console.error(' Could not find closing brace — add entry manually')
174
+ console.error(' Could not find closing brace for previewRegistry — add entry manually')
133
175
  return
134
176
  }
135
177
 
@@ -188,8 +230,9 @@ Options:
188
230
  --help, -h Print this help
189
231
 
190
232
  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).
233
+ BBAI_BLOCKS_TOKEN Used when --auth is not passed. Auto-loaded from
234
+ .env.local in the current directory if present.
235
+ Sent as Authorization: Bearer header (direct fetch)
236
+ and ?token= query param (shadcn's fetch).
194
237
  `)
195
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightbase/blocks",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CLI for installing blocks from the bbai-blocks registry into a bbai project",
5
5
  "type": "module",
6
6
  "bin": {