Небольшой рефакторинг
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
const stream = require('stream');
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
const download = require('download');
|
||||
const decompress = require('decompress');
|
||||
@@ -18,12 +21,13 @@ async function main() {
|
||||
await fs.move(publicDir, `${outDir}/public`);
|
||||
|
||||
await fs.ensureDir(tempDownloadDir);
|
||||
// Скачиваем ipfs
|
||||
const ipfsRemoteUrl = 'https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_linux-amd64.tar.gz';
|
||||
|
||||
d = download(ipfsRemoteUrl);
|
||||
d.pipe(fs.createWriteStream(`${tempDownloadDir}/ipfs.tar.gz`));
|
||||
d.on('end', async() => {
|
||||
const ipfsDecompressedFilename = `${tempDownloadDir}/go-ipfs/ipfs`;
|
||||
if (!await fs.pathExists(ipfsDecompressedFilename)) {
|
||||
// Скачиваем ipfs
|
||||
const ipfsRemoteUrl = 'https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_linux-amd64.tar.gz';
|
||||
|
||||
await pipeline(download(ipfsRemoteUrl), fs.createWriteStream(`${tempDownloadDir}/ipfs.tar.gz`));
|
||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
@@ -32,14 +36,17 @@ async function main() {
|
||||
decompressTargz()
|
||||
]
|
||||
});
|
||||
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
await fs.copy(`${tempDownloadDir}/go-ipfs/ipfs`, `${outDir}/ipfs`);
|
||||
console.log(`copied ${tempDownloadDir}/go-ipfs/ipfs to ${outDir}/ipfs`);
|
||||
//для development
|
||||
await fs.copy(`${tempDownloadDir}/go-ipfs/ipfs`, path.resolve(__dirname, '../server/ipfs'));
|
||||
});
|
||||
}
|
||||
|
||||
// копируем в дистрибутив
|
||||
await fs.copy(ipfsDecompressedFilename, `${outDir}/ipfs`);
|
||||
console.log(`copied ${tempDownloadDir}/go-ipfs/ipfs to ${outDir}/ipfs`);
|
||||
//для development
|
||||
const devIpfsFile = path.resolve(__dirname, '../server/ipfs');
|
||||
if (!await fs.pathExists(devIpfsFile)) {
|
||||
await fs.copy(ipfsDecompressedFilename, devIpfsFile);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user