switch to zip package
This commit is contained in:
parent
8408354320
commit
8b887383c6
@ -6,8 +6,8 @@ import * as path from 'path';
|
|||||||
import { mkdir as mkdirRecurisve } from 'mkdir-recursive';
|
import { mkdir as mkdirRecurisve } from 'mkdir-recursive';
|
||||||
import { getRNVersion } from './utils';
|
import { getRNVersion } from './utils';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as tar from 'tar';
|
import {ZipFile} from 'yazl';
|
||||||
import fstream from 'fstream';
|
|
||||||
|
|
||||||
function mkdir(dir){
|
function mkdir(dir){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -25,25 +25,37 @@ function pack(dir, output){
|
|||||||
return mkdir(path.dirname(output))
|
return mkdir(path.dirname(output))
|
||||||
.then(()=>{
|
.then(()=>{
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const dest = fs.createWriteStream(output);
|
var zipfile = new ZipFile();
|
||||||
|
|
||||||
var packer = tar.Pack({
|
function addDirectory(root, rel){
|
||||||
noProprietary: true,
|
if (rel) {
|
||||||
fromBase: true,
|
zipfile.addEmptyDirectory(rel);
|
||||||
})
|
}
|
||||||
.on('error', err => {
|
const childs = fs.readdirSync(root);
|
||||||
reject(err);
|
for (const name of childs) {
|
||||||
})
|
if (name === '.' || name === '..'){
|
||||||
.on('end', () => {
|
continue;
|
||||||
|
}
|
||||||
|
const fullPath = path.join(root, name);
|
||||||
|
const stat = fs.statSync(fullPath);
|
||||||
|
if (stat.isFile()) {
|
||||||
|
console.log('adding: ' + rel+name);
|
||||||
|
zipfile.addFile(fullPath, rel+name);
|
||||||
|
} else if (stat.isDirectory()) {
|
||||||
|
console.log('adding: ' + rel+name+'/');
|
||||||
|
addDirectory(fullPath, rel+name+'/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addDirectory(dir, '');
|
||||||
|
|
||||||
|
zipfile.outputStream.on('error', err => reject(err));
|
||||||
|
zipfile.outputStream.pipe(fs.createWriteStream(output))
|
||||||
|
.on("close", function() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
zipfile.end();
|
||||||
fstream.Reader({ path: dir, type: "Directory" })
|
|
||||||
.on('error', err => {
|
|
||||||
reject(err);
|
|
||||||
})
|
|
||||||
.pipe(packer)
|
|
||||||
.pipe(dest);
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user