itk-wasm
Version:
High-performance spatial analysis in a web browser, Node.js, and reproducible execution across programming languages and hardware architectures.
16 lines (14 loc) • 572 B
JavaScript
import fs from 'fs-extra'
function writeIfOverrideNotPresent(modulePath, content, comment='//') {
const commentEnd = comment === '<!--' ? ' -->' : ''
const prefix = `${comment} Generated file. To retain edits, remove this comment.${commentEnd}\n\n`
if (!fs.existsSync(modulePath)) {
fs.writeFileSync(modulePath, prefix + content)
return
}
const firstLine = fs.readFileSync(modulePath, 'utf-8').split('\n')[0]
if (firstLine.includes('Generated file')) {
fs.writeFileSync(modulePath, prefix + content)
}
}
export default writeIfOverrideNotPresent