Skip to content

Commit 65e5ddb

Browse files
authored
Merge pull request #2683 from OffchainLabs/clean-docgen-flow-v2
Clean docgen flow v2
2 parents ae6fdde + e8285a7 commit 65e5ddb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+988
-11578
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ build
1313
# Generated files
1414
.docusaurus
1515
.cache-loader
16+
sdk-sidebar.js
17+
docs/sdk/
18+
!docs/sdk/index.mdx
19+
!docs/sdk/migrate.mdx
20+
docs/partials/_glossary-partial.mdx
21+
docs/stylus-by-example/
22+
docs/api/
1623

1724
# Misc
1825
.DS_Store

.husky/pre-commit

Lines changed: 168 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,190 @@
11
#!/bin/sh
22

3-
# Function to handle errors
4-
handle_error() {
5-
echo "❌ Error: $1"
6-
exit 1
3+
# Pre-commit hook for arbitrum-docs repository
4+
# Enforces: redirect validation, submodule updates, code formatting, and type checking
5+
# Compatible with Husky v9+ (modern Husky architecture)
6+
# Performance optimized with selective file processing and parallel execution
7+
8+
# Exit immediately on any error
9+
set -e
10+
11+
# Husky environment detection and CI skip logic
12+
if [ "$HUSKY" = "0" ] || [ "$CI" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
13+
echo "🚀 Husky pre-commit hook skipped (CI environment or HUSKY=0)"
14+
exit 0
15+
fi
16+
17+
# Cross-platform color support detection
18+
if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ "$(tput colors)" -ge 8 ]; then
19+
RED='\033[0;31m'
20+
GREEN='\033[0;32m'
21+
YELLOW='\033[1;33m'
22+
BLUE='\033[0;34m'
23+
CYAN='\033[0;36m'
24+
BOLD='\033[1m'
25+
NC='\033[0m'
26+
else
27+
RED=''
28+
GREEN=''
29+
YELLOW=''
30+
BLUE=''
31+
CYAN=''
32+
BOLD=''
33+
NC=''
34+
fi
35+
36+
# Enhanced logging functions with emojis for better UX
37+
log_info() {
38+
printf "${BLUE}ℹ️ [INFO]${NC} %s\n" "$1"
739
}
840

9-
# Function to log success messages
1041
log_success() {
11-
echo "$1"
42+
printf "${GREEN}✅ [SUCCESS]${NC} %s\n" "$1"
1243
}
1344

14-
# Function to log info messages
15-
log_info() {
16-
echo "💡 $1"
45+
log_error() {
46+
printf "${RED}❌ [ERROR]${NC} %s\n" "$1" >&2
1747
}
1848

19-
# Function to run yarn command and check exit code
20-
run_yarn_command() {
21-
local command=$1
22-
local error_message=$2
49+
log_warning() {
50+
printf "${YELLOW}⚠️ [WARNING]${NC} %s\n" "$1"
51+
}
2352

24-
yarn $command
25-
local exit_code=$?
53+
log_step() {
54+
printf "${CYAN}${BOLD}🔄 %s${NC}\n" "$1"
55+
}
2656

27-
if [ $exit_code -ne 0 ]; then
28-
handle_error "$error_message"
57+
# Enhanced error handling with rollback suggestions
58+
exit_with_error() {
59+
log_error "$1"
60+
log_info "💡 Tip: Use 'git commit --no-verify' to bypass hooks (not recommended)"
61+
log_info "💡 Or set HUSKY=0 to disable all hooks temporarily"
62+
exit 1
63+
}
64+
65+
# Function to check command availability with installation hints
66+
check_command() {
67+
if ! command -v "$1" >/dev/null 2>&1; then
68+
case "$1" in
69+
yarn)
70+
exit_with_error "Yarn not found. Install with: npm install -g yarn"
71+
;;
72+
node)
73+
exit_with_error "Node.js not found. Install from: https://nodejs.org/"
74+
;;
75+
git)
76+
exit_with_error "Git not found. Install from: https://git-scm.com/"
77+
;;
78+
*)
79+
exit_with_error "Command '$1' not found. Please ensure it's installed and in your PATH."
80+
;;
81+
esac
2982
fi
3083
}
3184

