Skip to content

Commit

Permalink
feat: add option for SMF deploy summary path
Browse files Browse the repository at this point in the history
Closes #549
  • Loading branch information
AnthonyFuller committed Jan 3, 2025
1 parent cd069f3 commit 8a06cae
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
6 changes: 2 additions & 4 deletions components/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,8 @@ export class Controller {
log(LogLevel.ERROR, e)
}

const deployPath = SMFSupport.modFrameworkDataPath

if (typeof deployPath === "string") {
await this.smf.initSMFSupport(deployPath)
if (this.smf.lastDeploy) {
await this.smf.initSMFSupport()
}

await this._loadPlugins()
Expand Down
7 changes: 7 additions & 0 deletions components/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ export const defaultFlags: Flags = {
desc: "Forcibly disable installed mod checks",
default: false,
},
frameworkDeploySummaryPath: {
category: "Modding",
title: "frameworkDeploySummaryPath",
desc: 'The path of Simple Mod Framework\'s deploy summary file. By default, it is set to "AUTO", which will attempt to locate the file in predefined locations. Alternatively, you can specify a custom path.',
default: "AUTO",
showIngame: false,
},
experimentalHMR: {
category: "Experimental",
title: "experimentalHMR",
Expand Down
71 changes: 53 additions & 18 deletions components/smfSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,63 @@ export class SMFSupport {
public readonly lastDeploy: SMFLastDeploy | null

constructor(private readonly controller: Controller) {
const dataPath = SMFSupport.modFrameworkDataPath
const dataPaths = SMFSupport.modFrameworkDataPath

if (dataPath && existsSync(dataPath)) {
this.lastDeploy = parse(readFileSync(dataPath).toString())
return
if (dataPaths) {
for (const dataPath of dataPaths) {
if (!existsSync(dataPath)) continue
this.lastDeploy = parse(readFileSync(dataPath).toString())
return
}
}

this.lastDeploy = null
}

static get modFrameworkDataPath() {
return (
(process.env.LOCALAPPDATA &&
join(
process.env.LOCALAPPDATA,
"Simple Mod Framework",
"lastDeploy.json",
)) ||
false
)
static get modFrameworkDataPath(): string[] | false {
if (getFlag("frameworkDeploySummaryPath") !== "AUTO")
return [getFlag("frameworkDeploySummaryPath") as string]

switch (process.platform) {
case "win32":
return (
(process.env.LOCALAPPDATA && [
join(
process.env.LOCALAPPDATA,
"Simple Mod Framework",
"deploySummary.json",
),
join(
process.env.LOCALAPPDATA,
"Simple Mod Framework",
"lastDeploy.json",
),
]) ||
false
)
case "linux": {
if (!process.env.HOME) return false
const XDG_DATA_HOME =
process.env.XDG_DATA_HOME ??
join(process.env.HOME, ".local", "share")

return [
join(
XDG_DATA_HOME,
"app.simple-mod-framework",
"deploySummary.json",
),
join(
XDG_DATA_HOME,
"app.simple-mod-framework",
"lastDeploy.json",
),
]
}

default:
return false
}
}

private async executePlugin(plugin: string) {
Expand Down Expand Up @@ -141,10 +178,8 @@ export class SMFSupport {
}
}

public async initSMFSupport(modFrameworkDataPath: string) {
if (!(modFrameworkDataPath && existsSync(modFrameworkDataPath))) {
return
}
public async initSMFSupport() {
if (!this.lastDeploy) return

log(
LogLevel.INFO,
Expand Down

0 comments on commit 8a06cae

Please sign in to comment.