schemata-validator 0.1.0
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/LICENSE +21 -0
- package/README.md +119 -0
- package/bin/cli.js +5 -0
- package/data/classes.json +3748 -0
- package/data/properties.json +8274 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +24 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +46 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/format-parsers/html-parser.d.ts +15 -0
- package/dist/format-parsers/html-parser.js +32 -0
- package/dist/format-parsers/html-parser.js.map +1 -0
- package/dist/format-parsers/json-ld-parser.d.ts +34 -0
- package/dist/format-parsers/json-ld-parser.js +96 -0
- package/dist/format-parsers/json-ld-parser.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schemata-validator.d.ts +19 -0
- package/dist/schemata-validator.js +69 -0
- package/dist/schemata-validator.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/browse-folders.d.ts +6 -0
- package/dist/utils/browse-folders.js +18 -0
- package/dist/utils/browse-folders.js.map +1 -0
- package/dist/utils/display-cli-flags.d.ts +5 -0
- package/dist/utils/display-cli-flags.js +24 -0
- package/dist/utils/display-cli-flags.js.map +1 -0
- package/dist/utils/display-reporting.d.ts +7 -0
- package/dist/utils/display-reporting.js +38 -0
- package/dist/utils/display-reporting.js.map +1 -0
- package/dist/utils/dry-run-notice.d.ts +4 -0
- package/dist/utils/dry-run-notice.js +8 -0
- package/dist/utils/dry-run-notice.js.map +1 -0
- package/dist/utils/get-file-content.d.ts +6 -0
- package/dist/utils/get-file-content.js +10 -0
- package/dist/utils/get-file-content.js.map +1 -0
- package/dist/utils/get-files-to-validate.d.ts +9 -0
- package/dist/utils/get-files-to-validate.js +37 -0
- package/dist/utils/get-files-to-validate.js.map +1 -0
- package/dist/utils/parse-args.d.ts +7 -0
- package/dist/utils/parse-args.js +47 -0
- package/dist/utils/parse-args.js.map +1 -0
- package/dist/utils/pattern-to-regex.d.ts +6 -0
- package/dist/utils/pattern-to-regex.js +15 -0
- package/dist/utils/pattern-to-regex.js.map +1 -0
- package/dist/utils/prepare-reporting.d.ts +8 -0
- package/dist/utils/prepare-reporting.js +22 -0
- package/dist/utils/prepare-reporting.js.map +1 -0
- package/dist/utils/show-help.d.ts +4 -0
- package/dist/utils/show-help.js +13 -0
- package/dist/utils/show-help.js.map +1 -0
- package/dist/utils/show-version.d.ts +4 -0
- package/dist/utils/show-version.js +8 -0
- package/dist/utils/show-version.js.map +1 -0
- package/dist/validator/schema-graph-validator.d.ts +46 -0
- package/dist/validator/schema-graph-validator.js +164 -0
- package/dist/validator/schema-graph-validator.js.map +1 -0
- package/package.json +60 -0
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { SchemataValidator } from "./schemata-validator.js";
|
|
3
|
+
import { parseArgs } from "./utils/parse-args.js";
|
|
4
|
+
import { showHelp } from "./utils/show-help.js";
|
|
5
|
+
import { showVersion } from "./utils/show-version.js";
|
|
6
|
+
/**
|
|
7
|
+
* Runs the validator via the CLI.
|
|
8
|
+
*/
|
|
9
|
+
export const cli = async () => {
|
|
10
|
+
const { argv } = process;
|
|
11
|
+
const args = argv.slice(2);
|
|
12
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
13
|
+
showHelp();
|
|
14
|
+
}
|
|
15
|
+
else if (args.includes("--version") || args.includes("-v")) {
|
|
16
|
+
showVersion();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const validator = new SchemataValidator(parseArgs(args));
|
|
20
|
+
const reporting = await validator.validate();
|
|
21
|
+
validator.log(reporting);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,IAAmB,EAAE;IAC3C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,QAAQ,EAAE,CAAC;IACb,CAAC;SAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7D,WAAW,EAAE,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC7C,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const TAB: string;
|
|
2
|
+
export declare const WORKSPACE_NAME = "schemata-validator";
|
|
3
|
+
export declare const AVAILABLE_CLI_FLAGS: {
|
|
4
|
+
readonly files: {
|
|
5
|
+
readonly cliFlagName: "files";
|
|
6
|
+
readonly flag: "--files";
|
|
7
|
+
readonly alias: "-f";
|
|
8
|
+
readonly description: "Files to validate";
|
|
9
|
+
readonly type: "array";
|
|
10
|
+
};
|
|
11
|
+
readonly paths: {
|
|
12
|
+
readonly cliFlagName: "paths";
|
|
13
|
+
readonly flag: "--paths";
|
|
14
|
+
readonly alias: "-p";
|
|
15
|
+
readonly description: "Folders to include for validation";
|
|
16
|
+
readonly type: "array";
|
|
17
|
+
};
|
|
18
|
+
readonly exclude: {
|
|
19
|
+
readonly cliFlagName: "exclude";
|
|
20
|
+
readonly flag: "--exclude";
|
|
21
|
+
readonly alias: "-e";
|
|
22
|
+
readonly description: "Paths to skip";
|
|
23
|
+
readonly type: "array";
|
|
24
|
+
};
|
|
25
|
+
readonly dryRun: {
|
|
26
|
+
readonly cliFlagName: "dryRun";
|
|
27
|
+
readonly flag: "--dry-run";
|
|
28
|
+
readonly alias: "-d";
|
|
29
|
+
readonly description: "Bypass validation";
|
|
30
|
+
readonly type: "boolean";
|
|
31
|
+
};
|
|
32
|
+
readonly version: {
|
|
33
|
+
readonly cliFlagName: "version";
|
|
34
|
+
readonly flag: "--version";
|
|
35
|
+
readonly alias: "-v";
|
|
36
|
+
readonly description: "Show version number";
|
|
37
|
+
readonly type: "boolean";
|
|
38
|
+
};
|
|
39
|
+
readonly help: {
|
|
40
|
+
readonly cliFlagName: "help";
|
|
41
|
+
readonly flag: "--help";
|
|
42
|
+
readonly alias: "-h";
|
|
43
|
+
readonly description: "Show help";
|
|
44
|
+
readonly type: "boolean";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const TAB = " ".repeat(2);
|
|
2
|
+
export const WORKSPACE_NAME = "schemata-validator";
|
|
3
|
+
export const AVAILABLE_CLI_FLAGS = {
|
|
4
|
+
files: {
|
|
5
|
+
cliFlagName: "files",
|
|
6
|
+
flag: "--files",
|
|
7
|
+
alias: "-f",
|
|
8
|
+
description: "Files to validate",
|
|
9
|
+
type: "array"
|
|
10
|
+
},
|
|
11
|
+
paths: {
|
|
12
|
+
cliFlagName: "paths",
|
|
13
|
+
flag: "--paths",
|
|
14
|
+
alias: "-p",
|
|
15
|
+
description: "Folders to include for validation",
|
|
16
|
+
type: "array"
|
|
17
|
+
},
|
|
18
|
+
exclude: {
|
|
19
|
+
cliFlagName: "exclude",
|
|
20
|
+
flag: "--exclude",
|
|
21
|
+
alias: "-e",
|
|
22
|
+
description: "Paths to skip",
|
|
23
|
+
type: "array"
|
|
24
|
+
},
|
|
25
|
+
dryRun: {
|
|
26
|
+
cliFlagName: "dryRun",
|
|
27
|
+
flag: "--dry-run",
|
|
28
|
+
alias: "-d",
|
|
29
|
+
description: "Bypass validation",
|
|
30
|
+
type: "boolean"
|
|
31
|
+
},
|
|
32
|
+
version: {
|
|
33
|
+
cliFlagName: "version",
|
|
34
|
+
flag: "--version",
|
|
35
|
+
alias: "-v",
|
|
36
|
+
description: "Show version number",
|
|
37
|
+
type: "boolean"
|
|
38
|
+
},
|
|
39
|
+
help: {
|
|
40
|
+
cliFlagName: "help",
|
|
41
|
+
flag: "--help",
|
|
42
|
+
alias: "-h",
|
|
43
|
+
description: "Show help",
|
|
44
|
+
type: "boolean"
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE;QACL,WAAW,EAAE,OAAO;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,mBAAmB;QAChC,IAAI,EAAE,OAAO;KACd;IACD,KAAK,EAAE;QACL,WAAW,EAAE,OAAO;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,mCAAmC;QAChD,IAAI,EAAE,OAAO;KACd;IACD,OAAO,EAAE;QACP,WAAW,EAAE,SAAS;QACtB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,OAAO;KACd;IACD,MAAM,EAAE;QACN,WAAW,EAAE,QAAQ;QACrB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,mBAAmB;QAChC,IAAI,EAAE,SAAS;KAChB;IACD,OAAO,EAAE;QACP,WAAW,EAAE,SAAS;QACtB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,SAAS;KAChB;IACD,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM;QACnB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,WAAW;QACxB,IAAI,EAAE,SAAS;KAChB;CACO,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SchemaGraph } from "../types.js";
|
|
2
|
+
export declare class HTMLParser {
|
|
3
|
+
private readonly html;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs an instance of the HTMLParser class.
|
|
6
|
+
* @param html - The HTML document.
|
|
7
|
+
*/
|
|
8
|
+
constructor(html: string);
|
|
9
|
+
/**
|
|
10
|
+
* Parses the HTML document.
|
|
11
|
+
*
|
|
12
|
+
* @return The intermediate representation tree of the Schema.org vocabulary used by the HTML document.
|
|
13
|
+
*/
|
|
14
|
+
parse(): SchemaGraph;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { JSONLDParser } from "./json-ld-parser.js";
|
|
2
|
+
export class HTMLParser {
|
|
3
|
+
html;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs an instance of the HTMLParser class.
|
|
6
|
+
* @param html - The HTML document.
|
|
7
|
+
*/
|
|
8
|
+
constructor(html) {
|
|
9
|
+
this.html = html;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses the HTML document.
|
|
13
|
+
*
|
|
14
|
+
* @return The intermediate representation tree of the Schema.org vocabulary used by the HTML document.
|
|
15
|
+
*/
|
|
16
|
+
parse() {
|
|
17
|
+
const roots = [];
|
|
18
|
+
const jsonLDDataSet = this.html
|
|
19
|
+
.replace(/<!-{2}.*?-{2}>/gms, "")
|
|
20
|
+
.matchAll(/<script\s+type=["']?application\/ld\+json["']?>(?<jsonld>.*?)<\/script>/gms);
|
|
21
|
+
for (const jsonLDData of jsonLDDataSet) {
|
|
22
|
+
const jsonLD = jsonLDData.groups?.jsonld ?? "";
|
|
23
|
+
const jsonLDParser = new JSONLDParser(jsonLD);
|
|
24
|
+
if (jsonLD)
|
|
25
|
+
roots.push(...jsonLDParser.parse().roots);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
roots
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=html-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-parser.js","sourceRoot":"","sources":["../../src/format-parsers/html-parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,OAAO,UAAU;IACJ,IAAI,CAAS;IAE9B;;;OAGG;IACH,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,MAAM,KAAK,GAAiB,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI;aAC5B,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;aAChC,QAAQ,CAAC,4EAA4E,CAAC,CAAC;QAC1F,KAAK,MAAM,UAAU,IAAI,aAAa,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC;YAC/C,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;YAC9C,IAAI,MAAM;gBAAE,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,OAAO;YACL,KAAK;SACN,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSONLDData, SchemaGraph, SchemaNode, SchemaValue } from "../types.js";
|
|
2
|
+
export declare class JSONLDParser {
|
|
3
|
+
private readonly jsonLD;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs an instance of the JSONLDParser class.
|
|
6
|
+
* @param jsonLD - The JSON-LD data
|
|
7
|
+
*/
|
|
8
|
+
constructor(jsonLD: string);
|
|
9
|
+
/**
|
|
10
|
+
* Sets the schema value.
|
|
11
|
+
* @param value - The value from the JSON-LD to use as a value.
|
|
12
|
+
* @param index - The index of the value in its property array.
|
|
13
|
+
* @param parentPath - The JSON-LD path of the parent property.
|
|
14
|
+
* @return The schema value.
|
|
15
|
+
*/
|
|
16
|
+
setSchemaValue: (value: unknown, index: number, parentPath: string) => SchemaValue;
|
|
17
|
+
/**
|
|
18
|
+
* Sets the schema node.
|
|
19
|
+
* @param node - The object from the JSON-LD to use as a node.
|
|
20
|
+
* @param index - The index of the node in its parent array.
|
|
21
|
+
* @param [parentPath] - The JSON-LD path of the parent property (the string is empty for root nodes).
|
|
22
|
+
* @return The schema node.
|
|
23
|
+
*/
|
|
24
|
+
setSchemaNode: (node: JSONLDData, index: number, parentPath?: string) => SchemaNode;
|
|
25
|
+
/**
|
|
26
|
+
* Parses the JSON-LD data.
|
|
27
|
+
*
|
|
28
|
+
* Contexts other than Schema.org are skipped.
|
|
29
|
+
*
|
|
30
|
+
* Any commented parts of the JSON-LD are ignored.
|
|
31
|
+
* @return The intermediate representation tree of the Schema.org vocabulary used by the JSON-LD data.
|
|
32
|
+
*/
|
|
33
|
+
parse(): SchemaGraph;
|
|
34
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export class JSONLDParser {
|
|
2
|
+
jsonLD;
|
|
3
|
+
/**
|
|
4
|
+
* Constructs an instance of the JSONLDParser class.
|
|
5
|
+
* @param jsonLD - The JSON-LD data
|
|
6
|
+
*/
|
|
7
|
+
constructor(jsonLD) {
|
|
8
|
+
this.jsonLD = jsonLD;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Sets the schema value.
|
|
12
|
+
* @param value - The value from the JSON-LD to use as a value.
|
|
13
|
+
* @param index - The index of the value in its property array.
|
|
14
|
+
* @param parentPath - The JSON-LD path of the parent property.
|
|
15
|
+
* @return The schema value.
|
|
16
|
+
*/
|
|
17
|
+
setSchemaValue = (value, index, parentPath) => {
|
|
18
|
+
const parentPathWithIndex = `${parentPath}[${index}]`;
|
|
19
|
+
if (typeof value === "object" && value !== null) {
|
|
20
|
+
if ("@value" in value) {
|
|
21
|
+
const nestedValue = value["@value"];
|
|
22
|
+
return {
|
|
23
|
+
kind: "literal",
|
|
24
|
+
location: {
|
|
25
|
+
jsonLDPath: parentPathWithIndex
|
|
26
|
+
},
|
|
27
|
+
value: String(nestedValue)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
kind: "node",
|
|
32
|
+
linkLocation: {
|
|
33
|
+
jsonLDPath: parentPathWithIndex
|
|
34
|
+
},
|
|
35
|
+
node: this.setSchemaNode(value, index, parentPath)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
kind: "literal",
|
|
40
|
+
location: {
|
|
41
|
+
jsonLDPath: parentPathWithIndex
|
|
42
|
+
},
|
|
43
|
+
value: String(value)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Sets the schema node.
|
|
48
|
+
* @param node - The object from the JSON-LD to use as a node.
|
|
49
|
+
* @param index - The index of the node in its parent array.
|
|
50
|
+
* @param [parentPath] - The JSON-LD path of the parent property (the string is empty for root nodes).
|
|
51
|
+
* @return The schema node.
|
|
52
|
+
*/
|
|
53
|
+
setSchemaNode = (node, index, parentPath = "") => {
|
|
54
|
+
const nodePath = `${parentPath}[${index}]`;
|
|
55
|
+
const type = typeof node["@type"] === "string" ? node["@type"] : "Thing";
|
|
56
|
+
const id = typeof node["@id"] === "string" ? node["@id"] : undefined;
|
|
57
|
+
const schemaNode = id ? { type, id } : { type };
|
|
58
|
+
const properties = new Map();
|
|
59
|
+
for (const [key, rawValues] of Object.entries(node)) {
|
|
60
|
+
if (key.startsWith("@"))
|
|
61
|
+
continue;
|
|
62
|
+
const propertyPath = `${nodePath}.${key}`;
|
|
63
|
+
const values = (Array.isArray(rawValues) ? rawValues : [rawValues]).map((value, index) => this.setSchemaValue(value, index, propertyPath));
|
|
64
|
+
properties.set(key, values);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...schemaNode,
|
|
68
|
+
properties,
|
|
69
|
+
sourceFormat: "jsonld",
|
|
70
|
+
location: {
|
|
71
|
+
jsonLDPath: nodePath
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Parses the JSON-LD data.
|
|
77
|
+
*
|
|
78
|
+
* Contexts other than Schema.org are skipped.
|
|
79
|
+
*
|
|
80
|
+
* Any commented parts of the JSON-LD are ignored.
|
|
81
|
+
* @return The intermediate representation tree of the Schema.org vocabulary used by the JSON-LD data.
|
|
82
|
+
*/
|
|
83
|
+
parse() {
|
|
84
|
+
const parsedJSONLD = JSON.parse(this.jsonLD);
|
|
85
|
+
const nodes = (Array.isArray(parsedJSONLD) ? parsedJSONLD : [parsedJSONLD])
|
|
86
|
+
.filter(node => "@context" in node &&
|
|
87
|
+
typeof node["@context"] === "string" &&
|
|
88
|
+
node["@context"].match(/^ht{2}ps?:\/{2}schema\.org\/?$/))
|
|
89
|
+
.map(node => node);
|
|
90
|
+
const roots = nodes.flatMap((value, index) => this.setSchemaNode(value, index));
|
|
91
|
+
return {
|
|
92
|
+
roots
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=json-ld-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-ld-parser.js","sourceRoot":"","sources":["../../src/format-parsers/json-ld-parser.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACN,MAAM,CAAS;IAEhC;;;OAGG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACH,cAAc,GAAG,CAAC,KAAc,EAAE,KAAa,EAAE,UAAkB,EAAe,EAAE;QAClF,MAAM,mBAAmB,GAAG,GAAG,UAAU,IAAI,KAAK,GAAG,CAAC;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;gBACtB,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACpC,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE;wBACR,UAAU,EAAE,mBAAmB;qBAChC;oBACD,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC;iBAC3B,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,YAAY,EAAE;oBACZ,UAAU,EAAE,mBAAmB;iBAChC;gBACD,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,KAAmB,EAAE,KAAK,EAAE,UAAU,CAAC;aACjE,CAAC;QACJ,CAAC;QACD,OAAO;YACL,IAAI,EAAE,S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UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO;YACL,GAAG,UAAU;YACb,UAAU;YACV,YAAY,EAAE,QAAQ;YACtB,QAAQ,EAAE;gBACR,UAAU,EAAE,QAAQ;aACrB;SACF,CAAC;IACJ,CAAC,CAAC;IAEF;;;;;;;OAOG;IACH,KAAK;QACH,MAAM,YAAY,GAA8B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxE,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;aACxE,MAAM,CACL,IAAI,CAAC,EAAE,CACL,UAAU,IAAI,IAAI;YAClB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,QAAQ;YACpC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAC3D;aACA,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAkB,CAAC,CAAC;QACnC,MAAM,KAAK,GAAiB,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9F,OAAO;YACL,KAAK;SACN,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SchemataValidatorOptions, ValidationReporting } from "./types.js";
|
|
2
|
+
export declare class SchemataValidator {
|
|
3
|
+
private readonly options;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs an instance of the SchemataValidator class.
|
|
6
|
+
* @param [options] - The options to use.
|
|
7
|
+
*/
|
|
8
|
+
constructor(options?: SchemataValidatorOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Validates the Schema.org vocabulary.
|
|
11
|
+
* @return The validation reporting if not on dry-run mode, `undefined` otherwise.
|
|
12
|
+
*/
|
|
13
|
+
validate(): Promise<ValidationReporting[] | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Logs the reporting in the console.
|
|
16
|
+
* @param reporting - The reporting to log.
|
|
17
|
+
*/
|
|
18
|
+
log(reporting: ValidationReporting[] | undefined): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { HTMLParser } from "./format-parsers/html-parser.js";
|
|
2
|
+
import { JSONLDParser } from "./format-parsers/json-ld-parser.js";
|
|
3
|
+
import { displayReporting } from "./utils/display-reporting.js";
|
|
4
|
+
import { dryRunNotice } from "./utils/dry-run-notice.js";
|
|
5
|
+
import { getFileContent } from "./utils/get-file-content.js";
|
|
6
|
+
import { getFilesToValidate } from "./utils/get-files-to-validate.js";
|
|
7
|
+
import { prepareReporting } from "./utils/prepare-reporting.js";
|
|
8
|
+
import { SchemaGraphValidator } from "./validator/schema-graph-validator.js";
|
|
9
|
+
export class SchemataValidator {
|
|
10
|
+
options = {};
|
|
11
|
+
/**
|
|
12
|
+
* Constructs an instance of the SchemataValidator class.
|
|
13
|
+
* @param [options] - The options to use.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.options = options ?? {};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates the Schema.org vocabulary.
|
|
20
|
+
* @return The validation reporting if not on dry-run mode, `undefined` otherwise.
|
|
21
|
+
*/
|
|
22
|
+
async validate() {
|
|
23
|
+
try {
|
|
24
|
+
const { dryRun } = this.options;
|
|
25
|
+
if (dryRun)
|
|
26
|
+
dryRunNotice();
|
|
27
|
+
else {
|
|
28
|
+
const { data } = this.options;
|
|
29
|
+
const contents = data?.map((datum, index) => ({
|
|
30
|
+
type: "data",
|
|
31
|
+
resource: `data[${index}]`,
|
|
32
|
+
source: datum
|
|
33
|
+
})) ?? [];
|
|
34
|
+
if (!data) {
|
|
35
|
+
const filesToValidate = await getFilesToValidate(this.options);
|
|
36
|
+
for (const file of filesToValidate) {
|
|
37
|
+
const content = getFileContent(file);
|
|
38
|
+
if (content)
|
|
39
|
+
contents.push({ type: "file", resource: file, source: content });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const reporting = [];
|
|
43
|
+
for (const content of contents) {
|
|
44
|
+
const { type, resource, source } = content;
|
|
45
|
+
const contentSchemaGraph = type === "file" ? new HTMLParser(source).parse() : new JSONLDParser(source).parse();
|
|
46
|
+
const schemaGraphValidator = new SchemaGraphValidator(contentSchemaGraph);
|
|
47
|
+
const result = schemaGraphValidator.validate();
|
|
48
|
+
reporting.push(prepareReporting(resource, result));
|
|
49
|
+
}
|
|
50
|
+
return reporting;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error("\x1b[1;31m%s %s\x1b[0m", "Failed to validate the Schema.org vocabulary.", error instanceof Error ? error.message : String(error));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Logs the reporting in the console.
|
|
59
|
+
* @param reporting - The reporting to log.
|
|
60
|
+
*/
|
|
61
|
+
log(reporting) {
|
|
62
|
+
if (reporting) {
|
|
63
|
+
for (const reportingItem of reporting) {
|
|
64
|
+
displayReporting(reportingItem, Date.now());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=schemata-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemata-validator.js","sourceRoot":"","sources":["../src/schemata-validator.ts"],"names":[],"mappings":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QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type SchemataValidatorOptions = {
|
|
2
|
+
data?: string[];
|
|
3
|
+
files?: string[];
|
|
4
|
+
paths?: string[];
|
|
5
|
+
exclude?: string[];
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type JSONLDData = Record<string, unknown>;
|
|
9
|
+
type SourceLocation = {
|
|
10
|
+
jsonLDPath?: string;
|
|
11
|
+
};
|
|
12
|
+
type LiteralSchemaValue = {
|
|
13
|
+
kind: "literal";
|
|
14
|
+
location: SourceLocation;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
type NodeSchemaValue = {
|
|
18
|
+
kind: "node";
|
|
19
|
+
linkLocation: SourceLocation;
|
|
20
|
+
node: SchemaNode;
|
|
21
|
+
};
|
|
22
|
+
export type SchemaValue = LiteralSchemaValue | NodeSchemaValue;
|
|
23
|
+
export type SchemaNode = {
|
|
24
|
+
type: string;
|
|
25
|
+
id?: string;
|
|
26
|
+
sourceFormat: "jsonld" | "microdata";
|
|
27
|
+
location: SourceLocation;
|
|
28
|
+
properties: Map<string, SchemaValue[]>;
|
|
29
|
+
};
|
|
30
|
+
export type SchemaGraph = {
|
|
31
|
+
roots: SchemaNode[];
|
|
32
|
+
};
|
|
33
|
+
export interface ClassDefinition {
|
|
34
|
+
isPending: boolean;
|
|
35
|
+
extends?: string[];
|
|
36
|
+
supersededBy?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PropertyDefinition extends ClassDefinition {
|
|
39
|
+
propertyOf?: string[];
|
|
40
|
+
type?: string[];
|
|
41
|
+
}
|
|
42
|
+
export type ValidationResult = {
|
|
43
|
+
type: "error" | "warning";
|
|
44
|
+
path: string;
|
|
45
|
+
message: string;
|
|
46
|
+
};
|
|
47
|
+
interface ValidationReportingCommonProperties {
|
|
48
|
+
resource: string;
|
|
49
|
+
}
|
|
50
|
+
interface ValidationReportingFail extends ValidationReportingCommonProperties {
|
|
51
|
+
status: "fail";
|
|
52
|
+
result: ValidationResult[];
|
|
53
|
+
}
|
|
54
|
+
interface ValidationReportingPass extends ValidationReportingCommonProperties {
|
|
55
|
+
status: "pass";
|
|
56
|
+
result?: ValidationResult[];
|
|
57
|
+
}
|
|
58
|
+
export type ValidationReporting = ValidationReportingFail | ValidationReportingPass;
|
|
59
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browses the folders recursively from the given folder.
|
|
3
|
+
* @param folder - The folder from which to start the browsing.
|
|
4
|
+
* @return An array of all the directories found recursively, including the given folder.
|
|
5
|
+
*/
|
|
6
|
+
export declare const browseFolders: (folder: string) => Promise<string[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Browses the folders recursively from the given folder.
|
|
5
|
+
* @param folder - The folder from which to start the browsing.
|
|
6
|
+
* @return An array of all the directories found recursively, including the given folder.
|
|
7
|
+
*/
|
|
8
|
+
export const browseFolders = async (folder) => {
|
|
9
|
+
const entries = (await fs.readdir(folder, { withFileTypes: true })).map(async (entry) => {
|
|
10
|
+
const pathToEntry = path.join(folder, entry.name);
|
|
11
|
+
if (entry.isDirectory())
|
|
12
|
+
return await browseFolders(pathToEntry);
|
|
13
|
+
return [];
|
|
14
|
+
});
|
|
15
|
+
const directories = await Promise.all(entries);
|
|
16
|
+
return [folder, ...directories.flat()];
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=browse-folders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browse-folders.js","sourceRoot":"","sources":["../../src/utils/browse-folders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAqB,EAAE;IACvE,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;QACpF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,WAAW,EAAE;YAAE,OAAO,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;QACjE,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AVAILABLE_CLI_FLAGS, TAB } from "../constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* Displays the CLI flags when running the CLI with the `--help` or `-h` flags.
|
|
4
|
+
* @return The CLI flags, with their alias (if available), flag, description and type.
|
|
5
|
+
*/
|
|
6
|
+
export const displayCliFlags = () => {
|
|
7
|
+
const availableCliFlagsValues = Object.values(AVAILABLE_CLI_FLAGS);
|
|
8
|
+
const aliasMaxLength = Math.max(...availableCliFlagsValues.map(cliFlag => "alias" in cliFlag && cliFlag.alias ? cliFlag.alias.length : 0));
|
|
9
|
+
const flagMaxLength = Math.max(...availableCliFlagsValues.map(option => option.flag.length));
|
|
10
|
+
const descriptionMaxLength = Math.max(...availableCliFlagsValues.map(cliOption => cliOption.description.length));
|
|
11
|
+
const typeMaxLength = Math.max(...availableCliFlagsValues.map(option => option.type.length)) + 2;
|
|
12
|
+
const header = "Options";
|
|
13
|
+
const cliOptions = [];
|
|
14
|
+
for (const cliFlag of availableCliFlagsValues) {
|
|
15
|
+
const alias = "alias" in cliFlag ? `${cliFlag.alias}, ` : " ".repeat(aliasMaxLength + 2);
|
|
16
|
+
const cliOptionName = `${TAB}${alias}${cliFlag.flag.padEnd(flagMaxLength, " ")}`;
|
|
17
|
+
const description = `${cliFlag.description.padEnd(descriptionMaxLength, " ")}`;
|
|
18
|
+
const type = `[${cliFlag.type}]`.padStart(typeMaxLength, " ");
|
|
19
|
+
const cliOptionElements = [cliOptionName, description, type];
|
|
20
|
+
cliOptions.push(cliOptionElements.join(TAB));
|
|
21
|
+
}
|
|
22
|
+
return `${header}\n${cliOptions.join("\n")}`;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=display-cli-flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-cli-flags.js","sourceRoot":"","sources":["../../src/utils/display-cli-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAW,EAAE;IAC1C,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACnE,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC7B,GAAG,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CACvC,OAAO,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAC/D,CACF,CAAC;IACF,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,uBAAuB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAA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C/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ValidationReporting } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Displays the reporting in the console.
|
|
4
|
+
* @param reporting - The reporting to display.
|
|
5
|
+
* @param timestamp - The timestamp of the reporting.
|
|
6
|
+
*/
|
|
7
|
+
export declare const displayReporting: (reporting: ValidationReporting, timestamp: number) => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WORKSPACE_NAME } from "../constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* Displays the reporting in the console.
|
|
4
|
+
* @param reporting - The reporting to display.
|
|
5
|
+
* @param timestamp - The timestamp of the reporting.
|
|
6
|
+
*/
|
|
7
|
+
export const displayReporting = (reporting, timestamp) => {
|
|
8
|
+
const { resource, status, result } = reporting;
|
|
9
|
+
const statusIcon = status === "pass" ? "\u2714" : "\u2718";
|
|
10
|
+
const statusColour = status === "pass" ? 32 : 31;
|
|
11
|
+
const dateTime = Intl.DateTimeFormat(undefined, {
|
|
12
|
+
hour: "2-digit",
|
|
13
|
+
minute: "2-digit",
|
|
14
|
+
second: "2-digit",
|
|
15
|
+
hour12: false,
|
|
16
|
+
timeZone: "UTC"
|
|
17
|
+
}).format(timestamp);
|
|
18
|
+
console.group(`[${dateTime}]`, `[${WORKSPACE_NAME}]`, resource);
|
|
19
|
+
if (status === "fail") {
|
|
20
|
+
console.info(`\x1b[1;${statusColour}m${statusIcon} ${status}\x1b[0m`, `(messages: ${reporting.result.length})`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.info(`\x1b[1;${statusColour}m${statusIcon} ${status}\x1b[0m`);
|
|
24
|
+
}
|
|
25
|
+
if (result) {
|
|
26
|
+
for (const reportingMessage of result) {
|
|
27
|
+
const { type, path, message } = reportingMessage;
|
|
28
|
+
if (type === "error") {
|
|
29
|
+
console.error("\x1b[1;31mError:\x1b[0m", message);
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
console.warn("\x1b[1;33mWarning:\x1b[0m", message);
|
|
33
|
+
console.info(path);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
console.groupEnd();
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=display-reporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-reporting.js","sourceRoot":"","sources":["../../src/utils/display-reporting.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,SAA8B,EAAE,SAAiB,EAAQ,EAAE;IAC1F,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC/C,MAAM,UAAU,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC3D,MAAM,YAAY,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE;QAC9C,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACrB,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,GAAG,EAAE,IAAI,cAAc,GAAG,EAAE,QAAQ,CAAC,CAAC;IAChE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CACV,UAAU,YAAY,IAAI,UAAU,IAAI,MAAM,SAAS,EACvD,cAAc,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,CACzC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,UAAU,YAAY,IAAI,UAAU,IAAI,MAAM,SAAS,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,MAAM,gBAAgB,IAAI,MAAM,EAAE,CAAC;YACtC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;YACjD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;gBACrB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;YACpD,CAAC;;gBAAM,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,QAAQ,EAAE,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WORKSPACE_NAME } from "../constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* Prints a notice that the validation is skipped in dry-run mode.
|
|
4
|
+
*/
|
|
5
|
+
export const dryRunNotice = () => {
|
|
6
|
+
console.info(`[${WORKSPACE_NAME}]`, "Dry-run mode: validation skipped.");
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=dry-run-notice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dry-run-notice.js","sourceRoot":"","sources":["../../src/utils/dry-run-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAS,EAAE;IACrC,OAAO,CAAC,IAAI,CAAC,IAAI,cAAc,GAAG,EAAE,mCAAmC,CAAC,CAAC;AAC3E,CAAC,CAAC"}
|