| 61 | | 61 | |
| 62 | try { | 62 | try { |
| 63 | console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak')); | 63 | console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak')); |
| | 64 | fs.renameSync('./config.conf', './config.conf.cjs'); // Force loading as CommonJS |
| 64 | const require = createRequire(import.meta.url); | 65 | const require = createRequire(import.meta.url); |
| 65 | const config = require(path.join(process.cwd(), './config.conf')); | 66 | const config = require(path.join(process.cwd(), './config.conf.cjs')); |
| 66 | fs.copyFileSync('./config.conf', './config.conf.bak'); | 67 | fs.copyFileSync('./config.conf.cjs', './config.conf.bak'); |
| 67 | fs.rmSync('./config.conf'); | 68 | fs.rmSync('./config.conf.cjs'); |
| 68 | fs.writeFileSync('./config.yaml', yaml.stringify(config)); | 69 | fs.writeFileSync('./config.yaml', yaml.stringify(config)); |
| 69 | console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.')); | 70 | console.log(color.green('Conversion successful. Please check your config.yaml and fix it if necessary.')); |
| 70 | } catch (error) { | 71 | } catch (error) { |
| 71 | console.error(color.red('FATAL: Config conversion failed. Please check your config.conf file and try again.')); | 72 | console.error(color.red('FATAL: Config conversion failed. Please check your config.conf file and try again.'), error); |
| 72 | return; | 73 | return; |
| 73 | } | 74 | } |
| 74 | } | 75 | } |