({
id,
type,
serverId,
}: ApplyPatchesOptions)
| 134 | } |
| 135 | |
| 136 | export const generateApplyPatchesCommand = async ({ |
| 137 | id, |
| 138 | type, |
| 139 | serverId, |
| 140 | }: ApplyPatchesOptions) => { |
| 141 | const entity = |
| 142 | type === "application" |
| 143 | ? await findApplicationById(id) |
| 144 | : await findComposeById(id); |
| 145 | const { COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId); |
| 146 | const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH; |
| 147 | const codePath = join(basePath, entity.appName, "code"); |
| 148 | |
| 149 | const resultPatches = await findPatchesByEntityId(id, type); |
| 150 | const patches = resultPatches.filter((p) => p.enabled); |
| 151 | |
| 152 | if (patches.length === 0) { |
| 153 | return ""; |
| 154 | } |
| 155 | |
| 156 | let command = `echo "Applying ${patches.length} patch(es)...";`; |
| 157 | |
| 158 | for (const p of patches) { |
| 159 | const filePath = join(codePath, p.filePath); |
| 160 | |
| 161 | if (p.type === "delete") { |
| 162 | command += ` |
| 163 | rm -f "${filePath}"; |
| 164 | `; |
| 165 | } else { |
| 166 | command += ` |
| 167 | file="${filePath}" |
| 168 | dir="$(dirname "$file")" |
| 169 | mkdir -p "$dir" |
| 170 | echo "${encodeBase64(p.content)}" | base64 -d > "$file" |
| 171 | `; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return command; |
| 176 | }; |
no test coverage detected