Spaces:
Running
Running
| const fs = require('fs'); | |
| const path = require('path'); | |
| const BACKUP_BASE = path.resolve(__dirname, '..', '..'); | |
| const SRC_DIR = path.resolve(__dirname, '..'); | |
| const EXCLUDE_DIRS = ['node_modules', '.git', '.claude', 'dist']; | |
| function shouldExclude(full, srcDir) { | |
| const relative = path.relative(srcDir, full).replace(/\\/g, '/'); | |
| const basename = path.basename(full); | |
| for (const d of EXCLUDE_DIRS) { | |
| if (relative === d || relative.startsWith(d + '/')) return true; | |
| } | |
| return false; | |
| } | |
| function collectFiles(srcDir) { | |
| const files = []; | |
| function walk(dir) { | |
| const entries = fs.readdirSync(dir); | |
| for (const entry of entries) { | |
| const full = path.join(dir, entry); | |
| if (shouldExclude(full, srcDir)) continue; | |
| const stat = fs.statSync(full); | |
| if (stat.isDirectory()) walk(full); | |
| else files.push(full); | |
| } | |
| } | |
| walk(srcDir); | |
| return files; | |
| } | |
| function copyFiles(files, srcDir, destDir) { | |
| for (const full of files) { | |
| const relative = path.relative(srcDir, full); | |
| const dest = path.join(destDir, relative); | |
| fs.mkdirSync(path.dirname(dest), { recursive: true }); | |
| fs.copyFileSync(full, dest); | |
| } | |
| } | |
| const pkgPath = path.join(SRC_DIR, 'package.json'); | |
| const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); | |
| const version = pkg.version || 'unknown'; | |
| const now = new Date(); | |
| const ts = now.toISOString().replace(/[:.]/g, '-').slice(0, 19); | |
| const folderName = 'backend-service_v' + version + '_' + ts; | |
| const backupPath = path.join(BACKUP_BASE, folderName); | |
| console.log('Version: ' + version); | |
| console.log('Creating backup: ' + backupPath); | |
| const files = collectFiles(SRC_DIR); | |
| console.log('Found ' + files.length + ' source files'); | |
| copyFiles(files, SRC_DIR, backupPath); | |
| console.log('Backup complete: ' + backupPath); | |
| const serverJs = fs.readFileSync(path.join(backupPath, 'server.js'), 'utf-8'); | |
| const hasNewColors = serverJs.includes('#339CFF'); | |
| console.log('New ChatGPT colors in backup: ' + (hasNewColors ? 'YES' : 'NO')); | |