axios-miniprogram/scripts/zip.js

34 lines
931 B
JavaScript
Raw Normal View History

2021-05-30 19:04:06 +08:00
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const archiver = require('archiver');
const chalk = require('chalk');
2021-05-30 23:19:40 +08:00
const pkg = require('../package.json');
2021-05-30 19:04:06 +08:00
const zip = archiver('zip');
const distPath = path.resolve(__dirname, '..', 'dist');
2021-06-04 09:57:36 +08:00
const distZipName = `download/${pkg.version}.zip`;
2021-05-30 19:04:06 +08:00
const distZipPath = path.resolve(__dirname, '..', distZipName);
console.log();
console.log(chalk.cyan(`${distPath}${distZipName}...`));
rimraf(distZipPath, () => {
const outputStream = fs.createWriteStream(distZipPath);
const startTime = +new Date();
zip.on('error', (error) => {
throw error;
});
zip.on('finish', () => {
const endTime = +new Date();
const ss = ((endTime - startTime) / 1000).toFixed(1);
console.log(chalk.green(`created ${distZipName} in ${ss}s`));
});
zip.pipe(outputStream);
2021-05-30 23:19:40 +08:00
zip.directory(distPath, pkg.name);
2021-05-30 19:04:06 +08:00
zip.finalize();
});