Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/next/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ pub fn build(b: *std.Build) void {
linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
b.installArtifact(exe);

const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
const frontend_install = b.addSystemCommand(&.{ "npm", "install" });
frontend_install.setCwd(b.path("frontend"));
const frontend_install_step = b.step("frontend-install", "Install frontend dependencies");
frontend_install_step.dependOn(&frontend_install.step);

const frontend_build = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "run", "build" });
const frontend_build = b.addSystemCommand(&.{ "npm", "run", "build" });
frontend_build.setCwd(b.path("frontend"));
frontend_build.step.dependOn(&frontend_install.step);
const frontend_step = b.step("frontend-build", "Build the frontend");
frontend_step.dependOn(&frontend_build.step);
Expand Down
6 changes: 4 additions & 2 deletions examples/react/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ pub fn build(b: *std.Build) void {
linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
b.installArtifact(exe);

const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
const frontend_install = b.addSystemCommand(&.{ "npm", "install" });
frontend_install.setCwd(b.path("frontend"));
const frontend_install_step = b.step("frontend-install", "Install frontend dependencies");
frontend_install_step.dependOn(&frontend_install.step);

const frontend_build = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "run", "build" });
const frontend_build = b.addSystemCommand(&.{ "npm", "run", "build" });
frontend_build.setCwd(b.path("frontend"));
frontend_build.step.dependOn(&frontend_install.step);
const frontend_step = b.step("frontend-build", "Build the frontend");
frontend_step.dependOn(&frontend_build.step);
Expand Down
6 changes: 4 additions & 2 deletions examples/svelte/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ pub fn build(b: *std.Build) void {
linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
b.installArtifact(exe);

const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
const frontend_install = b.addSystemCommand(&.{ "npm", "install" });
frontend_install.setCwd(b.path("frontend"));
const frontend_install_step = b.step("frontend-install", "Install frontend dependencies");
frontend_install_step.dependOn(&frontend_install.step);

const frontend_build = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "run", "build" });
const frontend_build = b.addSystemCommand(&.{ "npm", "run", "build" });
frontend_build.setCwd(b.path("frontend"));
frontend_build.step.dependOn(&frontend_install.step);
const frontend_step = b.step("frontend-build", "Build the frontend");
frontend_step.dependOn(&frontend_build.step);
Expand Down
6 changes: 4 additions & 2 deletions examples/vue/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ pub fn build(b: *std.Build) void {
linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
b.installArtifact(exe);

const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
const frontend_install = b.addSystemCommand(&.{ "npm", "install" });
frontend_install.setCwd(b.path("frontend"));
const frontend_install_step = b.step("frontend-install", "Install frontend dependencies");
frontend_install_step.dependOn(&frontend_install.step);

const frontend_build = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "run", "build" });
const frontend_build = b.addSystemCommand(&.{ "npm", "run", "build" });
frontend_build.setCwd(b.path("frontend"));
frontend_build.step.dependOn(&frontend_install.step);
const frontend_step = b.step("frontend-build", "Build the frontend");
frontend_step.dependOn(&frontend_build.step);
Expand Down
23 changes: 18 additions & 5 deletions src/tooling/templates.zig
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
\\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
\\ b.installArtifact(exe);
\\
\\ const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
\\ const frontend_install = b.addSystemCommand(&.{ "npm", "install" });
\\ frontend_install.setCwd(b.path("frontend"));
\\ const frontend_install_step = b.step("frontend-install", "Install frontend dependencies");
\\ frontend_install_step.dependOn(&frontend_install.step);
\\
\\ const frontend_build = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "run", "build" });
\\ const frontend_build = b.addSystemCommand(&.{ "npm", "run", "build" });
\\ frontend_build.setCwd(b.path("frontend"));
\\ frontend_build.step.dependOn(&frontend_install.step);
\\ const frontend_step = b.step("frontend-build", "Build the frontend");
\\ frontend_step.dependOn(&frontend_build.step);
Expand Down Expand Up @@ -2004,6 +2006,8 @@ fn appZon(allocator: std.mem.Allocator, names: TemplateNames, frontend: Frontend
try appendZigString(&out, allocator, frontend.devUrl());
try out.appendSlice(allocator,
\\,
// `native dev` runs manifest commands from the app root and does not
// expose a command cwd, so this invocation still needs `--prefix`.
\\ .command = .{ "npm", "--prefix", "frontend", "run", "dev"
);
if (frontend != .next) {
Expand Down Expand Up @@ -2743,7 +2747,8 @@ fn readme(allocator: std.mem.Allocator, names: TemplateNames, framework_path: []
\\`zig build dev`, `zig build run`, and `zig build package` install frontend dependencies automatically. To install them explicitly, run:
\\
\\```sh
\\npm install --prefix frontend
\\cd frontend
\\npm install
\\```
\\
\\The generated build defaults to this Native SDK framework path:
Expand Down Expand Up @@ -2859,18 +2864,26 @@ test "writeDefaultApp emits Vite project files" {
defer std.testing.allocator.free(main_zig_text);
const runner_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/runner.zig");
defer std.testing.allocator.free(runner_zig_text);
const readme_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
defer std.testing.allocator.free(readme_text);
const package_json_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "frontend/package.json");
defer std.testing.allocator.free(package_json_text);
const main_js_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "frontend/src/main.js");
defer std.testing.allocator.free(main_js_text);

try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".frontend") != null);
try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "frontend/dist") != null);
try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "npm") != null);
try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"npm\", \"--prefix\", \"frontend\", \"run\", \"dev\"") != null);
try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".windows") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-install") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"install\", \"--prefix\", \"frontend\"") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"install\"") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_install.setCwd(b.path(\"frontend\"))") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-build") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"run\", \"build\"") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.setCwd(b.path(\"frontend\"))") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "--prefix") == null);
try std.testing.expect(std.mem.indexOf(u8, readme_text, "cd frontend\nnpm install") != null);
try std.testing.expect(std.mem.indexOf(u8, readme_text, "--prefix") == null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dev.step.dependOn(&frontend_install.step)") != null);
Expand Down