@eserstack/laroux-server 0.0.0-bootstrap.0 → 5.0.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.
Files changed (80) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +411 -0
  3. package/dist/adapters/react/error-chunk.d.ts +11 -0
  4. package/dist/adapters/react/error-chunk.js +12 -0
  5. package/dist/adapters/react/html-shell.d.ts +15 -0
  6. package/dist/adapters/react/html-shell.js +109 -0
  7. package/dist/adapters/react/inline-rsc-emitter.d.ts +62 -0
  8. package/dist/adapters/react/inline-rsc-emitter.js +120 -0
  9. package/dist/adapters/react/mod.d.ts +30 -0
  10. package/dist/adapters/react/mod.js +36 -0
  11. package/dist/adapters/react/render-app.d.ts +46 -0
  12. package/dist/adapters/react/render-app.js +44 -0
  13. package/dist/adapters/react/renderer.d.ts +15 -0
  14. package/dist/adapters/react/renderer.js +86 -0
  15. package/dist/adapters/react/rsc-flight-renderer.d.ts +64 -0
  16. package/dist/adapters/react/rsc-flight-renderer.js +623 -0
  17. package/dist/adapters/react/rsc-handler.d.ts +47 -0
  18. package/dist/adapters/react/rsc-handler.js +114 -0
  19. package/dist/adapters/react/script-json.d.ts +12 -0
  20. package/dist/adapters/react/script-json.js +18 -0
  21. package/dist/adapters/react/ssr-renderer.d.ts +63 -0
  22. package/dist/adapters/react/ssr-renderer.js +625 -0
  23. package/dist/bin-main.d.ts +1 -0
  24. package/dist/bin-main.js +18 -0
  25. package/dist/cli.d.ts +26 -0
  26. package/dist/cli.js +48 -0
  27. package/dist/commands/build.d.ts +78 -0
  28. package/dist/commands/build.js +221 -0
  29. package/dist/commands/dev.d.ts +50 -0
  30. package/dist/commands/dev.js +133 -0
  31. package/dist/commands/init.d.ts +29 -0
  32. package/dist/commands/init.js +228 -0
  33. package/dist/commands/serve.d.ts +47 -0
  34. package/dist/commands/serve.js +124 -0
  35. package/dist/config/load-config.d.ts +14 -0
  36. package/dist/config/load-config.js +67 -0
  37. package/dist/domain/action-registry.d.ts +83 -0
  38. package/dist/domain/action-registry.js +124 -0
  39. package/dist/domain/build-module.d.ts +30 -0
  40. package/dist/domain/build-module.js +50 -0
  41. package/dist/domain/hmr-manager.d.ts +51 -0
  42. package/dist/domain/hmr-manager.js +90 -0
  43. package/dist/domain/html-shell.d.ts +56 -0
  44. package/dist/domain/html-shell.js +15 -0
  45. package/dist/domain/middleware-dispatcher.d.ts +42 -0
  46. package/dist/domain/middleware-dispatcher.js +150 -0
  47. package/dist/domain/rebuild-handler.d.ts +52 -0
  48. package/dist/domain/rebuild-handler.js +52 -0
  49. package/dist/domain/renderer.d.ts +62 -0
  50. package/dist/domain/renderer.js +15 -0
  51. package/dist/domain/route-dispatcher.d.ts +40 -0
  52. package/dist/domain/route-dispatcher.js +134 -0
  53. package/dist/domain/server-modules.d.ts +65 -0
  54. package/dist/domain/server-modules.js +208 -0
  55. package/dist/main.d.ts +40 -0
  56. package/dist/main.js +256 -0
  57. package/dist/module.d.ts +24 -0
  58. package/dist/module.js +140 -0
  59. package/dist/options.d.ts +53 -0
  60. package/dist/options.js +14 -0
  61. package/dist/package.json +98 -0
  62. package/dist/proxy/types.d.ts +19 -0
  63. package/dist/proxy/types.js +3 -0
  64. package/dist/runtime/action-guard.d.ts +49 -0
  65. package/dist/runtime/action-guard.js +115 -0
  66. package/dist/runtime/html-shell.d.ts +66 -0
  67. package/dist/runtime/html-shell.js +246 -0
  68. package/dist/runtime/media-types.d.ts +13 -0
  69. package/dist/runtime/media-types.js +83 -0
  70. package/dist/runtime/path-containment.d.ts +11 -0
  71. package/dist/runtime/path-containment.js +27 -0
  72. package/dist/runtime/seo/generate-meta.d.ts +16 -0
  73. package/dist/runtime/seo/generate-meta.js +121 -0
  74. package/dist/runtime/seo/index.d.ts +5 -0
  75. package/dist/runtime/seo/index.js +5 -0
  76. package/dist/runtime/seo/types.d.ts +25 -0
  77. package/dist/runtime/seo/types.js +5 -0
  78. package/dist/runtime/server.d.ts +58 -0
  79. package/dist/runtime/server.js +699 -0
  80. package/package.json +84 -1
