create-bcp-app 0.1.28 → 0.2.0

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/README.md CHANGED
@@ -10,9 +10,9 @@ npm run dev
10
10
 
11
11
  ## Project-local BCP CLI
12
12
 
13
- `create-bcp-app` installs BCP Framework as a **project-local dependency**. It does not install the framework CLI globally.
13
+ `create-bcp-app` installs BCP Framework as a project-local dependency. It does not install the framework CLI globally.
14
14
 
15
- Generated npm scripts can use `bcp` directly because npm automatically prepends the project's `node_modules/.bin` directory to `PATH` while scripts are running:
15
+ Generated npm scripts use `bcp` because npm places `node_modules/.bin` on the script `PATH`:
16
16
 
17
17
  ```json
18
18
  {
@@ -21,42 +21,29 @@ Generated npm scripts can use `bcp` directly because npm automatically prepends
21
21
  "build": "bcp build",
22
22
  "start": "bcp start",
23
23
  "routes": "bcp routes",
24
+ "generate": "bcp generate",
24
25
  "update": "bcp update"
25
26
  }
26
27
  }
27
28
  ```
28
29
 
29
- For direct PowerShell usage, invoke the local CLI through `npm exec`:
30
+ For direct PowerShell usage, prefer the collision-free local alias:
30
31
 
31
32
  ```powershell
32
33
  npm exec -- bcp-framework --version
33
34
  npm exec -- bcp-framework doctor
34
35
  npm exec -- bcp-framework inspect
36
+ npm exec -- bcp-framework generate page dashboard/users
35
37
  npm exec -- bcp-framework routes
36
38
  npm exec -- bcp-framework dev
37
39
  npm exec -- bcp-framework build
38
40
  ```
39
41
 
40
- Typing `bcp-framework` directly in a normal PowerShell session may return `CommandNotFoundException` because PowerShell does not automatically add `node_modules/.bin` to its normal command search path.
42
+ Microsoft SQL Server can install another Windows executable named `bcp.exe`, so `bcp-framework` is the recommended interactive Windows command name.
41
43
 
42
- The Windows command shim can also be executed explicitly:
44
+ ## Interactive choices
43
45
 
44
- ```powershell
45
- .\node_modules\.bin\bcp-framework.cmd --version
46
- ```
47
-
48
- BCP Framework publishes the `bcp-framework` alias because Microsoft SQL Server can install another Windows executable named `bcp.exe`.
49
-
50
- Recommended convention:
51
-
52
- ```text
53
- Inside npm scripts -> bcp ...
54
- Direct PowerShell usage -> npm exec -- bcp-framework ...
55
- ```
56
-
57
- Using the project-local CLI also keeps the CLI version aligned with the exact BCP Framework dependency installed by the project.
58
-
59
- When running interactively, the generator asks:
46
+ The generator asks for optional application presets:
60
47
 
61
48
  ```text
62
49
  Use Tailwind CSS?
@@ -76,52 +63,86 @@ Select storage provider:
76
63
  Cloudflare R2
77
64
  ```
78
65
 
79
- ## Generated application defaults
80
-
81
- Generated applications include the project-root `@/` alias:
66
+ Equivalent non-interactive flags are available for CI/scaffolding automation.
82
67
 
83
- ```ts
84
- import {
85
- db,
86
- } from "@/lib/database";
87
- ```
68
+ ## Generated project metadata — 0.1.29
88
69
 
89
- The generated TypeScript configuration uses `module: "ESNext"` and `moduleResolution: "Bundler"` so extensionless application aliases match BCP's bundler and development runtime resolution.
70
+ New projects include:
90
71
 
91
- Modules that use React client hooks such as `useState` or `useEffect` must declare `"use client"` at the top of the module.
72
+ ```text
73
+ bcp.project.json
74
+ ```
92
75
 
93
- The generated BCP dependency is pinned to the exact framework release selected by the generator, and new projects include:
76
+ Example:
94
77
 
