From e024707ac9859550eb0bc09f073d0895b40ca77d Mon Sep 17 00:00:00 2001 From: kairi003 Date: Wed, 5 Apr 2023 04:39:34 +0900 Subject: [PATCH] Update: create branch-name zip file --- build.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/build.js b/build.js index 11926d2..7495cfd 100644 --- a/build.js +++ b/build.js @@ -2,18 +2,35 @@ const fs = require('fs'); const process = require('process'); const path = require('path'); const archiver = require('archiver'); +const { exec } = require('child_process'); -const zipPath = `src.zip`; -const output = fs.createWriteStream(path.join(__dirname, zipPath)); -process.chdir(path.join(__dirname, 'src')); - -const archive = archiver('zip', { - zlib: { level: 9 } +const getBranch = () => new Promise((resolve, reject) => { + exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) => { + if (typeof stdout === 'string') { + resolve(stdout.trim()); + } else { + reject(TypeError); + } + }); }); -archive.pipe(output); -archive.glob('**/*'); -archive.finalize(); +const build = async (name) => { + const zipPath = `${name}.zip`; + const output = fs.createWriteStream(path.join(__dirname, zipPath)); + + process.chdir(path.join(__dirname, 'src')); + + const archive = archiver('zip', { + zlib: { level: 9 } + }); + + archive.pipe(output); + archive.glob('**/*'); + + await archive.finalize(); +} + +getBranch().then(build);