2022-09-28 20:11:22 +02:00
|
|
|
const { resolve } = require("path")
|
|
|
|
const fs = require("fs")
|
2022-09-29 15:00:16 +02:00
|
|
|
const { error, success } = require("../utils")
|
2022-09-29 16:38:54 +02:00
|
|
|
const { updateDockerComposeService } = require("./utils")
|
2022-09-28 20:11:22 +02:00
|
|
|
|
|
|
|
exports.watchPlugins = async pluginPath => {
|
|
|
|
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
|
|
|
|
}
|
2022-09-29 16:38:54 +02:00
|
|
|
updateDockerComposeService(service => {
|
|
|
|
// 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}`)
|
|
|
|
})
|
|
|
|
console.log(
|
|
|
|
success(`Docker compose configured to watch directory: ${pluginPath}`)
|
|
|
|
)
|
2022-09-28 20:11:22 +02:00
|
|
|
}
|