95
78
  ```json
96
79
  {
97
- "scripts": {
98
- "update": "bcp update"
80
+ "schemaVersion": 1,
81
+ "framework": "bcp",
82
+ "projectName": "my-app",
83
+ "frameworkPackage": "npm:@chidchanun/bcp@0.1.29",
84
+ "createdWith": {
85
+ "package": "create-bcp-app",
86
+ "version": "0.1.29"
87
+ },
88
+ "packageManager": "npm",
89
+ "presets": {
90
+ "tailwind": true,
91
+ "database": "mysql",
92
+ "auth": "jwt-cookie",
93
+ "storage": "local"
99
94
  }
100
95
  }
101
96
  ```
102
97
 
103
- After a newer stable BCP release is published, update the project with:
98
+ This manifest records scaffold identity only. It is intended for:
99
+
100
+ - `bcp doctor`,
101
+ - `bcp inspect`,
102
+ - upgrade/migration tooling,
103
+ - project-aware documentation,
104
+ - `bcp-docs-web` examples/tooling.
105
+
106
+ It must not contain secrets. Never put database passwords, AWS/R2 credentials, JWT/session secrets or tokens in `bcp.project.json`.
107
+
108
+ The file should normally be committed to source control.
109
+
110
+ Existing projects created before `0.1.29` remain valid without it.
111
+
112
+ Read more: `docs/project-metadata.md` in the BCP Framework repository.
113
+
114
+ ## Generated application defaults
115
+
116
+ Generated applications include the project-root `@/` alias and TypeScript settings compatible with the BCP bundler.
117
+
118
+ Modules that use React client hooks such as `useState` or `useEffect` must declare `"use client"` at the top of the module.
119
+
120
+ The generated BCP dependency is pinned to the exact framework release selected by the generator.
121
+
122
+ Update later with:
104
123
 
105
124
  ```bash
106
125
  npm run update
107
126
  ```
108
127
 
109
- This resolves the npm `latest` release through BCP's updater, updates the exact framework dependency and refreshes the active package-manager lockfile. Use `bcp update --check` inside an npm script or `npm exec -- bcp-framework update --check` from PowerShell to inspect an available update without changing files.
128
+ Check without modifying files:
110
129
 
111
- ## Generated optional setup
130
+ ```powershell
131
+ npm exec -- bcp-framework update --check
132
+ ```
112
133
 
113
- ### Tailwind CSS
134
+ ## Tailwind CSS
114
135
 
115
136
  When Tailwind is enabled, the project includes:
116
137
 
117
- - `tailwindcss`
118
- - `@tailwindcss/cli`
119
- - `concurrently`
120
- - `app/globals.css`
121
- - a stylesheet link to `/bcp.css` in `app/layout.tsx`
122
- - starter Tailwind utility classes in `app/page.tsx`
138
+ - `tailwindcss`,
139
+ - `@tailwindcss/cli`,
140
+ - `concurrently`,
141
+ - `app/globals.css`,
142
+ - `/bcp.css` stylesheet setup,
143
+ - starter utility classes.
123
144
 
124
- The generated npm scripts compile Tailwind directly to `public/bcp.css` before starting BCP and keep Tailwind running in watch mode during development:
145
+ Generated commands include:
125
146
 
126
147
  ```text
127
148
  npm run css:build
@@ -129,11 +150,11 @@ npm run css:watch
129
150
  npm run css:build:prod
130
151
  ```
131
152
 
132
- `npm run dev` performs an initial CSS build, then runs the Tailwind watcher and `bcp dev` together. BCP serves `/bcp.css` as a normal static asset from `public/`. Starting with BCP 0.1.6, stylesheets at that path are inlined into SSR HTML when they are 8 KiB or smaller and the active Content Security Policy allows inline styles. Larger stylesheets remain external for normal browser caching. `npm run build` creates a minified stylesheet before the BCP production build.
153
+ `npm run build` creates the production stylesheet before the BCP production build.
133
154
 
