From 6842a4f571da6669c05aba1dc24ccd8383ff04c8 Mon Sep 17 00:00:00 2001 From: papeloto Date: Sat, 21 Mar 2020 14:46:00 +0100 Subject: [PATCH] feat: add recursive support --- dist/index.js | 12 +++++------- index.js | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1b2ab6d..9dff2d2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -60,6 +60,7 @@ const core = __webpack_require__(470); const files = core.getInput("files"); const dest = core.getInput("dest"); +const recursive = core.getInput("recursive") === "true"; console.log(`Ready to zip "${files}" into ${dest}`); @@ -76,15 +77,12 @@ files.split(" ").forEach(fileName => { const dir = path.dirname(fileName); const stats = fs.lstatSync(filePath); - console.log(`filePath: ${filePath}`); - console.log(`fileName: ${fileName}`); - console.log(`dir: ${dir}`); - console.log(`Is dir: ${stats.isDirectory()}`); - if (stats.isDirectory()) { - zip.addLocalFolder(filePath, dir === "." ? fileName : dir); + const zipDir = dir === "." ? fileName : dir; + zip.addLocalFolder(filePath, !recursive && zipDir); } else { - zip.addLocalFile(filePath, dir === "." ? "" : dir); + const zipDir = dir === "." ? "" : dir; + zip.addLocalFile(filePath, !recursive && zipDir); } console.log(` - ${fileName}`); diff --git a/index.js b/index.js index 17768ef..2de54ca 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ const core = require("@actions/core"); const files = core.getInput("files"); const dest = core.getInput("dest"); +const recursive = core.getInput("recursive") === "true"; console.log(`Ready to zip "${files}" into ${dest}`); @@ -21,15 +22,12 @@ files.split(" ").forEach(fileName => { const dir = path.dirname(fileName); const stats = fs.lstatSync(filePath); - console.log(`filePath: ${filePath}`); - console.log(`fileName: ${fileName}`); - console.log(`dir: ${dir}`); - console.log(`Is dir: ${stats.isDirectory()}`); - if (stats.isDirectory()) { - zip.addLocalFolder(filePath, dir === "." ? fileName : dir); + const zipDir = dir === "." ? fileName : dir; + zip.addLocalFolder(filePath, !recursive && zipDir); } else { - zip.addLocalFile(filePath, dir === "." ? "" : dir); + const zipDir = dir === "." ? "" : dir; + zip.addLocalFile(filePath, !recursive && zipDir); } console.log(` - ${fileName}`);