Fix running cspell on Windows
Maxim-Mazurok opened this issue · 0 comments
Maxim-Mazurok commented
cspell on windows attempts to check test\restDocs
, need to avoid that.
Probably use this script (may need to adapt it):
import path, { dirname } from "path";
import { readdirSync, statSync } from "fs";
import simpleGit from "simple-git";
import { fileURLToPath } from "url";
import { spawn } from "child_process";
const __dirname = dirname(fileURLToPath(import.meta.url));
const git = simpleGit();
const files: string[] = [];
async function throughDirectory(directory: string) {
for (const file of readdirSync(directory)) {
const absolutePath = path.join(directory, file);
await new Promise<void>((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
git.checkIgnore(absolutePath, async (error: unknown, data?: string[]) => {
if (error || !data) throw error;
if (data.length === 0) {
//not ignored
if (statSync(absolutePath).isDirectory()) await throughDirectory(absolutePath);
else files.push(absolutePath);
}
resolve();
});
});
}
}
const getNotIgnoredFiles = async (): Promise<string[]> => {
await throughDirectory(path.resolve(__dirname, ".."));
return files;
};
process.on("unhandledRejection", (reason) => {
throw reason;
});
const notIgnoredFiles = await getNotIgnoredFiles();
const cspellProcess = spawn("cspell --dot --fail-fast --file-list stdin", [], {
shell: true,
});
notIgnoredFiles.forEach((file) => {
cspellProcess.stdin.write(file.toString() + "\n");
});
cspellProcess.stdin.end();
cspellProcess.stdout.on("data", (data) => {
console.log(data.toString());
});
cspellProcess.stderr.on("data", (data) => {
console.error(data.toString());
});
cspellProcess.on("error", (error) => {
console.error(`Cspell Process error:\n${error}`);
process.exit(1);
});
cspellProcess.on("exit", (code, signal) => {
if (code) {
console.log(`Cspell Process exit with code: ${code}`);
process.exit(1);
}
if (signal) {
console.log(`Cspell Process killed with signal: ${signal}`);
process.exit(1);
}
});