32-
# Update submodules to ensure they are properly initialized and updated
33-
log_info "Updating submodules..."
34-
git submodule update --init --recursive
35-
submodule_exit_code=$?
85+
# Performance timing function
86+
time_command() {
87+
local start_time=$(date +%s)
88+
"$@"
89+
local end_time=$(date +%s)
90+
local duration=$((end_time - start_time))
91+
log_info "⏱️ Completed in ${duration}s"
92+
}
3693

37-
if [ $submodule_exit_code -ne 0 ]; then
38-
handle_error "Submodule update failed. Please check submodule configuration and try again."
39-
fi
94+
# Get list of staged files for selective processing
95+
get_staged_files() {
96+
git diff --cached --name-only --diff-filter=ACMR
97+
}
98+
99+
# Check if specific file types are staged
100+
has_staged_files() {
101+
get_staged_files | grep -E "$1" >/dev/null 2>&1
102+
}
40103

41-
log_success "Submodules updated successfully"
104+
# Main pre-commit validation
105+
main() {
106+
log_step "Starting pre-commit hook validation..."
42107

43-
# Check redirects (validation only, no file generation)
44-
log_info "Checking redirects..."
45-
run_yarn_command "check-redirects" "The redirect checker found issues that need to be addressed. Please check the output above and fix any issues before committing."
108+
# Environment and dependency checks
109+
log_info "🔍 Checking environment and dependencies..."
110+
check_command "node"
111+
check_command "yarn"
112+
check_command "git"
46113

47-
# Final formatting pass (formatting only, no file generation)
48-
log_info "Running final formatting pass..."
49-
run_yarn_command "format" "Final formatting failed"
114+
# Verify we're in a git repository
115+
if ! git rev-parse --git-dir >/dev/null 2>&1; then
116+
exit_with_error "Not in a git repository"
117+
fi
118+
119+
# Get staged files for optimization
120+
local staged_files
121+
staged_files=$(get_staged_files)
122+
123+
if [ -z "$staged_files" ]; then
124+
log_warning "No staged files found. Commit may be empty."
125+
exit 0
126+
fi
127+
128+
log_info "📁 Found $(echo "$staged_files" | wc -l | tr -d ' ') staged files"
129+
130+
# 1. Fast redirect validation (project-specific)
131+
log_step "Validating redirects..."
132+
time_command yarn check-redirects || exit_with_error "Redirect validation failed. Fix redirect issues before committing."
133+
log_success "Redirect validation passed"
134+
135+
# 2. Submodule updates (only if submodules are staged or .gitmodules changed)
136+
if echo "$staged_files" | grep -E "(\.gitmodules|submodules/)" >/dev/null 2>&1; then
137+
log_step "Updating git submodules..."
138+
time_command git submodule update --init --recursive || exit_with_error "Git submodule update failed. Check submodule configuration."
139+
log_success "Git submodules updated"
140+
else
141+
log_info "⏭️ Skipping submodule update (no submodule changes detected)"
142+
fi
143+
144+
# 3. Selective code formatting (only format staged files)
145+
if has_staged_files "\.(js|jsx|ts|tsx|json|md|mdx|scss)$"; then
146+
log_step "Formatting staged code files..."
147+
148+
# Use git to format only staged files for better performance
149+
local js_files md_files
150+
js_files=$(echo "$staged_files" | grep -E "\.(js|jsx|ts|tsx|json|scss)$" || true)
151+
md_files=$(echo "$staged_files" | grep -E "\.(md|mdx)$" || true)
50152

51-
# Auto-stage any files that were reformatted during the pre-commit process
52-
# Only stage files that already exist and were modified by formatting
53-
if [ -n "$(git diff --name-only)" ]; then
54-
# Filter out any new files and only add existing modified files
55-
modified_files=$(git diff --name-only | while read file; do
56-
if [ -f "$file" ] && git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
57-
echo "$file"
153+
# Format JavaScript/TypeScript files if any
154+
if [ -n "$js_files" ]; then
155+
log_info "🎨 Formatting JS/TS files..."
156+
echo "$js_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "JavaScript/TypeScript formatting failed"
58157
fi
59-
done)
60-
61-
if [ -n "$modified_files" ]; then
62-
log_info "Auto-staging existing files modified by formatters..."
63-
echo "$modified_files" | xargs git add
64-
log_success "Auto-staged formatted files"
158+
159+
# Format Markdown files if any
160+
if [ -n "$md_files" ]; then
161+
log_info "📝 Formatting Markdown files..."
162+
echo "$md_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "Markdown formatting failed"
163+
fi
164+
165+
# Re-stage formatted files
166+
echo "$staged_files" | grep -E "\.(js|jsx|ts|tsx|json|md|mdx|scss)$" | xargs git add || true
167+
log_success "Code formatting completed and files re-staged"
168+
else
169+
log_info "⏭️ Skipping code formatting (no formattable files staged)"
65170
fi
66-
fi
67171

68-
log_success "Pre-commit tasks completed"
69-
log_info "Note: File generation commands (precompiles, variable refs, etc.) have been removed from pre-commit"
70-
log_info "Run these manually when needed: yarn generate-precompiles-ref-tables, yarn update-variable-refs"
71-
log_info "To bypass hooks, use git commit --no-verify"
172+
# 4. TypeScript type checking (only if TS files are staged)
173+
if has_staged_files "\.(ts|tsx)$"; then
174+
log_step "Running TypeScript type checking..."
175+
time_command yarn typecheck || exit_with_error "TypeScript type checking failed. Fix type errors before committing."
176+
log_success "TypeScript type checking passed"
177+
else
178+
log_info "⏭️ Skipping TypeScript check (no TypeScript files staged)"
179+
fi
180+
181+
# Final success message with timing
182+
log_success "🎉 All pre-commit checks passed successfully!"
183+
log_info "✨ Commit is ready to proceed..."
184+
}
185+
186+
# Trap to handle interruptions gracefully
187+
trap 'log_error "Pre-commit hook interrupted"; exit 130' INT TERM
188+
189+
# Execute main function
190+
main "$@"

