Skip to content

Commit

Permalink
Merge pull request #170 from AttilaMihaly/create-missing-output-dirs
Browse files Browse the repository at this point in the history
Create missing output dirs. #169
  • Loading branch information
AttilaMihaly authored Oct 2, 2020
2 parents 8f1f1b5 + 8c60bbf commit fa9b7f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 9 additions & 3 deletions cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fs = require('fs')
const readdir = util.promisify(fs.readdir)
const mkdir = util.promisify(fs.mkdir)
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
const fsWriteFile = util.promisify(fs.writeFile)
// Elm imports
const worker = require('./Morphir.Elm.CLI').Elm.Morphir.Elm.CLI.init()

Expand Down Expand Up @@ -82,7 +82,7 @@ async function gen(input, outputPath, options) {
await mkdir(fileDir, { recursive: true })
console.log(`INSERT - ${filePath}`)
}
return writeFile(filePath, content)
return fsWriteFile(filePath, content)
})
const filesToDelete = await findFilesToDelete(outputPath, fileMap)
const deletePromises =
Expand Down Expand Up @@ -153,5 +153,11 @@ async function findFilesToDelete(outputPath, fileMap) {
return Promise.all(await readDir(outputPath, files))
}

async function writeFile(filePath, content) {
await mkdir(path.dirname(filePath), { recursive: true })
return await fsWriteFile(filePath, content)
}

exports.make = make;
exports.gen = gen;
exports.gen = gen;
exports.writeFile = writeFile;
9 changes: 1 addition & 8 deletions cli/morphir-elm-make.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
'use strict'

// NPM imports
const path = require('path')
const util = require('util')
const fs = require('fs')
const readdir = util.promisify(fs.readdir)
const lstat = util.promisify(fs.lstat)
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
const commander = require('commander')
const cli = require('./cli')

Expand All @@ -25,7 +18,7 @@ program
cli.make(program.projectDir)
.then((packageDef) => {
console.log(`Writing file ${program.output}.`)
writeFile(program.output, JSON.stringify(packageDef, null, 4))
cli.writeFile(program.output, JSON.stringify(packageDef, null, 4))
.then(() => {
console.log('Done.')
})
Expand Down

0 comments on commit fa9b7f0

Please sign in to comment.