Добавлена упаковка web-приложения внутрь исполнимого файла

This commit is contained in:
Book Pauk
2022-09-29 13:54:28 +07:00
parent bf5140fe0f
commit 03e89502d5
7 changed files with 78 additions and 34 deletions

View File

@@ -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
View 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();

View File

@@ -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();