@nifrajs/cli 5.12.0 → 5.13.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/CHANGELOG.md +61 -0
- package/dist/cli.d.ts +9 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +140 -19
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +29 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +102 -4
- package/dist/command-catalog.js.map +1 -1
- package/dist/deployment-adapters.d.ts +12 -0
- package/dist/deployment-adapters.d.ts.map +1 -0
- package/dist/deployment-adapters.js +92 -0
- package/dist/deployment-adapters.js.map +1 -0
- package/dist/dev-bun-config.d.ts +4 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +14 -4
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/init-agents.d.ts +5 -0
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +1 -1
- package/dist/init-agents.js.map +1 -1
- package/dist/load.d.ts +12 -3
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +19 -0
- package/dist/load.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +21 -3
- package/dist/mcp-root.js.map +1 -1
- package/dist/port.d.ts +6 -3
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +19 -7
- package/dist/port.js.map +1 -1
- package/dist/recipes/5.13.0.d.ts +9 -0
- package/dist/recipes/5.13.0.d.ts.map +1 -0
- package/dist/recipes/5.13.0.js +40 -0
- package/dist/recipes/5.13.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/rules/routes.js +2 -2
- package/dist/shell-files.d.ts +44 -0
- package/dist/shell-files.d.ts.map +1 -0
- package/dist/shell-files.js +201 -0
- package/dist/shell-files.js.map +1 -0
- package/dist/shell-init.d.ts +33 -0
- package/dist/shell-init.d.ts.map +1 -0
- package/dist/shell-init.js +99 -0
- package/dist/shell-init.js.map +1 -0
- package/docs/examples.json +97 -1
- package/docs/llms-full.txt +989 -40
- package/docs/types.json +606 -36
- package/package.json +11 -11
- package/src/cli.ts +185 -35
- package/src/command-catalog.ts +144 -7
- package/src/deployment-adapters.ts +107 -0
- package/src/dev-bun-config.ts +21 -2
- package/src/init-agents.ts +1 -1
- package/src/load.ts +36 -3
- package/src/mcp-http.ts +1 -1
- package/src/mcp-root.ts +21 -3
- package/src/port.ts +25 -8
- package/src/recipes/5.13.0.ts +41 -0
- package/src/recipes/index.ts +2 -0
- package/src/rules/routes.ts +2 -2
- package/src/shell-files.ts +225 -0
- package/src/shell-init.ts +139 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
4
4
|
"description": "The nifra CLI - zero-config dev/build/start for a nifra app (`nifra dev`, `nifra build`, `nifra start`).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@nifrajs/client": "5.
|
|
74
|
-
"@nifrajs/core": "5.
|
|
75
|
-
"@nifrajs/agent-review": "5.
|
|
76
|
-
"@nifrajs/i18n": "5.
|
|
77
|
-
"@nifrajs/mcp": "5.
|
|
78
|
-
"@nifrajs/mcp-db": "5.
|
|
79
|
-
"@nifrajs/runner": "5.
|
|
80
|
-
"@nifrajs/schema": "5.
|
|
81
|
-
"@nifrajs/testing": "5.
|
|
82
|
-
"@nifrajs/web": "5.
|
|
73
|
+
"@nifrajs/client": "5.13.0",
|
|
74
|
+
"@nifrajs/core": "5.13.0",
|
|
75
|
+
"@nifrajs/agent-review": "5.13.0",
|
|
76
|
+
"@nifrajs/i18n": "5.13.0",
|
|
77
|
+
"@nifrajs/mcp": "5.13.0",
|
|
78
|
+
"@nifrajs/mcp-db": "5.13.0",
|
|
79
|
+
"@nifrajs/runner": "5.13.0",
|
|
80
|
+
"@nifrajs/schema": "5.13.0",
|
|
81
|
+
"@nifrajs/testing": "5.13.0",
|
|
82
|
+
"@nifrajs/web": "5.13.0"
|
|
83
83
|
},
|
|
84
84
|
"repository": {
|
|
85
85
|
"type": "git",
|
package/src/cli.ts
CHANGED
|
@@ -46,9 +46,16 @@ export interface Flags {
|
|
|
46
46
|
/** `--out <dir>`; without it `dist`, or `.vercel/output` for a Vercel build. */
|
|
47
47
|
readonly out: string | undefined
|
|
48
48
|
readonly poll: boolean
|
|
49
|
-
/** `nifra build --target <t>`: emit a full deploy dir for this target. Without it,
|
|
50
|
-
* `nifra.config.ts
|
|
49
|
+
/** `nifra build --target <t>`: emit a full deploy dir for this target. Without it, use `target` from
|
|
50
|
+
* `nifra.config.ts`, else `bun`; a configured adapter must be selected by its id. */
|
|
51
51
|
readonly target: string | undefined
|
|
52
|
+
/** `nifra build|dev --transport <module>`: the module whose default export is the `fetch` the client
|
|
53
|
+
* reaches its server through, for this run only. It overrides `transport` from the framework config,
|
|
54
|
+
* so one app can ship a web build and a native-shell build. */
|
|
55
|
+
readonly transport: string | undefined
|
|
56
|
+
/** `nifra build --target static --prerender <paths>`: comma-separated page paths to prerender for this
|
|
57
|
+
* build whether or not their route exports `prerender`. */
|
|
58
|
+
readonly prerender: string | undefined
|
|
52
59
|
/** `nifra build --report`: print a per-chunk size + gzip table after the build. */
|
|
53
60
|
readonly report: boolean
|
|
54
61
|
/** `nifra build --vite`: force the client + server through Vite/Rollup. Without a flag the pipeline is
|
|
@@ -151,8 +158,12 @@ Usage:
|
|
|
151
158
|
nifra db role Print the SQL for a read-only Postgres role. Runs nothing.
|
|
152
159
|
nifra db audit [--limit <n>] What nifra db ran (.nifra/db-audit.jsonl), never the rows.
|
|
153
160
|
nifra build [--out <dir>] [--report] Emit a complete deploy directory.
|
|
161
|
+
[--transport <module>] Reach the server through this module's fetch (a native shell).
|
|
162
|
+
[--prerender <paths>] With --target static: also prerender these pages (comma-separated,
|
|
163
|
+
such as /,/about) whether or not their route exports prerender.
|
|
154
164
|
[--target <t>] Target a FULL deploy dir for <t>:
|
|
155
|
-
bun | node | deno | cloudflare | vercel | static
|
|
165
|
+
bun | node | deno | cloudflare | vercel | static, or an installed
|
|
166
|
+
public adapter selected by deploymentAdapter in nifra.config.ts. Packages
|
|
156
167
|
buildClient + buildServer (+ prerender for static, bun and
|
|
157
168
|
node, whose server answers those pages from file) so an app
|
|
158
169
|
no longer hand-writes build-<target>.ts + _worker.ts +
|
|
@@ -330,7 +341,8 @@ Usage:
|
|
|
330
341
|
nifra port [--target <t>] [--json] Portability linter: print a feature × deploy-target capability
|
|
331
342
|
[--ci] [--strict] matrix (in-memory stores, in-process cron/WebSocket, Bun/Deno
|
|
332
343
|
globals, node: builtins) with file:line evidence. --target auto-
|
|
333
|
-
detected from build/deploy scripts, wrangler.toml,
|
|
344
|
+
detected from build/deploy scripts, wrangler.toml, vercel config,
|
|
345
|
+
or installed adapter metadata (base runtime only);
|
|
334
346
|
--ci (or any --target) exits nonzero when a used feature is
|
|
335
347
|
unsupported on the target; --strict also fails on caveats.
|
|
336
348
|
nifra i18n check [entry] Check i18n catalogs: coverage, missing + unused keys, ICU syntax,
|
|
@@ -356,7 +368,7 @@ set in the process environment is never overwritten by a file.
|
|
|
356
368
|
${renderCommandCatalogHelp()}`
|
|
357
369
|
|
|
358
370
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
359
|
-
const CLI_VERSION = "5.
|
|
371
|
+
const CLI_VERSION = "5.13.0"
|
|
360
372
|
|
|
361
373
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
362
374
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -493,11 +505,13 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
493
505
|
"launches; refusing to serve without the client-boundary plugins.",
|
|
494
506
|
)
|
|
495
507
|
}
|
|
508
|
+
const { publicEnvDefines } = await import("@nifrajs/web/build")
|
|
496
509
|
const { bunfigPath, launchToken } = await writeBunDevConfig(
|
|
497
510
|
app.cwd,
|
|
498
511
|
app.configPath,
|
|
499
512
|
app.framework.define,
|
|
500
513
|
app.framework.publicEnvPrefix,
|
|
514
|
+
publicEnvDefines(app.framework.publicEnvPrefix ?? "PUBLIC_", process.env),
|
|
501
515
|
)
|
|
502
516
|
// Bun 1.4 on Windows may discard the script-relative portion of argv when `--config` is
|
|
503
517
|
// present. Keep a second, authenticated copy of the user vector in the child's environment so
|
|
@@ -624,6 +638,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
624
638
|
indicator: showsIndicator(flags, fw),
|
|
625
639
|
allowedHosts: fw.dev?.allowedHosts ?? [],
|
|
626
640
|
live: fw.live?.clientEntry,
|
|
641
|
+
...transportOption(flags, fw, app.cwd),
|
|
627
642
|
createApp: (clientEntry, importQuery, dev) =>
|
|
628
643
|
createWebApp({
|
|
629
644
|
adapter: asAdapter(fw.adapter),
|
|
@@ -682,6 +697,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
682
697
|
...(flags.allowDuplicateIdentity ? { allowDuplicateIdentity: true } : {}),
|
|
683
698
|
indicator: showsIndicator(flags, fw),
|
|
684
699
|
live: fw.live?.clientEntry,
|
|
700
|
+
...transportOption(flags, fw, cwd),
|
|
685
701
|
...(fw.conditions ? { conditions: fw.conditions } : {}),
|
|
686
702
|
...(fw.define ? { define: fw.define } : {}),
|
|
687
703
|
// `load` resolves route modules through VITE, not through Bun. That is what makes the Vite
|
|
@@ -827,24 +843,64 @@ async function assertFreshWorkspaceDists(cwd: string): Promise<void> {
|
|
|
827
843
|
)
|
|
828
844
|
}
|
|
829
845
|
|
|
846
|
+
/** Build the requested runtime and transactionally add files from a selected deployment adapter. */
|
|
830
847
|
async function buildForTarget(
|
|
831
848
|
app: LoadedApp,
|
|
832
849
|
flag: string | undefined,
|
|
833
850
|
flags: Flags,
|
|
834
851
|
): Promise<void> {
|
|
835
|
-
const {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
)
|
|
852
|
+
const {
|
|
853
|
+
buildWithDeploymentAdapter,
|
|
854
|
+
isBuildTarget,
|
|
855
|
+
parseBuildTarget,
|
|
856
|
+
renderSizeReport,
|
|
857
|
+
validateVercelRuntime,
|
|
858
|
+
} = await import("@nifrajs/web/build")
|
|
859
|
+
const { framework: fw } = app
|
|
860
|
+
const configuredAdapter = fw.deploymentAdapter
|
|
861
|
+
const adapter = configuredAdapter?.adapter
|
|
862
|
+
if (adapter !== undefined && flag === undefined && fw.target === undefined) {
|
|
863
|
+
throw new Error(
|
|
864
|
+
`[nifra] deploymentAdapter "${adapter.id}" is configured; set target = "${adapter.id}" or pass --target ${adapter.id} to select it`,
|
|
865
|
+
)
|
|
866
|
+
}
|
|
867
|
+
const requestedTarget = flag ?? fw.target ?? "bun"
|
|
868
|
+
const adapterSelected = adapter !== undefined && requestedTarget === adapter.id
|
|
869
|
+
if (!isBuildTarget(requestedTarget) && !adapterSelected) {
|
|
870
|
+
if (adapter === undefined) {
|
|
871
|
+
try {
|
|
872
|
+
parseBuildTarget(
|
|
873
|
+
requestedTarget,
|
|
874
|
+
flag === undefined ? "target in nifra.config.ts" : "--target",
|
|
875
|
+
)
|
|
876
|
+
} catch (error) {
|
|
877
|
+
throw new Error(
|
|
878
|
+
`${error instanceof Error ? error.message : String(error)} (no deploymentAdapter is configured in nifra.config.ts)`,
|
|
879
|
+
)
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
throw new Error(
|
|
883
|
+
`[nifra] target "${requestedTarget}" does not match the configured deployment adapter "${adapter?.id}"`,
|
|
884
|
+
)
|
|
885
|
+
}
|
|
886
|
+
const target = adapterSelected
|
|
887
|
+
? adapter.baseTarget
|
|
888
|
+
: parseBuildTarget(
|
|
889
|
+
requestedTarget,
|
|
890
|
+
flag === undefined ? "target in nifra.config.ts" : "--target",
|
|
891
|
+
)
|
|
892
|
+
if (adapterSelected && app.configPath === adapterFile(app.cwd)) {
|
|
893
|
+
throw new Error(
|
|
894
|
+
"[nifra] deploymentAdapter is build-time config, but this file is also the generated server's runtime import. " +
|
|
895
|
+
"Add backend/framework.ts for adapter and clientModule, keep deploymentAdapter in nifra.config.ts, and re-export the runtime fields there.",
|
|
896
|
+
)
|
|
897
|
+
}
|
|
842
898
|
if (flags.vite && flags.bun) {
|
|
843
899
|
throw new Error("[nifra] `nifra build` takes `--vite` or `--bun`, not both.")
|
|
844
900
|
}
|
|
845
|
-
const { framework: fw } = app
|
|
846
901
|
validateVercelRuntime(target, fw.vercelRuntime)
|
|
847
902
|
if (fw.componentPipeline !== undefined) {
|
|
903
|
+
const componentPipeline = fw.componentPipeline
|
|
848
904
|
// The component pipeline already owns its Vercel Node handler; this selector is ordinary SSR only.
|
|
849
905
|
if (fw.vercelRuntime !== undefined)
|
|
850
906
|
throw new Error(
|
|
@@ -870,16 +926,46 @@ async function buildForTarget(
|
|
|
870
926
|
target === "vercel" && flags.out === undefined
|
|
871
927
|
? resolve(app.cwd, ".vercel/output")
|
|
872
928
|
: app.outDir
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
929
|
+
const buildComponents = (output: string) =>
|
|
930
|
+
buildServerComponents({
|
|
931
|
+
...componentPipeline,
|
|
932
|
+
target,
|
|
933
|
+
root: app.cwd,
|
|
934
|
+
outDir: output,
|
|
935
|
+
plugins: asComponentPlugins(app.resolvedPlugins.vitePlugins),
|
|
936
|
+
})
|
|
937
|
+
let result: Awaited<ReturnType<typeof buildComponents>>
|
|
938
|
+
let adapterRun: string | undefined
|
|
939
|
+
if (adapterSelected && adapter !== undefined) {
|
|
940
|
+
const packaged = await buildWithDeploymentAdapter({
|
|
941
|
+
adapter,
|
|
942
|
+
appRoot: app.cwd,
|
|
943
|
+
outDir,
|
|
944
|
+
options: configuredAdapter?.options,
|
|
945
|
+
secretExemptions: fw.secretExemptions,
|
|
946
|
+
componentPipeline: true,
|
|
947
|
+
protectedPaths: [
|
|
948
|
+
app.routesDir,
|
|
949
|
+
resolve(app.cwd, BACKEND_APP_FILE),
|
|
950
|
+
adapterFile(app.cwd),
|
|
951
|
+
...(fw.publicDir === false ? [] : [resolve(fw.publicDir ?? resolve(app.cwd, "public"))]),
|
|
952
|
+
],
|
|
953
|
+
build: async (stagingOutDir) => {
|
|
954
|
+
const built = await buildComponents(stagingOutDir)
|
|
955
|
+
await assertFreshWorkspaceDists(app.cwd)
|
|
956
|
+
return built
|
|
957
|
+
},
|
|
958
|
+
})
|
|
959
|
+
result = packaged.result
|
|
960
|
+
adapterRun = packaged.run
|
|
961
|
+
} else {
|
|
962
|
+
result = await buildComponents(outDir)
|
|
963
|
+
await assertFreshWorkspaceDists(app.cwd)
|
|
964
|
+
}
|
|
881
965
|
console.log(
|
|
882
|
-
|
|
966
|
+
adapterRun === undefined
|
|
967
|
+
? `[nifra/components] Built ${fw.componentPipeline.adapter} for ${target} (${result.build}) in ${outDir}`
|
|
968
|
+
: `[nifra/components] Built ${componentPipeline.adapter} for ${adapter!.id} (base ${target}, ${result.build}) in ${outDir}\n from output directory: ${adapterRun}`,
|
|
883
969
|
)
|
|
884
970
|
return
|
|
885
971
|
}
|
|
@@ -946,10 +1032,10 @@ async function buildForTarget(
|
|
|
946
1032
|
clientPlugins: asBunPlugins(app.resolvedPlugins.clientPlugins),
|
|
947
1033
|
serverPlugins: asBunPlugins(app.resolvedPlugins.serverPlugins),
|
|
948
1034
|
}
|
|
949
|
-
const
|
|
1035
|
+
const workDir = resolve(cwd, ".nifra-build")
|
|
1036
|
+
const buildOptions = {
|
|
950
1037
|
routesDir,
|
|
951
|
-
|
|
952
|
-
workDir: resolve(cwd, ".nifra-build"),
|
|
1038
|
+
workDir,
|
|
953
1039
|
clientModule: fw.clientModule,
|
|
954
1040
|
adapterImport: frameworkFile,
|
|
955
1041
|
...(fw.use ? { useImport: frameworkFile } : {}),
|
|
@@ -967,19 +1053,52 @@ async function buildForTarget(
|
|
|
967
1053
|
...(fw.vercelRuntime !== undefined ? { vercelRuntime: fw.vercelRuntime } : {}),
|
|
968
1054
|
...(fw.selfHost !== undefined ? { selfHost: fw.selfHost } : {}),
|
|
969
1055
|
live: fw.live?.clientEntry,
|
|
1056
|
+
...transportOption(flags, fw, cwd),
|
|
1057
|
+
prerenderPaths: prerenderPaths(flags, target),
|
|
970
1058
|
// Prerendering drives a built app: the static target is made of its pages, and a bun or node server
|
|
971
1059
|
// answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
|
|
972
1060
|
// transforms the prerender pass (Bun's runtime) does not apply: those pages keep rendering on demand.
|
|
973
1061
|
...(target === "static" || (!useVite && (target === "bun" || target === "node"))
|
|
974
1062
|
? { prerenderApp: await buildPrerenderApp(app) }
|
|
975
1063
|
: {}),
|
|
976
|
-
}
|
|
1064
|
+
}
|
|
1065
|
+
let result: Awaited<ReturnType<typeof buildTarget>>
|
|
1066
|
+
let adapterRun: string | undefined
|
|
1067
|
+
if (adapterSelected && adapter !== undefined) {
|
|
1068
|
+
const packaged = await buildWithDeploymentAdapter({
|
|
1069
|
+
adapter,
|
|
1070
|
+
appRoot: cwd,
|
|
1071
|
+
outDir,
|
|
1072
|
+
options: configuredAdapter?.options,
|
|
1073
|
+
secretExemptions: fw.secretExemptions,
|
|
1074
|
+
protectedPaths: [
|
|
1075
|
+
routesDir,
|
|
1076
|
+
workDir,
|
|
1077
|
+
frameworkFile,
|
|
1078
|
+
backendFile,
|
|
1079
|
+
...(fw.publicDir === false ? [] : [resolve(fw.publicDir ?? resolve(cwd, "public"))]),
|
|
1080
|
+
],
|
|
1081
|
+
build: async (stagingOutDir) => {
|
|
1082
|
+
const built = await buildTarget(target, { ...buildOptions, outDir: stagingOutDir })
|
|
1083
|
+
await assertFreshWorkspaceDists(cwd)
|
|
1084
|
+
return built
|
|
1085
|
+
},
|
|
1086
|
+
})
|
|
1087
|
+
result = packaged.result
|
|
1088
|
+
adapterRun = packaged.run
|
|
1089
|
+
} else {
|
|
1090
|
+
result = await buildTarget(target, { ...buildOptions, outDir })
|
|
1091
|
+
await assertFreshWorkspaceDists(cwd)
|
|
1092
|
+
}
|
|
977
1093
|
// A production build must not certify itself green while a workspace-linked dependency ships a dist
|
|
978
1094
|
// artifact older than (or absent next to) its source: the `bun`->src condition let this compile read
|
|
979
1095
|
// live source, but the deployed app and every node consumer read `dist/`. Gate here, after the compile
|
|
980
1096
|
// proved the source is buildable, so the failure names the package to rebuild rather than a bundle error.
|
|
981
|
-
|
|
982
|
-
|
|
1097
|
+
console.log(
|
|
1098
|
+
adapterRun === undefined
|
|
1099
|
+
? `nifra build (${target}, ${decision.pipeline}) → ${result.run}`
|
|
1100
|
+
: `nifra build (${adapter!.id}, base ${target}, ${decision.pipeline}) → ${outDir}\n from output directory: ${adapterRun}`,
|
|
1101
|
+
)
|
|
983
1102
|
// The pipeline is stated on every build, not only the surprising ones - an auto-selected Vite build
|
|
984
1103
|
// must never look like the default, and a default Bun build must not leave the question open either.
|
|
985
1104
|
console.log(` ${describePipeline(decision)}`)
|
|
@@ -1041,12 +1160,15 @@ async function start(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
1041
1160
|
await import(serverFile)
|
|
1042
1161
|
}
|
|
1043
1162
|
|
|
1044
|
-
const VALUE_FLAGS: Readonly<Record<string, "port" | "out" | "target">> =
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1163
|
+
const VALUE_FLAGS: Readonly<Record<string, "port" | "out" | "target" | "transport" | "prerender">> =
|
|
1164
|
+
{
|
|
1165
|
+
"--port": "port",
|
|
1166
|
+
"-p": "port",
|
|
1167
|
+
"--out": "out",
|
|
1168
|
+
"--target": "target",
|
|
1169
|
+
"--transport": "transport",
|
|
1170
|
+
"--prerender": "prerender",
|
|
1171
|
+
}
|
|
1050
1172
|
|
|
1051
1173
|
type SwitchField = "poll" | "report" | "vite" | "bun" | "allowDuplicateIdentity" | "noIndicator"
|
|
1052
1174
|
|
|
@@ -1059,6 +1181,30 @@ const SWITCH_FLAGS: Readonly<Record<string, SwitchField>> = {
|
|
|
1059
1181
|
"--no-indicator": "noIndicator",
|
|
1060
1182
|
}
|
|
1061
1183
|
|
|
1184
|
+
/** The `transport` build option: `--transport` for this run, else the framework config's. */
|
|
1185
|
+
function transportOption(
|
|
1186
|
+
flags: Pick<Flags, "transport">,
|
|
1187
|
+
fw: { readonly transport?: string },
|
|
1188
|
+
cwd: string,
|
|
1189
|
+
): { transport?: string } {
|
|
1190
|
+
const module = flags.transport ?? fw.transport
|
|
1191
|
+
return module === undefined ? {} : { transport: resolve(cwd, module) }
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/** `--prerender /,/about` as page paths, which only a static build can honour. */
|
|
1195
|
+
function prerenderPaths(flags: Pick<Flags, "prerender">, target: string): string[] | undefined {
|
|
1196
|
+
if (flags.prerender === undefined) return undefined
|
|
1197
|
+
if (target !== "static") {
|
|
1198
|
+
throw new Error(
|
|
1199
|
+
`[nifra] --prerender applies to \`--target static\` (this build is ${target}): other targets prerender the routes that export \`prerender\``,
|
|
1200
|
+
)
|
|
1201
|
+
}
|
|
1202
|
+
return flags.prerender
|
|
1203
|
+
.split(",")
|
|
1204
|
+
.map((path) => path.trim())
|
|
1205
|
+
.filter((path) => path !== "")
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1062
1208
|
/** The flags of `nifra dev`, `build` and `start`, as `--flag value` or `--flag=value`. Anything else is
|
|
1063
1209
|
* refused: an ignored `--target=vercel` would build the default target and exit 0. */
|
|
1064
1210
|
export function parseFlags(args: readonly string[]): Flags {
|
|
@@ -1068,6 +1214,8 @@ export function parseFlags(args: readonly string[]): Flags {
|
|
|
1068
1214
|
let port = Number(Bun.env.PORT ?? DEFAULT_DEV_PORT)
|
|
1069
1215
|
let out: string | undefined
|
|
1070
1216
|
let target: string | undefined
|
|
1217
|
+
let transport: string | undefined
|
|
1218
|
+
let prerender: string | undefined
|
|
1071
1219
|
const switches: Record<SwitchField, boolean> = {
|
|
1072
1220
|
poll: Bun.env.CHOKIDAR_USEPOLLING === "1",
|
|
1073
1221
|
report: false,
|
|
@@ -1087,6 +1235,8 @@ export function parseFlags(args: readonly string[]): Flags {
|
|
|
1087
1235
|
throw new Error(`[nifra] ${name} needs a value`)
|
|
1088
1236
|
if (valueField === "port") port = Number(value)
|
|
1089
1237
|
else if (valueField === "out") out = value
|
|
1238
|
+
else if (valueField === "transport") transport = value
|
|
1239
|
+
else if (valueField === "prerender") prerender = value
|
|
1090
1240
|
else target = value
|
|
1091
1241
|
continue
|
|
1092
1242
|
}
|
|
@@ -1107,7 +1257,7 @@ export function parseFlags(args: readonly string[]): Flags {
|
|
|
1107
1257
|
if (!Number.isFinite(port) || port < 0 || port > 65535) {
|
|
1108
1258
|
throw new Error(`[nifra] invalid --port: ${port}`)
|
|
1109
1259
|
}
|
|
1110
|
-
return { port, out, target, ...switches }
|
|
1260
|
+
return { port, out, target, transport, prerender, ...switches }
|
|
1111
1261
|
}
|
|
1112
1262
|
|
|
1113
1263
|
/**
|
package/src/command-catalog.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { cdnCheckSpec } from "./cdn-check.ts"
|
|
|
17
17
|
import { type CheckResult, checkDiagnostics, renderCheckReport } from "./check.ts"
|
|
18
18
|
import type { ContractsLock } from "./contracts.ts"
|
|
19
19
|
import { dbAuditSpec, dbQuerySpec, dbRoleSpec, dbSchemaSpec } from "./db-tool.ts"
|
|
20
|
+
import { readDeploymentAdapterMetadata } from "./deployment-adapters.ts"
|
|
20
21
|
import { errorsSpec, explainSpec, logsSpec } from "./dev-feed-tool.ts"
|
|
21
22
|
import { toSarifLog } from "./diagnostics.ts"
|
|
22
23
|
import type { DoctorResult } from "./doctor.ts"
|
|
@@ -393,6 +394,36 @@ interface TargetInput {
|
|
|
393
394
|
readonly dir?: string | undefined
|
|
394
395
|
}
|
|
395
396
|
|
|
397
|
+
interface ShellInput {
|
|
398
|
+
readonly kind?: string | undefined
|
|
399
|
+
readonly origin?: string | undefined
|
|
400
|
+
readonly name?: string | undefined
|
|
401
|
+
readonly id?: string | undefined
|
|
402
|
+
readonly mobile?: "android" | "ios" | "all" | undefined
|
|
403
|
+
readonly force?: boolean | undefined
|
|
404
|
+
readonly json?: boolean | undefined
|
|
405
|
+
readonly dir?: string | undefined
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface ShellOutput {
|
|
409
|
+
readonly ok: boolean
|
|
410
|
+
readonly kind: "tauri"
|
|
411
|
+
readonly files: readonly {
|
|
412
|
+
readonly path: string
|
|
413
|
+
readonly action: string
|
|
414
|
+
readonly note?: string | undefined
|
|
415
|
+
}[]
|
|
416
|
+
readonly origin: string
|
|
417
|
+
readonly id: string
|
|
418
|
+
readonly name: string
|
|
419
|
+
readonly next: readonly string[]
|
|
420
|
+
readonly mobile: readonly {
|
|
421
|
+
readonly platform: string
|
|
422
|
+
readonly ok: boolean
|
|
423
|
+
readonly note: string
|
|
424
|
+
}[]
|
|
425
|
+
}
|
|
426
|
+
|
|
396
427
|
interface TargetOutput {
|
|
397
428
|
readonly ok: boolean
|
|
398
429
|
readonly target: string
|
|
@@ -830,6 +861,36 @@ const MIGRATE_SCHEMA = input<MigrateInput>(
|
|
|
830
861
|
},
|
|
831
862
|
)
|
|
832
863
|
|
|
864
|
+
const SHELL_SCHEMA = input<ShellInput>(
|
|
865
|
+
objectSchema({
|
|
866
|
+
kind: { type: "string", enum: ["tauri"] },
|
|
867
|
+
origin: { type: "string" },
|
|
868
|
+
name: { type: "string" },
|
|
869
|
+
id: { type: "string" },
|
|
870
|
+
mobile: { type: "string", enum: ["android", "ios", "all"] },
|
|
871
|
+
force: { type: "boolean" },
|
|
872
|
+
json: { type: "boolean" },
|
|
873
|
+
dir: { type: "string" },
|
|
874
|
+
}),
|
|
875
|
+
(value) => {
|
|
876
|
+
const raw = withDir(record(value))
|
|
877
|
+
const kind = optionalString(raw.kind, "kind")
|
|
878
|
+
if (kind !== "tauri") throw new TypeError("kind must be tauri: `nifra shell tauri`")
|
|
879
|
+
const mobile = optionalString(raw.mobile, "mobile")
|
|
880
|
+
if (mobile !== undefined && mobile !== "android" && mobile !== "ios" && mobile !== "all")
|
|
881
|
+
throw new TypeError("mobile must be android, ios or all")
|
|
882
|
+
return {
|
|
883
|
+
kind,
|
|
884
|
+
origin: optionalString(raw.origin, "origin"),
|
|
885
|
+
name: optionalString(raw.name, "name"),
|
|
886
|
+
id: optionalString(raw.id, "id"),
|
|
887
|
+
mobile,
|
|
888
|
+
dir: raw.dir,
|
|
889
|
+
...parseBooleanFlags(raw, ["force", "json"]),
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
)
|
|
893
|
+
|
|
833
894
|
const TARGET_SCHEMA = input<TargetInput>(
|
|
834
895
|
objectSchema({ target: { type: "string" }, json: { type: "boolean" }, dir: { type: "string" } }),
|
|
835
896
|
(value) => {
|
|
@@ -1725,10 +1786,74 @@ const scaffoldSpec: CommandSpec<ScaffoldInput, HoleScaffoldResult> = {
|
|
|
1725
1786
|
success: (out) => out.ok,
|
|
1726
1787
|
}
|
|
1727
1788
|
|
|
1789
|
+
const shellSpec: CommandSpec<ShellInput, ShellOutput> = {
|
|
1790
|
+
name: "shell",
|
|
1791
|
+
summary:
|
|
1792
|
+
"Add a Tauri 2 shell to the app (`shell tauri`): the transport module and a src-tauri/ project that wraps a static build made with --transport. Writes files only and keeps any that exist unless --force.",
|
|
1793
|
+
input: SHELL_SCHEMA,
|
|
1794
|
+
output: output({
|
|
1795
|
+
type: "object",
|
|
1796
|
+
properties: {
|
|
1797
|
+
ok: { type: "boolean" },
|
|
1798
|
+
kind: { type: "string" },
|
|
1799
|
+
files: { type: "array" },
|
|
1800
|
+
origin: { type: "string" },
|
|
1801
|
+
id: { type: "string" },
|
|
1802
|
+
name: { type: "string" },
|
|
1803
|
+
next: { type: "array" },
|
|
1804
|
+
mobile: { type: "array" },
|
|
1805
|
+
},
|
|
1806
|
+
required: ["ok", "kind", "files", "origin", "id", "name", "next", "mobile"],
|
|
1807
|
+
}),
|
|
1808
|
+
transports: ["cli"],
|
|
1809
|
+
stability: "stable",
|
|
1810
|
+
argv: {
|
|
1811
|
+
positionals: ["kind"],
|
|
1812
|
+
flags: [
|
|
1813
|
+
{ name: "dir", field: "dir", type: "string" },
|
|
1814
|
+
{ name: "json", field: "json", type: "boolean" },
|
|
1815
|
+
{ name: "origin", field: "origin", type: "string" },
|
|
1816
|
+
{ name: "name", field: "name", type: "string" },
|
|
1817
|
+
{ name: "id", field: "id", type: "string" },
|
|
1818
|
+
{ name: "mobile", field: "mobile", type: "string" },
|
|
1819
|
+
{ name: "force", field: "force", type: "boolean" },
|
|
1820
|
+
],
|
|
1821
|
+
},
|
|
1822
|
+
async run(value, ctx) {
|
|
1823
|
+
const { initMobile, runShellInit, shellNextSteps } = await import("./shell-init.ts")
|
|
1824
|
+
const dir = resolve(ctx.cwd, value.dir ?? ".")
|
|
1825
|
+
const result = await runShellInit(dir, {
|
|
1826
|
+
origin: value.origin,
|
|
1827
|
+
name: value.name,
|
|
1828
|
+
id: value.id,
|
|
1829
|
+
force: value.force === true,
|
|
1830
|
+
})
|
|
1831
|
+
const platforms: readonly ("android" | "ios")[] =
|
|
1832
|
+
value.mobile === undefined ? [] : value.mobile === "all" ? ["android", "ios"] : [value.mobile]
|
|
1833
|
+
const mobile = await initMobile(dir, platforms)
|
|
1834
|
+
return {
|
|
1835
|
+
ok: mobile.every((m) => m.ok),
|
|
1836
|
+
kind: "tauri",
|
|
1837
|
+
...result,
|
|
1838
|
+
next: shellNextSteps(),
|
|
1839
|
+
mobile,
|
|
1840
|
+
}
|
|
1841
|
+
},
|
|
1842
|
+
render: (out) => [
|
|
1843
|
+
...out.files.map(
|
|
1844
|
+
(file) => `${file.action.padEnd(8)} ${file.path}${file.note ? ` (${file.note})` : ""}`,
|
|
1845
|
+
),
|
|
1846
|
+
`server origin ${out.origin}, bundle id ${out.id} (change both if they are not yours)`,
|
|
1847
|
+
...out.mobile.map((m) => (m.ok ? `✓ tauri ${m.platform} init` : `✖ ${m.platform}: ${m.note}`)),
|
|
1848
|
+
...out.next.map((step, i) => ` ${i + 1}. ${step}`),
|
|
1849
|
+
],
|
|
1850
|
+
success: (out) => out.ok,
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1728
1853
|
const targetSpec: CommandSpec<TargetInput, TargetOutput> = {
|
|
1729
1854
|
name: "target",
|
|
1730
1855
|
summary:
|
|
1731
|
-
"Show
|
|
1856
|
+
"Show or switch the build target. Besides built-ins, an installed deploymentAdapter can select its custom target id.",
|
|
1732
1857
|
input: TARGET_SCHEMA,
|
|
1733
1858
|
output: output({
|
|
1734
1859
|
type: "object",
|
|
@@ -1750,23 +1875,34 @@ const targetSpec: CommandSpec<TargetInput, TargetOutput> = {
|
|
|
1750
1875
|
{ name: "dir", field: "dir", type: "string" },
|
|
1751
1876
|
],
|
|
1752
1877
|
},
|
|
1878
|
+
/** Show or switch built-in targets and configured adapter IDs without importing adapter code. */
|
|
1753
1879
|
async run(value, ctx) {
|
|
1754
1880
|
const dir = resolve(ctx.cwd, value.dir ?? ".")
|
|
1755
|
-
const { parseBuildTarget, planBuildTarget } = await import("@nifrajs/web/build")
|
|
1881
|
+
const { isBuildTarget, parseBuildTarget, planBuildTarget } = await import("@nifrajs/web/build")
|
|
1756
1882
|
const { readConfigTarget, writeConfigTarget } = await import("./config-target.ts")
|
|
1757
1883
|
const current = readConfigTarget(dir)
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1884
|
+
const requested = value.target ?? current ?? "bun"
|
|
1885
|
+
// A custom id is accepted only when an installed package declares it, so a typo cannot be written.
|
|
1886
|
+
const adapterMetadata = isBuildTarget(requested)
|
|
1887
|
+
? undefined
|
|
1888
|
+
: readDeploymentAdapterMetadata(dir, requested)
|
|
1889
|
+
const target =
|
|
1890
|
+
adapterMetadata?.id ??
|
|
1891
|
+
parseBuildTarget(
|
|
1892
|
+
requested,
|
|
1893
|
+
value.target === undefined ? "target in nifra.config.ts" : "target",
|
|
1894
|
+
)
|
|
1762
1895
|
const changed = value.target !== undefined && value.target !== current
|
|
1763
1896
|
if (changed) writeConfigTarget(dir, target)
|
|
1897
|
+
const run = isBuildTarget(target)
|
|
1898
|
+
? planBuildTarget(target, "dist").run
|
|
1899
|
+
: `custom deployment adapter "${target}"${adapterMetadata === undefined ? "" : ` (base ${adapterMetadata.baseTarget})`}; configure deploymentAdapter in nifra.config.ts`
|
|
1764
1900
|
return {
|
|
1765
1901
|
ok: true,
|
|
1766
1902
|
target,
|
|
1767
1903
|
...(changed && current !== undefined ? { previous: current } : {}),
|
|
1768
1904
|
changed,
|
|
1769
|
-
run
|
|
1905
|
+
run,
|
|
1770
1906
|
}
|
|
1771
1907
|
},
|
|
1772
1908
|
render: (out) => [
|
|
@@ -2180,6 +2316,7 @@ export const commandSpecs = Object.freeze([
|
|
|
2180
2316
|
migrateSpec,
|
|
2181
2317
|
scaffoldSpec,
|
|
2182
2318
|
targetSpec,
|
|
2319
|
+
shellSpec,
|
|
2183
2320
|
typesSpec,
|
|
2184
2321
|
schemasSpec,
|
|
2185
2322
|
snapshotSpec,
|