add Nuxt hook extract zip file
This commit is contained in:
parent
503443ec13
commit
5411684a0f
5 changed files with 43 additions and 7 deletions
|
|
@ -3,9 +3,10 @@ import path from "node:path";
|
|||
import AdmZip from "adm-zip";
|
||||
import Ajv from "ajv";
|
||||
import addFormats from "ajv-formats";
|
||||
import { app } from "electron";
|
||||
import log from "electron-log/main";
|
||||
|
||||
import packageJson from "./../package.json";
|
||||
|
||||
/**
|
||||
* In charge to unzip data from showroom Bo,
|
||||
* validate data config and check version
|
||||
|
|
@ -42,15 +43,26 @@ export default abstract class UnzipData {
|
|||
}
|
||||
|
||||
const zip = new AdmZip(fs.readFileSync(UnzipData.zipFileToUse));
|
||||
// * Clear export dir
|
||||
fs.rmSync(path.resolve(__dirname, "../public/data/pictures"), { recursive: true, force: true });
|
||||
fs.rmSync(path.resolve(__dirname, "../src/assets/data.json"), { recursive: true, force: true });
|
||||
UnzipData.removeOldExtractedFiles();
|
||||
zip.extractAllTo("public/data");
|
||||
// * Move data to src assets
|
||||
fs.renameSync(
|
||||
path.resolve(__dirname, "../public/data/data.json"),
|
||||
path.resolve(__dirname, "../src/assets/data.json")
|
||||
);
|
||||
return UnzipData.loadJsonDataFile();
|
||||
}
|
||||
|
||||
public static removeOldExtractedFiles() {
|
||||
// * Clear export dir
|
||||
fs.rmSync(path.resolve(__dirname, "../public/data/pictures"), { recursive: true, force: true });
|
||||
fs.rmSync(path.resolve(__dirname, "../src/assets/data.json"), { recursive: true, force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Load json data file that was extracted
|
||||
*/
|
||||
public static loadJsonDataFile(): TypeApp | null {
|
||||
const jsonData = fs.readFileSync(
|
||||
path.resolve(__dirname, "../src/assets/data.json"),
|
||||
{ encoding: "utf8", flag: "r" }
|
||||
|
|
@ -63,7 +75,7 @@ export default abstract class UnzipData {
|
|||
}
|
||||
|
||||
const appJsonConfig: TypeApp = JSON.parse(jsonData);
|
||||
const appVersion: string = app.getVersion();
|
||||
const appVersion: string = packageJson.version;
|
||||
|
||||
if (appJsonConfig.version !== appVersion) {
|
||||
throw new Error(`App version ${appVersion} is not compatible with config version ${appJsonConfig.version}`);
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ app.whenReady().then(() => {
|
|||
|
||||
winHandler.onCreated(_browserWindow => {
|
||||
try {
|
||||
const appData = UnzipData.loadZipFileContent();
|
||||
const appData = UnzipData.loadJsonDataFile();
|
||||
if (!appData) {
|
||||
throw new Error("No zip file to load");
|
||||
throw new Error("No json data to load");
|
||||
}
|
||||
|
||||
winHandler.loadPage("");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,19 @@
|
|||
import { resolve } from "path";
|
||||
import UnzipData from "./electron/UnzipData";
|
||||
|
||||
|
||||
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||
export default defineNuxtConfig({
|
||||
hooks: {
|
||||
"build:before": () => {
|
||||
if (process.env.npm_lifecycle_event === "typecheck") {
|
||||
return;
|
||||
}
|
||||
if (!UnzipData.loadZipFileContent()) {
|
||||
throw new Error("No zip file to load");
|
||||
}
|
||||
}
|
||||
},
|
||||
experimental: {
|
||||
polyfillVueUseHead: false
|
||||
},
|
||||
|
|
|
|||
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -21,6 +21,7 @@
|
|||
"@types/adm-zip": "^0.5.5",
|
||||
"@types/bootstrap": "^5.2.10",
|
||||
"@types/dompurify": "^3.0.3",
|
||||
"@types/electron-builder": "^2.8.0",
|
||||
"@types/konami-code-js": "^0.8.1",
|
||||
"@vue/eslint-config-typescript": "^12.0.0",
|
||||
"adm-zip": "^0.5.10",
|
||||
|
|
@ -4808,6 +4809,16 @@
|
|||
"@types/trusted-types": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/electron-builder": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/electron-builder/-/electron-builder-2.8.0.tgz",
|
||||
"integrity": "sha512-j3A9mOA7JUALYUdF97NXh3ZLOulNWcr5C+O3H16hhOqi2UccWjOcXb0rrtGNOpLAhuUlsHkLasGtrne0Xc3FyA==",
|
||||
"deprecated": "This is a stub types definition for electron-builder (https://github.com/loopline-systems/electron-builder). electron-builder provides its own type definitions, so you don't need @types/electron-builder installed!",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"electron-builder": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
"@types/adm-zip": "^0.5.5",
|
||||
"@types/bootstrap": "^5.2.10",
|
||||
"@types/dompurify": "^3.0.3",
|
||||
"@types/electron-builder": "^2.8.0",
|
||||
"@types/konami-code-js": "^0.8.1",
|
||||
"@vue/eslint-config-typescript": "^12.0.0",
|
||||
"adm-zip": "^0.5.10",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue