refactor(builds): refactored how the builds works to include the build number now
this will be for the new lst - ccc
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import fsp from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import archiver from "archiver";
|
||||
import { format } from "date-fns";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
import { emitBuildLog } from "./build.utils.js";
|
||||
import { updateAppStats } from "./updateAppStats.utils.js";
|
||||
@@ -17,33 +18,31 @@ const exists = async (target: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getNextBuildNumber = async (buildNumberFile: string) => {
|
||||
if (!(await exists(buildNumberFile))) {
|
||||
await fsp.writeFile(buildNumberFile, "1", "utf8");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const raw = await fsp.readFile(buildNumberFile, "utf8");
|
||||
const current = Number.parseInt(raw.trim(), 10);
|
||||
const getNextBuildNumber = async (versionPath: string) => {
|
||||
const raw = await fsp.readFile(versionPath, "utf8");
|
||||
const config = JSON.parse(raw);
|
||||
const current = Number.parseInt(config.build.trim(), 10);
|
||||
|
||||
let nextBuild: string;
|
||||
if (Number.isNaN(current) || current < 1) {
|
||||
await fsp.writeFile(buildNumberFile, "1", "utf8");
|
||||
return 1;
|
||||
nextBuild = "1";
|
||||
} else {
|
||||
nextBuild = String(current + 1); // Incrementing the build number
|
||||
}
|
||||
|
||||
const next = current + 1;
|
||||
const updatedConfig = {
|
||||
...config,
|
||||
build: nextBuild,
|
||||
lastBuildDate: format(new Date(Date.now()), "M/d/yyyy HH:mm"),
|
||||
};
|
||||
|
||||
await fsp.writeFile(buildNumberFile, String(next), "utf8");
|
||||
await fsp.writeFile(
|
||||
versionPath,
|
||||
JSON.stringify(updatedConfig, null, 4) + "\n",
|
||||
"utf8",
|
||||
);
|
||||
|
||||
// update the server with the next build number
|
||||
|
||||
await updateAppStats({
|
||||
currentBuild: next,
|
||||
lastBuildAt: new Date(),
|
||||
building: true,
|
||||
});
|
||||
|
||||
return next;
|
||||
return { version: config.version, build: config.build };
|
||||
};
|
||||
|
||||
const cleanupOldBuilds = async (buildFolder: string, maxBuilds: number) => {
|
||||
@@ -53,7 +52,8 @@ const cleanupOldBuilds = async (buildFolder: string, maxBuilds: number) => {
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isFile()) continue;
|
||||
if (!/^LSTV3-\d+\.zip$/i.test(entry.name)) continue;
|
||||
//if (!/^LSTV3-\d+\.zip$/i.test(entry.name)) continue;
|
||||
if (!entry.name.includes("LSTV3")) continue;
|
||||
|
||||
const fullPath = path.join(buildFolder, entry.name);
|
||||
const stat = await fsp.stat(fullPath);
|
||||
@@ -85,7 +85,7 @@ export const zipBuild = async () => {
|
||||
}
|
||||
|
||||
const includesFile = path.join(appDir, ".includes");
|
||||
const buildNumberFile = path.join(appDir, ".buildNumber");
|
||||
const version = path.join(appDir, "package.json");
|
||||
const buildFolder = path.join(appDir, "builds");
|
||||
const tempFolder = path.join(appDir, "temp", "zip-temp");
|
||||
if (!(await exists(includesFile))) {
|
||||
@@ -95,11 +95,13 @@ export const zipBuild = async () => {
|
||||
|
||||
await fsp.mkdir(buildFolder, { recursive: true });
|
||||
|
||||
const buildNumber = await getNextBuildNumber(buildNumberFile);
|
||||
const zipFileName = `LSTV3-${buildNumber}.zip`;
|
||||
const lstVersion = await getNextBuildNumber(version);
|
||||
const zipFileName = `LSTV3-${lstVersion.version}.${lstVersion.build}.zip`;
|
||||
const zipFile = path.join(buildFolder, zipFileName);
|
||||
// make the folders in case they are not created already
|
||||
emitBuildLog(`Using build number: ${buildNumber}`);
|
||||
emitBuildLog(
|
||||
`Using version, build number: ${lstVersion.version}.${lstVersion.build}`,
|
||||
);
|
||||
|
||||
if (await exists(tempFolder)) {
|
||||
await fsp.rm(tempFolder, { recursive: true, force: true });
|
||||
@@ -170,7 +172,7 @@ export const zipBuild = async () => {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
buildNumber,
|
||||
build: lstVersion.build,
|
||||
zipFile,
|
||||
zipFileName,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user