custom-app
Version:
ITIMS��Ʒ�鿪��ר��React���,�Dz��ý��ּ�dhcc-app���������
54 lines (46 loc) • 1.76 kB
JavaScript
let fs = require("fs");
// let unzip = require("unzip");
let unzipper = require("unzipper");
let spinner = require('../util/spinner');
let chalk = require('chalk')
module.exports = function (resFile, outputPath) {
spinner.logWithSpinner('', chalk.cyan("from:" + resFile + ' to ' + outputPath + ' unzip start'))
// var extract = unzipper.Extract({ path: outputPath + "/" });
// extract.on('error', function (err) {
// console.log(chalk.red(err));
// spinner.stopSpinner();
// //解压异常处理
// });
// extract.on('close', function () {
// spinner.logWithSpinner(chalk.cyan("from:" + resFile + ' to ' + outputPath + ' unzip success'));
// spinner.logWithSpinner(' ', ' ');
// spinner.stopSpinner();
// //解压完成处理
// });
// fs.createReadStream(resFile).pipe(extract);
if (!fs.existsSync(outputPath + "/config")) {
fs.mkdirSync(outputPath + "/config");
}
if (!fs.existsSync(outputPath + "/src")) {
fs.mkdirSync(outputPath + "/src");
}
if (!fs.existsSync(outputPath + "/config/dll")) {
// fs.mkdirSync(outputPath + "/config/dll");
}
if (!fs.existsSync(outputPath + "/src/demo")) {
//fs.mkdirSync(outputPath + "/src/demo");
}
fs.createReadStream(resFile)
.pipe(unzipper.Parse())
.on('entry', function (entry) {
var fileName = entry.path;
var type = entry.type; // 'Directory' or 'File'
var size = entry.size;
if (type === "File") {
entry.pipe(fs.createWriteStream(outputPath + "/" + fileName));
}
});
spinner.logWithSpinner(chalk.cyan("from:" + resFile + ' to ' + outputPath + ' unzip success'));
spinner.logWithSpinner(' ', ' ');
spinner.stopSpinner();
}