mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 22:16:08 +00:00
WIP
This commit is contained in:
parent
4025145867
commit
6eee94e3e5
@ -55,7 +55,11 @@ pub fn build(b: *std.Build) !void {
|
||||
const zmpl_module = zmpl_dep.module("zmpl");
|
||||
|
||||
const jetkv_dep = b.dependency("jetkv", .{ .target = target, .optimize = optimize });
|
||||
const jetquery_dep = b.dependency("jetquery", .{ .target = target, .optimize = optimize });
|
||||
const jetquery_dep = b.dependency("jetquery", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.jetquery_migrations_path = @as([]const u8, "src/app/database/migrations"),
|
||||
});
|
||||
const zmd_dep = b.dependency("zmd", .{ .target = target, .optimize = optimize });
|
||||
const httpz_dep = b.dependency("httpz", .{ .target = target, .optimize = optimize });
|
||||
const pg_dep = b.dependency("pg", .{ .target = target, .optimize = optimize });
|
||||
|
@ -22,8 +22,9 @@
|
||||
.hash = "1220411a8c46d95bbf3b6e2059854bcb3c5159d428814099df5294232b9980517e9c",
|
||||
},
|
||||
.pg = .{
|
||||
.url = "https://github.com/karlseguin/pg.zig/archive/1b4011d4c8218c70471477e283608daf919bee3a.tar.gz",
|
||||
.hash = "122086d9461b75535b630019374f8a068eff467e657a46d2bb577fe0a507f1cd2fca",
|
||||
// .url = "https://github.com/karlseguin/pg.zig/archive/1491270ac43c7eba91992bb06b3758254c36e39a.tar.gz",
|
||||
// .hash = "1220bcc68967188de7ad5d520a4629c0d1e169c111d87e6978a3c128de5ec2b6bdd0",
|
||||
.path = "../pg.zig",
|
||||
},
|
||||
.smtp_client = .{
|
||||
.url = "https://github.com/karlseguin/smtp_client.zig/archive/8fcfad9ca2d9e446612c79f4e54050cfbe81b38d.tar.gz",
|
||||
|
@ -14,6 +14,12 @@ pub fn build(b: *std.Build) !void {
|
||||
});
|
||||
|
||||
const zig_args_dep = b.dependency("args", .{ .target = target, .optimize = optimize });
|
||||
const jetquery_dep = b.dependency("jetquery", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.jetquery_migrations_path = @as([]const u8, "src/app/database/migrations"),
|
||||
});
|
||||
exe.root_module.addImport("jetquery", jetquery_dep.module("jetquery"));
|
||||
|
||||
exe.root_module.addImport("args", zig_args_dep.module("args"));
|
||||
exe.root_module.addImport(
|
||||
|
@ -8,6 +8,9 @@
|
||||
.url = "https://github.com/ikskuh/zig-args/archive/0abdd6947a70e6d8cc83b66228cea614aa856206.tar.gz",
|
||||
.hash = "1220411a8c46d95bbf3b6e2059854bcb3c5159d428814099df5294232b9980517e9c",
|
||||
},
|
||||
.jetquery = .{
|
||||
.path = "../../jetquery",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"",
|
||||
|
@ -9,11 +9,12 @@ const layout = @import("generate/layout.zig");
|
||||
const middleware = @import("generate/middleware.zig");
|
||||
const job = @import("generate/job.zig");
|
||||
const mailer = @import("generate/mailer.zig");
|
||||
const migration = @import("generate/migration.zig");
|
||||
|
||||
/// Command line options for the `generate` command.
|
||||
pub const Options = struct {
|
||||
pub const meta = .{
|
||||
.usage_summary = "[view|partial|layout|mailer|middleware|job|secret] [options]",
|
||||
.usage_summary = "[view|partial|layout|mailer|middleware|job|secret|migration] [options]",
|
||||
.full_text =
|
||||
\\Generate scaffolding for views, middleware, and other objects.
|
||||
\\
|
||||
@ -38,7 +39,7 @@ pub fn run(
|
||||
|
||||
_ = options;
|
||||
|
||||
const Generator = enum { view, partial, layout, mailer, middleware, job, secret };
|
||||
const Generator = enum { view, partial, layout, mailer, middleware, job, secret, migration };
|
||||
var sub_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer sub_args.deinit();
|
||||
|
||||
@ -55,6 +56,7 @@ pub fn run(
|
||||
.{ "mailer", .mailer },
|
||||
.{ "middleware", .middleware },
|
||||
.{ "secret", .secret },
|
||||
.{ "migration", .migration },
|
||||
});
|
||||
for (inner_map.kvs) |kv| try available_buf.append(kv.key);
|
||||
break :blk inner_map;
|
||||
@ -67,6 +69,7 @@ pub fn run(
|
||||
.{ "mailer", .mailer },
|
||||
.{ "middleware", .middleware },
|
||||
.{ "secret", .secret },
|
||||
.{ "migration", .migration },
|
||||
});
|
||||
for (inner_map.keys()) |key| try available_buf.append(key);
|
||||
break :blk inner_map;
|
||||
@ -75,6 +78,10 @@ pub fn run(
|
||||
const available_help = try std.mem.join(allocator, "|", available_buf.items);
|
||||
defer allocator.free(available_help);
|
||||
|
||||
var arena_allocator = std.heap.ArenaAllocator.init(allocator);
|
||||
defer arena_allocator.deinit();
|
||||
const arena = arena_allocator.allocator();
|
||||
|
||||
const generate_type: ?Generator = if (positionals.len > 0) map.get(positionals[0]) else null;
|
||||
|
||||
if (positionals.len > 1) {
|
||||
@ -91,13 +98,14 @@ pub fn run(
|
||||
|
||||
if (generate_type) |capture| {
|
||||
return switch (capture) {
|
||||
.view => view.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.partial => partial.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.layout => layout.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.mailer => mailer.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.job => job.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.middleware => middleware.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.secret => secret.run(allocator, cwd, sub_args.items, other_options.help),
|
||||
.view => view.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.partial => partial.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.layout => layout.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.mailer => mailer.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.job => job.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.middleware => middleware.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.secret => secret.run(arena, cwd, sub_args.items, other_options.help),
|
||||
.migration => migration.run(arena, cwd, sub_args.items, other_options.help),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
34
cli/commands/generate/migration.zig
Normal file
34
cli/commands/generate/migration.zig
Normal file
@ -0,0 +1,34 @@
|
||||
const std = @import("std");
|
||||
|
||||
const jetquery = @import("jetquery");
|
||||
|
||||
/// Run the migration generator. Create a migration in `src/app/database/migrations/`
|
||||
pub fn run(allocator: std.mem.Allocator, cwd: std.fs.Dir, args: [][]const u8, help: bool) !void {
|
||||
if (help or args.len != 1) {
|
||||
std.debug.print(
|
||||
\\Generate a new Migration. Migrations modify the application's database schema.
|
||||
\\
|
||||
\\Example:
|
||||
\\
|
||||
\\ jetzig generate migration create_iguanas
|
||||
\\
|
||||
, .{});
|
||||
|
||||
if (help) return;
|
||||
|
||||
return error.JetzigCommandError;
|
||||
}
|
||||
|
||||
const name = args[0];
|
||||
|
||||
const migrations_dir = try cwd.makeOpenPath(
|
||||
try std.fs.path.join(allocator, &.{ "src", "app", "database", "migrations" }),
|
||||
.{},
|
||||
);
|
||||
const migration = jetquery.Migration.init(
|
||||
allocator,
|
||||
name,
|
||||
.{ .migrations_path = try migrations_dir.realpathAlloc(allocator, ".") },
|
||||
);
|
||||
try migration.save();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
const jetquery = @import("jetquery");
|
||||
|
||||
pub fn up(repo: *jetquery.Repo) !void {
|
||||
_ = repo;
|
||||
}
|
||||
|
||||
pub fn down(repo: *jetquery.Repo) !void {
|
||||
_ = repo;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user