134
- ### Database
155
+ ## Database presets
135
156
 
136
- The database choice adds a starter `lib/database.ts`, updates `.env.example`, and installs the matching driver:
157
+ The database choice adds starter configuration and the matching driver:
137
158
 
138
159
  - MySQL: `mysql2`
139
160
  - PostgreSQL: `pg`
@@ -141,17 +162,15 @@ The database choice adds a starter `lib/database.ts`, updates `.env.example`, an
141
162
  - MongoDB: `mongodb`
142
163
  - None: no database dependency
143
164
 
144
- The generated database helper starts with:
165
+ Server-only database helpers begin with:
145
166
 
146
167
  ```ts
147
168
  import "bcp/server-only";
148
169
  ```
149
170
 
150
- This prevents database code from being used in a page/client module graph. Query the database from an API route or a route-level server data loader and consume only serializable results from hydrated pages.
151
-
152
- For MySQL, the generated helper exports the BCP database primitives through `bcp/database`.
171
+ For MySQL, the generated helper exposes the BCP database primitives through `bcp/database`.
153
172
 
154
- The generated MySQL `.env.example` uses separate connection settings:
173
+ Generated MySQL environment variables:
155
174
 
156
175
  ```dotenv
157
176
  DB_HOST=localhost
@@ -163,7 +182,7 @@ DB_NAME=bcp_app
163
182
 
164
183
  The generator intentionally does not force an ORM.
165
184
 
166
- ### Storage provider
185
+ ## Storage providers
167
186
 
168
187
  Selecting a storage provider creates:
169
188
 
@@ -171,23 +190,42 @@ Selecting a storage provider creates:
171
190
  lib/storage.ts
172
191
  ```
173
192
 
174
- and adds the provider-specific settings to `.env.example`.
193
+ and adds provider-specific environment settings.
175
194
 
176
- #### Local Server
195
+ ### Local Server
177
196
 
178
197
  ```bash
179
198
  npx create-bcp-app my-app --storage local
180
199
  ```
181
200
 
182
- Generated environment setting:
201
+ Generated structure:
202
+
203
+ ```text
204
+ lib/
205
+ └─ storage.ts
206
+
207
+ storage/
208
+ ├─ .gitkeep
209
+ └─ README.md
210
+ ```
211
+
212
+ Environment:
183
213
 
184
214
  ```dotenv
185
215
  STORAGE_LOCAL_DIRECTORY=./storage
186
216
  ```
187
217
 
188
- The generated helper uses `createLocalStorage()` and adds `storage/` to `.gitignore` so uploaded files are not accidentally committed.
218
+ `.gitignore` keeps the visible scaffold while ignoring runtime objects:
189
219
 
190
- #### Amazon S3
220
+ ```gitignore
221
+ storage/*
222
+ !storage/.gitkeep
223
+ !storage/README.md
224
+ ```
225
+
226
+ The generated helper uses `createLocalStorage()`.
227
+
228
+ ### Amazon S3
191
229
 
192
230
  ```bash
193
231
  npx create-bcp-app my-app --storage amazon-s3
@@ -204,9 +242,9 @@ AWS_SESSION_TOKEN=
204
242
  AWS_S3_PREFIX=
205
243
  ```
206
244
 
207
- The generated helper uses `createS3Storage()`. Explicit credentials can be left unset when the deployment uses the AWS SDK server-side credential provider chain, such as an IAM role.
245
+ The helper uses `createS3Storage()`. Explicit credentials can remain unset when deployment uses the AWS SDK server-side credential chain, such as an IAM role.
208
246
 
209
- #### Cloudflare R2
247
+ ### Cloudflare R2
210
248
 
211
249
  ```bash
212
250
  npx create-bcp-app my-app --storage cloudflare-r2
@@ -222,7 +260,7 @@ R2_SECRET_ACCESS_KEY=
222
260
  R2_PREFIX=
223
261
  ```
