mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
32ac8e73fd
* Fix Biome lint violations and add Biome CI check Biome was not configured to respect .gitignore, so ~92% of the 13,355 reported diagnostics came from gitignored build artifacts. Enable VCS integration (useIgnoreFile), apply safe auto-fixes across the repo, fix the remaining mechanical errors by hand, downgrade judgment-call a11y / dangerouslySetInnerHTML rules to warnings, and add a 'biome ci' job to the Lint workflow so violations block PRs going forward. * Use an empty changeset (no behavior change, no release needed)
124 lines
3.5 KiB
JavaScript
124 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Auto-generates _workflows.ts registry file for workbenches
|
|
*
|
|
* Usage: node generate-workflows-registry.js [workflowsDir] [outputPath] [--esm]
|
|
*
|
|
* Defaults:
|
|
* workflowsDir: ./workflows
|
|
* outputPath: ./_workflows.ts
|
|
*
|
|
* Options:
|
|
* --esm: Add .js extension to imports (required for ESM with NodeNext moduleResolution)
|
|
*/
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
// Parse arguments
|
|
const args = process.argv.slice(2);
|
|
const esmMode = args.includes('--esm');
|
|
const nonFlagArgs = args.filter((arg) => !arg.startsWith('--'));
|
|
|
|
// Get arguments or use defaults
|
|
const workflowsDir = nonFlagArgs[0] || './workflows';
|
|
const outputPath = nonFlagArgs[1] || './_workflows.ts';
|
|
|
|
// Calculate relative path from output to workflows directory
|
|
const outputDir = path.dirname(outputPath);
|
|
const relativeWorkflowsPath = path
|
|
.relative(outputDir, workflowsDir)
|
|
.replace(/\\/g, '/');
|
|
|
|
// Files to skip
|
|
const SKIP_FILES = ['helpers.ts'];
|
|
const SKIP_PREFIX = '_';
|
|
|
|
function generateSafeIdentifier(filename) {
|
|
// Convert filename to safe JS identifier
|
|
// e.g., "1_simple.ts" -> "workflow_1_simple"
|
|
return (
|
|
'workflow_' + filename.replace(/\.tsx?$/, '').replace(/[^a-zA-Z0-9_]/g, '_')
|
|
);
|
|
}
|
|
|
|
function generateRegistry() {
|
|
// Check if workflows directory exists
|
|
if (!fs.existsSync(workflowsDir)) {
|
|
console.error(`Error: Workflows directory not found: ${workflowsDir}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Read all files from workflows directory
|
|
const files = fs
|
|
.readdirSync(workflowsDir)
|
|
.filter((file) => {
|
|
// Only .ts files
|
|
if (!file.endsWith('.ts') && !file.endsWith('.tsx')) return false;
|
|
// Skip helpers and files starting with _
|
|
if (SKIP_FILES.includes(file)) return false;
|
|
if (file.startsWith(SKIP_PREFIX)) return false;
|
|
return true;
|
|
})
|
|
.sort(); // Sort for consistent output
|
|
|
|
if (files.length === 0) {
|
|
console.warn('Warning: No workflow files found to register');
|
|
}
|
|
|
|
// Determine file extension for imports
|
|
const importExtension = esmMode ? '.js' : '';
|
|
|
|
// Generate imports
|
|
const imports = files
|
|
.map((file) => {
|
|
const identifier = generateSafeIdentifier(file);
|
|
// Use relative path from output directory to workflows directory
|
|
let importPath;
|
|
const baseName = file.replace(/\.tsx?$/, '');
|
|
if (relativeWorkflowsPath && relativeWorkflowsPath !== 'workflows') {
|
|
importPath = `${relativeWorkflowsPath}/${baseName}${importExtension}`;
|
|
} else {
|
|
importPath = `./workflows/${baseName}${importExtension}`;
|
|
}
|
|
return `import * as ${identifier} from '${importPath}';`;
|
|
})
|
|
.join('\n');
|
|
|
|
// Generate registry object entries
|
|
const registryEntries = files
|
|
.map((file) => {
|
|
const identifier = generateSafeIdentifier(file);
|
|
return ` 'workflows/${file}': ${identifier},`;
|
|
})
|
|
.join('\n');
|
|
|
|
// Generate full content
|
|
const content = `// Auto-generated by workbench/scripts/generate-workflows-registry.js
|
|
// Do not edit this file manually - it will be regenerated on build
|
|
|
|
${imports}
|
|
|
|
export const allWorkflows = {
|
|
${registryEntries}
|
|
} as const;
|
|
`;
|
|
|
|
// Write to output file
|
|
fs.writeFileSync(outputPath, content, 'utf-8');
|
|
|
|
console.log(`✓ Generated ${outputPath} with ${files.length} workflow(s)`);
|
|
for (const file of files) {
|
|
console.log(` - workflows/${file}`);
|
|
}
|
|
}
|
|
|
|
// Run the generator
|
|
try {
|
|
generateRegistry();
|
|
} catch (error) {
|
|
console.error('Error generating workflows registry:', error);
|
|
process.exit(1);
|
|
}
|