|
1 |
| -import { InstallArgs, PackageInstaller } from "./PackageInstaller"; |
2 |
| -import path from "path"; |
3 |
| -import FsProvider from "../providers/generic/file/FsProvider"; |
| 1 | +import path from 'path'; |
| 2 | + |
| 3 | +import { InstallArgs, PackageInstaller } from './PackageInstaller'; |
| 4 | +import FileWriteError from '../model/errors/FileWriteError'; |
| 5 | +import FsProvider from '../providers/generic/file/FsProvider'; |
| 6 | +import FileUtils from '../utils/FileUtils'; |
| 7 | + |
4 | 8 |
|
5 | 9 | export class GodotMLInstaller implements PackageInstaller {
|
| 10 | + // JSON_Schema_Validator present on v7.0.1+ only. |
| 11 | + private static readonly TRACKED = ['mod_loader', 'JSON_Schema_Validator'] |
| 12 | + |
6 | 13 | /**
|
7 | 14 | * Handles installation of GodotML
|
8 | 15 | */
|
9 | 16 | async install(args: InstallArgs) {
|
10 | 17 | const { packagePath, profile } = args;
|
11 | 18 |
|
12 |
| - const copyFrom = path.join(packagePath, "addons", "mod_loader"); |
13 |
| - const copyTo = profile.joinToProfilePath("addons", "mod_loader"); |
14 |
| - const fs = FsProvider.instance; |
| 19 | + try { |
| 20 | + for (const fileOrFolder of GodotMLInstaller.TRACKED) { |
| 21 | + const copyFrom = path.join(packagePath, 'addons', fileOrFolder); |
| 22 | + |
| 23 | + if (!await FsProvider.instance.exists(copyFrom)) { |
| 24 | + continue; |
| 25 | + } |
15 | 26 |
|
16 |
| - if (await fs.exists(copyFrom)) { |
17 |
| - if (!await fs.exists(copyTo)) { |
18 |
| - await fs.mkdirs(copyTo); |
| 27 | + const copyTo = profile.joinToProfilePath('addons', fileOrFolder); |
| 28 | + await FileUtils.copyFileOrFolder(copyFrom, copyTo); |
19 | 29 | }
|
20 |
| - await fs.copyFolder(copyFrom, copyTo); |
| 30 | + } catch (e) { |
| 31 | + throw FileWriteError.fromThrownValue(e, 'Failed to install GodotML'); |
21 | 32 | }
|
22 | 33 | }
|
23 | 34 | }
|
0 commit comments