@chidchanun/bcp 0.1.8 → 0.1.10

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 (29) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +218 -7
  3. package/docs/application-modules.md +63 -3
  4. package/docs/releasing.md +34 -19
  5. package/docs/route-guards.md +240 -0
  6. package/docs/server-data-loaders.md +240 -0
  7. package/docs/updating.md +130 -0
  8. package/package.json +1 -1
  9. package/packages/bundler/src/server-production-guards.ts +497 -0
  10. package/packages/bundler/src/server-production-middleware.ts +33 -8
  11. package/packages/bundler/src/server-production.ts +25 -0
  12. package/packages/cli/src/args.ts +58 -0
  13. package/packages/cli/src/index.ts +41 -13
  14. package/packages/cli/src/update.ts +860 -0
  15. package/packages/client/src/index.tsx +5 -0
  16. package/packages/client/src/loader-data.tsx +229 -0
  17. package/packages/client/src/router-v2.tsx +254 -29
  18. package/packages/server/src/dev-navigation-target.ts +188 -0
  19. package/packages/server/src/index.ts +209 -119
  20. package/packages/server/src/navigation-payload.ts +24 -1
  21. package/packages/server/src/navigation-response.ts +284 -0
  22. package/packages/server/src/page-guard.ts +529 -0
  23. package/packages/server/src/page-loader.ts +643 -0
  24. package/packages/server/src/standalone-production-runtime-v2-guard.ts +815 -0
  25. package/packages/server/src/standalone-production-runtime-v2-navigation.ts +785 -0
  26. package/packages/server/src/standalone-production-runtime-v2.ts +131 -19
  27. package/packages/server/src/standalone-production-runtime-v3.ts +1 -1
  28. package/packages/server/src/standalone-production-runtime-v4.ts +42 -2
  29. package/packages/server/src/static-dev-server.ts +21 -17
@@ -6,6 +6,7 @@ export type CliCommand =
6
6
  | "build"
7
7
  | "start"
8
8
  | "routes"
9
+ | "update"
9
10
  | "help"
10
11
  | "version";
11
12
 
@@ -17,6 +18,12 @@ export interface CliOptions {
17
18
  port?: number;
18
19
 
19
20
  hostname?: string;
21
+
22
+ updateTarget?: string;
23
+
24
+ updateCheck?: boolean;
25
+
26
+ updateDryRun?: boolean;
20
27
  }
21
28
 
