Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1303e35981 | ||
|
|
ecd58d1fb1 | ||
|
|
7c9c3ffc0d | ||
|
|
cbf01630f6 |
4 changed files with 19 additions and 52 deletions
|
|
@ -9,8 +9,7 @@ import packageJson from "./../package.json";
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === "development";
|
const isDev = process.env.NODE_ENV === "development";
|
||||||
const root = path.join(__dirname, "..");
|
const root = path.join(__dirname, "..");
|
||||||
const sourcePublicPath = path.join(root, "public");
|
const publicPath = isDev ? path.join(root, "public") : path.join(root, ".output/public");
|
||||||
const runtimePublicPath = isDev ? sourcePublicPath : path.join(root, ".output/public");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In charge to unzip data from showroom Bo,
|
* In charge to unzip data from showroom Bo,
|
||||||
|
|
@ -19,15 +18,6 @@ const runtimePublicPath = isDev ? sourcePublicPath : path.join(root, ".output/pu
|
||||||
export default abstract class UnzipData {
|
export default abstract class UnzipData {
|
||||||
static zipFileToUse: string|null;
|
static zipFileToUse: string|null;
|
||||||
|
|
||||||
private static resolvePublicPath(relativePath: string): string {
|
|
||||||
const runtimePath = path.join(runtimePublicPath, relativePath) as fs.PathLike;
|
|
||||||
if (fs.existsSync(runtimePath)) {
|
|
||||||
return runtimePath as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.join(sourcePublicPath, relativePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init zipFileToUse if not already inited
|
* Init zipFileToUse if not already inited
|
||||||
*/
|
*/
|
||||||
|
|
@ -35,11 +25,8 @@ export default abstract class UnzipData {
|
||||||
if (!UnzipData.zipFileToUse) {
|
if (!UnzipData.zipFileToUse) {
|
||||||
// * Try to locate last zip file and load it.
|
// * Try to locate last zip file and load it.
|
||||||
const zipFile = fs.readdirSync("static/data")
|
const zipFile = fs.readdirSync("static/data")
|
||||||
.map((entryPath) => {
|
.map(path => { return {path: `static/data/${path}`, "stat": fs.lstatSync(`static/data/${path}`)}; })
|
||||||
const fullPath = path.join("static/data", entryPath);
|
.filter(obj => obj.stat.isFile() && obj.path.endsWith(".zip"))
|
||||||
return { path: fullPath, stat: fs.lstatSync(fullPath) };
|
|
||||||
})
|
|
||||||
.filter((entry) => entry.stat.isFile() && entry.path.endsWith(".zip"))
|
|
||||||
.sort((objA, objB) => objB.stat.mtime.getTime() - objA.stat.mtime.getTime())
|
.sort((objA, objB) => objB.stat.mtime.getTime() - objA.stat.mtime.getTime())
|
||||||
.at(0) ?? null;
|
.at(0) ?? null;
|
||||||
|
|
||||||
|
|
@ -61,26 +48,30 @@ export default abstract class UnzipData {
|
||||||
|
|
||||||
const zip = new AdmZip(fs.readFileSync(UnzipData.zipFileToUse));
|
const zip = new AdmZip(fs.readFileSync(UnzipData.zipFileToUse));
|
||||||
UnzipData.removeOldExtractedFiles();
|
UnzipData.removeOldExtractedFiles();
|
||||||
zip.extractAllTo("public/data");
|
zip.extractAllTo(publicPath + "/data");
|
||||||
|
|
||||||
|
// * Schemas Copy for production build
|
||||||
|
if (!isDev) {
|
||||||
|
fs.cpSync(path.join(root, "public/schemas"), path.join(publicPath, "schemas"), { recursive: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static removeOldExtractedFiles() {
|
private static removeOldExtractedFiles() {
|
||||||
// * Clear export dir
|
// * Clear export dir
|
||||||
fs.rmSync("public/data/pictures", { recursive: true, force: true });
|
fs.rmSync(publicPath + "/data/pictures", { recursive: true, force: true });
|
||||||
fs.rmSync("public/data/data.json", { force: true });
|
fs.rmSync(publicPath + "/data/data.json", { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load json data file that was extracted
|
* Load json data file that was extracted
|
||||||
*/
|
*/
|
||||||
public static loadJsonDataFile(): TypeApp | null {
|
public static loadJsonDataFile(): TypeApp | null {
|
||||||
const jsonDataPath = UnzipData.resolvePublicPath("data/data.json");
|
|
||||||
const jsonSchemaPath = UnzipData.resolvePublicPath("schemas");
|
|
||||||
|
|
||||||
const jsonData = fs.readFileSync(
|
const jsonData = fs.readFileSync(
|
||||||
jsonDataPath,
|
path.join(publicPath, "data/data.json"),
|
||||||
{ encoding: "utf8", flag: "r" }
|
{ encoding: "utf8", flag: "r" }
|
||||||
);
|
);
|
||||||
|
const jsonSchemaPath = path.join(publicPath, "schemas");
|
||||||
|
|
||||||
if (!UnzipData.validateAgainstJsonSchema(jsonSchemaPath, jsonData)) {
|
if (!UnzipData.validateAgainstJsonSchema(jsonSchemaPath, jsonData)) {
|
||||||
log.warn(`Data for file ${UnzipData.zipFileToUse} is not valid JSON`);
|
log.warn(`Data for file ${UnzipData.zipFileToUse} is not valid JSON`);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import { resolve } from "path";
|
||||||
import log from "electron-log/main";
|
import log from "electron-log/main";
|
||||||
import UnzipData from "./electron/UnzipData";
|
import UnzipData from "./electron/UnzipData";
|
||||||
|
|
||||||
|
UnzipData.loadZipFileContent();
|
||||||
|
|
||||||
// https://nuxt.com/docs/api/configuration/nuxt-config
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
hooks: {
|
hooks: {
|
||||||
|
|
@ -71,7 +73,7 @@ export default defineNuxtConfig({
|
||||||
pinia: "/node_modules/@pinia/nuxt/node_modules/pinia/dist/pinia.mjs"
|
pinia: "/node_modules/@pinia/nuxt/node_modules/pinia/dist/pinia.mjs"
|
||||||
},
|
},
|
||||||
i18n: {
|
i18n: {
|
||||||
locales: UnzipData.loadJsonDataFile()?.settings.locales ?? ["fr"],
|
locales: UnzipData.loadJsonDataFile()?.settings.locales,
|
||||||
defaultLocale: "fr",
|
defaultLocale: "fr",
|
||||||
// * Ajouter aussi la locale dans ce fichier
|
// * Ajouter aussi la locale dans ce fichier
|
||||||
vueI18n: "./i18n.config.ts"
|
vueI18n: "./i18n.config.ts"
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,12 @@
|
||||||
"static/**/*"
|
"static/**/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"data:prepare": "node scripts/prepare-data.mjs",
|
"build": "nuxi build --prerender && electron-builder -w",
|
||||||
"build": "npm run data:prepare && nuxi build --prerender && electron-builder -w",
|
"dev": "cross-env NODE_ENV=development nuxt dev",
|
||||||
"dev": "npm run data:prepare && cross-env NODE_ENV=development nuxt dev",
|
|
||||||
"generate": "nuxt generate",
|
"generate": "nuxt generate",
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxt preview",
|
||||||
"cleanup": "nuxt cleanup",
|
"cleanup": "nuxt cleanup",
|
||||||
"typecheck": "npm run data:prepare && nuxt typecheck",
|
"typecheck": "nuxt typecheck",
|
||||||
"postinstall": "nuxt prepare",
|
"postinstall": "nuxt prepare",
|
||||||
"lint:ts": "npm run typecheck",
|
"lint:ts": "npm run typecheck",
|
||||||
"lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
|
"lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
import AdmZip from "adm-zip";
|
|
||||||
|
|
||||||
const root = process.cwd();
|
|
||||||
const dataDir = path.join(root, "static", "data");
|
|
||||||
const publicDataDir = path.join(root, "public", "data");
|
|
||||||
|
|
||||||
const zipFiles = fs.readdirSync(dataDir, { withFileTypes: true })
|
|
||||||
.filter((entry) => entry.isFile() && entry.name.endsWith(".zip"))
|
|
||||||
.map((entry) => path.join(dataDir, entry.name))
|
|
||||||
.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);
|
|
||||||
|
|
||||||
const latestZip = zipFiles.at(0);
|
|
||||||
if (!latestZip) {
|
|
||||||
throw new Error("No zip data to load in static/data");
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.rmSync(path.join(publicDataDir, "pictures"), { recursive: true, force: true });
|
|
||||||
fs.rmSync(path.join(publicDataDir, "data.json"), { force: true });
|
|
||||||
|
|
||||||
const zip = new AdmZip(latestZip);
|
|
||||||
zip.extractAllTo(publicDataDir);
|
|
||||||
|
|
||||||
console.info(`Prepared data from: ${latestZip}`);
|
|
||||||
Loading…
Add table
Reference in a new issue