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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
- name: Run tests
run: yarn test

- name: Check for missing redirects
run: yarn tsx scripts/check-redirects.ts --ci
- name: Check for deleted markdown files
run: yarn tsx scripts/check-markdown.ts --ci
7 changes: 4 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ main() {
log_info "📁 Found $(echo "$staged_files" | wc -l | tr -d ' ') staged files"

# 1. Fast redirect validation (project-specific)
log_step "Validating redirects..."
time_command yarn check-redirects || exit_with_error "Redirect validation failed. Fix redirect issues before committing."
log_success "Redirect validation passed"
# log_step "Validating redirects..."
# Will need to replace the 'check-redirects' line below when we replace it
# time_command yarn check-redirects || exit_with_error "Redirect validation failed. Fix redirect issues before committing."
# log_success "Redirect validation passed"

# 2. Submodule updates (only if submodules are staged or .gitmodules changed)
if echo "$staged_files" | grep -E "(\.gitmodules|submodules/)" >/dev/null 2>&1; then
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,3 @@ This part will update the glossary.
### Formatting

1. Run `yarn format` from the root directory.

### Redirects

1. From the root directory, run `yarn check-redirects`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"typecheck": "tsc",
"test": "vitest run",
"test:watch": "vitest",
"check-redirects": "tsx scripts/check-redirects.ts",
"check-releases": "ts-node scripts/check-releases.ts",
"check-markdown": "tsx scripts/check-markdown.ts",
"notion:update": "tsx scripts/notion-update.ts",
"notion:verify-quicklooks": "tsx scripts/notion-verify-quicklooks.ts",
"lint:markdown": "markdownlint \"docs/**/*.{md,mdx}\" --ignore \"docs/sdk/**\"",
Expand Down
84 changes: 84 additions & 0 deletions scripts/check-markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { execSync } from 'child_process';
import { exit } from 'process';

// Function to check for staged deletions of .md or .mdx files
function checkStagedMarkdownDeletions() {
try {
// Run git diff --cached --name-status to get staged changes
const output = execSync('git diff --cached --name-status').toString().trim();
// Split the output into lines
const lines = output.split('\n');
// Filter for deletions (D) of .md or .mdx files
const deletedMarkdownFiles = lines
.filter((line) => {
const parts = line.split('\t');
const status = parts[0];
const file = parts[1];
return status === 'D' && (file.endsWith('.md') || file.endsWith('.mdx'));
})
.map((line) => line.split('\t')[1]); // Extract the file names
if (deletedMarkdownFiles.length > 0) {
console.error('# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ');
console.error('Error: The following Markdown files are staged for deletion:');
deletedMarkdownFiles.forEach((file) => console.error(`- ${file}`));
console.error('Please unstage these deletions or remove them if unintended.');
console.error('# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ');
} else {
console.log('No staged deletions of Markdown files found.');
// No exit here, to allow continuing to the next check
}
} catch (error) {
console.error('Failed to execute git command. Ensure this is run in a git repository.');
console.error(error.message);
exit(1);
}
}

// Function to check for staged renames or moves of .md or .mdx files
function checkStagedMarkdownRenames() {
try {
// Run git diff --cached --name-status to get staged changes
const output = execSync('git diff --cached --name-status').toString().trim();

// Split the output into lines
const lines = output.split('\n');

// Array to hold details of renamed/moved files
const renamedMarkdownFiles: string[] = [];

lines.forEach((line) => {
if (!line.trim()) return;

const parts = line.split('\t');
const status = parts[0];

if (status.startsWith('R')) {
// For renames: parts[0] is Rxxx, parts[1] is old file, parts[2] is new file
const oldFile = parts[1];
const newFile = parts[2];
if (oldFile.endsWith('.md') || oldFile.endsWith('.mdx')) {
renamedMarkdownFiles.push(`${oldFile} -> ${newFile}`);
}
}
});

if (renamedMarkdownFiles.length > 0) {
console.error('# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ');
console.error('Error: The following Markdown files are staged for rename or move:');
renamedMarkdownFiles.forEach((detail) => console.error(`- ${detail}`));
console.error('Please unstage these changes or review them if unintended.');
console.error('# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ');
} else {
console.log('No staged renames or moves of Markdown files found.');
// No exit here, to allow the script to complete
}
} catch (error) {
console.error('Failed to execute git command. Ensure this is run in a git repository.');
console.error(error.message);
exit(1);
}
}

// Run both checks
checkStagedMarkdownDeletions();
checkStagedMarkdownRenames();
Loading
Loading