-
Notifications
You must be signed in to change notification settings - Fork 11
/
zip.js
47 lines (38 loc) · 1.25 KB
/
zip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable */
const AdmZip = require('adm-zip');
const chalk = require('chalk');
/* eslint-enable */
const fs = require('fs');
const { name, version } = require('./package.json');
const divider = '---------------------------------';
async function zipFunc() {
const distExists = await fs.existsSync('./dist');
const distZipsExists = await fs.existsSync('./dist_zips');
// if dist exists
if (distExists) {
// if zip
if (distZipsExists === false) {
await fs.mkdirSync('./dist_zips');
}
// creating archives
const zip = new AdmZip();
// add manifest file to zip
zip.addLocalFile('./manifest.json');
// add dist directory to zip
zip.addLocalFolder('./dist/', 'dist');
// save zip to directory
const zipName = `${name}_v${version}`;
const zipPath = `./dist_zips/${zipName}.zip`;
zip.writeZip(zipPath);
console.log(chalk.greenBright('plugin bundled and zipped'));
console.log(chalk.greenBright(`location: ${zipPath}`));
console.log(chalk.blackBright(divider));
} else {
console.log(chalk.red('/dist/ does not exist'));
console.log(
chalk.red(`make sure you run: ${chalk.green.bold('npm run bundle')}`)
);
console.log(chalk.blackBright(divider));
}
}
zipFunc();