aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--priv/templates/component-entry.mjs4
-rw-r--r--src/lustre/cli/build.gleam21
2 files changed, 11 insertions, 14 deletions
diff --git a/priv/templates/component-entry.mjs b/priv/templates/component-entry.mjs
new file mode 100644
index 0000000..c9e2823
--- /dev/null
+++ b/priv/templates/component-entry.mjs
@@ -0,0 +1,4 @@
+import { register } from '../dev/javascript/lustre/client-component.ffi.mjs';
+import { name, {component_name} as component } from '../dev/javascript/{app_name}/{module_path}.mjs';
+
+register(component(), name); \ No newline at end of file
diff --git a/src/lustre/cli/build.gleam b/src/lustre/cli/build.gleam
index 352329d..656cfcc 100644
--- a/src/lustre/cli/build.gleam
+++ b/src/lustre/cli/build.gleam
@@ -11,7 +11,7 @@ import glint.{type Command, CommandInput}
import glint/flag
import lustre/cli/esbuild
import lustre/cli/project.{type Module}
-import lustre/cli/utils.{keep, replace, try}
+import lustre/cli/utils.{keep, replace, template, try}
import lustre/cli/step.{type Step}
import simplifile
@@ -47,11 +47,8 @@ JavaScript module for you to host or distribute.
let _ = simplifile.create_directory_all(tempdir)
let _ = simplifile.create_directory_all(outdir)
let entry =
- "import { main } from '../dev/javascript/${project_name}/${project_name}.mjs';
-
- main();
- "
- |> string.replace("${project_name}", project_name)
+ template("entry-with-main.mjs")
+ |> string.replace("{app_name}", project_name)
let entryfile = filepath.join(tempdir, "entry.mjs")
let ext = case minify {
@@ -117,14 +114,10 @@ present.
use project_name <- step.try(get_project_name(), keep)
let entry =
- "import { register } from '../dev/javascript/lustre/client-component.ffi.mjs';
- import { name, ${component} as component } from '../dev/javascript/${project_name}/${module_path}.mjs';
-
- register(component(), name);
- "
- |> string.replace("${component}", component)
- |> string.replace("${project_name}", project_name)
- |> string.replace("${module_path}", module_path)
+ template("component-entry.mjs")
+ |> string.replace("{component_name}", component)
+ |> string.replace("{app_name}", project_name)
+ |> string.replace("{module_path}", module_path)
let entryfile = filepath.join(tempdir, "entry.mjs")
let ext = case minify {