Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running cspell on Windows #724

Open
Maxim-Mazurok opened this issue Oct 2, 2022 · 0 comments
Open

Fix running cspell on Windows #724

Maxim-Mazurok opened this issue Oct 2, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Maxim-Mazurok
Copy link
Owner

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);
  }
});
@Maxim-Mazurok Maxim-Mazurok added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant