mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 07:00:23 +00:00
refactor: Use glob pattern to find litegraph files with declare keywords
Instead of hardcoding the list of files, dynamically find all TypeScript files in litegraph that contain 'declare' keywords using glob pattern matching.
This commit is contained in:
@@ -5,52 +5,72 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { globSync } from 'glob'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const rootDir = path.resolve(__dirname, '..')
|
||||
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src')
|
||||
|
||||
const filesToProcess = [
|
||||
'LGraphNode.ts',
|
||||
'widgets/BaseWidget.ts',
|
||||
'subgraph/SubgraphInput.ts',
|
||||
'subgraph/SubgraphNode.ts',
|
||||
'subgraph/SubgraphOutput.ts',
|
||||
'subgraph/EmptySubgraphInput.ts',
|
||||
'subgraph/EmptySubgraphOutput.ts'
|
||||
]
|
||||
|
||||
const backupMap = new Map<string, string>()
|
||||
|
||||
/**
|
||||
* Find all TypeScript files in litegraph that contain 'declare' keywords
|
||||
*/
|
||||
function findFilesWithDeclare(): string[] {
|
||||
// Search for all .ts files in litegraph src directory
|
||||
const pattern = path.join(litegraphSrcDir, '**/*.ts')
|
||||
const files = globSync(pattern, {
|
||||
ignore: ['**/*.test.ts', '**/*.spec.ts', '**/node_modules/**']
|
||||
})
|
||||
|
||||
// Filter to only files that actually contain 'declare' keyword
|
||||
return files.filter(filePath => {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf-8')
|
||||
// Check for class property declarations with 'declare' keyword
|
||||
return /^\s*declare\s+/m.test(content)
|
||||
} catch (error) {
|
||||
console.warn(` ⚠ Could not read ${filePath}: ${error.message}`)
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function preprocessLitegraph() {
|
||||
console.log('Preprocessing litegraph files for i18n collection...')
|
||||
|
||||
for (const relativePath of filesToProcess) {
|
||||
const filePath = path.join(litegraphSrcDir, relativePath)
|
||||
const filesToProcess = findFilesWithDeclare()
|
||||
|
||||
if (filesToProcess.length === 0) {
|
||||
console.log(' ℹ No files with declare keywords found')
|
||||
return
|
||||
}
|
||||
|
||||
console.log(` Found ${filesToProcess.length} files with declare keywords`)
|
||||
|
||||
for (const filePath of filesToProcess) {
|
||||
const originalContent = fs.readFileSync(filePath, 'utf-8')
|
||||
|
||||
if (fs.existsSync(filePath)) {
|
||||
const originalContent = fs.readFileSync(filePath, 'utf-8')
|
||||
|
||||
// Only process if file contains 'declare' keywords
|
||||
if (originalContent.includes('declare ')) {
|
||||
// Store original content in memory
|
||||
backupMap.set(filePath, originalContent)
|
||||
|
||||
// Remove 'declare' keyword from class properties
|
||||
const modifiedContent = originalContent.replace(
|
||||
/^(\s*)declare\s+/gm,
|
||||
'$1// @ts-ignore - removed declare for Playwright\n$1'
|
||||
)
|
||||
|
||||
// Write modified content
|
||||
fs.writeFileSync(filePath, modifiedContent)
|
||||
console.log(` ✓ Processed ${relativePath}`)
|
||||
}
|
||||
}
|
||||
// Store original content in memory
|
||||
backupMap.set(filePath, originalContent)
|
||||
|
||||
// Remove 'declare' keyword from class properties
|
||||
const modifiedContent = originalContent.replace(
|
||||
/^(\s*)declare\s+/gm,
|
||||
'$1// @ts-ignore - removed declare for Playwright\n$1'
|
||||
)
|
||||
|
||||
// Write modified content
|
||||
fs.writeFileSync(filePath, modifiedContent)
|
||||
console.log(` ✓ Processed ${path.relative(litegraphSrcDir, filePath)}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function restoreLitegraph() {
|
||||
if (backupMap.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Restoring original litegraph files...')
|
||||
|
||||
for (const [filePath, originalContent] of backupMap.entries()) {
|
||||
|
||||
Reference in New Issue
Block a user