From e14c8823d2a8d3a5e6d8893fb650fa0570cd946a Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 7 Oct 2022 15:05:37 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20createWebApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/createWebApp.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/server/createWebApp.js b/server/createWebApp.js index 3f472ae..705f18c 100644 --- a/server/createWebApp.js +++ b/server/createWebApp.js @@ -4,20 +4,41 @@ const webApp = require('../dist/public.json'); const ZipReader = require('./core/ZipReader'); module.exports = async(config) => { + const verFile = `${config.publicDir}/version.txt`; const zipFile = `${config.tempDir}/public.zip`; - await fs.writeFile(zipFile, webApp.data, {encoding: 'base64'}); + if (await fs.pathExists(verFile)) { + const curPublicVersion = await fs.readFile(verFile, 'utf8'); + if (curPublicVersion == config.version) + return; + } - const zipReader = new ZipReader(); - await zipReader.open(zipFile); + //сохраним files + const filesDir = `${config.publicDir}/files`; + let tmpFilesDir = ''; + if (await fs.pathExists(filesDir)) { + tmpFilesDir = `${config.dataDir}/files`; + if (!await fs.pathExists(tmpFilesDir)) + await fs.move(filesDir, tmpFilesDir); + } await fs.remove(config.publicDir); + //извлекаем новый webApp + await fs.writeFile(zipFile, webApp.data, {encoding: 'base64'}); + const zipReader = new ZipReader(); + await zipReader.open(zipFile); + try { await zipReader.extractAllToDir(config.publicDir); } finally { await zipReader.close(); } + //восстановим files + if (tmpFilesDir) + await fs.move(tmpFilesDir, filesDir); + + await fs.writeFile(verFile, config.version); await fs.remove(zipFile); }; \ No newline at end of file