add dashboard

This commit is contained in:
2026-11-12 14:03:53 +01:00
parent 53f1896d05
commit 68bb7ff810
14 changed files with 2037 additions and 280 deletions

View File

@@ -68,6 +68,53 @@ async function create(opts) {
}
}
// Renames a project folder and/or moves it into another projects folder.
// Same drive: a plain rename. Other drive: robocopy everything (no excludes),
// check that nothing is missing, only then delete the original.
// opts: { from (absolute project path), rootPath (target projects folder), name }
async function move(opts) {
if (running) throw new Error(`Es läuft gerade schon „${running}“.`)
const name = checkName(opts.name)
const src = path.resolve(opts.from)
const dest = path.join(path.resolve(opts.rootPath), name)
if (path.basename(src).toLowerCase() === '_tools') throw new Error('_Tools wird nicht umbenannt oder verschoben.')
if (src === dest) throw new Error('Name und Ordner sind unverändert.')
const caseOnly = src.toLowerCase() === dest.toLowerCase()
if (!caseOnly && fs.existsSync(dest)) throw new Error(`Es gibt schon einen Ordner „${name}“ in ${opts.rootPath}.`)
if (dest.toLowerCase().startsWith(src.toLowerCase() + path.sep)) throw new Error('Ein Projekt kann nicht in sich selbst verschoben werden.')
running = path.basename(src)
try {
const copyMove = async () => {
const args = [src, dest, '/E', '/XJ', '/R:1', '/W:1', '/COPY:DAT', '/DCOPY:T', '/MT:8', '/NJH', '/NJS', '/NP', '/NFL', '/NDL']
const r = await run('robocopy', args, { timeout: 2 * 60 * 60 * 1000 })
if (r.code < 0 || r.code >= 8) throw new Error(`Kopieren fehlgeschlagen (robocopy ${r.code}). Das Original in ${src} ist unverändert; die angefangene Kopie liegt in ${dest}.`)
// check: a listing run must find nothing left to copy
const chk = await run('robocopy', [src, dest, '/E', '/XJ', '/L', '/NJH', '/NJS', '/NP', '/NDL', '/FP', '/R:0', '/W:0'], { timeout: 30 * 60 * 1000 })
const missing = chk.stdout.split(/\r?\n/).filter((l) => /\t/.test(l) && !/\*EXTRA/i.test(l)).length
if (chk.code < 0 || chk.code >= 8 || missing) throw new Error(`Kopie unvollständig (${missing} Dateien fehlen). Das Original in ${src} bleibt erhalten; die Kopie liegt in ${dest}.`)
fs.rmSync(src, { recursive: true, force: true, maxRetries: 3 })
}
if (process.env.DASHBOARD_TEST_FORCE_COPY && !caseOnly) await copyMove()
else {
try {
if (caseOnly) {
// Windows: a case-only rename needs a detour
const tmp = `${src}.__umbenennen__${Date.now()}`
fs.renameSync(src, tmp)
fs.renameSync(tmp, dest)
} else fs.renameSync(src, dest)
} catch (e) {
if (e.code === 'EXDEV') await copyMove()
else if (e.code === 'EPERM' || e.code === 'EBUSY' || e.code === 'EACCES') throw new Error('Der Ordner ist in Benutzung (VS Code, Konsole, laufendes Programm, Explorer-Fenster?) – schließen und nochmal versuchen.')
else throw e
}
}
return { name, path: dest }
} finally {
running = null
}
}
const busy = () => !!running
module.exports = { create, checkName, busy }
module.exports = { create, move, checkName, busy }