Skip to content

Commit f4f4ccc

Browse files
authored
Merge pull request #6 from amtrack/feat/js-implementation
feat: rewrite in JavaScript
2 parents d1130cf + ec8c967 commit f4f4ccc

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
.PHONY: lint test
22

3-
lint:
4-
shellcheck *.sh
5-
63
test:
74
bats *.bats

cli.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ setup() {
66

77
@test "single-line" {
88
cat fixtures/single-line.txt | {
9-
run ./cli.sh
9+
run ./cli.js
1010
[ "$status" -eq 0 ]
1111
[ "${lines[0]}" = "debug-one" ]
1212
}
1313
}
1414

1515
@test "single-log" {
1616
cat fixtures/single-log.txt | {
17-
run ./cli.sh
17+
run ./cli.js
1818
[ "$status" -eq 0 ]
1919
[ "${lines[0]}" = "debug-one" ]
2020
}
2121
}
2222

2323
@test "multiple-logs-multiple-lines" {
2424
cat fixtures/multiple-logs-multiple-lines.txt | {
25-
run ./cli.sh
25+
run ./cli.js
2626
[ "$status" -eq 0 ]
2727
[ "${lines[0]}" = "debug-one" ]
2828
[ "${lines[1]}" = "debug-two" ]
@@ -33,7 +33,7 @@ setup() {
3333

3434
@test "full" {
3535
cat fixtures/full.txt | {
36-
run ./cli.sh
36+
run ./cli.js
3737
[ "$status" -eq 0 ]
3838
[ "${lines[0]}" = "debug-one" ]
3939
[ "${lines[1]}" = "debug-two" ]

cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync } from "fs";
4+
import { filterApexLogs } from "./index.js";
5+
6+
const input = readFileSync(0, "utf8");
7+
console.log(filterApexLogs(input));

cli.sh

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

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const regex =
2+
/(.*USER_DEBUG(\|[^\|]*){2}\|)((.|\n)+?)((\n[\d]{2}:[\d]{2}:[\d]{2}\.[\d]{2}|$))/g;
3+
4+
export function filterApexLogs(input) {
5+
let output = "";
6+
let m;
7+
while ((m = regex.exec(input)) !== null) {
8+
if (m[3]) {
9+
output += m[3] + "\n";
10+
}
11+
}
12+
return output;
13+
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
"name": "apex-log-filter",
33
"version": "0.0.0-development",
44
"description": "CLI for filtering USER_DEBUG output from Salesforce Anonymous Apex execution logs",
5-
"main": "",
5+
"main": "index.js",
6+
"type": "module",
67
"scripts": {
7-
"lint": "shellcheck *.sh",
88
"test": "bats *.bats"
99
},
1010
"bin": {
11-
"apex-log-filter": "cli.sh"
11+
"apex-log-filter": "cli.js"
1212
},
1313
"files": [
14-
"cli.sh"
14+
"index.js",
15+
"cli.js"
1516
],
1617
"repository": "amtrack/apex-log-filter",
1718
"author": "Matthias Rolke <[email protected]>",

0 commit comments

Comments
 (0)