make-pot.sh
37 lines
| 1 | #!/usr/bin/env bash |
| 2 | # Generate languages/cookie-law-info.pot from the plugin root. |
| 3 | # |
| 4 | # WP-CLI only scans .js/.jsx for gettext — not .ts/.tsx (see wp-cli/i18n-command |
| 5 | # JsCodeExtractor extensions). So we merge a second POT from react-gettext-parser |
| 6 | # on lite/admin/dist/js/index.js (run `npm run dev:build` in lite/admin first if dist is missing). |
| 7 | # |
| 8 | # Minified JS and node_modules are excluded from the PHP run to avoid OOM in Peast. |
| 9 | set -euo pipefail |
| 10 | |
| 11 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 12 | cd "$ROOT" |
| 13 | |
| 14 | export WP_CLI_PHP_ARGS='-d memory_limit=2G' |
| 15 | |
| 16 | EXCLUDE='node_modules,lite/admin/node_modules,lite/admin/dist,dist,vendor,.git,lite/frontend/js/script.min.js,lite/frontend/js/wca.min.js,lite/frontend/js/gcm.min.js,lite/admin/modules/dashboard-widget/assets/js/chart.min.js' |
| 17 | |
| 18 | REACT_POT="$ROOT/languages/.tmp-admin-react.pot" |
| 19 | ADMIN_BUNDLE="$ROOT/lite/admin/dist/js/index.js" |
| 20 | |
| 21 | if [[ -f "$ROOT/lite/admin/package.json" ]]; then |
| 22 | if [[ ! -f "$ADMIN_BUNDLE" ]]; then |
| 23 | echo "Error: $ADMIN_BUNDLE not found. Build the admin app first:" >&2 |
| 24 | echo " cd lite/admin && npm run dev:build" >&2 |
| 25 | exit 1 |
| 26 | fi |
| 27 | (cd "$ROOT/lite/admin" && npm run -s i18n:extract-react) |
| 28 | fi |
| 29 | |
| 30 | if [[ -f "$REACT_POT" ]]; then |
| 31 | wp i18n make-pot "$ROOT" "$ROOT/languages/cookie-law-info.pot" --exclude="$EXCLUDE" --merge="$REACT_POT" "$@" |
| 32 | rm -f "$REACT_POT" |
| 33 | else |
| 34 | echo "Warning: react POT not found at $REACT_POT (run: cd lite/admin && npm install). Running wp make-pot only." >&2 |
| 35 | wp i18n make-pot "$ROOT" "$ROOT/languages/cookie-law-info.pot" --exclude="$EXCLUDE" "$@" |
| 36 | fi |
| 37 |