224
262
 
225
- The generated helper uses the S3-compatible BCP adapter with:
263
+ The helper configures the S3-compatible adapter with:
226
264
 
227
265
  ```text
228
266
  region: auto
@@ -231,11 +269,11 @@ endpoint: https://<account-id>.r2.cloudflarestorage.com
231
269
 
232
270
  Storage credentials are server-only. Do not expose them through `BCP_PUBLIC_*` variables.
233
271
 
234
- The selected preset only scaffolds the initial provider configuration. Application code can later switch to another BCP storage adapter without changing the generic storage APIs used by routes and services.
272
+ The storage preset is only an initial scaffold; application routes/services can later use another BCP adapter while keeping generic storage APIs.
235
273
 
236
- ### JWT Cookie authentication
274
+ ## JWT Cookie authentication
237
275
 
238
- Selecting `JWT Cookie` creates a secure-by-default authentication foundation:
276
+ Selecting `JWT Cookie` creates:
239
277
 
240
278
  ```text
241
279
  lib/
@@ -247,32 +285,44 @@ app/api/auth/
247
285
  └─ me/route.ts
248
286
  ```
249
287
 
250
- The preset uses the session primitives from `bcp/server` and adds this environment variable:
288
+ and adds:
251
289
 
252
290
  ```dotenv
253
291
  BCP_SESSION_SECRET=
254
292
  ```
255
293
 
256
- Set `BCP_SESSION_SECRET` to a cryptographically random secret of at least 32 bytes before using authentication.
294
+ Set this to a cryptographically random secret of at least 32 bytes before real authentication use.
257
295
 
258
- The generated `authenticateCredentials(email, password)` intentionally returns `null` until the application connects it to its own user table and password-hash verification. This prevents a newly generated application from accepting unverified credentials or trusting identity data sent directly by the browser.
296
+ The generated `authenticateCredentials(email, password)` returns `null` until the application connects it to its own user store and password-hash verification. This prevents a fresh project from trusting unverified browser identity data.
259
297
 
260
- After implementing credential verification, the generated flow is:
298
+ ## Project generators after creation
261
299
 
262
- ```text
263
- POST /api/auth/login
264
- -> authenticateCredentials()
265
- -> createSession()
266
- -> HttpOnly JWT cookie
300
+ BCP `0.1.29+` can scaffold additional framework files after the project has been created:
301
+
302
+ ```bash
303
+ npm run generate -- page dashboard/users
304
+ npm run generate -- api users
305
+ npm run generate -- middleware
306
+ npm run generate -- migration create_users
307
+ ```
267
308
 
268
- GET /api/auth/me
269
- -> getSession()
270
- -> current user
309
+ Equivalent direct CLI:
271
310
 
272
- POST /api/auth/logout
273
- -> destroySession()
311
+ ```bash
312
+ bcp generate page dashboard/users
313
+ bcp generate api users
314
+ bcp generate middleware
315
+ bcp generate migration create_users
316
+ ```
317
+
318
+ From PowerShell:
319
+
320
+ ```powershell
321
+ npm exec -- bcp-framework generate page dashboard/users
274
322
  ```
275
323
 
324
+ Use `--force` only when intentionally replacing an existing page/API/middleware scaffold.
325
+
276
326
  ## Options
277
327
 
278
328
  ```text
@@ -297,8 +347,8 @@ npx create-bcp-app my-app --no-tailwind --database mongodb
297
347
  npx create-bcp-app my-app --yes
298
348
  ```
299
349
 
300
- The `--bcp` option is primarily useful for prerelease and local package testing, for example:
350
+ The `--bcp` option is mainly for prerelease/local package verification:
301
351
 
