|
1 | 1 | // Imports the necessary libraries |
2 | 2 | import { select } from '@inquirer/prompts'; |
3 | 3 | import { splashLogo } from 'helpbot/loaders'; |
| 4 | +import AutoGitUpdate from 'auto-git-update'; |
4 | 5 |
|
5 | 6 | // Stores the name of the menu |
6 | 7 | const menuName = new URL(import.meta.url).pathname.split('/').pop().replace('.js', ''); |
@@ -166,67 +167,22 @@ export default async (beforeError, forceUpdate) => { |
166 | 167 | // Shows a message indicating that the bot is downloading the new version |
167 | 168 | console.log(`⬇️ ${await client.functions.utils.parseLocale(locale.downloadingNewVersion, { targetVersion: `v${latestRemoteTag}`, repositoryURL: repoUrl })} ...`); |
168 | 169 |
|
169 | | - // Stores the working directory |
170 | | - const workingDirectory = String(process.cwd()); |
171 | | - |
172 | | - // Stores the temporary directory |
173 | | - const tmpDir = `${workingDirectory}/tmp`; |
174 | | - |
175 | 170 | try { |
176 | 171 |
|
177 | | - // Creates the temporary directory if it doesn't exist, or empties it if it does |
178 | | - if (!fs.existsSync(tmpDir)) await fs.promises.mkdir(tmpDir); |
179 | | - else await fs.promises.rm(tmpDir, { recursive: true }); |
180 | | - |
181 | | - // Clones the repository in the temporary directory |
182 | | - await git.clone(repoUrl, tmpDir); |
183 | | - |
184 | | - // Changes the working directory to the temporary directory |
185 | | - process.chdir(tmpDir); |
186 | | - |
187 | | - // Stops the process |
188 | | - process.exit(0); // --- EXPERIMENTAL --- |
189 | | - |
190 | | - // Switches to the latest remote tag |
191 | | - await git.fetch(['--all']); |
192 | | - await git.reset(['--hard', latestRemoteTag]); |
193 | | - |
194 | | - // Changes the working directory back to the original directory |
195 | | - process.chdir(workingDirectory); |
196 | | - |
197 | | - // Creates an array with the files to exclude from the update |
198 | | - const excludeFiles = ['./config.json']; |
199 | | - |
200 | | - // Copied the files from the temporary directory to the original directory |
201 | | - await fs.readdir('./tmp', async (err, files) => { |
202 | | - |
203 | | - // If an error occurred, throws it |
204 | | - if (err) throw err; |
205 | | - |
206 | | - // For each file in the temporary directory |
207 | | - for (const file of files) { |
208 | | - |
209 | | - // If the file is not in the exclude list, copies it |
210 | | - if (!excludeFiles.includes(file)) await fs.copy(`./tmp/${file}`, `./${file}`); |
211 | | - }; |
212 | | - }); |
213 | | - |
214 | | - // Deletes the files that are not in the temporary directory |
215 | | - await fs.readdir('.', async (err, files) => { |
216 | | - |
217 | | - // If an error occurred, throws it |
218 | | - if (err) throw err; |
219 | | - |
220 | | - // For each file in the original directory |
221 | | - for (const file of files) { |
222 | | - |
223 | | - // If the file is not in the temporary directory, deletes it |
224 | | - if (!fs.existsSync(`./tmp/${file}`)) await fs.unlink(`./${file}`); |
225 | | - }; |
226 | | - }); |
227 | | - |
228 | | - // Deletes the temporary directory |
229 | | - await fs.promises.rmdir('./tmp'); |
| 172 | + // Generates athe configuration for the updater |
| 173 | + const updateConfiguration = { |
| 174 | + repository: repoUrl, |
| 175 | + fromReleases: false, |
| 176 | + branch: localConfig.betaEnabled = localConfig.betaEnabled ? 'beta' : 'master', |
| 177 | + tempLocation: './tmp/', |
| 178 | + ignoreFiles: ['config.json'] |
| 179 | + } |
| 180 | + |
| 181 | + // Creates a new instance of the updater |
| 182 | + const updater = new AutoGitUpdate(updateConfiguration); |
| 183 | + |
| 184 | + // Updates the bot |
| 185 | + await updater.autoUpdate(); |
230 | 186 |
|
231 | 187 | // Requires the child_process library |
232 | 188 | const { exec } = require('child_process'); |
|
0 commit comments