Comparing version 2.3.1 to 2.4.0
115
bin/cli.js
@@ -7,2 +7,3 @@ #!/usr/bin/env node | ||
import path from "path"; | ||
import process from "process"; | ||
import gui from "../src/cli/gui.js"; | ||
@@ -48,2 +49,3 @@ import Logger from "../src/lib/logger.js"; | ||
${chalk.bold("svglint")} [--config config.js] [--ci] [--debug] ${chalk.bold("file1.svg file2.svg")} | ||
${chalk.bold("svglint")} --stdin [--config config.js] [--ci] [--debug] < ${chalk.bold("file1.svg")} | ||
@@ -55,3 +57,4 @@ ${chalk.yellow("Options:")} | ||
${chalk.bold("--debug, -d")} Show debug logs | ||
${chalk.bold("--ci, -C")} Only output to stdout once, when linting is finished`, { | ||
${chalk.bold("--ci, -C")} Only output to stdout once, when linting is finished | ||
${chalk.bold("--stdin")} Read an SVG from stdin`, { | ||
importMeta: import.meta, | ||
@@ -61,3 +64,4 @@ flags: { | ||
debug: { type: "boolean", alias: "d" }, | ||
ci: { type: "boolean", alias: "C" } | ||
ci: { type: "boolean", alias: "C" }, | ||
stdin: { type: "boolean" } | ||
} | ||
@@ -76,6 +80,2 @@ }); | ||
GUI.setCI(cli.flags.ci); | ||
const files = cli.input | ||
.map(v => glob.sync(v)) | ||
.reduce((a, v) => a.concat(v), []) | ||
.map(v => path.resolve(process.cwd(), v)); | ||
@@ -100,37 +100,76 @@ // load the config | ||
// lint all the files | ||
// also keep track so we know when every linting has finished | ||
let hasErrors = false; | ||
let activeLintings = files.length; | ||
const onLintingDone = () => { | ||
--activeLintings; | ||
logger.debug("Linting done,", activeLintings, "to go"); | ||
if (activeLintings <= 0) { | ||
process.exit( | ||
hasErrors ? EXIT_CODES.violations : EXIT_CODES.success | ||
); | ||
} | ||
}; | ||
files.forEach(filePath => { | ||
SVGLint.lintFile(filePath, configObj) | ||
.then(linting => { | ||
// handle case where linting failed (e.g. invalid file) | ||
if (!linting) { | ||
onLintingDone(); | ||
return; | ||
} | ||
if (cli.flags.stdin) { | ||
// lint what's provided on stdin | ||
const chunks = []; | ||
// otherwise add it to GUI and wait for it to finish | ||
GUI.addLinting(linting); | ||
linting.on("done", () => { | ||
if (linting.state === linting.STATES.error) { | ||
hasErrors = true; | ||
process.stdin.on("readable", () => { | ||
let chunk; | ||
while (null !== (chunk = process.stdin.read())) { | ||
chunks.push(chunk); | ||
} | ||
}); | ||
process.stdin.on("end", () => { | ||
SVGLint.lintSource(chunks.join(""), configObj) | ||
.then(linting => { | ||
// handle case where linting failed (e.g. invalid file) | ||
if (!linting) { | ||
process.exit(EXIT_CODES.success); | ||
} | ||
onLintingDone(); | ||
// otherwise add it to GUI and wait for it to finish | ||
GUI.addLinting(linting); | ||
linting.on("done", () => { | ||
if (linting.state === linting.STATES.error) { | ||
process.exit(EXIT_CODES.violations); | ||
} else { | ||
process.exit(EXIT_CODES.success); | ||
} | ||
}); | ||
}) | ||
.catch(e => { | ||
logger.error("Failed to lint\n", e); | ||
}); | ||
}) | ||
.catch(e => { | ||
logger.error("Failed to lint file", filePath, "\n", e); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
// lint all the CLI specified files | ||
const files = cli.input | ||
.map(v => glob.sync(v)) | ||
.reduce((a, v) => a.concat(v), []) | ||
.map(v => path.resolve(process.cwd(), v)); | ||
// keep track so we know when every linting has finished | ||
let hasErrors = false; | ||
let activeLintings = files.length; | ||
const onLintingDone = () => { | ||
--activeLintings; | ||
logger.debug("Linting done,", activeLintings, "to go"); | ||
if (activeLintings <= 0) { | ||
process.exit( | ||
hasErrors ? EXIT_CODES.violations : EXIT_CODES.success | ||
); | ||
} | ||
}; | ||
files.forEach(filePath => { | ||
SVGLint.lintFile(filePath, configObj) | ||
.then(linting => { | ||
// handle case where linting failed (e.g. invalid file) | ||
if (!linting) { | ||
onLintingDone(); | ||
return; | ||
} | ||
// otherwise add it to GUI and wait for it to finish | ||
GUI.addLinting(linting); | ||
linting.on("done", () => { | ||
if (linting.state === linting.STATES.error) { | ||
hasErrors = true; | ||
} | ||
onLintingDone(); | ||
}); | ||
}) | ||
.catch(e => { | ||
logger.error("Failed to lint file", filePath, "\n", e); | ||
}); | ||
}); | ||
} | ||
})(); |
{ | ||
"name": "svglint", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "Linter for SVGs", | ||
@@ -42,3 +42,3 @@ "type": "module", | ||
"cheerio": "^1.0.0-rc.6", | ||
"fast-xml-parser": "^3.12.13", | ||
"fast-xml-parser": "^4.2.4", | ||
"glob": "^7.1.2", | ||
@@ -45,0 +45,0 @@ "htmlparser2": "^3.9.1", |
@@ -22,2 +22,3 @@ # SVGLint | ||
svglint [--config config.js] [--ci] [--debug] file1.svg file2.svg | ||
svglint --stdin [--config config.js] [--ci] [--debug] < file1.svg | ||
@@ -30,2 +31,3 @@ Options: | ||
--ci, -C Only output to stdout once, when linting is finished | ||
--stdin Read an SVG from stdin | ||
``` | ||
@@ -32,0 +34,0 @@ |
@@ -0,1 +1,2 @@ | ||
import process from "process"; | ||
import { chalk } from "../util.js"; | ||
@@ -2,0 +3,0 @@ const columns = process.stdout.columns || 80; |
import path from "path"; | ||
import fs from "fs"; | ||
import process from "process"; | ||
@@ -4,0 +5,0 @@ /** |
/** | ||
* @fileoverview Utilities for the CLI. | ||
*/ | ||
import process from "process"; | ||
import { Chalk, supportsColor as chalkSupportsColor } from "chalk"; | ||
@@ -5,0 +6,0 @@ import ansiRegex from "ansi-regex"; |
@@ -11,2 +11,3 @@ /** | ||
import path from "path"; | ||
import process from "process"; | ||
import * as cheerio from "cheerio"; | ||
@@ -13,0 +14,0 @@ import * as parse from "./parse.js"; |
@@ -10,2 +10,3 @@ /** | ||
import path from "path"; | ||
import process from "process"; | ||
@@ -12,0 +13,0 @@ /** |
import Logger from "../lib/logger.js"; | ||
import xmlParser from "fast-xml-parser"; | ||
import { XMLValidator } from "fast-xml-parser"; | ||
const logger = Logger("rule:valid"); | ||
@@ -37,3 +37,3 @@ | ||
} | ||
const result = xmlParser.validate(ast.source); | ||
const result = XMLValidator.validate(ast.source); | ||
if (result !== true) { | ||
@@ -40,0 +40,0 @@ reporter.error(result.err.msg, null, ast); |
Sorry, the diff of this file is not supported yet
150605
3100
81
6
+ Addedfast-xml-parser@4.5.1(transitive)
- Removedfast-xml-parser@3.21.1(transitive)
Updatedfast-xml-parser@^4.2.4