Skip to content

Commit

Permalink
Add .ocamlformat
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahbeckford committed Dec 6, 2024
1 parent c45cfa7 commit f308cfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*.java text
*.json text
*.md text
.ocamlformat text

# Declare files that will always have LF line endings on checkout.
*.capnp text eol=lf
Expand Down
24 changes: 20 additions & 4 deletions src/DkStd_Std/Project/Init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ let contents_extensions_json_untrimmed = {|
]
}|}

let contents_ocamlformat_untrimmed = {|
profile=conventional
exp-grouping=preserve
nested-match=align
|}

let () =
Arg.parse speclist anon_fun usage_msg;
if !new_project_dir = "" then Utils.fail "NEW_PROJECT_DIR argument is missing";
Expand All @@ -128,9 +134,9 @@ let () =
(* git init *)
if not (Bos.OS.Dir.exists Fpath.(new_project_dirp / ".git") |> Utils.rmsg) then
Utils.git ~slots ["init"; "--quiet"; "--initial-branch=main"];

(* dk, dk.cmd, __dk.cmake, .gitattributes *)
let copy_if ?mode s =
let copy_if ?mode s =
let src = Fpath.(dkcoder_project_dirp / s) in
let dest = Fpath.(new_project_dirp / s) in
if not (Bos.OS.File.exists dest |> Utils.rmsg) then (
Expand All @@ -149,7 +155,15 @@ let () =
if not (Bos.OS.File.exists gitignore |> Utils.rmsg) then (
Printf.eprintf "dkcoder: create .gitignore\n%!";
Bos.OS.File.write gitignore (String.trim contents_gitignore_untrimmed) |> Utils.rmsg);


(* .ocamlformat *)
let ocamlformat = Fpath.(new_project_dirp / ".ocamlformat") in
if not (Bos.OS.File.exists ocamlformat |> Utils.rmsg) then (
Printf.eprintf "dkcoder: create .ocamlformat\n%!";
(* Use CRLF on Windows since .ocamlformat is ".ocamlformat text" in .gitattributes *)
Out_channel.with_open_text (Fpath.to_string ocamlformat) (fun oc ->
Out_channel.output_string oc (String.trim contents_ocamlformat_untrimmed)));

(* .vscode/ *)
let vscode_dirp = Fpath.(new_project_dirp / ".vscode") in
Bos.OS.Dir.create vscode_dirp |> Utils.rmsg |> ignore;
Expand All @@ -171,7 +185,9 @@ let () =
Out_channel.output_string oc (String.trim contents_settings_json_untrimmed)));

(* git add, git update-index *)
let project_files = ["dk"; "dk.cmd"; "__dk.cmake"; ".gitattributes"; ".gitignore";
let project_files = ["dk"; "dk.cmd"; "__dk.cmake";
".gitattributes"; ".gitignore";
".ocamlformat";
".vscode/settings.json"; ".vscode/extensions.json"] in
Utils.git ~quiet:() ~slots ("add" :: project_files);
Utils.git ~quiet:() ~slots ["update-index"; "--chmod=+x"; "dk"];
Expand Down

0 comments on commit f308cfe

Please sign in to comment.