2023-03-02 19:21:45 +01:00
|
|
|
import { resolve } from "path"
|
|
|
|
import fs from "fs"
|
|
|
|
import { error, success } from "../utils"
|
|
|
|
import { updateDockerComposeService } from "./utils"
|
|
|
|
import { DockerCompose } from "./types"
|
2022-09-28 20:11:22 +02:00
|
|
|
|
2023-03-02 19:21:45 +01:00
|
|
|
export async function watchPlugins(pluginPath: string, silent: boolean) {
|
2022-09-28 20:11:22 +02:00
|
|
|
const PLUGIN_PATH = "/plugins"
|
|
|
|
// get absolute path
|
|
|
|
pluginPath = resolve(pluginPath)
|
|
|
|
if (!fs.existsSync(pluginPath)) {
|
|
|
|
console.log(
|
|
|
|
error(
|
|
|
|
`The directory "${pluginPath}" does not exist, please create and then try again.`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
2023-03-02 19:21:45 +01:00
|
|
|
updateDockerComposeService((service: DockerCompose) => {
|
2022-09-29 16:38:54 +02:00
|
|
|
// set environment variable
|
|
|
|
service.environment["PLUGINS_DIR"] = PLUGIN_PATH
|
|
|
|
// add volumes to parsed yaml
|
|
|
|
if (!service.volumes) {
|
|
|
|
service.volumes = []
|
|
|
|
}
|
|
|
|
const found = service.volumes.find(vol => vol.includes(PLUGIN_PATH))
|
|
|
|
if (found) {
|
|
|
|
service.volumes.splice(service.volumes.indexOf(found), 1)
|
|
|
|
}
|
|
|
|
service.volumes.push(`${pluginPath}:${PLUGIN_PATH}`)
|
|
|
|
})
|
2022-09-30 18:13:50 +02:00
|
|
|
if (!silent) {
|
|
|
|
console.log(
|
|
|
|
success(`Docker compose configured to watch directory: ${pluginPath}`)
|
|
|
|
)
|
|
|
|
}
|
2022-09-28 20:11:22 +02:00
|
|
|
}
|