Улучшение createWebApp
This commit is contained in:
@@ -4,20 +4,41 @@ const webApp = require('../dist/public.json');
|
|||||||
const ZipReader = require('./core/ZipReader');
|
const ZipReader = require('./core/ZipReader');
|
||||||
|
|
||||||
module.exports = async(config) => {
|
module.exports = async(config) => {
|
||||||
|
const verFile = `${config.publicDir}/version.txt`;
|
||||||
const zipFile = `${config.tempDir}/public.zip`;
|
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();
|
//сохраним files
|
||||||
await zipReader.open(zipFile);
|
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);
|
await fs.remove(config.publicDir);
|
||||||
|
|
||||||
|
//извлекаем новый webApp
|
||||||
|
await fs.writeFile(zipFile, webApp.data, {encoding: 'base64'});
|
||||||
|
const zipReader = new ZipReader();
|
||||||
|
await zipReader.open(zipFile);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await zipReader.extractAllToDir(config.publicDir);
|
await zipReader.extractAllToDir(config.publicDir);
|
||||||
} finally {
|
} finally {
|
||||||
await zipReader.close();
|
await zipReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//восстановим files
|
||||||
|
if (tmpFilesDir)
|
||||||
|
await fs.move(tmpFilesDir, filesDir);
|
||||||
|
|
||||||
|
await fs.writeFile(verFile, config.version);
|
||||||
await fs.remove(zipFile);
|
await fs.remove(zipFile);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user