@@ -11,14 +11,14 @@ let getSourceDirectories ~includeDev ~baseDir config =
1111 | `Assoc _ -> (
1212 let dir =
1313 item |> YojsonHelpers. get " dir"
14- |> bind Yojson.Safe.Util. to_string_option
14+ |> bind YojsonHelpers. string_opt
1515 |> Option. value ~default: " Must specify directory"
1616 in
1717 let typ =
1818 if includeDev then " lib"
1919 else
2020 item |> YojsonHelpers. get " type"
21- |> bind Yojson.Safe.Util. to_string_option
21+ |> bind YojsonHelpers. string_opt
2222 |> Option. value ~default: " lib"
2323 in
2424
@@ -94,22 +94,27 @@ let nameSpaceToName n =
9494 |> List. map String. capitalize_ascii
9595 |> String. concat " "
9696
97+ type namespace_config =
98+ | NamespaceDisabled
99+ | NamespaceFromPackageName
100+ | NamespaceExplicit of string
101+
102+ let getNamespaceConfig config =
103+ match config |> YojsonHelpers. get " namespace" with
104+ | None | Some (`Bool false ) -> NamespaceDisabled
105+ | Some (`Bool true ) -> NamespaceFromPackageName
106+ | Some (`String namespace ) -> NamespaceExplicit namespace
107+ | Some _ -> NamespaceDisabled
108+
97109let getNamespace config =
98- let ns = config |> YojsonHelpers. get " namespace" in
99- let fromString = ns |> bind Yojson.Safe.Util. to_string_option in
100- let isNamespaced =
101- ns
102- |> bind Yojson.Safe.Util. to_bool_option
103- |> Option. value ~default: (fromString |> Option. is_some)
104- in
105- let either x y = if x = None then y else x in
106- if isNamespaced then
110+ match getNamespaceConfig config with
111+ | NamespaceDisabled -> None
112+ | NamespaceExplicit namespace -> Some (nameSpaceToName namespace)
113+ | NamespaceFromPackageName ->
107114 let fromName =
108- config |> YojsonHelpers. get " name"
109- |> bind Yojson.Safe.Util. to_string_option
115+ config |> YojsonHelpers. get " name" |> bind YojsonHelpers. string_opt
110116 in
111- either fromString fromName |> Option. map nameSpaceToName
112- else None
117+ fromName |> Option. map nameSpaceToName
113118
114119module StringSet = Set. Make (String )
115120
@@ -122,9 +127,8 @@ let getPublic config =
122127 | None -> None
123128 | Some public ->
124129 Some
125- (public
126- |> List. filter_map Yojson.Safe.Util. to_string_option
127- |> StringSet. of_list))
130+ (public |> List. filter_map YojsonHelpers. string_opt |> StringSet. of_list)
131+ )
128132
129133let collectFiles directory =
130134 let allFiles = Files. readDirectory directory in
@@ -262,7 +266,7 @@ let findDependencyFiles base config =
262266 with
263267 | None , None -> []
264268 | Some deps , None | _ , Some deps ->
265- deps |> List. filter_map Yojson.Safe.Util. to_string_option
269+ deps |> List. filter_map YojsonHelpers. string_opt
266270 in
267271 let devDeps =
268272 match
@@ -275,7 +279,7 @@ let findDependencyFiles base config =
275279 with
276280 | None , None -> []
277281 | Some devDeps , None | _ , Some devDeps ->
278- devDeps |> List. filter_map ( fun x -> Some ( Yojson.Safe.Util. to_string x))
282+ devDeps |> List. filter_map YojsonHelpers. string_opt
279283 in
280284 let deps = deps @ devDeps in
281285 Log. log (" Dependencies: " ^ String. concat " " deps);
0 commit comments