main ini
This commit is contained in:
32
lib/tools.js
Normal file
32
lib/tools.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// Which projects use the shared generator in _Tools\ComfyGen (via gen.cmd) and
|
||||
// which still carry their own copy of generator scripts.
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const GEN_DIR = /^(sprite-?generator|sprite-?gen|design-?gen|asset-?gen)$/i
|
||||
|
||||
function ls(dir) {
|
||||
try { return fs.readdirSync(dir, { withFileTypes: true }) } catch { return [] }
|
||||
}
|
||||
|
||||
function toolInfo(projectPath) {
|
||||
const generators = []
|
||||
const dirs = [projectPath, ...ls(projectPath).filter((e) => e.isDirectory() && !e.name.startsWith('.') && !/^(_archiv|node_modules)$/i.test(e.name)).map((e) => path.join(projectPath, e.name))]
|
||||
for (const dir of dirs) {
|
||||
for (const e of ls(dir)) {
|
||||
if (!e.isDirectory() || !GEN_DIR.test(e.name)) continue
|
||||
const gdir = path.join(dir, e.name)
|
||||
const files = ls(gdir).filter((f) => f.isFile()).map((f) => f.name)
|
||||
const shared = files.includes('gen.cmd')
|
||||
generators.push({
|
||||
rel: path.relative(projectPath, gdir),
|
||||
kind: shared ? 'comfygen' : 'copy',
|
||||
scripts: files.filter((f) => f.endsWith('.py')),
|
||||
hasOutput: fs.existsSync(path.join(gdir, 'output')),
|
||||
})
|
||||
}
|
||||
}
|
||||
return { generators }
|
||||
}
|
||||
|
||||
module.exports = { toolInfo }
|
||||
Reference in New Issue
Block a user