-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
activate.ts
68 lines (53 loc) · 2.08 KB
/
activate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { IArg } from '@oclif/parser/lib/args';
import Command from '../command';
import Config from '../config';
import { nonInteractive } from '../flags';
import Insurer from '../insurer';
import ISteamMod from '../interfaces/iSteamMod';
import Mod from '../mod';
import Processor from '../processor';
export default class ActivateCommand extends Command {
public static description = 'Activates mods by adding their symlinks and keys back.';
public static examples = [
'magma activate',
'magma activate 723217262',
'magma activate 450814997 723217262 713709341',
];
public static strict = false;
public static args = [{ description: 'Steam Workshop item IDs.', name: 'id' }] as IArg[];
public static flags = {
nonInteractive,
};
public async init(): Promise<void> {
Config.ensureIsInitialized();
Config.ensureIsLatestVersion();
}
public async run(): Promise<void> {
const { argv, flags } = this.parse(ActivateCommand);
let steamIds = argv.map(arg => parseInt(arg, 10));
// Get only those mods that are deactivated
const mods = Config.get('mods');
const filteredMods: ISteamMod[] = Mod.filterSteamMods(mods) as ISteamMod[];
if (filteredMods.length === 0) {
console.log('There are no mods to activate.');
return;
}
if (steamIds.length === 0) {
const insurer = new Insurer(flags.nonInteractive);
steamIds = await insurer.ensureValidIds(filteredMods, 'What mods would you like to activate?');
}
for (const steamId of steamIds) {
const mod = mods[mods.findIndex(m => m.steamId === steamId)];
// If user gave a non-existant mod id
if (mod === undefined) { continue; }
// Add mod keys
Processor.updateKeys([mod]);
// Add symlink
Processor.linkMods([mod]);
// Add to config
mod.isActive = true;
}
Processor.updateServerConfigFile(mods);
Config.set('mods', mods);
}
}