Добавлена упаковка web-приложения внутрь исполнимого файла
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
const fs = require('fs-extra');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
|
||||||
const outDir = `${distDir}/linux`;
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
await fs.emptyDir(outDir);
|
|
||||||
// перемещаем public на место
|
|
||||||
if (await fs.pathExists(publicDir))
|
|
||||||
await fs.move(publicDir, `${outDir}/public`);
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
||||||
43
build/prepkg.js
Normal file
43
build/prepkg.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
const platform = process.argv[2];
|
||||||
|
|
||||||
|
const distDir = path.resolve(__dirname, '../dist');
|
||||||
|
const tmpDir = `${distDir}/tmp`;
|
||||||
|
const publicDir = `${tmpDir}/public`;
|
||||||
|
const outDir = `${distDir}/${platform}`;
|
||||||
|
|
||||||
|
async function build() {
|
||||||
|
if (platform != 'linux' && platform != 'win')
|
||||||
|
throw new Error(`Unknown platform: ${platform}`);
|
||||||
|
|
||||||
|
await fs.emptyDir(outDir);
|
||||||
|
|
||||||
|
// перемещаем public на место
|
||||||
|
if (await fs.pathExists(publicDir)) {
|
||||||
|
|
||||||
|
const zipFile = `${tmpDir}/public.zip`;
|
||||||
|
const jsonFile = `${distDir}/public.json`;//distDir !!!
|
||||||
|
|
||||||
|
await fs.remove(zipFile);
|
||||||
|
execSync(`zip -r ${zipFile} .`, {cwd: publicDir, stdio: 'inherit'});
|
||||||
|
|
||||||
|
const data = (await fs.readFile(zipFile)).toString('base64');
|
||||||
|
await fs.writeFile(jsonFile, JSON.stringify({data}));
|
||||||
|
} else {
|
||||||
|
throw new Error(`publicDir: ${publicDir} does not exist`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
await build();
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
15
build/win.js
15
build/win.js
@@ -1,15 +0,0 @@
|
|||||||
const fs = require('fs-extra');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
|
||||||
const outDir = `${distDir}/win`;
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
await fs.emptyDir(outDir);
|
|
||||||
// перемещаем public на место
|
|
||||||
if (await fs.pathExists(publicDir))
|
|
||||||
await fs.move(publicDir, `${outDir}/public`);
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
||||||
@@ -10,14 +10,15 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon --inspect --ignore server/.inpx-web --ignore client --exec 'node --expose-gc server --lib-dir=server/.inpx-web/lib'",
|
"dev": "nodemon --inspect --ignore server/.inpx-web --ignore client --exec 'node --expose-gc server --lib-dir=server/.inpx-web/lib'",
|
||||||
"build:client": "webpack --config build/webpack.prod.config.js",
|
"build:client": "webpack --config build/webpack.prod.config.js",
|
||||||
"build:linux": "npm run build:client && node build/linux && pkg -t node16-linux-x64 -C GZip --options max-old-space-size=4096,expose-gc -o dist/linux/inpx-web .",
|
"build:linux": "npm run build:client && node build/prepkg.js linux && pkg -t node16-linux-x64 -C GZip --options max-old-space-size=4096,expose-gc -o dist/linux/inpx-web .",
|
||||||
"build:win": "npm run build:client && node build/win && pkg -t node16-win-x64 -C GZip --options max-old-space-size=4096,expose-gc -o dist/win/inpx-web .",
|
"build:win": "npm run build:client && node build/prepkg.js win && pkg -t node16-win-x64 -C GZip --options max-old-space-size=4096,expose-gc -o dist/win/inpx-web .",
|
||||||
"build:client-dev": "webpack --config build/webpack.dev.config.js",
|
"build:client-dev": "webpack --config build/webpack.dev.config.js",
|
||||||
"postinstall": "npm run build:client-dev"
|
"postinstall": "npm run build:client-dev"
|
||||||
},
|
},
|
||||||
"bin": "server/index.js",
|
"bin": "server/index.js",
|
||||||
"pkg": {
|
"pkg": {
|
||||||
"scripts": "server/config/*.js"
|
"scripts": "server/config/*.js",
|
||||||
|
"assets": "dist/public.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.18.9",
|
"@babel/core": "^7.18.9",
|
||||||
|
|||||||
@@ -464,11 +464,14 @@ class WebWorker {
|
|||||||
|
|
||||||
async periodicCleanDir(dirConfig) {
|
async periodicCleanDir(dirConfig) {
|
||||||
try {
|
try {
|
||||||
|
for (const config of dirConfig)
|
||||||
|
await fs.ensureDir(config.dir);
|
||||||
|
|
||||||
let lastCleanDirTime = 0;
|
let lastCleanDirTime = 0;
|
||||||
while (1) {// eslint-disable-line no-constant-condition
|
while (1) {// eslint-disable-line no-constant-condition
|
||||||
//чистка папок
|
//чистка папок
|
||||||
if (Date.now() - lastCleanDirTime >= cleanDirPeriod) {
|
if (Date.now() - lastCleanDirTime >= cleanDirPeriod) {
|
||||||
for (const config of Object.values(dirConfig)) {
|
for (const config of dirConfig) {
|
||||||
try {
|
try {
|
||||||
await this.cleanDir(config);
|
await this.cleanDir(config);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|||||||
23
server/createWebApp.js
Normal file
23
server/createWebApp.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
|
const webApp = require('../dist/public.json');
|
||||||
|
const ZipReader = require('./core/ZipReader');
|
||||||
|
|
||||||
|
module.exports = async(config) => {
|
||||||
|
const zipFile = `${config.tempDir}/public.zip`;
|
||||||
|
|
||||||
|
await fs.writeFile(zipFile, webApp.data, {encoding: 'base64'});
|
||||||
|
|
||||||
|
const zipReader = new ZipReader();
|
||||||
|
await zipReader.open(zipFile);
|
||||||
|
|
||||||
|
await fs.remove(config.publicDir);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await zipReader.extractAllToDir(config.publicDir);
|
||||||
|
} finally {
|
||||||
|
await zipReader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.remove(zipFile);
|
||||||
|
};
|
||||||
@@ -52,6 +52,10 @@ async function init() {
|
|||||||
await fs.ensureDir(config.tempDir);
|
await fs.ensureDir(config.tempDir);
|
||||||
await fs.emptyDir(config.tempDir);
|
await fs.emptyDir(config.tempDir);
|
||||||
|
|
||||||
|
//web app
|
||||||
|
const createWebApp = require('./createWebApp');
|
||||||
|
await createWebApp(config);
|
||||||
|
|
||||||
//cli
|
//cli
|
||||||
if (argv.help) {
|
if (argv.help) {
|
||||||
showHelp();
|
showHelp();
|
||||||
|
|||||||
Reference in New Issue
Block a user