|
| 1 | +import { readFileSync, writeFileSync } from "fs"; |
| 2 | +import path from "path"; |
| 3 | +import { fileURLToPath } from "url"; |
| 4 | + |
| 5 | +// inspired by code in https://github.com/streetsidesoftware/cspell/issues/3215 |
| 6 | +// this file just generates the word list file in this directory that contains |
| 7 | +// all our dependecy package names |
| 8 | + |
| 9 | +const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file |
| 10 | +const __dirname = path.dirname(__filename); // get the name of the directory |
| 11 | + |
| 12 | +const packageJsons = [ |
| 13 | + path.join(__dirname, "../package.json"), |
| 14 | + path.join(__dirname, "../packages/engine/package.json"), |
| 15 | + path.join(__dirname, "../packages/widgets/package.json"), |
| 16 | +]; |
| 17 | +const words = packageJsons.reduce((acc, packageJsonPath) => { |
| 18 | + const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")); |
| 19 | + const packageNames = Object.keys(packageJson.dependencies ?? {}).concat( |
| 20 | + Object.keys(packageJson.devDependencies ?? {}), |
| 21 | + ); |
| 22 | + // remove the @ org symbol and dashes to get just words in package names |
| 23 | + const setOfWords = packageNames |
| 24 | + .flatMap((name) => name.replace(/[@]/g, "").split(/\/|\-/)) |
| 25 | + .map((word) => word.replace(".js", "")); |
| 26 | + setOfWords.forEach((word) => acc.add(word)); |
| 27 | + return acc; |
| 28 | +}, new Set()); |
| 29 | + |
| 30 | +// if https://github.com/streetsidesoftware/vscode-spell-checker/issues/3002 |
| 31 | +// ever gets addressed this can be used to auto-generate the list of package names |
| 32 | +// to pass to cspell directly. Right now it works in the CLI but not in the extension |
| 33 | +writeFileSync("./cspell-packages.txt", Array.from(words).join("\n")); |
0 commit comments