Skip to content

Commit ef26110

Browse files
authored
[Bsb] Fix error msg grammar & color (#2715)
1 parent d2e3864 commit ef26110

File tree

1 file changed

+74
-74
lines changed

1 file changed

+74
-74
lines changed

jscomp/bsb/bsb_theme_init.ml

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -26,136 +26,136 @@
2626

2727

2828

29-
let replace s env : string =
30-
Bsb_regex.global_substitute "\\${bsb:\\([-a-zA-Z0-9]+\\)}"
31-
(fun (_s : string) templates ->
32-
match templates with
33-
| key::_ ->
29+
let replace s env : string =
30+
Bsb_regex.global_substitute "\\${bsb:\\([-a-zA-Z0-9]+\\)}"
31+
(fun (_s : string) templates ->
32+
match templates with
33+
| key::_ ->
3434
String_hashtbl.find_exn env key
35-
| _ -> assert false
35+
| _ -> assert false
3636
) s
3737

38-
let (//) = Filename.concat
38+
let (//) = Filename.concat
3939

4040

41-
let run_npm_link cwd name =
42-
Format.fprintf Format.std_formatter
43-
"Symlink bs-platform in %s @." (cwd//name);
44-
if Ext_sys.is_windows_or_cygwin then
45-
begin
46-
let npm_link = "npm link bs-platform" in
47-
let exit_code = Sys.command npm_link in
48-
if exit_code <> 0 then
41+
let run_npm_link cwd name =
42+
Format.fprintf Format.std_formatter
43+
"Symlink bs-platform in %s @." (cwd//name);
44+
if Ext_sys.is_windows_or_cygwin then
45+
begin
46+
let npm_link = "npm link bs-platform" in
47+
let exit_code = Sys.command npm_link in
48+
if exit_code <> 0 then
4949
begin
5050
prerr_endline ("failed to run : " ^ npm_link);
5151
exit exit_code
5252
end
53-
end
54-
else
55-
begin
56-
let (//) = Filename.concat in
53+
end
54+
else
55+
begin
56+
let (//) = Filename.concat in
5757
let node_bin = "node_modules" // ".bin" in
5858
Bsb_build_util.mkp node_bin;
59-
let p = ".." // "bs-platform" // "lib" in
60-
let link a =
61-
Unix.symlink (p//a) (node_bin // a) in
62-
link "bsb" ;
59+
let p = ".." // "bs-platform" // "lib" in
60+
let link a =
61+
Unix.symlink (p//a) (node_bin // a) in
62+
link "bsb" ;
6363
link "bsc" ;
64-
link "bsrefmt";
64+
link "bsrefmt";
6565
Unix.symlink
6666
(Filename.dirname (Filename.dirname Sys.executable_name))
6767
(Filename.concat "node_modules" "bs-platform")
6868
end
69-
let enter_dir cwd x action =
70-
Unix.chdir x ;
71-
match action () with
72-
| exception e -> Unix.chdir cwd ; raise e
73-
| v -> v
69+
let enter_dir cwd x action =
70+
Unix.chdir x ;
71+
match action () with
72+
| exception e -> Unix.chdir cwd ; raise e
73+
| v -> v
7474

7575

76-
let rec process_theme_aux env cwd (x : OCamlRes.Res.node) =
77-
match x with
78-
| File (name,content) ->
76+
let rec process_theme_aux env cwd (x : OCamlRes.Res.node) =
77+
match x with
78+
| File (name,content) ->
7979
Ext_io.write_file (cwd // name) (replace content env)
80-
| Dir (current, nodes) ->
80+
| Dir (current, nodes) ->
8181
Unix.mkdir (cwd//current) 0o777;
8282
List.iter (fun x -> process_theme_aux env (cwd//current) x ) nodes
8383

8484
let list_themes () =
8585
Format.fprintf Format.std_formatter "Available themes: @.";
86-
Bsb_templates.root
86+
Bsb_templates.root
8787
|>
8888
List.iter (fun (x : OCamlRes.Res.node) ->
89-
match x with
90-
| Dir (x, _) ->
91-
Format.fprintf Format.std_formatter "%s@." x
89+
match x with
90+
| Dir (x, _) ->
91+
Format.fprintf Format.std_formatter "%s@." x
9292

9393
| _ -> ()
94-
)
94+
)
9595

96-
(* @raise [Not_found] *)
97-
let process_themes env theme proj_dir (themes : OCamlRes.Res.node list ) =
98-
match List.find (fun (x : OCamlRes.Res.node) ->
99-
match x with
96+
(* @raise [Not_found] *)
97+
let process_themes env theme proj_dir (themes : OCamlRes.Res.node list ) =
98+
match List.find (fun (x : OCamlRes.Res.node) ->
99+
match x with
100100
| Dir (dir, _) -> dir = theme
101-
| File _ -> false
102-
) themes with
103-
| exception Not_found ->
101+
| File _ -> false
102+
) themes with
103+
| exception Not_found ->
104104
list_themes ();
105105
raise (Arg.Bad( "theme " ^ theme ^ " not found") )
106-
| Dir(_theme, nodes ) ->
106+
| Dir(_theme, nodes ) ->
107107
List.iter (fun node -> process_theme_aux env proj_dir node ) nodes
108-
| _ -> assert false
108+
| _ -> assert false
109109

110110
(** TODO: run npm link *)
111-
let init_sample_project ~cwd ~theme name =
112-
let env = String_hashtbl.create 0 in
113-
List.iter (fun (k,v) -> String_hashtbl.add env k v ) [
111+
let init_sample_project ~cwd ~theme name =
112+
let env = String_hashtbl.create 0 in
113+
List.iter (fun (k,v) -> String_hashtbl.add env k v ) [
114114
"proj-version", "0.1.0";
115115
"bs-version", Bs_version.version;
116116
"bsb" , Filename.current_dir_name // "node_modules" // ".bin" // "bsb"
117117
];
118-
let action = fun _ ->
119-
process_themes env theme Filename.current_dir_name Bsb_templates.root;
118+
let action = fun _ ->
119+
process_themes env theme Filename.current_dir_name Bsb_templates.root;
120120
run_npm_link cwd name
121-
in
122-
begin match name with
123-
| "." ->
121+
in
122+
begin match name with
123+
| "." ->
124124
let name = Filename.basename cwd in
125-
if Ext_namespace.is_valid_npm_package_name name then
126-
begin
125+
if Ext_namespace.is_valid_npm_package_name name then
126+
begin
127127
String_hashtbl.add env "name" name;
128128
action ()
129129
end
130-
else
130+
else
131131
begin
132-
Format.fprintf Format.err_formatter
132+
Format.fprintf Format.err_formatter
133133
"@{<error>Invalid package name@} %S.@} The project name must be a valid npm name, thus can't contain upper-case letters, for example."
134134
name ;
135-
exit 2
135+
exit 2
136136
end
137137

138-
| _ ->
139-
if Ext_namespace.is_valid_npm_package_name name
140-
then begin
141-
Format.fprintf Format.std_formatter "Making directory %s@." name;
142-
if Sys.file_exists name then
143-
begin
144-
Format.fprintf Format.err_formatter "%s already existed@." name ;
138+
| _ ->
139+
if Ext_namespace.is_valid_npm_package_name name
140+
then begin
141+
Format.fprintf Format.std_formatter "Making directory %s@." name;
142+
if Sys.file_exists name then
143+
begin
144+
Format.fprintf Format.err_formatter "@{<error>%s already exists@}@." name ;
145145
exit 2
146-
end
146+
end
147147
else
148-
begin
149-
Unix.mkdir name 0o777;
148+
begin
149+
Unix.mkdir name 0o777;
150150
String_hashtbl.add env "name" name;
151151
enter_dir cwd name action
152152
end
153-
end else begin
154-
Format.fprintf Format.err_formatter
153+
end else begin
154+
Format.fprintf Format.err_formatter
155155
"@{<error>Invalid package name@} %S.@} The project name must be a valid npm name, thus can't contain upper-case letters, for example."
156156
name ;
157-
exit 2
158-
end
157+
exit 2
158+
end
159159
end
160160

161161

0 commit comments

Comments
 (0)