Skip to content

Commit

Permalink
Merge pull request #157 from terascope/ensure-output-dir-exists
Browse files Browse the repository at this point in the history
v0.7.7 - Ensure output dir exists
  • Loading branch information
peterdemartini authored Apr 20, 2021
2 parents 9fa2a9e + 35a0ab9 commit 1773a06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "0.7.6",
"version": "0.7.7",
"description": "Download a specific release from github",
"main": "lib/index.js",
"typings": "index.d.ts",
Expand Down
11 changes: 10 additions & 1 deletion src/downloadRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MultiProgress = require('multi-progress');
async function downloadRelease(
user,
repo,
outputDir,
_outputDir,
filterRelease = pass,
filterAsset = pass,
leaveZipped = false,
Expand Down Expand Up @@ -47,6 +47,15 @@ async function downloadRelease(
progress = bar.update.bind(bar);
}

const outputDir = path.isAbsolute(_outputDir) ? _outputDir : path.resolve(_outputDir);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}

if (!fs.statSync(outputDir).isDirectory()) {
throw new Error(`Output path "${outputDir}" must be a directory`);
}

const destf = path.join(outputDir, asset.name);
if (!fs.existsSync(destf)) {
const dest = fs.createWriteStream(destf);
Expand Down

0 comments on commit 1773a06

Please sign in to comment.