/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const fs = require( 'fs-extra' );
const upath = require( 'upath' );

/**
 * Saves .html files to file system.
 *
 * @param {Array.<HtmlFile>} files HtmlFile objects containing content to be written to .html files to file system.
 * @param {String} destinationDir Additional destination path. Additional because files already have its own path.
 * @returns {Promise<void>}
 */
module.exports = async ( files, destinationDir = '.' ) => {
	const writePromises = files.map( file =>
		fs.outputFile(
			upath.join( destinationDir, file.dirname, file.basename ),
			file.content
		)
	);

	return Promise.all( writePromises );
};