302
352
  ```bash
303
- npx create-bcp-app my-app --bcp file:../bcp-0.1.27.tgz
353
+ npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.1.29.tgz
304
354
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bcp-app",
3
- "version": "0.1.28",
3
+ "version": "0.2.0",
4
4
  "description": "Create a new BCP Framework application.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.mjs CHANGED
@@ -55,6 +55,9 @@ export async function createBcpApp(
55
55
  normalizeStorageProvider(
56
56
  options.storage
57
57
  );
58
+ const packageManager =
59
+ options.packageManager ??
60
+ "npm";
58
61
 
59
62
  ensureTargetDirectory(
60
63
  targetDirectory
@@ -99,6 +102,8 @@ export async function createBcpApp(
99
102
  "bcp start",
100
103
  routes:
101
104
  "bcp routes",
105
+ generate:
106
+ "bcp generate",
102
107
  update:
103
108
  "bcp update",
104
109
  typecheck:
@@ -164,13 +169,31 @@ export async function createBcpApp(
164
169
  "utf8"
165
170
  );
166
171
 
172
+ writeProjectMetadata(
173
+ targetDirectory,
174
+ {
175
+ projectName,
176
+ packageSpecifier,
177
+ packageManager,
178
+ createBcpAppVersion:
179
+ packageMetadata.version,
180
+ tailwind:
181
+ selectedOptions.tailwind,
182
+ database:
183
+ selectedOptions.database,
184
+ auth:
185
+ selectedOptions.auth,
186
+ storage:
187
+ selectedStorage,
188
+ }
189
+ );
190
+
167
191
  if (
168
192
  options.install !== false
169
193
  ) {
170
194
  await runInstall(
171
195
  targetDirectory,
172
- options.packageManager ??
173
- "npm"
196
+ packageManager
174
197
  );
175
198
  }
176
199
 
@@ -426,6 +449,53 @@ function configureFrameworkAuthEntry(
426
449
  );
427
450
  }
428
451
 
452
+ function writeProjectMetadata(
453
+ targetDirectory,
454
+ metadata
455
+ ) {
456
+ const manifest = {
457
+ schemaVersion:
458
+ 1,
459
+ framework:
460
+ "bcp",
461
+ projectName:
462
+ metadata.projectName,
463
+ frameworkPackage:
464
+ metadata.packageSpecifier,
465
+ createdWith: {
466
+ package:
467
+ "create-bcp-app",
468
+ version:
469
+ metadata.createBcpAppVersion,
470
+ },
471
+ packageManager:
472
+ metadata.packageManager,
473
+ presets: {
474
+ tailwind:
475
+ metadata.tailwind,
476
+ database:
477
+ metadata.database,
478
+ auth:
479
+ metadata.auth,
480
+ storage:
481
+ metadata.storage,
482
+ },
483
+ };
484
+
485
+ fs.writeFileSync(
486
+ path.join(
487
+ targetDirectory,
488
+ "bcp.project.json"
489
+ ),
490
+ `${JSON.stringify(
491
+ manifest,
492
+ null,
493
+ 2
494
+ )}\n`,
495
+ "utf8"
496
+ );
497
+ }
498
+
429
499
  function readPackageMetadata() {
430
500
  const packageJson =
431
501
  JSON.parse(
@@ -17,32 +17,66 @@ Generated projects use the project-local BCP Framework CLI through npm scripts:
17
17
  ```bash
18
18
  npm run dev
19
19
  npm run routes
20
+ npm run generate -- page dashboard/users
20
21
  npm run typecheck
21
22
  npm run build
22
23
  npm start
23
24
  npm run update