README.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Arbitrum Docs, built with docusaurus; docs are live at https://developer.arbitru
77
This repository is organized as follows:
88

99
### Documentation Content
10+
1011
- **`docs/`** - Main documentation content directory
1112
- `arbitrum-bridge/` - Bridge-related documentation
1213
- `build-decentralized-apps/` - Developer guides and references
@@ -25,18 +26,20 @@ This repository is organized as follows:
2526
- `welcome/` - Getting started content
2627

2728
### Application Code
29+
2830
- **`src/`** - Docusaurus application source code
29-
- `components/` - React components for the documentation site
30-
- `css/` - Styling and themes
31-
- `pages/` - Custom pages and landing pages
32-
- `resources/` - Global variables and configuration
33-
- `scripts/` - Build scripts
34-
- `theme/` - Docusaurus theme customizations
31+
- `components/` - React components for the documentation site
32+
- `css/` - Styling and themes
33+
- `pages/` - Custom pages and landing pages
34+
- `resources/` - Global variables and configuration
35+
- `scripts/` - Build scripts
36+
- `theme/` - Docusaurus theme customizations
3537

3638
### Configuration & Dependencies
39+
3740
- **`submodules/`** - Git submodule containing SDK source code
38-
- **`arbitrum-sdk/`** - Git submodule containing SDK source code
39-
- **`stylus-by-example/`** - Git submodule containing Stylus examples
41+
- **`arbitrum-sdk/`** - Git submodule containing SDK source code
42+
- **`stylus-by-example/`** - Git submodule containing Stylus examples
4043
- **`scripts/`** - Repository maintenance, build scripts, and content generators
4144
- **`static/`** - Static assets (images, files, JSON data)
4245