22
29
  export function parseCliArgs(
@@ -33,6 +40,15 @@ export function parseCliArgs(
33
40
  let hostname:
34
41
  string | undefined;
35
42
 
43
+ let updateTarget:
44
+ string | undefined;
45
+
46
+ let updateCheck =
47
+ false;
48
+
49
+ let updateDryRun =
50
+ false;
51
+
36
52
  let commandSet = false;
37
53
 
38
54
  for (
@@ -152,6 +168,22 @@ export function parseCliArgs(
152
168
  continue;
153
169
  }
154
170
 
171
+ if (
172
+ argument === "--check"
173
+ ) {
174
+ updateCheck =
175
+ true;
176
+ continue;
177
+ }
178
+
179
+ if (
180
+ argument === "--dry-run"
181
+ ) {
182
+ updateDryRun =
183
+ true;
184
+ continue;
185
+ }
186
+
155
187
  if (
156
188
  argument.startsWith("-")
157
189
  ) {
@@ -179,6 +211,16 @@ export function parseCliArgs(
179
211
  continue;
180
212
  }
181
213
 
214
+ if (
215
+ commandSet &&
216
+ command === "update" &&
217
+ updateTarget === undefined
218
+ ) {
219
+ updateTarget =
220
+ argument;
221
+ continue;
222
+ }
223
+
182
224
  if (commandSet) {
183
225
  throw new Error(
184
226
  `Unexpected argument: ${argument}`
@@ -190,6 +232,7 @@ export function parseCliArgs(
190
232
  argument === "build" ||
191
233
  argument === "start" ||
192
234
  argument === "routes" ||
235
+ argument === "update" ||
193
236
  argument === "help" ||
194
237
  argument === "version"
195
238
  ) {
@@ -203,11 +246,26 @@ export function parseCliArgs(
203
246
  );
204
247
  }
205
248
 
249
+ if (
250
+ command !== "update" &&
251
+ (
252
+ updateCheck ||
253
+ updateDryRun
254
+ )
255
+ ) {
256
+ throw new Error(
257
+ "Options --check and --dry-run are only valid with `bcp update`."
258
+ );
259
+ }
260
+
206
261
  return {
207
262
  command,
208
263
  rootDirectory,
209
264
  port,
210
265
  hostname,
266
+ updateTarget,
267
+ updateCheck,
268
+ updateDryRun,
211
269
  };
212
270
  }
213
271
 
@@ -61,6 +61,11 @@ switch (cliOptions.command) {
61
61
  break;
62
62
  }
63
63
 
64
+ case "update": {
65
+ await runUpdate();
66
+ break;
67
+ }
68
+
64
69
  case "help": {
65
70
  printHelp();
66
71
  break;
@@ -314,11 +319,6 @@ async function runStart() {
314
319
  );
315
320
  }
316
321
 
317
- /*
318
- * Keep build-time configuration frozen in server.mjs/config.json.
319
- * Only explicit runtime environment values and CLI options should
320
- * override the standalone artifact after it has been built.
321
- */
322
322
  if (
323
323
  cliOptions.port !==
324
324
  undefined
@@ -357,6 +357,30 @@ async function runStart() {
357
357
  );
358
358
  }
359
359
 
360
+ async function runUpdate() {
361
+ const rootDirectory =
362
+ resolveProjectRoot(
363
+ cliOptions.rootDirectory
364
+ );
365
+
366
+ const {
367
+ runBcpUpdate,
368
+ } =
369
+ await import(
370
+ "./update.js"
371
+ );
372
+
373
+ await runBcpUpdate({
374
+ rootDirectory,
375
+ target:
376
+ cliOptions.updateTarget,
377
+ check:
378
+ cliOptions.updateCheck,
379
+ dryRun:
380
+ cliOptions.updateDryRun,
381
+ });
382
+ }
383
+
360
384
  function installShutdownHandlers(
361
385
  server: {
362
386
  stop(): Promise<void>;
@@ -505,18 +529,21 @@ Usage:
505
529
  bcp <command> [options]
506
530
 
507
531
  Commands:
508
- dev Start the development server
509
- build Create optimized client assets and standalone server.mjs
510
- start Start the standalone production build
511
- routes Print discovered page and API routes
512
- help Show this help message
513
- version Show framework version
532
+ dev Start the development server
533
+ build Create optimized client assets and standalone server.mjs
534
+ start Start the standalone production build
535
+ routes Print discovered page and API routes
536
+ update [target] Update BCP Framework (default target: latest)
537
+ help Show this help message
538
+ version Show framework version
514
539
 
515
540
  Options:
516
541
  --root <path> Project root directory
517
542
  --port <number> Override configured HTTP port
518
543
  --hostname <host> Override configured HTTP hostname
519
544
  --host <host> Alias for --hostname
545
+ --check Check for a BCP update without changing files
546
+ --dry-run Preview a BCP update without changing files
520
547
  -h, --help Show help
521
548
  -v, --version Show version
522
549
 
@@ -526,10 +553,11 @@ Config precedence:
526
553
 
527
554
  Examples:
528
555
  bcp dev
529
- bcp dev --port 4000
530
556
  bcp build
531
557
  bcp start
532
- bcp start --port 4000
533
558
  bcp routes
559
+ bcp update
560
+ bcp update --check
561
+ bcp update 0.1.10
534
562
  `);
535
563
  }