24
25
  ```
25
26
 
26
- The generated scripts call commands such as `bcp dev`, `bcp build` and `bcp start`. This works because npm automatically adds the project's `node_modules/.bin` directory to `PATH` while an npm script is running.
27
+ The generated scripts call commands such as `bcp dev`, `bcp generate`, `bcp build` and `bcp start`. npm automatically adds the project's `node_modules/.bin` directory to `PATH` while an npm script is running.
27
28
 
28
- ## Direct CLI usage
29
+ ## Project metadata
29
30
 
30
- BCP Framework is installed as a **project-local dependency**. It is not installed globally by `create-bcp-app`.
31
+ Projects created with BCP `0.1.29+` include:
31
32
 
32
- Because of that, typing this directly in a normal PowerShell session may not work:
33
+ ```text
34
+ bcp.project.json
35
+ ```
33
36
 
34
- ```powershell
35
- bcp-framework doctor
37
+ It records non-secret scaffold choices such as Tailwind, database, authentication and storage presets so BCP diagnostics/tooling can understand the project without guessing configuration from source files.
38
+
39
+ Commit this file with the project. Do not put passwords, access keys, session secrets or tokens in it.
40
+
41
+ ## Generate framework files
42
+
43
+ BCP `0.1.29+` can generate common project files:
44
+
45
+ ```bash
46
+ npm run generate -- page dashboard/users
47
+ npm run generate -- api users
48
+ npm run generate -- middleware
49
+ npm run generate -- migration create_users
36
50
  ```
37
51
 
38
- PowerShell does not automatically add `node_modules/.bin` to its normal command search path.
52
+ Equivalent direct BCP CLI commands are:
39
53
 
40
- Use `npm exec` when you want to invoke the project-local CLI directly:
54
+ ```bash
55
+ bcp generate page dashboard/users
56
+ bcp generate api users
57
+ bcp generate middleware
58
+ bcp generate migration create_users
59
+ ```
60
+
61
+ Existing page/API/middleware targets are not replaced unless `--force` is supplied explicitly.
62
+
63
+ After generating routes, inspect them with:
64
+
65
+ ```bash
66
+ npm run routes
67
+ ```
68
+
69
+ ## Direct CLI usage
70
+
71
+ BCP Framework is installed as a project-local dependency. It is not installed globally by `create-bcp-app`.
72
+
73
+ PowerShell does not automatically add `node_modules/.bin` to its normal command search path, so use `npm exec` for direct commands:
41
74
 
42
75
  ```powershell
43
76
  npm exec -- bcp-framework --version
44
77
  npm exec -- bcp-framework doctor
45
78
  npm exec -- bcp-framework inspect
79
+ npm exec -- bcp-framework generate page dashboard/users
46
80
  npm exec -- bcp-framework routes
47
81
  npm exec -- bcp-framework dev
48
82
  npm exec -- bcp-framework build
@@ -54,11 +88,7 @@ You can also execute the Windows command shim explicitly:
54
88
  .\node_modules\.bin\bcp-framework.cmd --version
55
89
  ```
56
90
 
57
- Using the project-local CLI is recommended because it guarantees that the CLI version matches the BCP Framework version installed by this application.
58
-
59
- ### Why `bcp-framework` instead of `bcp` in PowerShell?
60
-
61
- Microsoft SQL Server can install another Windows executable named `bcp.exe`. To avoid that command-name collision, BCP Framework publishes the additional `bcp-framework` alias.
91
+ Microsoft SQL Server can install another Windows executable named `bcp.exe`, so the `bcp-framework` alias avoids that command-name collision.
62
92
 
63
93
  Use this convention:
64
94
 
@@ -67,6 +97,24 @@ Inside npm scripts -> bcp ...
67
97
  Direct PowerShell usage -> npm exec -- bcp-framework ...
68
98
  ```
69
99
 
100
+ ## Project diagnostics
101
+
102
+ Run:
103
+
104
+ ```powershell
105
+ npm exec -- bcp-framework doctor
106
+ npm exec -- bcp-framework inspect
107
+ ```
108
+
109
+ Machine-readable reports:
110
+
111
+ ```powershell
112
+ npm exec -- bcp-framework doctor --json
113
+ npm exec -- bcp-framework inspect --json
114
+ ```
115
+
116
+ Doctor checks common project/runtime problems while Inspect shows the resolved configuration, routes, dependencies and project metadata BCP sees.
117
+
70
118
  ## Production
71
119
 
72
120
  Create the standalone production build: