mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-02 04:50:06 -05:00
af26fbebe6
Co-authored-by: Jessica Sachs <jess@jessicasachs.io> Co-authored-by: Barthélémy Ledoux <bart@cypress.io> Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: Zach Bloomquist <github@chary.us> Co-authored-by: Dmitriy Kovalenko <dmtr.kovalenko@outlook.com> Co-authored-by: ElevateBart <ledouxb@gmail.com> Co-authored-by: Ben Kucera <14625260+Bkucera@users.noreply.github.com>
42 lines
954 B
JavaScript
42 lines
954 B
JavaScript
const path = require('path')
|
|
const { fs } = require('./util/fs')
|
|
|
|
module.exports = {
|
|
readFile (projectRoot, file, options = {}) {
|
|
const filePath = path.resolve(projectRoot, file)
|
|
const readFn = path.extname(filePath) === '.json' ? fs.readJsonAsync : fs.readFileAsync
|
|
|
|
return readFn(filePath, options.encoding || 'utf8')
|
|
.then((contents) => {
|
|
return {
|
|
contents,
|
|
filePath,
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
err.filePath = filePath
|
|
throw err
|
|
})
|
|
},
|
|
|
|
writeFile (projectRoot, file, contents, options = {}) {
|
|
const filePath = path.resolve(projectRoot, file)
|
|
const writeOptions = {
|
|
encoding: options.encoding || 'utf8',
|
|
flag: options.flag || 'w',
|
|
}
|
|
|
|
return fs.outputFile(filePath, contents, writeOptions)
|
|
.then(() => {
|
|
return {
|
|
contents,
|
|
filePath,
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
err.filePath = filePath
|
|
throw err
|
|
})
|
|
},
|
|
}
|