package/dist/cli.js ADDED
@@ -0,0 +1,48 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * laroux.js — standalone CLI entry point.
4
+ *
5
+ * Usage:
6
+ * node ./cli.ts <command> [options]
7
+ * npx laroux <command> [options] # the bin of the npm package `laroux`
8
+ *
9
+ * @module
10
+ */
11
+ import * as results from "@eserstack/primitives/results";
12
+ import { runtime } from "@eserstack/standards/cross-runtime";
13
+ import * as module from "./module.js";
14
+ import config from "./package.json" with { type: "json" };
15
+ const app = module.moduleDef.toCommand("laroux", config.version);
16
+ /**
17
+ * Run the `laroux` command line with the process arguments.
18
+ *
19
+ * @returns ok when the command succeeded; otherwise the message to print and
20
+ * the exit code to set
21
+ */
22
+ export const main = async () => {
23
+ return await app.parse();
24
+ };
25
+ /**
26
+ * Run the `laroux` command line as a bin does: a failure prints its message to
27
+ * stderr and sets the process exit code. The `laroux` bin of the npm package
28
+ * `laroux` calls this, so the CLI and the app share one copy of this package.
29
+ */
30
+ export const run = async () => {
31
+ const result = await main();
32
+ results.match(result, {
33
+ ok: () => { },
34
+ fail: (error) => {
35
+ if (error.message !== undefined) {
36
+ // The failure message is CLI output for the user, written to stderr.
37
+ // oxlint-disable-next-line no-console
38
+ console.error(error.message);
39
+ }
40
+ runtime.process.setExitCode(error.exitCode);
41
+ },
42
+ });
43
+ };
44
+ if (import.meta.main) {
45
+ // CLI entry point: the process runs the command and exits when it settles.
46
+ // oxlint-disable-next-line node/no-top-level-await
47
+ await run();
48
+ }
@@ -0,0 +1,78 @@
1
+ import * as streams from "@eserstack/streams";
2
+ import * as results from "@eserstack/primitives/results";
3
+ import type { CssPlugin, CssProcessor, FontOptimizer, FrameworkPlugin, ImageOptimizer } from "@eserstack/laroux-bundler";
4
+ /** Lowest level the bundler logs during the build. */
5
+ export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
6
+ /** Inputs of one production build, after the flags are parsed. */
7
+ export type BuildCommandOptions = {
8
+ /** App root that holds laroux.config.ts and the source directory */
9
+ readonly projectRoot: string;
10
+ /** Output directory, relative to projectRoot */
11
+ readonly outDir: string;
12
+ /** Minify the client bundle */
13
+ readonly minify: boolean;
14
+ /** Remove the output directory before building */
15
+ readonly clean: boolean;
16
+ /** Print the chunk sizes after a successful build */
17
+ readonly analyze: boolean;
18
+ /** Lowest level the bundler logs */
19
+ readonly logLevel: LogLevel;
20
+ /** Bundler framework plugin; the CLI passes the React plugin */
21
+ readonly frameworkPlugin: FrameworkPlugin;
22
+ /** Bundler CSS plugin; the CLI passes the Tailwind plugin */
23
+ readonly cssPlugin?: CssPlugin;
24
+ /** Stylesheet processor; the CLI passes the Lightning CSS processor */
25
+ readonly cssProcessor?: CssProcessor;
26
+ /** Font optimizer; the CLI passes the Google Fonts optimizer */
27
+ readonly fontOptimizer?: FontOptimizer;
28
+ /** Image optimizer; the CLI passes the sharp optimizer */
29
+ readonly imageOptimizer?: ImageOptimizer;
30
+ /** Where the build's log lines go; defaults to stdout */
31
+ readonly logSink?: streams.Sink<unknown>;
32
+ };
33
+ type CliResult = results.Result<void, {
34
+ message?: string;
35
+ exitCode: number;
36
+ }>;
37
+ /**
38
+ * The help text of `laroux build`.
39
+ *
40
+ * @returns The usage line, the options and examples
41
+ */
42
+ export declare const helpText: () => string;
43
+ /** The build inputs that come from the flags and the working directory. */
44
+ export type BuildFlagOptions = Pick<BuildCommandOptions, "projectRoot" | "outDir" | "minify" | "clean" | "analyze" | "logLevel">;
45
+ /** The parts of `laroux build` a test replaces; each defaults to the real one. */
46
+ export type BuildCommandDeps = {
47
+ /** Runs the build; defaults to {@link buildWithDefaultAdapters} */
48
+ readonly build?: (options: BuildFlagOptions) => Promise<CliResult>;
49
+ /** Where the command writes its own lines; defaults to stdout */
50
+ readonly sink?: streams.Sink<unknown>;
51
+ };
52
+ /**
53
+ * Run `laroux build [options]`: build the app in the working directory for
54
+ * production.
55
+ *
56
+ * @param args - The arguments after `build`
57
+ * @param deps - Replacements for the build and the output
58
+ * @returns The result of the build
59
+ */
60
+ export declare const main: (args?: readonly string[], deps?: BuildCommandDeps) => Promise<CliResult>;
61
+ /**
62
+ * Build the app at options.projectRoot for production with the React,
63
+ * Tailwind, Lightning CSS, Google Fonts and sharp adapters.
64
+ *
65
+ * @param options - The parsed flags and the project root
66
+ * @returns The result of {@link runBuild}
67
+ */
68
+ export declare const buildWithDefaultAdapters: (options: BuildFlagOptions) => Promise<CliResult>;
69
+ /**
70
+ * Build the app at options.projectRoot for production. Fails with exit code
71
+ * 1, and skips the bundle analysis, when the bundler build fails; the bundler
72
+ * has already logged the failing step and its error.
73
+ */
74
+ export declare const runBuild: (options: BuildCommandOptions) => Promise<results.Result<void, {
75
+ message?: string;
76
+ exitCode: number;
77
+ }>>;
78
+ export {};
@@ -0,0 +1,221 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * laroux build command
4
+ *
5
+ * Builds the application for production.
6
+ *
7
+ * @module
8
+ */
9
+ import * as shellArgs from "@eserstack/shell/args";
10
+ import * as span from "@eserstack/streams/span";
11
+ import * as streams from "@eserstack/streams";
12
+ import * as results from "@eserstack/primitives/results";
13
+ const VALID_LOG_LEVELS = [
14
+ "trace",
15
+ "debug",
16
+ "info",
17
+ "warn",
18
+ "error",
19
+ "fatal",
20
+ ];
21
+ /** Exit code of a build whose bundler step failed. */
22
+ const BUILD_FAILED_EXIT_CODE = 1;
23
+ const FLAGS = [
24
+ {
25
+ name: "out-dir",
26
+ type: "string",
27
+ default: "dist",
28
+ description: "Output directory",
29
+ },
30
+ { name: "clean", type: "boolean", description: "Clean output first" },
31
+ { name: "no-minify", type: "boolean", description: "Disable minification" },
32
+ { name: "analyze", type: "boolean", description: "Analyze bundle size" },
33
+ {
34
+ name: "log-level",
35
+ type: "string",
36
+ default: "info",
37
+ description: `Log level (${VALID_LOG_LEVELS.join(", ")})`,
38
+ },
39
+ { name: "help", short: "h", type: "boolean", description: "Show this help" },
40
+ ];
41
+ /**
42
+ * The help text of `laroux build`.
43
+ *
44
+ * @returns The usage line, the options and examples
45
+ */
46
+ export const helpText = () => shellArgs.generateHelp({
47
+ name: "build",
48
+ description: "Build the app in the working directory for production",
49
+ usage: "laroux build [options]",
50
+ flags: FLAGS,
51
+ children: [],
52
+ examples: ["laroux build", "laroux build --clean --analyze"],
53
+ }, ["laroux", "build"]);
54
+ /**
55
+ * Run `laroux build [options]`: build the app in the working directory for
56
+ * production.
57
+ *
58
+ * @param args - The arguments after `build`
59
+ * @param deps - Replacements for the build and the output
60
+ * @returns The result of the build
61
+ */
62
+ export const main = async (args, deps = {}) => {
63
+ const { flags } = shellArgs.parseFlags(args ?? [], FLAGS);
64
+ if (flags["help"] === true) {
65
+ const out = streams.output({
66
+ renderer: streams.renderers.ansi(),
67
+ sink: deps.sink ?? streams.sinks.stdout(),
68
+ });
69
+ out.writeln(helpText());
70
+ await out.close();
71
+ return results.ok(undefined);
72
+ }
73
+ const logLevelInput = flags["log-level"] ?? "info";
74
+ const logLevel = VALID_LOG_LEVELS.includes(logLevelInput.toLowerCase())
75
+ ? logLevelInput.toLowerCase()
76
+ : "info";
77
+ const crossRuntime = await import("@eserstack/standards/cross-runtime");
78
+ const build = deps.build ?? buildWithDefaultAdapters;
79
+ return await build({
80
+ projectRoot: crossRuntime.runtime.process.cwd(),
81
+ outDir: flags["out-dir"],
82
+ minify: !flags["no-minify"],
83
+ clean: flags["clean"],
84
+ analyze: flags["analyze"],
85
+ logLevel,
86
+ });
87
+ };
88
+ /**
89
+ * Build the app at options.projectRoot for production with the React,
90
+ * Tailwind, Lightning CSS, Google Fonts and sharp adapters.
91
+ *
92
+ * @param options - The parsed flags and the project root
93
+ * @returns The result of {@link runBuild}
94
+ */
95
+ export const buildWithDefaultAdapters = async (options) => {
96
+ const [crossRuntime, reactBundler, tailwindcss, lightningcss, fonts, sharp] = await Promise.all([
97
+ import("@eserstack/standards/cross-runtime"),
98
+ import("@eserstack/laroux-bundler/adapters/react"),
99
+ import("@eserstack/laroux-bundler/adapters/tailwindcss"),
100
+ import("@eserstack/laroux-bundler/adapters/lightningcss"),
101
+ import("@eserstack/laroux-bundler/adapters/fonts"),
102
+ import("@eserstack/laroux-bundler/adapters/sharp"),
103
+ ]);
104
+ const { projectRoot } = options;
105
+ return await runBuild({
106
+ ...options,
107
+ frameworkPlugin: reactBundler.reactPlugin,
108
+ cssPlugin: tailwindcss.createTailwindPlugin({
109
+ globalCssPath: crossRuntime.runtime.path.resolve(projectRoot, "src/app/styles/global.css"),
110
+ }),
111
+ cssProcessor: lightningcss.lightningCssProcessor,
112
+ fontOptimizer: fonts.googleFontOptimizer,
113
+ imageOptimizer: sharp.sharpImageOptimizer,
114
+ });
115
+ };
116
+ /**
117
+ * Build the app at options.projectRoot for production. Fails with exit code
118
+ * 1, and skips the bundle analysis, when the bundler build fails; the bundler
119
+ * has already logged the failing step and its error.
120
+ */
121
+ export const runBuild = async (options) => {
122
+ const out = streams.output({
123
+ renderer: streams.renderers.ansi(),
124
+ sink: streams.sinks.stdout(),
125
+ });
126
+ out.writeln(span.cyan("\n📦 Building for production...\n"));
127
+ const logging = await import("@eserstack/logging");
128
+ const crossRuntime = await import("@eserstack/standards/cross-runtime");
129
+ const runtime = crossRuntime.runtime;
130
+ const { projectRoot, outDir, minify, clean, analyze, logLevel } = options;
131
+ const logLevelMap = {
132
+ trace: logging.Severities.Trace,
133
+ debug: logging.Severities.Debug,
134
+ info: logging.Severities.Info,
135
+ warn: logging.Severities.Warning,
136
+ error: logging.Severities.Error,
137
+ fatal: logging.Severities.Critical,
138
+ };
139
+ const loggingOut = streams.output({
140
+ renderer: streams.renderers.ansi(),
141
+ sink: options.logSink ?? streams.sinks.stdout(),
142
+ });
143
+ await logging.config.configure({
144
+ sinks: {
145
+ console: logging.sinks.getOutputSink(loggingOut),
146
+ },
147
+ loggers: [
148
+ {
149
+ category: ["laroux-bundler"],
150
+ lowestLevel: logLevelMap[logLevel],
151
+ sinks: ["console"],
152
+ },
153
+ ],
154
+ });
155
+ const [system, loadConfig] = await Promise.all([
156
+ import("@eserstack/laroux-bundler/system"),
157
+ import("../config/load-config.js"),
158
+ ]);
159
+ const bundlerLogger = logging.logger.getLogger(["laroux-bundler", "cli"]);
160
+ const baseConfig = await loadConfig.loadConfig(projectRoot);
161
+ const buildConfig = {
162
+ projectRoot,
163
+ srcDir: runtime.path.resolve(projectRoot, baseConfig.srcDir),
164
+ distDir: runtime.path.resolve(projectRoot, outDir),
165
+ logLevel,
166
+ fonts: baseConfig.fonts,
167
+ images: baseConfig.images,
168
+ cssModuleTypes: baseConfig.cssModuleTypes,
169
+ noCssModuleAutoReference: baseConfig.noCssModuleAutoReference,
170
+ browserShims: baseConfig.browserShims,
171
+ serverExternals: baseConfig.build.serverExternals,
172
+ build: {
173
+ ...baseConfig.build,
174
+ minify,
175
+ },
176
+ };
177
+ if (clean && (await runtime.fs.exists(buildConfig.distDir))) {
178
+ await runtime.fs.remove(buildConfig.distDir, { recursive: true });
179
+ bundlerLogger.debug(`Cleaned ${buildConfig.distDir}`);
180
+ }
181
+ const context = system.createBuildContext(buildConfig, {
182
+ framework: options.frameworkPlugin,
183
+ css: options.cssPlugin,
184
+ cssProcessor: options.cssProcessor,
185
+ fontOptimizer: options.fontOptimizer,
186
+ imageOptimizer: options.imageOptimizer,
187
+ bundlerBackend: "rolldown",
188
+ });
189
+ const buildResult = await system.build(context);
190
+ await logging.config.reset();
191
+ // The log lines reach the output's sink asynchronously; they are all there
192
+ // before the build reports its result.
193
+ await loggingOut.flush();
194
+ if (!buildResult.success) {
195
+ await out.close();
196
+ return results.fail({
197
+ message: `laroux build: building ${projectRoot} failed; the "Build failed" log entry above names the step and its error`,
198
+ exitCode: BUILD_FAILED_EXIT_CODE,
199
+ });
200
+ }
201
+ if (analyze) {
202
+ out.writeln(span.cyan("\n📊 Bundle Analysis:\n"));
203
+ try {
204
+ const manifestPath = runtime.path.join(buildConfig.distDir, "client", "manifest.json");
205
+ const manifestText = await runtime.fs.readTextFile(manifestPath);
206
+ const manifest = JSON.parse(manifestText);
207
+ out.writeln(span.text("Chunks:"));
208
+ for (const [file, info] of Object.entries(manifest.files)) {
209
+ const sizeKB = (info.size / 1024).toFixed(2);
210
+ out.writeln(span.text(` ${file.padEnd(30)} ${sizeKB.padStart(8)} KB`));
211
+ }
212
+ const totalSize = Object.values(manifest.files).reduce((sum, file) => sum + file.size, 0);
213
+ out.writeln(span.dim(`\nTotal: ${(totalSize / 1024).toFixed(2)} KB`));
214
+ }
215
+ catch {
216
+ out.writeln(span.yellow("Could not analyze build (manifest.json not found)"));
217
+ }
218
+ }
219
+ await out.close();
220
+ return results.ok(undefined);
221
+ };
@@ -0,0 +1,50 @@
1
+ import * as streams from "@eserstack/streams";
2
+ import * as results from "@eserstack/primitives/results";
3
+ declare const VALID_LOG_LEVELS: readonly ["trace", "debug", "info", "warn", "error", "fatal"];
4
+ /** Lowest level the dev server logs. */
5
+ export type LogLevel = (typeof VALID_LOG_LEVELS)[number];
6
+ type CliResult = results.Result<void, {
7
+ message?: string;
8
+ exitCode: number;
9
+ }>;
10
+ /**
11
+ * The help text of `laroux dev`.
12
+ *
13
+ * @returns The usage line, the options and examples
14
+ */
15
+ export declare const helpText: () => string;
16
+ /** The dev server inputs, after the flags are parsed. */
17
+ export type DevServerOptions = {
18
+ /** Port the server listens on */
19
+ readonly port: number | undefined;
20
+ /** Lowest level the server logs */
21
+ readonly logLevel: LogLevel;
22
+ /** Serve hot module replacement updates */
23
+ readonly hmr: boolean;
24
+ /** Open the app in a browser once the server listens */
25
+ readonly open: boolean;
26
+ };
27
+ /** The parts of `laroux dev` a test replaces; each defaults to the real one. */
28
+ export type DevCommandDeps = {
29
+ /** Starts the server; defaults to {@link startDevServer} */
30
+ readonly start?: (options: DevServerOptions) => Promise<CliResult>;
31
+ /** Where the command writes its own lines; defaults to stdout */
32
+ readonly sink?: streams.Sink<unknown>;
33
+ };
34
+ /**
35
+ * Start the dev server in the working directory with the React, Tailwind,
36
+ * Lightning CSS, Google Fonts and sharp adapters.
37
+ *
38
+ * @param options - The parsed flags
39
+ * @returns ok when the server stopped; exit code 1 when its build failed
40
+ */
41
+ export declare const startDevServer: (options: DevServerOptions) => Promise<CliResult>;
42
+ /**
43
+ * Run `laroux dev [options]`: start the dev server in the working directory.
44
+ *
45
+ * @param args - The arguments after `dev`
46
+ * @param deps - Replacements for the server start and the output
47
+ * @returns The result of the server start
48
+ */
49
+ export declare const main: (args?: readonly string[], deps?: DevCommandDeps) => Promise<CliResult>;
50
+ export {};
@@ -0,0 +1,133 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * laroux dev command
4
+ *
5
+ * Starts development server with hot reload.
6
+ *
7
+ * @module
8
+ */
9
+ import * as shellArgs from "@eserstack/shell/args";
10
+ import * as span from "@eserstack/streams/span";
11
+ import * as streams from "@eserstack/streams";
12
+ import * as results from "@eserstack/primitives/results";
13
+ const VALID_LOG_LEVELS = [
14
+ "trace",
15
+ "debug",
16
+ "info",
17
+ "warn",
18
+ "error",
19
+ "fatal",
20
+ ];
21
+ const FLAGS = [
22
+ {
23
+ name: "port",
24
+ short: "p",
25
+ type: "number",
26
+ default: 8000,
27
+ description: "Server port",
28
+ },
29
+ { name: "no-hmr", type: "boolean", description: "Disable HMR" },
30
+ {
31
+ name: "log-level",
32
+ type: "string",
33
+ default: "info",
34
+ description: `Log level (${VALID_LOG_LEVELS.join(", ")})`,
35
+ },
36
+ {
37
+ name: "open",
38
+ short: "o",
39
+ type: "boolean",
40
+ description: "Open browser",
41
+ },
42
+ { name: "help", short: "h", type: "boolean", description: "Show this help" },
43
+ ];
44
+ /**
45
+ * The help text of `laroux dev`.
46
+ *
47
+ * @returns The usage line, the options and examples
48
+ */
49
+ export const helpText = () => shellArgs.generateHelp({
50
+ name: "dev",
51
+ description: "Start the development server with hot reload",
52
+ usage: "laroux dev [options]",
53
+ flags: FLAGS,
54
+ children: [],
55
+ examples: ["laroux dev", "laroux dev --port 3000 --open"],
56
+ }, ["laroux", "dev"]);
57
+ /**
58
+ * Start the dev server in the working directory with the React, Tailwind,
59
+ * Lightning CSS, Google Fonts and sharp adapters.
60
+ *
61
+ * @param options - The parsed flags
62
+ * @returns ok when the server stopped; exit code 1 when its build failed
63
+ */
64
+ export const startDevServer = async (options) => {
65
+ const [server, reactAdapter, reactBundler, tailwind, lightningcss, fonts, sharp,] = await Promise.all([
66
+ import("../main.js"),
67
+ import("../adapters/react/mod.js"),
68
+ import("@eserstack/laroux-bundler/adapters/react"),
69
+ import("@eserstack/laroux-bundler/adapters/tailwindcss"),
70
+ import("@eserstack/laroux-bundler/adapters/lightningcss"),
71
+ import("@eserstack/laroux-bundler/adapters/fonts"),
72
+ import("@eserstack/laroux-bundler/adapters/sharp"),
73
+ ]);
74
+ try {
75
+ await server.startServer({
76
+ mode: "dev",
77
+ port: options.port,
78
+ logLevel: options.logLevel,
79
+ hmr: options.hmr,
80
+ open: options.open,
81
+ renderer: reactAdapter.reactRenderer,
82
+ htmlShell: reactAdapter.reactHtmlShellBuilder,
83
+ frameworkPlugin: reactBundler.reactPlugin,
84
+ cssPlugin: tailwind.createTailwindPlugin({
85
+ globalCssPath: "src/app/styles/global.css",
86
+ }),
87
+ cssProcessor: lightningcss.lightningCssProcessor,
88
+ fontOptimizer: fonts.googleFontOptimizer,
89
+ imageOptimizer: sharp.sharpImageOptimizer,
90
+ });
91
+ }
92
+ catch (error) {
93
+ // The build already logged its error; the CLI prints this summary and
94
+ // exits non-zero instead of serving a stale or empty dist/.
95
+ if (error instanceof server.BuildFailedError) {
96
+ return results.fail({ message: error.message, exitCode: 1 });
97
+ }
98
+ throw error;
99
+ }
100
+ return results.ok(undefined);
101
+ };
102
+ /**
103
+ * Run `laroux dev [options]`: start the dev server in the working directory.
104
+ *
105
+ * @param args - The arguments after `dev`
106
+ * @param deps - Replacements for the server start and the output
107
+ * @returns The result of the server start
108
+ */
109
+ export const main = async (args, deps = {}) => {
110
+ const { flags } = shellArgs.parseFlags(args ?? [], FLAGS);
111
+ const out = streams.output({
112
+ renderer: streams.renderers.ansi(),
113
+ sink: deps.sink ?? streams.sinks.stdout(),
114
+ });
115
+ if (flags["help"] === true) {
116
+ out.writeln(helpText());
117
+ await out.close();
118
+ return results.ok(undefined);
119
+ }
120
+ out.writeln(span.cyan("\n⚡ Starting development server...\n"));
121
+ await out.close();
122
+ const logLevelInput = flags["log-level"] ?? "info";
123
+ const logLevel = VALID_LOG_LEVELS.includes(logLevelInput.toLowerCase())
124
+ ? logLevelInput.toLowerCase()
125
+ : "info";
126
+ const start = deps.start ?? startDevServer;
127
+ return await start({
128
+ port: flags["port"],
129
+ logLevel,
130
+ hmr: !flags["no-hmr"],
131
+ open: flags["open"] ?? false,
132
+ });
133
+ };
@@ -0,0 +1,29 @@
1
+ import * as results from "@eserstack/primitives/results";
2
+ /**
3
+ * The templates `laroux init --template` accepts, each with the name of the
4
+ * kit recipe it scaffolds.
5
+ */
6
+ export declare const TEMPLATE_RECIPES: Readonly<Record<string, string>>;
7
+ /** The folder init creates the project in when none is given. */
8
+ export declare const DEFAULT_FOLDER = "my-laroux-app";
9
+ type CliResult = results.Result<void, {
10
+ message?: string;
11
+ exitCode: number;
12
+ }>;
13
+ /**
14
+ * The help text of `laroux init`.
15
+ *
16
+ * @returns The usage line, the options and examples
17
+ */
18
+ export declare const helpText: () => string;
19
+ /**
20
+ * Run `laroux init [folder] [options]`: scaffold the template's kit recipe
21
+ * into `folder` (default `my-laroux-app`) under the working directory. A
22
+ * failed run removes the folder when it created it.
23
+ *
24
+ * @param args - The arguments after `init`
25
+ * @returns ok when the project was created or the help was printed;
26
+ * otherwise the message to print and exit code 1
27
+ */
28
+ export declare const main: (args?: readonly string[]) => Promise<CliResult>;
29
+ export {};