()
| 137 | |
| 138 | |
| 139 | export async function declareLocalType() { |
| 140 | if (!process.env.DB_DRIVER) throw new Error('环境变量 DB_DRIVER 未定义') |
| 141 | const targetPath = path.resolve('local.d.ts') |
| 142 | const fileContent = ` |
| 143 | declare global { |
| 144 | type DB_DRIVER ='${process.env.DB_DRIVER}' |
| 145 | } |
| 146 | export {} |
| 147 | `.trim() |
| 148 | try { |
| 149 | // 仅当内容变化时才写入 |
| 150 | const existingContent = await asyncFs.readFile(targetPath, 'utf8').catch(() => '') |
| 151 | if (existingContent.trim() === fileContent) return |
| 152 | await asyncFs.writeFile(targetPath, fileContent, { encoding: 'utf-8' }) |
| 153 | console.log(`Type declaration updated at ${targetPath}`) |
| 154 | } catch (error) { |
| 155 | console.error('Failed to generate type declaration:', error) |
| 156 | process.exit(1) |
| 157 | } |
| 158 | } |
no outgoing calls
no test coverage detected