#!/bin/bash
## Description: Run cspell on the ai_governance module, matching GitLab CI's setup (module's own .cspell.json words/flagWords, plus core's Drupal dictionaries and built-in dictionaries prepare-cspell.php adds).
## Usage: cspell-module [cspell args...]
## Example: "ddev cspell-module"

set -e
MODULE_DIR=/var/www/html/web/modules/custom/ai_governance
cd "$MODULE_DIR"

CONFIG=$(mktemp "$MODULE_DIR/.cspell-ci-equivalent.XXXXXX.json")
trap 'rm -f "$CONFIG"' EXIT

jq '. + {
  dictionaries: (.dictionaries + ["companies","fonts","html","php","softwareTerms","misc","typescript","node","css","bash","filetypes","npm","lorem-ipsum","sql","fullstack","drupal","dictionary"]),
  dictionaryDefinitions: (.dictionaryDefinitions + [
    {name:"drupal", path:"/var/www/html/web/core/misc/cspell/drupal-dictionary.txt"},
    {name:"dictionary", path:"/var/www/html/web/core/misc/cspell/dictionary.txt"}
  ]),
  ignorePaths: (.ignorePaths + ["*.patch","*.svg","*_ignore_*",".cspell-ci-equivalent.*.json"])
}' .cspell.json > "$CONFIG"

npx --yes cspell -c "$CONFIG" --show-suggestions --no-progress "$@" .
