|
5 | 5 | @module("path") external dirname: string => string = "dirname" |
6 | 6 | @val external __dirname: string = "__dirname" |
7 | 7 |
|
8 | | -module Buffer = { |
9 | | - type t |
10 | | - |
11 | | - @send external toString: t => string = "toString" |
12 | | -} |
13 | | - |
14 | 8 | type processEnvOptions = {stdio?: string} |
15 | | -type spawnSyncResult = { |
16 | | - stdout: Buffer.t, |
17 | | - stderr: Buffer.t, |
18 | | - status: Js.Null.t<int>, |
19 | | -} |
| 9 | +type spawnSyncResult = {status: Js.Null.t<int>} |
20 | 10 |
|
21 | 11 | @module("child_process") |
22 | 12 | external spawnSync: (string, array<string>, option<processEnvOptions>) => spawnSyncResult = |
@@ -89,9 +79,14 @@ switch args->Belt.List.fromArray { |
89 | 79 | } |
90 | 80 | | list{"-h" | "--help"} => logAndExit(~log=help, ~code=0) |
91 | 81 | | list{"-v" | "--version"} => |
92 | | - switch readFileSync("./package.json")->Js.Json.parseExn->Js.Json.decodeObject { |
| 82 | + let packageJson = join([__dirname, "..", "package.json"]) |
| 83 | + switch readFileSync(packageJson)->Js.Json.parseExn->Js.Json.decodeObject { |
93 | 84 | | None => logAndExit(~log="error: failed to find version in package.json", ~code=1) |
94 | | - | Some(dict) => logAndExit(~log=dict->Js.Dict.unsafeGet("version"), ~code=0) |
| 85 | + | Some(dict) => |
| 86 | + switch dict->Js.Dict.get("version") { |
| 87 | + | Some(version) => logAndExit(~log=version, ~code=0) |
| 88 | + | None => logAndExit(~log="error: failed to find version in package.json", ~code=1) |
| 89 | + } |
95 | 90 | } |
96 | 91 | | _ => logAndExit(~log=help, ~code=1) |
97 | 92 | } |
0 commit comments