testsAndMisc/linux_configuration/utils/lib/offline_js.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

143 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# JavaScript documentation download and indexing.
#
# Sourced by setup_offline_docs.sh; split out to keep offline_cpp.sh under the
# 250-line cap. Sourced rather than run, so it inherits the caller's
# strict mode and the variables defined above the source line.
#==============================================================================
# JavaScript/MDN Documentation
# Clone the actual MDN content repository for full documentation
# https://github.com/mdn/content
#==============================================================================
download_js_docs() {
print_header "JavaScript/MDN Documentation"
local dest="$DOCS_DIR/javascript"
local mdn_repo="$DOCS_DIR/mdn-content"
# Check if already cloned
if [ -d "$mdn_repo/files/en-us/web/javascript" ]; then
print_status "MDN content already present"
build_js_index
return 0
fi
print_status "Cloning MDN content repository (sparse checkout for web docs)..."
print_status "This may take a few minutes on first run..."
mkdir -p "$mdn_repo"
cd "$mdn_repo" || exit 1
# Initialize sparse checkout to only get what we need
if [ ! -d ".git" ]; then
git init
git remote add origin https://github.com/mdn/content.git
git config core.sparseCheckout true
# Only checkout web-related documentation (JS, HTML, CSS, Web APIs)
cat > .git/info/sparse-checkout << 'SPARSE'
/files/en-us/web/javascript/
/files/en-us/web/api/
/files/en-us/web/html/
/files/en-us/web/css/
/files/en-us/glossary/
SPARSE
print_status "Fetching MDN content (JavaScript, HTML, CSS, Web APIs)..."
git fetch --depth 1 origin main
git checkout main
else
print_status "Updating MDN content..."
git pull --depth 1 origin main 2> /dev/null || true
fi
cd - > /dev/null || exit 1
# Create symlink for easier access
mkdir -p "$dest"
ln -sf "$mdn_repo/files/en-us/web/javascript" "$dest/javascript"
ln -sf "$mdn_repo/files/en-us/web/api" "$dest/web-api"
ln -sf "$mdn_repo/files/en-us/web/html" "$dest/html"
ln -sf "$mdn_repo/files/en-us/web/css" "$dest/css"
ln -sf "$mdn_repo/files/en-us/glossary" "$dest/glossary"
build_js_index
print_success "MDN offline documentation ready"
local doc_count
doc_count=$(find "$mdn_repo/files" -name "index.md" 2> /dev/null | wc -l)
print_status "Downloaded $doc_count documentation pages"
}
build_js_index() {
print_status "Building MDN documentation index..."
local mdn_repo="$DOCS_DIR/mdn-content"
local index="$INDEX_DIR/js_index.txt"
if [ ! -d "$mdn_repo/files" ]; then
print_error "MDN content not found"
return 1
fi
# Build comprehensive index from MDN markdown files
{
# Index JavaScript reference
find "$mdn_repo/files/en-us/web/javascript/reference" -name "index.md" 2> /dev/null | while read -r file; do
local dir
dir=$(dirname "$file")
local term
term=$(basename "$dir")
# Extract title from frontmatter if available
local title
title=$(grep -m1 "^title:" "$file" 2> /dev/null | sed 's/^title:\s*//' | tr -d '"')
echo "${term}|${file}|${title:-$term}"
done
# Index Web APIs
find "$mdn_repo/files/en-us/web/api" -name "index.md" 2> /dev/null | while read -r file; do
local dir
dir=$(dirname "$file")
local term
term=$(basename "$dir")
local title
title=$(grep -m1 "^title:" "$file" 2> /dev/null | sed 's/^title:\s*//' | tr -d '"')
echo "${term}|${file}|${title:-$term}"
done
# Index HTML elements
find "$mdn_repo/files/en-us/web/html/element" -name "index.md" 2> /dev/null | while read -r file; do
local dir
dir=$(dirname "$file")
local term
term=$(basename "$dir")
echo "${term}|${file}|HTML <${term}> element"
done
# Index CSS properties
find "$mdn_repo/files/en-us/web/css" -maxdepth 2 -name "index.md" 2> /dev/null | while read -r file; do
local dir
dir=$(dirname "$file")
local term
term=$(basename "$dir")
local title
title=$(grep -m1 "^title:" "$file" 2> /dev/null | sed 's/^title:\s*//' | tr -d '"')
echo "${term}|${file}|${title:-$term}"
done
# Index Glossary
find "$mdn_repo/files/en-us/glossary" -name "index.md" 2> /dev/null | while read -r file; do
local dir
dir=$(dirname "$file")
local term
term=$(basename "$dir")
local title
title=$(grep -m1 "^title:" "$file" 2> /dev/null | sed 's/^title:\s*//' | tr -d '"')
echo "${term}|${file}|${title:-$term}"
done
} | sort -t'|' -k1,1 -u > "$index"
local count
count=$(wc -l < "$index")
print_success "MDN index created with $count entries"
}