Skip to content

Commit 397f26b

Browse files
committed
Cleanup stuff
1 parent ad84ca1 commit 397f26b

File tree

20 files changed

+214
-205
lines changed

20 files changed

+214
-205
lines changed

.githooks/pre-push

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if ! ( make format-check ); then
4+
echo "some files are not properly formatted, refusing to push"
5+
exit 1
6+
fi

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
opam-disable-sandboxing: true
6363

6464
- name: Install deps
65-
run: opam install . --deps-only --with-doc --with-test
65+
run: make install
6666

6767
- name: Pin some deps
6868
run: make pin

.npmignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.github
22
.vscode
3-
esy.lock/*
4-
esy.lock
3+
_opam
4+
_build

Makefile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ test-watch: ## Run the unit tests in watch mode
3939
test-promote: ## Updates snapshots and promotes it to correct
4040
$(DUNE) build @runtest --auto-promote
4141

42+
.PHONY: setup-githooks
43+
setup-githooks: ## Setup githooks
44+
git config core.hooksPath .githooks
45+
4246
.PHONY: deps
4347
deps: $(opam_file) ## Alias to update the opam file and install the needed deps
4448

4549
.PHONY: format
4650
format: ## Format the codebase with ocamlformat
47-
$(DUNE) build @fmt --auto-promote
51+
@DUNE_CONFIG__GLOBAL_LOCK=disabled $(DUNE) build @fmt --auto-promote
4852

4953
.PHONY: format-check
5054
format-check: ## Checks if format is correct
51-
$(DUNE) build @fmt
55+
@DUNE_CONFIG__GLOBAL_LOCK=disabled $(DUNE) build @fmt
5256

5357
.PHONY: pin
5458
pin: ## Pin dependencies
@@ -60,15 +64,8 @@ create-switch: ## Create opam switch
6064
opam switch create . 5.1.0 --deps-only --with-test -y
6165

6266
.PHONY: install
63-
install: create-switch pin ## Install dependencies
67+
install:
68+
opam install . --deps-only --with-test --with-doc --with-dev-setup -y
6469

6570
.PHONY: init
66-
init: install ## Create a local dev enviroment
67-
68-
.PHONY: subst
69-
subst: ## Run dune substitute
70-
$(DUNE) subst
71-
72-
$(opam_file): dune-project ## Update the package dependencies when new deps are added to dune-project
73-
$(DUNE) build @install
74-
opam install . --deps-only --with-test # Install the new dependencies
71+
init: setup-githooks create-switch pin install install-npm ## Create a local dev enviroment

dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(dirs bin js source test website)

dune-project

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
(lang dune 3.0)
1+
(lang dune 3.12)
22

33
(using menhir 2.0)
4+
(using melange 0.1)
45

56
(generate_opam_files true)
67

@@ -21,8 +22,8 @@
2122

2223
(package
2324
(name query-json)
24-
(synopsis "Faster, simpler and more portable implementation of `jq` in Reason")
25-
(description "query-json is a faster and simpler re-implementation of jq's language in Reason, compiled to a native binary and as a JavaScript library.
25+
(synopsis "Faster, simpler and more portable implementation of `jq` in OCaml")
26+
(description "query-json is a faster and simpler re-implementation of jq's language in OCaml, compiled to a native binary and as a JavaScript library.
2627
2728
It's a CLI to run small programs against JSON, the same idea as sed but for JSON files.
2829

esy.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

js/Js.re renamed to js/Js.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
[@warning "-32"]
21
let run = QueryJsonJs.run;

js/Js.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val run : string -> string -> (string, string) result

query-json-js.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bug-reports: "https://github.com/davesnx/query-json/issues"
1717
depends: [
1818
"ocaml"
1919
"reason"
20-
"dune" {>= "3.0"}
20+
"dune" {>= "3.12"}
2121
"yojson"
2222
"cmdliner"
2323
"js_of_ocaml"

query-json-web.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ license: "MIT"
1515
homepage: "https://github.com/davesnx/query-json"
1616
bug-reports: "https://github.com/davesnx/query-json/issues"
1717
depends: [
18-
"dune" {>= "3.0"}
18+
"dune" {>= "3.12"}
1919
"ocaml"
2020
"reason"
2121
"js_of_ocaml"

query-json.opam

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# This file is generated by dune, edit dune-project instead
22
opam-version: "2.0"
33
version: "0.5.10"
4-
synopsis:
5-
"Faster, simpler and more portable implementation of `jq` in Reason"
4+
synopsis: "Faster, simpler and more portable implementation of `jq` in OCaml"
65
description: """
7-
query-json is a faster and simpler re-implementation of jq's language in Reason, compiled to a native binary and as a JavaScript library.
6+
query-json is a faster and simpler re-implementation of jq's language in OCaml, compiled to a native binary and as a JavaScript library.
87

98
It's a CLI to run small programs against JSON, the same idea as sed but for JSON files.
109

@@ -17,7 +16,7 @@ bug-reports: "https://github.com/davesnx/query-json/issues"
1716
depends: [
1817
"ocaml"
1918
"reason"
20-
"dune" {>= "3.0"}
19+
"dune" {>= "3.12"}
2120
"menhir"
2221
"cmdliner"
2322
"yojson"

source/Chalk.re

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
let bold = Printf.sprintf("\x1b[1m%s\x1b[0m");
2+
let underline = Printf.sprintf("\x1b[4m%s\x1b[0m");
3+
let invert = Printf.sprintf("\x1b[7m%s\x1b[0m");
4+
5+
let red = Printf.sprintf("\x1b[31m%s\x1b[39m");
6+
let green = Printf.sprintf("\x1b[32m%s\x1b[39m");
7+
let yellow = Printf.sprintf("\x1b[33m%s\x1b[39m");
8+
let blue = Printf.sprintf("\x1b[34m%s\x1b[39m");
9+
let magenta = Printf.sprintf("\x1b[35m%s\x1b[39m");
10+
let cyan = Printf.sprintf("\x1b[36m%s\x1b[39m");
11+
let gray = Printf.sprintf("\x1b[90m%s\x1b[39m");
12+
let white = Printf.sprintf("\x1b[97m%s\x1b[39m");
13+
14+
let light_gray = Printf.sprintf("\x1b[37m%s\x1b[39m");
15+
let light_red = Printf.sprintf("\x1b[91m%s\x1b[39m");
16+
let light_green = Printf.sprintf("\x1b[92m%s\x1b[39m");
17+
let light_yellow = Printf.sprintf("\x1b[93m%s\x1b[39m");
18+
let light_blue = Printf.sprintf("\x1b[94m%s\x1b[39m");
19+
let light_magenta = Printf.sprintf("\x1b[95m%s\x1b[39m");
20+
let light_cyan = Printf.sprintf("\x1b[96m%s\x1b[39m");
21+
22+
let bg_red = Printf.sprintf("\x1b[41m%s\x1b[49m");
23+
let bg_green = Printf.sprintf("\x1b[42m%s\x1b[49m");
24+
let bg_yellow = Printf.sprintf("\x1b[43m%s\x1b[49m");
25+
let bg_blue = Printf.sprintf("\x1b[44m%s\x1b[49m");
26+
let bg_magenta = Printf.sprintf("\x1b[45m%s\x1b[49m");
27+
let bg_cyan = Printf.sprintf("\x1b[46m%s\x1b[49m");
28+
let bg_gray = Printf.sprintf("\x1b[100m%s\x1b[49m");
29+
let bg_white = Printf.sprintf("\x1b[107m%s\x1b[49m");
30+
31+
let bg_light_gray = Printf.sprintf("\x1b[47m%s\x1b[49m");
32+
let bg_light_red = Printf.sprintf("\x1b[101m%s\x1b[49m");
33+
let bg_light_green = Printf.sprintf("\x1b[102m%s\x1b[49m");
34+
let bg_light_yellow = Printf.sprintf("\x1b[103m%s\x1b[49m");
35+
let bg_light_blue = Printf.sprintf("\x1b[104m%s\x1b[49m");
36+
let bg_light_magenta = Printf.sprintf("\x1b[105m%s\x1b[49m");
37+
let bg_light_cyan = Printf.sprintf("\x1b[106m%s\x1b[49m");

source/Compiler.re

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
open Ast;
2-
open Console;
32

43
let appendArticle = (noun: string) => {
54
let starts_with_any = (str: string, chars: list(string)) => {
@@ -22,13 +21,15 @@ let appendArticle = (noun: string) => {
2221
};
2322

2423
let makeErrorWrongOperation = (op, memberKind, value: Json.t) => {
25-
"Trying to "
26-
++ Formatting.singleQuotes(Chalk.bold(op))
27-
++ " on "
28-
++ (appendArticle(memberKind) |> Chalk.bold)
29-
++ ":"
30-
++ Formatting.enter(1)
31-
++ Chalk.gray(Json.toString(value, ~colorize=false, ~summarize=true));
24+
Console.(
25+
"Trying to "
26+
++ Formatting.singleQuotes(Chalk.bold(op))
27+
++ " on "
28+
++ (appendArticle(memberKind) |> Chalk.bold)
29+
++ ":"
30+
++ Formatting.enter(1)
31+
++ Chalk.gray(Json.toString(value, ~colorize=false, ~summarize=true))
32+
);
3233
};
3334

3435
let getFieldName = json => {
@@ -165,19 +166,23 @@ let filter = (fn: Json.t => bool, json: Json.t) => {
165166
};
166167

167168
let makeEmptyListError = op => {
168-
"Trying to "
169-
++ Formatting.singleQuotes(Chalk.bold(op))
170-
++ " on an empty array.";
169+
Console.(
170+
"Trying to "
171+
++ Formatting.singleQuotes(Chalk.bold(op))
172+
++ " on an empty array."
173+
);
171174
};
172175

173176
let makeAcessingToMissingItem = (accessIndex, length) => {
174-
"Trying to read "
175-
++ Formatting.singleQuotes(
176-
"[" ++ Chalk.bold(string_of_int(accessIndex)) ++ "]",
177-
)
178-
++ " from an array with "
179-
++ string_of_int(length)
180-
++ " elements only.";
177+
Console.(
178+
"Trying to read "
179+
++ Formatting.singleQuotes(
180+
"[" ++ Chalk.bold(string_of_int(accessIndex)) ++ "]",
181+
)
182+
++ " from an array with "
183+
++ string_of_int(length)
184+
++ " elements only."
185+
);
181186
};
182187

183188
let head = (json: Json.t) => {
@@ -205,13 +210,15 @@ let tail = (json: Json.t) => {
205210
};
206211

207212
let makeErrorMissingMember = (op, key, value: Json.t) => {
208-
"Trying to "
209-
++ Formatting.doubleQuotes(Chalk.bold(op))
210-
++ " on an object, that don't have the field "
211-
++ Formatting.doubleQuotes(key)
212-
++ ":"
213-
++ Formatting.enter(1)
214-
++ Chalk.gray(Json.toString(value, ~colorize=false, ~summarize=true));
213+
Console.(
214+
"Trying to "
215+
++ Formatting.doubleQuotes(Chalk.bold(op))
216+
++ " on an object, that don't have the field "
217+
++ Formatting.doubleQuotes(key)
218+
++ ":"
219+
++ Formatting.enter(1)
220+
++ Chalk.gray(Json.toString(value, ~colorize=false, ~summarize=true))
221+
);
215222
};
216223

217224
let member = (key: string, opt: bool, json: Json.t) => {

source/Console.re

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
module Chalk = {
2-
let bold = Printf.sprintf("\x1b[1m%s\x1b[0m");
3-
let underline = Printf.sprintf("\x1b[4m%s\x1b[0m");
4-
let invert = Printf.sprintf("\x1b[7m%s\x1b[0m");
5-
6-
let red = Printf.sprintf("\x1b[31m%s\x1b[39m");
7-
let green = Printf.sprintf("\x1b[32m%s\x1b[39m");
8-
let yellow = Printf.sprintf("\x1b[33m%s\x1b[39m");
9-
let blue = Printf.sprintf("\x1b[34m%s\x1b[39m");
10-
let magenta = Printf.sprintf("\x1b[35m%s\x1b[39m");
11-
let cyan = Printf.sprintf("\x1b[36m%s\x1b[39m");
12-
let gray = Printf.sprintf("\x1b[90m%s\x1b[39m");
13-
let white = Printf.sprintf("\x1b[97m%s\x1b[39m");
14-
15-
let light_gray = Printf.sprintf("\x1b[37m%s\x1b[39m");
16-
let light_red = Printf.sprintf("\x1b[91m%s\x1b[39m");
17-
let light_green = Printf.sprintf("\x1b[92m%s\x1b[39m");
18-
let light_yellow = Printf.sprintf("\x1b[93m%s\x1b[39m");
19-
let light_blue = Printf.sprintf("\x1b[94m%s\x1b[39m");
20-
let light_magenta = Printf.sprintf("\x1b[95m%s\x1b[39m");
21-
let light_cyan = Printf.sprintf("\x1b[96m%s\x1b[39m");
22-
23-
let bg_red = Printf.sprintf("\x1b[41m%s\x1b[49m");
24-
let bg_green = Printf.sprintf("\x1b[42m%s\x1b[49m");
25-
let bg_yellow = Printf.sprintf("\x1b[43m%s\x1b[49m");
26-
let bg_blue = Printf.sprintf("\x1b[44m%s\x1b[49m");
27-
let bg_magenta = Printf.sprintf("\x1b[45m%s\x1b[49m");
28-
let bg_cyan = Printf.sprintf("\x1b[46m%s\x1b[49m");
29-
let bg_gray = Printf.sprintf("\x1b[100m%s\x1b[49m");
30-
let bg_white = Printf.sprintf("\x1b[107m%s\x1b[49m");
31-
32-
let bg_light_gray = Printf.sprintf("\x1b[47m%s\x1b[49m");
33-
let bg_light_red = Printf.sprintf("\x1b[101m%s\x1b[49m");
34-
let bg_light_green = Printf.sprintf("\x1b[102m%s\x1b[49m");
35-
let bg_light_yellow = Printf.sprintf("\x1b[103m%s\x1b[49m");
36-
let bg_light_blue = Printf.sprintf("\x1b[104m%s\x1b[49m");
37-
let bg_light_magenta = Printf.sprintf("\x1b[105m%s\x1b[49m");
38-
let bg_light_cyan = Printf.sprintf("\x1b[106m%s\x1b[49m");
39-
};
40-
411
module Formatting = {
422
let indent = n => String.make(n * 2, ' ');
433
let enter = n => String.make(n, '\n');
@@ -96,8 +56,10 @@ module Errors = {
9656
++ " is not valid in q, use "
9757
++ Formatting.singleQuotes(name)
9858
++ " instead";
59+
9960
let notImplemented = f =>
10061
Formatting.singleQuotes(f) ++ " is not implemented";
62+
10163
let missing = f =>
10264
Formatting.singleQuotes(f)
10365
++ " looks like a function and maybe is not implemented or missing in the parser. Either way, could you open an issue 'https://github.com/davesnx/query-json/issues/new'";

0 commit comments

Comments
 (0)