mirror of
https://github.com/papeloto/action-zip
synced 2024-11-22 05:29:35 -08:00
38 lines
814 B
JavaScript
38 lines
814 B
JavaScript
|
const fs = require("fs");
|
||
|
const path = require("path");
|
||
|
const AdmZip = require("adm-zip");
|
||
|
const core = require("@actions/core");
|
||
|
|
||
|
const inputFiles = core.getInput("files", { required: true });
|
||
|
const filename = core.getInput("filename");
|
||
|
|
||
|
const files = inputFiles.split(" ");
|
||
|
|
||
|
console.log(`Ready to zip "${inputFiles}" into ${filename}`);
|
||
|
|
||
|
const zip = new AdmZip();
|
||
|
|
||
|
files.forEach(file => {
|
||
|
if (!fs.existsSync(file)) {
|
||
|
console.log(` - ${file} (Not Found)`);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
const dir = path.dirname(file);
|
||
|
const stats = fs.lstatSync(file);
|
||
|
|
||
|
if (stats.isDirectory()) {
|
||
|
zip.addLocalFolder(file, dir);
|
||
|
} else {
|
||
|
zip.addLocalFile(file, dir === "." ? "" : dir);
|
||
|
}
|
||
|
|
||
|
console.log(` - ${file}`);
|
||
|
});
|
||
|
|
||
|
zip.writeZip(filename);
|
||
|
|
||
|
console.log(`\nZipped file ${filename}`);
|
||
|
|
||
|
core.setOutput(filename);
|