Skip to content

Commit a681c06

Browse files
committed
Add package "tools" from rescript-vscode repo
1 parent 94329ca commit a681c06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2295
-1
lines changed

dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(dirs compiler tests analysis)
1+
(dirs compiler tests analysis tools)

dune-project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@
5151
(cppo
5252
(= 1.6.9))
5353
dune))
54+
55+
(package
56+
(name tools)
57+
(synopsis "ReScript Tools")
58+
(depends
59+
(ocaml
60+
(>= 4.10))
61+
(cppo
62+
(= 1.6.9))
63+
analysis
64+
dune))

tools.opam

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is generated by dune, edit dune-project instead
2+
opam-version: "2.0"
3+
synopsis: "ReScript Tools"
4+
maintainer: ["Hongbo Zhang <bobzhang1988@gmail.com>" "Cristiano Calcagno"]
5+
authors: ["Hongbo Zhang <bobzhang1988@gmail.com>"]
6+
license: "LGPL-3.0-or-later"
7+
homepage: "https://github.com/rescript-lang/rescript-compiler"
8+
bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
9+
depends: [
10+
"ocaml" {>= "4.10"}
11+
"cppo" {= "1.6.9"}
12+
"analysis"
13+
"dune"
14+
]
15+
build: [
16+
["dune" "subst"] {pinned}
17+
[
18+
"dune"
19+
"build"
20+
"-p"
21+
name
22+
"-j"
23+
jobs
24+
"@install"
25+
"@runtest" {with-test}
26+
"@doc" {with-doc}
27+
]
28+
]

