Skip to content

Commit 6ddc0dc

Browse files
committed
Complete Phase 87: Developer Experience (cljw new project template)
- Add `cljw new <name>` command: scaffolds deps.edn, src/, test/ with template - Template includes main function, test file with run-tests, and :test alias - Add help text and examples for new command - Phase 87 complete: test cmd (87.1), nREPL macroexpand (87.2), REPL polish (87.3), project template (87.4)
1 parent 98d55e5 commit 6ddc0dc

3 files changed

Lines changed: 129 additions & 10 deletions

File tree

‎.dev/memo.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,23 @@ Java interop policy: Library-driven. Test real libraries as-is (no forking/embed
5959

6060
## Current Task
6161

62-
Phase 87: Developer Experience
63-
87.4: Project template (cljw new my-app)
64-
- Scaffold new project: deps.edn, src/ns.clj, test/ns_test.clj
65-
- Template should follow CW conventions
62+
Phase 88: v0.2.0 Release
63+
88.1: Version bump + CHANGELOG
6664

6765
## Previous Task
6866

69-
87.3: REPL ns-qualified tab completion + special commands (:quit, :help).
70-
87.2: nREPL macroexpand op + cons rendering fix + shutdown panic fix.
71-
87.1: cljw test already implemented.
67+
Phase 87 COMPLETE (Developer Experience).
68+
87.1: cljw test (already existed). 87.2: nREPL macroexpand op. 87.3: REPL polish. 87.4: cljw new.
7269

7370
## Task Queue
7471

7572
```
76-
87.4: Project template (cljw new my-app)
73+
88.1: Version bump + CHANGELOG
74+
88.2: Release notes
75+
88.3: Benchmark record (full history entry)
76+
88.4: Binary audit (no debug symbols, no embedded secrets)
77+
88.5: GitHub Release with pre-built binaries (macOS ARM64 + Linux x86_64)
78+
88.6: Cross-platform smoke test before release
7779
```
7880

7981
## 83E Audit Results & Scope Reduction

‎.dev/roadmap.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Status: DONE / IN-PROGRESS / PENDING / DEFERRED
2525
| 83E | Core All-Zig Migration | 2.5 | DONE (scope-reduced) |
2626
| 84 | Testing Expansion | 2 | DONE |
2727
| 85 | Library Compatibility Expansion | 2 | DONE |
28-
| 87 | Developer Experience | 3 | IN-PROGRESS |
29-
| 88 | v0.2.0 Release | 3 | PENDING |
28+
| 87 | Developer Experience | 3 | DONE |
29+
| 88 | v0.2.0 Release | 3 | IN-PROGRESS |
3030
| 86 | Distribution | 4 | PENDING |
3131
| 89 | Performance Optimization | 4 | PENDING |
3232
| 90 | JIT Expansion | 4 | PENDING |

‎src/main.zig‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn printHelp() void {
6060
\\ cljw -P Resolve deps only
6161
\\ cljw build <file> [-o out] Build standalone binary
6262
\\ cljw test [files...] Run tests
63+
\\ cljw new <name> Create new project
6364
\\
6465
\\deps.edn flags:
6566
\\ -A:alias[:alias...] Apply alias(es) for REPL
@@ -91,6 +92,7 @@ fn printHelp() void {
9192
\\ cljw -X:build my.ns/task Exec function with :build alias
9293
\\ cljw -P Fetch git dependencies
9394
\\ cljw build app.clj -o app Build standalone binary
95+
\\ cljw new my-app Create new project
9496
\\
9597
) catch {};
9698
}
@@ -180,6 +182,12 @@ pub fn main() !void {
180182
return;
181183
}
182184

185+
// Handle `new` subcommand: cljw new <project-name>
186+
if (args.len >= 2 and std.mem.eql(u8, args[1], "new")) {
187+
handleNewCommand(args[2..]);
188+
return;
189+
}
190+
183191
// Parse flags
184192
const CliMode = enum { normal, alias_repl, main_mode, exec_mode, resolve_only, show_path };
185193
var mode: CliMode = .normal;
@@ -1134,6 +1142,115 @@ fn checkTestFailures(result: Value) bool {
11341142
return false;
11351143
}
11361144

1145+
/// Handle `cljw new <project-name>` subcommand.
1146+
/// Creates a new project directory with deps.edn, src/, and test/ scaffolding.
1147+
fn handleNewCommand(new_args: []const [:0]const u8) void {
1148+
const stderr: std.fs.File = .{ .handle = std.posix.STDERR_FILENO };
1149+
const stdout: std.fs.File = .{ .handle = std.posix.STDOUT_FILENO };
1150+
1151+
if (new_args.len == 0) {
1152+
_ = stderr.write("Usage: cljw new <project-name>\n") catch {};
1153+
std.process.exit(1);
1154+
}
1155+
1156+
const project_name = new_args[0];
1157+
1158+
// Validate project name (alphanumeric, hyphens, underscores)
1159+
for (project_name) |c| {
1160+
if (!std.ascii.isAlphanumeric(c) and c != '-' and c != '_' and c != '.') {
1161+
_ = stderr.write("Error: invalid project name (use alphanumeric, hyphens, underscores)\n") catch {};
1162+
std.process.exit(1);
1163+
}
1164+
}
1165+
1166+
// Convert project name to namespace: hyphens -> underscores for dirs/files
1167+
var ns_name_buf: [256]u8 = undefined;
1168+
const ns_name = blk: {
1169+
if (project_name.len > ns_name_buf.len) {
1170+
_ = stderr.write("Error: project name too long\n") catch {};
1171+
std.process.exit(1);
1172+
}
1173+
@memcpy(ns_name_buf[0..project_name.len], project_name);
1174+
// Namespace uses hyphens (Clojure convention), file path uses underscores
1175+
break :blk ns_name_buf[0..project_name.len];
1176+
};
1177+
1178+
var file_name_buf: [256]u8 = undefined;
1179+
const file_name = blk: {
1180+
@memcpy(file_name_buf[0..project_name.len], project_name);
1181+
// Replace hyphens with underscores for file paths
1182+
for (file_name_buf[0..project_name.len]) |*c| {
1183+
if (c.* == '-') c.* = '_';
1184+
}
1185+
break :blk file_name_buf[0..project_name.len];
1186+
};
1187+
1188+
// Create project directory
1189+
std.fs.cwd().makeDir(project_name) catch |e| {
1190+
if (e == error.PathAlreadyExists) {
1191+
_ = stderr.write("Error: directory already exists\n") catch {};
1192+
} else {
1193+
_ = stderr.write("Error creating directory\n") catch {};
1194+
}
1195+
std.process.exit(1);
1196+
};
1197+
1198+
var project_dir = std.fs.cwd().openDir(project_name, .{}) catch {
1199+
_ = stderr.write("Error: cannot open project directory\n") catch {};
1200+
std.process.exit(1);
1201+
};
1202+
defer project_dir.close();
1203+
1204+
// Create subdirectories
1205+
project_dir.makePath("src") catch {};
1206+
project_dir.makePath("test") catch {};
1207+
1208+
// Write deps.edn
1209+
{
1210+
var buf: [1024]u8 = undefined;
1211+
var stream = std.io.fixedBufferStream(&buf);
1212+
const w = stream.writer();
1213+
w.print("{{:paths [\"src\"]\n :deps {{}}\n :aliases\n {{:test {{:extra-paths [\"test\"]}}}}}}\n", .{}) catch {};
1214+
project_dir.writeFile(.{ .sub_path = "deps.edn", .data = stream.getWritten() }) catch {};
1215+
}
1216+
1217+
// Write src/<file_name>.clj
1218+
{
1219+
var path_buf: [512]u8 = undefined;
1220+
var path_stream = std.io.fixedBufferStream(&path_buf);
1221+
path_stream.writer().print("src/{s}.clj", .{file_name}) catch {};
1222+
const src_path = path_stream.getWritten();
1223+
1224+
var buf: [1024]u8 = undefined;
1225+
var stream = std.io.fixedBufferStream(&buf);
1226+
const w = stream.writer();
1227+
w.print("(ns {s})\n\n(defn -main [& args]\n (println \"Hello from {s}!\"))\n", .{ ns_name, ns_name }) catch {};
1228+
project_dir.writeFile(.{ .sub_path = src_path, .data = stream.getWritten() }) catch {};
1229+
}
1230+
1231+
// Write test/<file_name>_test.clj
1232+
{
1233+
var path_buf: [512]u8 = undefined;
1234+
var path_stream = std.io.fixedBufferStream(&path_buf);
1235+
path_stream.writer().print("test/{s}_test.clj", .{file_name}) catch {};
1236+
const test_path = path_stream.getWritten();
1237+
1238+
var buf: [1024]u8 = undefined;
1239+
var stream = std.io.fixedBufferStream(&buf);
1240+
const w = stream.writer();
1241+
w.print("(ns {s}-test\n (:require [clojure.test :refer [deftest is testing run-tests]]\n [{s} :refer :all]))\n\n(deftest greeting-test\n (testing \"main function\"\n (is (= 1 1))))\n\n(run-tests)\n", .{ ns_name, ns_name }) catch {};
1242+
project_dir.writeFile(.{ .sub_path = test_path, .data = stream.getWritten() }) catch {};
1243+
}
1244+
1245+
{
1246+
var msg_buf: [1024]u8 = undefined;
1247+
var msg_stream = std.io.fixedBufferStream(&msg_buf);
1248+
const w = msg_stream.writer();
1249+
w.print("Project '{s}' created!\n\n cd {s}\n cljw -M -m {s} # Run main\n cljw test # Run tests\n cljw # Start REPL\n", .{ project_name, project_name, ns_name }) catch {};
1250+
_ = stdout.write(msg_stream.getWritten()) catch {};
1251+
}
1252+
}
1253+
11371254
/// Recursively collect .clj files from a directory.
11381255
/// str_alloc: arena for path strings (long-lived), list_alloc: for ArrayList backing.
11391256
fn collectTestFiles(str_alloc: Allocator, list_alloc: Allocator, dir_path: []const u8, out: *std.ArrayList([]const u8)) void {

0 commit comments

Comments
 (0)