webpipe-js 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -15
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +47 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,9 @@ var Parser = class {
|
|
|
73
73
|
while (i < this.text.length && this.text[i] !== "\n") i++;
|
|
74
74
|
return i;
|
|
75
75
|
}
|
|
76
|
+
getLineNumber(pos) {
|
|
77
|
+
return this.text.slice(0, pos).split("\n").length;
|
|
78
|
+
}
|
|
76
79
|
parseProgram() {
|
|
77
80
|
this.skipSpaces();
|
|
78
81
|
const configs = [];
|
|
@@ -86,26 +89,31 @@ var Parser = class {
|
|
|
86
89
|
const start = this.pos;
|
|
87
90
|
const cfg = this.tryParse(() => this.parseConfig());
|
|
88
91
|
if (cfg) {
|
|
92
|
+
cfg.lineNumber = this.getLineNumber(start);
|
|
89
93
|
configs.push(cfg);
|
|
90
94
|
continue;
|
|
91
95
|
}
|
|
92
96
|
const namedPipe = this.tryParse(() => this.parseNamedPipeline());
|
|
93
97
|
if (namedPipe) {
|
|
98
|
+
namedPipe.lineNumber = this.getLineNumber(start);
|
|
94
99
|
pipelines.push(namedPipe);
|
|
95
100
|
continue;
|
|
96
101
|
}
|
|
97
102
|
const variable = this.tryParse(() => this.parseVariable());
|
|
98
103
|
if (variable) {
|
|
104
|
+
variable.lineNumber = this.getLineNumber(start);
|
|
99
105
|
variables.push(variable);
|
|
100
106
|
continue;
|
|
101
107
|
}
|
|
102
108
|
const route = this.tryParse(() => this.parseRoute());
|
|
103
109
|
if (route) {
|
|
110
|
+
route.lineNumber = this.getLineNumber(start);
|
|
104
111
|
routes.push(route);
|
|
105
112
|
continue;
|
|
106
113
|
}
|
|
107
114
|
const describe = this.tryParse(() => this.parseDescribe());
|
|
108
115
|
if (describe) {
|
|
116
|
+
describe.lineNumber = this.getLineNumber(start);
|
|
109
117
|
describes.push(describe);
|
|
110
118
|
continue;
|
|
111
119
|
}
|
|
@@ -659,28 +667,52 @@ function printDescribe(describe) {
|
|
|
659
667
|
}
|
|
660
668
|
function prettyPrint(program) {
|
|
661
669
|
const lines = [];
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
lines.push("");
|
|
667
|
-
});
|
|
668
|
-
}
|
|
670
|
+
const allItems = [];
|
|
671
|
+
program.configs.forEach((config) => {
|
|
672
|
+
allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
|
|
673
|
+
});
|
|
669
674
|
program.routes.forEach((route) => {
|
|
670
|
-
|
|
671
|
-
lines.push("");
|
|
675
|
+
allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
|
|
672
676
|
});
|
|
673
677
|
program.pipelines.forEach((pipeline) => {
|
|
674
|
-
|
|
675
|
-
lines.push("");
|
|
678
|
+
allItems.push({ type: "pipeline", item: pipeline, lineNumber: pipeline.lineNumber || 0 });
|
|
676
679
|
});
|
|
677
680
|
program.variables.forEach((variable) => {
|
|
678
|
-
|
|
681
|
+
allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
|
|
679
682
|
});
|
|
680
|
-
if (program.variables.length > 0) lines.push("");
|
|
681
683
|
program.describes.forEach((describe) => {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
+
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
685
|
+
});
|
|
686
|
+
allItems.sort((a, b) => a.lineNumber - b.lineNumber);
|
|
687
|
+
let hasConfigs = false;
|
|
688
|
+
allItems.forEach((entry, index) => {
|
|
689
|
+
if (entry.type === "config" && !hasConfigs) {
|
|
690
|
+
lines.push("## Config");
|
|
691
|
+
hasConfigs = true;
|
|
692
|
+
}
|
|
693
|
+
switch (entry.type) {
|
|
694
|
+
case "config":
|
|
695
|
+
lines.push(printConfig(entry.item));
|
|
696
|
+
lines.push("");
|
|
697
|
+
break;
|
|
698
|
+
case "route":
|
|
699
|
+
lines.push(printRoute(entry.item));
|
|
700
|
+
lines.push("");
|
|
701
|
+
break;
|
|
702
|
+
case "pipeline":
|
|
703
|
+
lines.push(printPipeline(entry.item));
|
|
704
|
+
lines.push("");
|
|
705
|
+
break;
|
|
706
|
+
case "variable":
|
|
707
|
+
lines.push(printVariable(entry.item));
|
|
708
|
+
const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
|
|
709
|
+
if (nextNonVariable) lines.push("");
|
|
710
|
+
break;
|
|
711
|
+
case "describe":
|
|
712
|
+
lines.push(printDescribe(entry.item));
|
|
713
|
+
lines.push("");
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
684
716
|
});
|
|
685
717
|
return lines.join("\n").trim();
|
|
686
718
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ interface Program {
|
|
|
8
8
|
interface Config {
|
|
9
9
|
name: string;
|
|
10
10
|
properties: ConfigProperty[];
|
|
11
|
+
lineNumber?: number;
|
|
11
12
|
}
|
|
12
13
|
interface ConfigProperty {
|
|
13
14
|
key: string;
|
|
@@ -30,16 +31,19 @@ type ConfigValue = {
|
|
|
30
31
|
interface NamedPipeline {
|
|
31
32
|
name: string;
|
|
32
33
|
pipeline: Pipeline;
|
|
34
|
+
lineNumber?: number;
|
|
33
35
|
}
|
|
34
36
|
interface Variable {
|
|
35
37
|
varType: string;
|
|
36
38
|
name: string;
|
|
37
39
|
value: string;
|
|
40
|
+
lineNumber?: number;
|
|
38
41
|
}
|
|
39
42
|
interface Route {
|
|
40
43
|
method: string;
|
|
41
44
|
path: string;
|
|
42
45
|
pipeline: PipelineRef;
|
|
46
|
+
lineNumber?: number;
|
|
43
47
|
}
|
|
44
48
|
type PipelineRef = {
|
|
45
49
|
kind: 'Inline';
|
|
@@ -78,6 +82,7 @@ interface Describe {
|
|
|
78
82
|
name: string;
|
|
79
83
|
mocks: Mock[];
|
|
80
84
|
tests: It[];
|
|
85
|
+
lineNumber?: number;
|
|
81
86
|
}
|
|
82
87
|
interface Mock {
|
|
83
88
|
target: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface Program {
|
|
|
8
8
|
interface Config {
|
|
9
9
|
name: string;
|
|
10
10
|
properties: ConfigProperty[];
|
|
11
|
+
lineNumber?: number;
|
|
11
12
|
}
|
|
12
13
|
interface ConfigProperty {
|
|
13
14
|
key: string;
|
|
@@ -30,16 +31,19 @@ type ConfigValue = {
|
|
|
30
31
|
interface NamedPipeline {
|
|
31
32
|
name: string;
|
|
32
33
|
pipeline: Pipeline;
|
|
34
|
+
lineNumber?: number;
|
|
33
35
|
}
|
|
34
36
|
interface Variable {
|
|
35
37
|
varType: string;
|
|
36
38
|
name: string;
|
|
37
39
|
value: string;
|
|
40
|
+
lineNumber?: number;
|
|
38
41
|
}
|
|
39
42
|
interface Route {
|
|
40
43
|
method: string;
|
|
41
44
|
path: string;
|
|
42
45
|
pipeline: PipelineRef;
|
|
46
|
+
lineNumber?: number;
|
|
43
47
|
}
|
|
44
48
|
type PipelineRef = {
|
|
45
49
|
kind: 'Inline';
|
|
@@ -78,6 +82,7 @@ interface Describe {
|
|
|
78
82
|
name: string;
|
|
79
83
|
mocks: Mock[];
|
|
80
84
|
tests: It[];
|
|
85
|
+
lineNumber?: number;
|
|
81
86
|
}
|
|
82
87
|
interface Mock {
|
|
83
88
|
target: string;
|
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,9 @@ var Parser = class {
|
|
|
30
30
|
while (i < this.text.length && this.text[i] !== "\n") i++;
|
|
31
31
|
return i;
|
|
32
32
|
}
|
|
33
|
+
getLineNumber(pos) {
|
|
34
|
+
return this.text.slice(0, pos).split("\n").length;
|
|
35
|
+
}
|
|
33
36
|
parseProgram() {
|
|
34
37
|
this.skipSpaces();
|
|
35
38
|
const configs = [];
|
|
@@ -43,26 +46,31 @@ var Parser = class {
|
|
|
43
46
|
const start = this.pos;
|
|
44
47
|
const cfg = this.tryParse(() => this.parseConfig());
|
|
45
48
|
if (cfg) {
|
|
49
|
+
cfg.lineNumber = this.getLineNumber(start);
|
|
46
50
|
configs.push(cfg);
|
|
47
51
|
continue;
|
|
48
52
|
}
|
|
49
53
|
const namedPipe = this.tryParse(() => this.parseNamedPipeline());
|
|
50
54
|
if (namedPipe) {
|
|
55
|
+
namedPipe.lineNumber = this.getLineNumber(start);
|
|
51
56
|
pipelines.push(namedPipe);
|
|
52
57
|
continue;
|
|
53
58
|
}
|
|
54
59
|
const variable = this.tryParse(() => this.parseVariable());
|
|
55
60
|
if (variable) {
|
|
61
|
+
variable.lineNumber = this.getLineNumber(start);
|
|
56
62
|
variables.push(variable);
|
|
57
63
|
continue;
|
|
58
64
|
}
|
|
59
65
|
const route = this.tryParse(() => this.parseRoute());
|
|
60
66
|
if (route) {
|
|
67
|
+
route.lineNumber = this.getLineNumber(start);
|
|
61
68
|
routes.push(route);
|
|
62
69
|
continue;
|
|
63
70
|
}
|
|
64
71
|
const describe = this.tryParse(() => this.parseDescribe());
|
|
65
72
|
if (describe) {
|
|
73
|
+
describe.lineNumber = this.getLineNumber(start);
|
|
66
74
|
describes.push(describe);
|
|
67
75
|
continue;
|
|
68
76
|
}
|
|
@@ -616,28 +624,52 @@ function printDescribe(describe) {
|
|
|
616
624
|
}
|
|
617
625
|
function prettyPrint(program) {
|
|
618
626
|
const lines = [];
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
lines.push("");
|
|
624
|
-
});
|
|
625
|
-
}
|
|
627
|
+
const allItems = [];
|
|
628
|
+
program.configs.forEach((config) => {
|
|
629
|
+
allItems.push({ type: "config", item: config, lineNumber: config.lineNumber || 0 });
|
|
630
|
+
});
|
|
626
631
|
program.routes.forEach((route) => {
|
|
627
|
-
|
|
628
|
-
lines.push("");
|
|
632
|
+
allItems.push({ type: "route", item: route, lineNumber: route.lineNumber || 0 });
|
|
629
633
|
});
|
|
630
634
|
program.pipelines.forEach((pipeline) => {
|
|
631
|
-
|
|
632
|
-
lines.push("");
|
|
635
|
+
allItems.push({ type: "pipeline", item: pipeline, lineNumber: pipeline.lineNumber || 0 });
|
|
633
636
|
});
|
|
634
637
|
program.variables.forEach((variable) => {
|
|
635
|
-
|
|
638
|
+
allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
|
|
636
639
|
});
|
|
637
|
-
if (program.variables.length > 0) lines.push("");
|
|
638
640
|
program.describes.forEach((describe) => {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
+
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
642
|
+
});
|
|
643
|
+
allItems.sort((a, b) => a.lineNumber - b.lineNumber);
|
|
644
|
+
let hasConfigs = false;
|
|
645
|
+
allItems.forEach((entry, index) => {
|
|
646
|
+
if (entry.type === "config" && !hasConfigs) {
|
|
647
|
+
lines.push("## Config");
|
|
648
|
+
hasConfigs = true;
|
|
649
|
+
}
|
|
650
|
+
switch (entry.type) {
|
|
651
|
+
case "config":
|
|
652
|
+
lines.push(printConfig(entry.item));
|
|
653
|
+
lines.push("");
|
|
654
|
+
break;
|
|
655
|
+
case "route":
|
|
656
|
+
lines.push(printRoute(entry.item));
|
|
657
|
+
lines.push("");
|
|
658
|
+
break;
|
|
659
|
+
case "pipeline":
|
|
660
|
+
lines.push(printPipeline(entry.item));
|
|
661
|
+
lines.push("");
|
|
662
|
+
break;
|
|
663
|
+
case "variable":
|
|
664
|
+
lines.push(printVariable(entry.item));
|
|
665
|
+
const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
|
|
666
|
+
if (nextNonVariable) lines.push("");
|
|
667
|
+
break;
|
|
668
|
+
case "describe":
|
|
669
|
+
lines.push(printDescribe(entry.item));
|
|
670
|
+
lines.push("");
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
641
673
|
});
|
|
642
674
|
return lines.join("\n").trim();
|
|
643
675
|
}
|