-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_json.ml
107 lines (99 loc) · 3.31 KB
/
package_json.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(**************************************************************************)
(* *)
(* Copyright (c) 2023 John Jackson. *)
(* *)
(* This Source Code Form is subject to the terms of the Mozilla Public *)
(* License, v. 2.0. If a copy of the MPL was not distributed with this *)
(* file, You can obtain one at http://mozilla.org/MPL/2.0/. *)
(* *)
(**************************************************************************)
(** This generates a package.json file with the main JS file path and the
version number. You can then execute npm commands (link, publish, etc.) in
the build context directory. *)
let comma ppf () = Format.fprintf ppf ",@ "
let s = Format.dprintf "%S"
let b = Format.dprintf "%B"
let member ppf (k, v) = Format.fprintf ppf "@[<hv 2>%S:@ %t@]" k v
let o =
Format.dprintf "@[<hv 2>{@;<1 0>%a@;<1 -2>}@]"
(Format.pp_print_list ~pp_sep:comma member)
let a =
Format.dprintf "@[<hv 2>[@;<1 0>%a@;<1 -2>]@]"
(Format.pp_print_list ~pp_sep:comma ( |> ))
module SetString = Set.Make (String)
let version = ref ""
let path = ref ""
let exports = ref [ ("./package.json", s "./package.json") ]
let imports = ref []
let files = ref SetString.empty
let () =
Arg.parse
[
("--version", Set_string version, "Version");
( "--export",
Tuple
[
Set_string path;
String
(fun file ->
files := SetString.add file !files;
exports := (!path, s file) :: !exports);
],
"Subpath export" );
( "--import",
Tuple
[
Set_string path;
String
(fun file ->
files := SetString.add file !files;
imports := (!path, s file) :: !imports);
],
"Internal subpath import" );
]
invalid_arg "Generate the package.json."
let () =
o
[
("name", s "acutis-lang");
("version", s !version);
("private", b false);
("description", s "A simple and type-safe template language");
( "keywords",
a
[
s "template";
s "language";
s "parser";
s "interpreter";
s "eleventy-plugin";
s "eleventy";
s "ocaml";
] );
("homepage", s "https://johnridesa.bike/acutis/");
( "bugs",
o
[
("url", s "https://github.com/johnridesabike/acutis/issues");
("email", s "[email protected]");
] );
( "repository",
o
[
("type", s "git");
("url", s "https://github.com/johnridesabike/acutis.git");
] );
("license", s "MPL-2.0");
( "author",
o
[
("name", s "John Jackson");
("url", s "https://johnridesa.bike/");
("email", s "[email protected]");
] );
("type", s "module");
("exports", o !exports);
("imports", o !imports);
("files", a (SetString.to_seq !files |> Seq.map s |> List.of_seq));
]
Format.std_formatter