-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: split apm in more files and add more apm docs
- Loading branch information
root
committed
May 22, 2024
1 parent
ef3bbe9
commit 410a06a
Showing
10 changed files
with
127 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { AbstractPackage, AbstractPackageManager } from "./ApmInterface.js" | ||
export { AbstractPackageManagerWrapper } from "./Wrapper.js" | ||
export { ApmChecker, ApmInit, apmChecker, getApm, registerDefaultApmMapperChecker } from "./checker.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { SshHost } from "../SshHost.js" | ||
import { Awaitable } from "../utils/base.js" | ||
import { AbstractPackageManager } from "./ApmInterface.js" | ||
import { AbstractPackageManagerWrapper } from "./apm.js" | ||
import { initAptApm } from "./apt.js" | ||
import { initDnfApm } from "./dnf.js" | ||
import { initYumApm } from "./yum.js" | ||
|
||
export type ApmInit = ( | ||
sshHost: SshHost | ||
) => Awaitable<AbstractPackageManager> | ||
|
||
export type ApmChecker = ( | ||
sshHost: SshHost, | ||
) => Awaitable<AbstractPackageManager | undefined | void> | ||
|
||
export const apmChecker: ApmChecker[] = [] | ||
|
||
export async function getApm( | ||
sshHost: SshHost | ||
): Promise<AbstractPackageManagerWrapper> { | ||
for (const apmCheck of apmChecker) { | ||
const apm = await apmCheck( | ||
sshHost, | ||
) | ||
if (apm) { | ||
return new AbstractPackageManagerWrapper( | ||
apm | ||
) | ||
} | ||
} | ||
|
||
throw new Error( | ||
"No package manager found for:\n" + | ||
" " + sshHost.settings.user + "@" + | ||
sshHost.settings.host + ":" + sshHost.settings.port | ||
) | ||
} | ||
|
||
export function registerDefaultApmMapperChecker(): void { | ||
apmChecker.push( | ||
async (sshHost) => { | ||
if ( | ||
await sshHost.cmdExists("apt") && | ||
await sshHost.cmdExists("apt-get") | ||
) { | ||
return initAptApm(sshHost) | ||
} | ||
} | ||
) | ||
|
||
apmChecker.push( | ||
async (sshHost) => { | ||
if ( | ||
await sshHost.cmdExists("dnf") | ||
) { | ||
return initDnfApm(sshHost) | ||
} | ||
} | ||
) | ||
|
||
apmChecker.push( | ||
async (sshHost) => { | ||
if ( | ||
await sshHost.cmdExists("yum") | ||
) { | ||
return initYumApm(sshHost) | ||
} | ||
} | ||
) | ||
} | ||
|
||
registerDefaultApmMapperChecker() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters