Рефакторинг
This commit is contained in:
44
build/linux.js
Normal file
44
build/linux.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const download = require('download');
|
||||
const decompress = require('decompress');
|
||||
const decompressTargz = require('decompress-targz');
|
||||
|
||||
const distDir = path.resolve(__dirname, '../dist');
|
||||
const publicDir = `${distDir}/tmp/public`;
|
||||
const outDir = `${distDir}/linux`;
|
||||
|
||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||
|
||||
async function main() {
|
||||
// перемещаем public на место
|
||||
await fs.emptyDir(outDir);
|
||||
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() => {
|
||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
await decompress(`${tempDownloadDir}/ipfs.tar.gz`, `${tempDownloadDir}`, {
|
||||
plugins: [
|
||||
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'));
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,69 +0,0 @@
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
|
||||
const fs = require('fs');
|
||||
const download = require('download');
|
||||
const decompress = require('decompress');
|
||||
const decompressTargz = require('decompress-targz');
|
||||
|
||||
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const DisableOutputWebpackPlugin = require('disable-output-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const EventHooksPlugin = require('event-hooks-webpack-plugin');
|
||||
|
||||
const distDir = path.resolve(__dirname, '../dist');
|
||||
const publicDir = `${distDir}/tmp/public`;
|
||||
const outDir = `${distDir}/linux`;
|
||||
|
||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
entry: `${publicDir}/index.html`,
|
||||
output: {
|
||||
path: outDir
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
use: 'null-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin([outDir, tempDownloadDir], {root: distDir}),
|
||||
new DisableOutputWebpackPlugin(),
|
||||
new CopyWebpackPlugin([
|
||||
{ from: publicDir, to: `${outDir}/public` }
|
||||
]
|
||||
),
|
||||
new EventHooksPlugin({
|
||||
done: () => {
|
||||
fs.mkdirSync(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', () => {
|
||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
decompress(`${tempDownloadDir}/ipfs.tar.gz`, `${tempDownloadDir}`, {
|
||||
plugins: [
|
||||
decompressTargz()
|
||||
]
|
||||
}).then(() => {
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
fs.copyFileSync(`${tempDownloadDir}/go-ipfs/ipfs`, `${outDir}/ipfs`);
|
||||
console.log(`copied ${tempDownloadDir}/go-ipfs/ipfs to ${outDir}/ipfs`);
|
||||
//для development
|
||||
fs.copyFileSync(`${tempDownloadDir}/go-ipfs/ipfs`, path.resolve(__dirname, '../server/ipfs'));
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
]
|
||||
};
|
||||
@@ -1,91 +0,0 @@
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
|
||||
const fs = require('fs');
|
||||
const download = require('download');
|
||||
const decompress = require('decompress');
|
||||
const decompressTargz = require('decompress-targz');
|
||||
|
||||
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const DisableOutputWebpackPlugin = require('disable-output-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const EventHooksPlugin = require('event-hooks-webpack-plugin');
|
||||
|
||||
const distDir = path.resolve(__dirname, '../dist');
|
||||
const publicDir = `${distDir}/tmp/public`;
|
||||
const outDir = `${distDir}/win`;
|
||||
|
||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
entry: `${publicDir}/index.html`,
|
||||
output: {
|
||||
path: outDir
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.html$/,
|
||||
use: 'null-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new CleanWebpackPlugin([outDir, tempDownloadDir], {root: distDir}),
|
||||
new DisableOutputWebpackPlugin(),
|
||||
new CopyWebpackPlugin([
|
||||
{ from: publicDir, to: `${outDir}/public` }
|
||||
]
|
||||
),
|
||||
new EventHooksPlugin({
|
||||
done: () => {
|
||||
fs.mkdirSync(tempDownloadDir);
|
||||
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.0.4';
|
||||
const sqliteFile = 'node-v64-win32-x64';
|
||||
|
||||
const sqliteFilename = `${sqliteFile}.tar.gz`;
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/${sqliteFile}/node_sqlite3.node`;
|
||||
const sqliteDistFilename = `${outDir}/node_sqlite3.node`;
|
||||
|
||||
// Скачиваем node_sqlite3.node для винды, т.к. pkg не включает его в сборку
|
||||
const url = `${sqliteRemoteUrl}/${sqliteFilename}`;
|
||||
let d = download(url);
|
||||
d.pipe(fs.createWriteStream(`${tempDownloadDir}/${sqliteFilename}`));
|
||||
d.on('end', () => {
|
||||
console.log(`done downloading ${url}`);
|
||||
|
||||
//распаковываем
|
||||
decompress(`${tempDownloadDir}/${sqliteFilename}`, `${tempDownloadDir}`, {
|
||||
plugins: [
|
||||
decompressTargz()
|
||||
]
|
||||
}).then(() => {
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
fs.copyFileSync(sqliteDecompressedFilename, sqliteDistFilename);
|
||||
console.log(`copied ${sqliteDecompressedFilename} to ${sqliteDistFilename}`);
|
||||
});
|
||||
});
|
||||
|
||||
// Скачиваем ipfs
|
||||
const ipfsRemoteUrl = 'https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_windows-amd64.zip';
|
||||
|
||||
d = download(ipfsRemoteUrl);
|
||||
d.pipe(fs.createWriteStream(`${tempDownloadDir}/ipfs.zip`));
|
||||
d.on('end', () => {
|
||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
decompress(`${tempDownloadDir}/ipfs.zip`, `${tempDownloadDir}`).then(() => {
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
fs.copyFileSync(`${tempDownloadDir}/go-ipfs/ipfs.exe`, `${outDir}/ipfs.exe`);
|
||||
console.log(`copied ${tempDownloadDir}/go-ipfs/ipfs.exe to ${outDir}/ipfs.exe`);
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
]
|
||||
};
|
||||
58
build/win.js
Normal file
58
build/win.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const download = require('download');
|
||||
const decompress = require('decompress');
|
||||
const decompressTargz = require('decompress-targz');
|
||||
|
||||
const distDir = path.resolve(__dirname, '../dist');
|
||||
const publicDir = `${distDir}/tmp/public`;
|
||||
const outDir = `${distDir}/win`;
|
||||
|
||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||
|
||||
async function main() {
|
||||
// перемещаем public на место
|
||||
await fs.emptyDir(outDir);
|
||||
await fs.move(publicDir, `${outDir}/public`);
|
||||
|
||||
await fs.ensureDir(tempDownloadDir);
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.0.4/node-v64-win32-x64.tar.gz';
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/node-v64-win32-x64/node_sqlite3.node`;
|
||||
|
||||
// Скачиваем node_sqlite3.node для винды, т.к. pkg не включает его в сборку
|
||||
let d = download(sqliteRemoteUrl);
|
||||
d.pipe(fs.createWriteStream(`${tempDownloadDir}/sqlite.tar.gz`));
|
||||
d.on('end', async() => {
|
||||
console.log(`done downloading ${sqliteRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
await decompress(`${tempDownloadDir}/sqlite.tar.gz`, `${tempDownloadDir}`, {
|
||||
plugins: [
|
||||
decompressTargz()
|
||||
]
|
||||
});
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
await fs.copy(sqliteDecompressedFilename, `${outDir}/node_sqlite3.node`);
|
||||
console.log(`copied ${sqliteDecompressedFilename} to ${outDir}/node_sqlite3.node`);
|
||||
});
|
||||
|
||||
// Скачиваем ipfs
|
||||
const ipfsRemoteUrl = 'https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_windows-amd64.zip';
|
||||
|
||||
d = download(ipfsRemoteUrl);
|
||||
d.pipe(fs.createWriteStream(`${tempDownloadDir}/ipfs.zip`));
|
||||
d.on('end', async() => {
|
||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||
|
||||
//распаковываем
|
||||
await decompress(`${tempDownloadDir}/ipfs.zip`, `${tempDownloadDir}`);
|
||||
console.log('files decompressed');
|
||||
// копируем в дистрибутив
|
||||
await fs.copy(`${tempDownloadDir}/go-ipfs/ipfs.exe`, `${outDir}/ipfs.exe`);
|
||||
console.log(`copied ${tempDownloadDir}/go-ipfs/ipfs.exe to ${outDir}/ipfs.exe`);
|
||||
});
|
||||
}
|
||||
|
||||
main();
|
||||
33
package-lock.json
generated
33
package-lock.json
generated
@@ -4435,7 +4435,6 @@
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz",
|
||||
"integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"jsonfile": "^4.0.0",
|
||||
@@ -4508,14 +4507,12 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@@ -4530,20 +4527,17 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@@ -4660,8 +4654,7 @@
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@@ -4673,7 +4666,6 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@@ -4688,7 +4680,6 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
@@ -4696,14 +4687,12 @@
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.2.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.1",
|
||||
"yallist": "^3.0.0"
|
||||
@@ -4722,7 +4711,6 @@
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@@ -4803,8 +4791,7 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@@ -4816,7 +4803,6 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@@ -4938,7 +4924,6 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@@ -6193,7 +6178,6 @@
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
@@ -11202,8 +11186,7 @@
|
||||
"universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||
},
|
||||
"unpipe": {
|
||||
"version": "1.0.0",
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
"scripts": {
|
||||
"dev": "nodemon --inspect server",
|
||||
"build:client": "webpack --config build/webpack.prod.config.js",
|
||||
"build:linux": "npm run build:client && webpack --config build/webpack.linux.config.js && pkg -t latest-linux-x64 -o dist/linux/liberama .",
|
||||
"build:linux": "npm run build:client && node build/linux && pkg -t latest-linux-x64 -o dist/linux/liberama .",
|
||||
"build:win": "npm run build:client && webpack --config build/webpack.win.config.js && pkg -t latest-win-x64 -o dist/win/liberama .",
|
||||
"lint": "eslint --ext=.js,.vue client server",
|
||||
"build:client-dev": "webpack --config build/webpack.dev.config.js",
|
||||
"postinstall": "npm run build:client-dev && npm run build:linux"
|
||||
"postinstall": "npm run build:client-dev && npm run build:linux",
|
||||
"test": "node build/win"
|
||||
},
|
||||
"bin": "server/index.js",
|
||||
"pkg": {
|
||||
@@ -63,6 +64,7 @@
|
||||
"download": "^7.1.0",
|
||||
"element-ui": "^2.4.11",
|
||||
"express": "^4.16.4",
|
||||
"fs-extra": "^7.0.1",
|
||||
"lodash": "^4.17.11",
|
||||
"sql-template-strings": "^2.2.2",
|
||||
"sqlite": "^3.0.0",
|
||||
|
||||
Reference in New Issue
Block a user