@@ -46,32 +49,50 @@ For most of the docs content, you can contribute by simply reviewing our [docs c
4649

4750
The following are the only exceptions:
4851

49-
- Contributing to the three troubleshooting pages — [nodes](docs/partials/_troubleshooting-nodes-partial.mdx), [builders](docs/partials/_troubleshooting-building-partial.mdx), and [users](docs/partials/_troubleshooting-users-partial.mdx) require internal Offchain Labs access. If you'd like to make a suggestion about content on any of those pages, open an [issue ticket](https://github.com/OffchainLabs/arbitrum-docs/issues).
52+
- Contributing to the three troubleshooting pages — [nodes](docs/partials/_troubleshooting-nodes-partial.mdx), [builders](docs/partials/_troubleshooting-building-partial.mdx), and [users](docs/partials/_troubleshooting-users-partial.mdx) require internal Offchain Labs access. If you'd like to make a suggestion about content on any of those pages, open an [issue ticket](https://github.com/OffchainLabs/arbitrum-docs/issues).
5053

5154
- To request to have your project added to the [3rd party node providers page](docs/build-decentralized-apps/reference/01-node-providers.mdx), use [this form](https://docs.google.com/forms/d/e/1FAIpQLSc_v8j7sc4ffE6U-lJJyLMdBoIubf7OIhGtCqvK3cGPGoLr7w/viewform).
5255

5356
### Initial set up
57+
5458
1. Clone this repo
59+
5560
```shell
5661
git clone git@github.com:OffchainLabs/arbitrum-docs.git
5762
```
63+
5864
2.Install node dependencies
5965

6066
```shell
6167
yarn
6268
```
63-
3. Start the development server
69+
70+
3.Update the submodules
71+
72+
```shell
73+
git submodule update --init --recursive
74+
```
75+
76+
4. Build
77+
78+
```shell
79+
yarn build
80+
```
81+
82+
5. Start the development server
83+
6484
```shell
6585
yarn start
6686
```
67-
Note: SDK docs are generated automatically on fresh clones. Use `SKIP_SDK_DOCS=true` to skip generation when docs already exist.
87+
6888
### Dev Build
6989

7090
To start a build server to serve the docs site locally, run this command from the root directory:
7191

7292
```shell
7393
yarn start
7494
```
95+
7596
### Build
7697

7798
While in the root directory, this command will build the site:
@@ -85,6 +106,7 @@ To test the build locally, you can use the following command:
85106
```shell
86107
yarn serve
87108
```
109+
88110
### Update glossary
89111

90112
You can add any terms to the glossary by following these steps:
@@ -124,4 +146,3 @@ This part will update the glossary.
124146
### Redirects
125147

126148
1. From the root directory, run `yarn check-redirects`.
127-

docs/how-arbitrum-works/bold/partials/_bold-public-preview-banner-partial.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::caution ALPHA RELEASE, PUBLIC PREVIEW DOCS
22

3-
The BoLD dispute protocol is currently deployed on a public testnet (that posts assertions to Ethereum Sepolia) and is tagged as an `alpha` release. The code has been audited by [Trail of Bits](https://github.com/trailofbits/publications/blob/master/reviews/2024-04-offchainbold-securityreview.pdf) and in a [public audit competition with Code4rena](https://code4rena.com/audits/2024-05-arbitrum-bold), but **should not be used in production scenarios**. Please note that the public testnet is intended for Arbitrum users and researchers to test and experiment with the BoLD dispute protocol for the purposes of education and hardening the protocol via the surfacing of bugs. The public testnet may be paused, and its parameters may be updated at any time in response to scenarios that impact the network and its ability to fulfill its function as a working, reliable test environment. This documentation is currently in [public preview](../public-preview-expectations.md).
3+
The BoLD dispute protocol is currently deployed on a public testnet (that posts assertions to Ethereum Sepolia) and is tagged as an `alpha` release. The code has been audited by [Trail of Bits](https://github.com/trailofbits/publications/blob/master/reviews/2024-04-offchainbold-securityreview.pdf) and in a [public audit competition with Code4rena](https://code4rena.com/audits/2024-05-arbitrum-bold), but **should not be used in production scenarios**. Please note that the public testnet is intended for Arbitrum users and researchers to test and experiment with the BoLD dispute protocol for the purposes of education and hardening the protocol via the surfacing of bugs. The public testnet may be paused, and its parameters may be updated at any time in response to scenarios that impact the network and its ability to fulfill its function as a working, reliable test environment. This documentation is currently in [public preview](../public-preview-expectations.mdx).
44

55
To provide feedback, click the _Request an update_ button at the top of this document, [join the Arbitrum Discord](https://discord.gg/arbitrum), or reach out to our team directly by completing [this form](http://bit.ly/3yy6EUK).
66

File renamed without changes.

0 commit comments

Comments
 (0)