Adds some more polish
This commit is contained in:
parent
b3d0b3a90c
commit
11bd836ec3
18 changed files with 272 additions and 29 deletions
39
source/Utilities/BuildContext.ts
Normal file
39
source/Utilities/BuildContext.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import * as fs from "node:fs";
|
||||
import {Nullable} from "../types/Nullable";
|
||||
import {DataManager} from "discord.js";
|
||||
import * as util from "node:util";
|
||||
|
||||
export type BuildContext = {
|
||||
target: string,
|
||||
commitHash: string,
|
||||
commitLink: string,
|
||||
label: string,
|
||||
}
|
||||
|
||||
export class BuildContextGetter {
|
||||
private static EXPECTED_PATHS = [
|
||||
"./deploy.json",
|
||||
"./dist/deploy.json"
|
||||
];
|
||||
private static GIT_PATH = "https://git.iedsoftworks.com/neintonine/pnp-scheduler/commit/%s";
|
||||
|
||||
getContext(): Nullable<BuildContext> {
|
||||
const path = this.findValidPath();
|
||||
if (!path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const jsonData = fs.readFileSync(path).toString();
|
||||
const data = JSON.parse(jsonData);
|
||||
return {
|
||||
...data,
|
||||
commitLink: util.format(BuildContextGetter.GIT_PATH, data.commitHash)
|
||||
}
|
||||
}
|
||||
|
||||
private findValidPath(): Nullable<string> {
|
||||
return BuildContextGetter.EXPECTED_PATHS.find((path) => {
|
||||
return fs.existsSync(path);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue