Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,39 @@ main() {
js_files=$(echo "$staged_files" | grep -E "\.(js|jsx|ts|tsx|json|scss)$" || true)
md_files=$(echo "$staged_files" | grep -E "\.(md|mdx)$" || true)

# Filter out files that should be ignored by Prettier
# When passing files explicitly to Prettier, .prettierignore is bypassed
# So we need to manually filter them out
filter_prettier_ignored() {
local files="$1"
local filtered=""
while IFS= read -r file; do
if [ -n "$file" ]; then
# Check if file is ignored by Prettier
if npx prettier --file-info "$file" 2>/dev/null | grep -q '"ignored": false'; then
filtered="$filtered$file"$'\n'
fi
fi
done <<< "$files"
echo "$filtered"
}

# Format JavaScript/TypeScript files if any
if [ -n "$js_files" ]; then
log_info "🎨 Formatting JS/TS files..."
echo "$js_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "JavaScript/TypeScript formatting failed"
js_files=$(filter_prettier_ignored "$js_files")
if [ -n "$js_files" ]; then
echo "$js_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "JavaScript/TypeScript formatting failed"
fi
fi

# Format Markdown files if any
if [ -n "$md_files" ]; then
log_info "📝 Formatting Markdown files..."
echo "$md_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "Markdown formatting failed"
md_files=$(filter_prettier_ignored "$md_files")
if [ -n "$md_files" ]; then
echo "$md_files" | xargs yarn prettier --write --config "./.prettierrc.js" || exit_with_error "Markdown formatting failed"
fi
fi

# Re-stage formatted files
Expand Down
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
../arbitrum-docs/partials/_troubleshooting-stylus-partial.mdx
../arbitrum-docs/partials/_troubleshooting-users-partial.mdx
../arbitrum-docs/CODEOWNERS.md

# SDK documentation landing pages (manually maintained, skip formatting)
docs/sdk/index.mdx
docs/sdk/migrate.mdx
1 change: 1 addition & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const config = {

// Output options
out: './docs/sdk',
cleanOutputDir: false, // Don't clean output dir to preserve manual files
hideGenerator: true,
validation: {
notExported: false,
Expand Down
26 changes: 18 additions & 8 deletions scripts/sdkDocsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ function load(app) {
const sdkOutputDir = app.options.getValue('out'); // This is the SDK directory
const sourceDir = path.join(sdkOutputDir, '../../submodules/arbitrum-sdk/docs');

app.renderer.on(RendererEvent.START, async () => {
cleanDirectory(sdkOutputDir, ['index.mdx', 'migrate.mdx']); // Preserve manual files
app.renderer.on(RendererEvent.START, () => {
// Clean generated docs but preserve manually maintained files
cleanDirectory(sdkOutputDir, ['index.mdx', 'migrate.mdx']);
});

app.renderer.on(RendererEvent.END, async () => {
// Create the manual introduction and migration files
createManualFiles(sdkOutputDir);
app.renderer.on(RendererEvent.END, () => {
// Create manual SDK files only if they don't exist (bootstrap templates)
// index.mdx and migrate.mdx are manually maintained and should not be regenerated
const indexPath = path.join(sdkOutputDir, 'index.mdx');
const migratePath = path.join(sdkOutputDir, 'migrate.mdx');

if (!fs.existsSync(indexPath) || !fs.existsSync(migratePath)) {
createManualFiles(sdkOutputDir);
}

// Generate sidebar only from the actual TypeDoc generated content
const sidebarItems = generateSidebarFromSDKContent(sdkOutputDir);
Expand Down Expand Up @@ -636,9 +643,12 @@ Message classes have been renamed and their methods updated:
| ----------- | -------------------------------- |
| \`waitForL2\` | \`waitForChildTransactionReceipt\` |`;

// Write the files
fs.writeFileSync(path.join(sdkOutputDir, 'index.mdx'), introductionContent, 'utf8');
fs.writeFileSync(path.join(sdkOutputDir, 'migrate.mdx'), migrationContent, 'utf8');
// Bootstrap: Write template files (only called when files don't exist)
const indexPath = path.join(sdkOutputDir, 'index.mdx');
const migratePath = path.join(sdkOutputDir, 'migrate.mdx');

fs.writeFileSync(indexPath, introductionContent, 'utf8');
fs.writeFileSync(migratePath, migrationContent, 'utf8');

// Remove the TypeDoc-generated index.md file if it exists
const indexMdPath = path.join(sdkOutputDir, 'index.md');
Expand Down