create directories recursively if necessary to output the file (match elm make behavior)

This commit is contained in:
Matthew Griffith 2020-08-22 12:01:33 -04:00
parent 3317354e26
commit 8e1d5348fc

View File

@ -53,6 +53,13 @@ async function run(inputFilePath: string | undefined) {
false,
toolDefaults
);
// Make sure all the folders up to the output file exist, if not create them.
// This mirrors elm make behavior.
const outputDirectory = path.dirname(program.output);
if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory, { recursive: true });
}
fs.writeFileSync(program.output, transformed);
const fileName = path.basename(inputFilePath);
console.log('Success!');