tools/CHANGELOG.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Changelog
2+
3+
> **Tags:**
4+
>
5+
> - :boom: [Breaking Change]
6+
> - :eyeglasses: [Spec Compliance]
7+
> - :rocket: [New Feature]
8+
> - :bug: [Bug Fix]
9+
> - :memo: [Documentation]
10+
> - :house: [Internal]
11+
> - :nail_care: [Polish]
12+
13+
## master
14+
15+
## 0.6.4
16+
17+
#### :rocket: New Feature
18+
19+
- Add `moduletypeid` field for explicitly annotated module type. https://github.com/rescript-lang/rescript-vscode/pull/1019
20+
21+
### :bug: Bug Fix
22+
23+
- Print module structure with signature to module path. https://github.com/rescript-lang/rescript-vscode/pull/1018
24+
25+
## 0.6.3
26+
27+
#### :bug: Bug Fix
28+
29+
- Make sure Linux binaries are statically linked.
30+
31+
#### :nail_care: Polish
32+
33+
- Reverse order of extracted embeds, so they're in the correct order.
34+
35+
## 0.6.2
36+
37+
#### :rocket: New Feature
38+
39+
- Ship Linux ARM64 binaries.
40+
41+
## 0.6.1
42+
43+
#### :rocket: New Feature
44+
45+
- Expose `getBinaryPath` JS function that you can import to get the binary to call for the current platform.
46+
47+
## 0.6.0
48+
49+
#### :rocket: New Feature
50+
51+
- _internal_ Add experimental command for extracting (string) contents from extension points.
52+
53+
## 0.5.0
54+
55+
#### :rocket: New Feature
56+
57+
- Add `source` property to type, value, module and module alias. https://github.com/rescript-lang/rescript-vscode/pull/900.
58+
59+
#### :bug: Bug Fix
60+
61+
- Print docstrings for nested submodules. https://github.com/rescript-lang/rescript-vscode/pull/897
62+
- Print `deprecated` field for module. https://github.com/rescript-lang/rescript-vscode/pull/897
63+
64+
## 0.4.0
65+
66+
#### :bug: Bug Fix
67+
68+
- Support inline record fields in constructors. https://github.com/rescript-lang/rescript-vscode/pull/889
69+
- Fix docstrings for module alias. Get internal docstrings of module file. https://github.com/rescript-lang/rescript-vscode/pull/878
70+
- Fix extracted docs of types include escaped linebreaks in signature. https://github.com/rescript-lang/rescript-vscode/pull/891
71+
72+
## 0.3.0
73+
74+
#### :rocket: New Feature
75+
76+
- Expose more `decode` functions. https://github.com/rescript-lang/rescript-vscode/pull/866
77+
78+
#### :house: [Internal]
79+
80+
- Add env var `FROM_COMPILER` to extract docstrings from compiler repo. https://github.com/rescript-lang/rescript-vscode/pull/868
81+
82+
#### :bug: Bug Fix
83+
84+
- Fix tagged variant for `Module` and add attr to interface files. https://github.com/rescript-lang/rescript-vscode/pull/866
85+
- Fix `rescript-tools --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873
86+
- Fix output truncate when run `rescript-tools doc path/to/file.res` in a separate process. https://github.com/rescript-lang/rescript-vscode/pull/868

tools/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# ReScript Tools
2+
3+
## Install
4+
5+
```sh
6+
npm install --save-dev @rescript/tools
7+
```
8+
9+
## CLI Usage
10+
11+
```sh
12+
rescript-tools --help
13+
```
14+
15+
### Generate documentation
16+
17+
Print JSON:
18+
19+
```sh
20+
rescript-tools doc src/EntryPointLibFile.res
21+
```
22+
23+
Write JSON:
24+
25+
```sh
26+
rescript-tools doc src/EntryPointLibFile.res > doc.json
27+
```
28+
29+
### Reanalyze
30+
31+
```sh
32+
rescript-tools reanalyze --help
33+
```
34+
35+
## Decode JSON
36+
37+
Add to `bs-dev-dependencies`:
38+
39+
```json
40+
"bs-dev-dependencies": ["@rescript/tools"]
41+
```
42+
43+
```rescript
44+
// Read JSON file and parse with `Js.Json.parseExn`
45+
json->RescriptTools.Docgen.decodeFromJson
46+
```

tools/bin/dune

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(env
2+
(static
3+
(flags
4+
(:standard -ccopt -static))))
5+
6+
(executable
7+
(public_name rescript-tools)
8+
(package tools)
9+
(modes byte exe)
10+
; The main module that will become the binary.
11+
(name main)
12+
(libraries tools)
13+
(flags
14+
(:standard -w "+6+26+27+32+33+39")))

tools/bin/main.ml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
let docHelp =
2+
{|ReScript Tools
3+
4+
Output documentation to standard output
5+
6+
Usage: rescript-tools doc <FILE>
7+
8+
Example: rescript-tools doc ./path/to/EntryPointLib.res|}
9+
10+
let help =
11+
{|ReScript Tools
12+
13+
Usage: rescript-tools [command]
14+
15+
Commands:
16+
17+
doc Generate documentation
18+
reanalyze Reanalyze
19+
-v, --version Print version
20+
-h, --help Print help|}
21+
22+
let logAndExit = function
23+
| Ok log ->
24+
Printf.printf "%s\n" log;
25+
exit 0
26+
| Error log ->
27+
Printf.eprintf "%s\n" log;
28+
exit 1
29+
30+
let version = Version.version
31+
32+
let main () =
33+
match Sys.argv |> Array.to_list |> List.tl with
34+
| "doc" :: rest -> (
35+
match rest with
36+
| ["-h"] | ["--help"] -> logAndExit (Ok docHelp)
37+
| [path] ->
38+
(* NOTE: Internal use to generate docs from compiler *)
39+
let () =
40+
match Sys.getenv_opt "FROM_COMPILER" with
41+
| Some "true" -> Analysis.Cfg.isDocGenFromCompiler := true
42+
| _ -> ()
43+
in
44+
logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false)
45+
| _ -> logAndExit (Error docHelp))
46+
| "reanalyze" :: _ ->
47+
let len = Array.length Sys.argv in
48+
for i = 1 to len - 2 do
49+
Sys.argv.(i) <- Sys.argv.(i + 1)
50+
done;
51+
Sys.argv.(len - 1) <- "";
52+
Reanalyze.cli ()
53+
| "extract-embedded" :: extPointNames :: filename :: _ ->
54+
logAndExit
55+
(Ok
56+
(Tools.extractEmbedded
57+
~extensionPoints:(extPointNames |> String.split_on_char ',')
58+
~filename))
59+
| ["-h"] | ["--help"] -> logAndExit (Ok help)
60+
| ["-v"] | ["--version"] -> logAndExit (Ok version)
61+
| _ -> logAndExit (Error help)
62+
63+
let () = main ()

tools/bin/version.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let version = "0.6.4"

tools/binaries/.gitkeep

Whitespace-only changes.

tools/npm/RescriptTools.res

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Docgen = Tools_Docgen
2+
3+
/** Returns the full file system path to the `rescript-tools` binary for the current platform, side stepping the JS that wraps the CLI.
4+
5+
You can use this when you're already running a JS process and want to avoid the overhead of starting another one.
6+
7+
## Examples
8+
```rescript
9+
// Prints the current ReScript Tools version.
10+
let stringifiedJson = ChildProcess.execFileSync(RescriptTools.getBinaryPath(), ["-v"])
11+
```
12+
*/
13+
@module("./getBinaryPath.js")
14+
external getBinaryPath: unit => string = "getBinaryPath"

0 commit comments

Comments
 (0)