summaryrefslogtreecommitdiffstats
path: root/packages/gitbook/src/output/helper/writeFile.js
blob: ab36418c2fabcc894c8f23fe84c0c9a758c91520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const path = require('path');
const fs = require('../../utils/fs');

/**
    Write a file to the output folder

    @param {Output} output
    @param {String} filePath
    @param {Buffer|String} content
    @return {Promise}
*/
function writeFile(output, filePath, content) {
    const rootFolder = output.getRoot();
    filePath = path.join(rootFolder, filePath);

    return fs.ensureFile(filePath)
    .then(() => {
        return fs.writeFile(filePath, content);
    })
    .thenResolve(output);
}

module.exports = writeFile;