forked from chegele/BDSAddonInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·77 lines (62 loc) · 2.83 KB
/
Copy pathcli.js
File metadata and controls
executable file
·77 lines (62 loc) · 2.83 KB
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
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
import BDSAddonInstaller from './index.js';
import path from 'path';
import fs from 'fs-extra';
let args = process.argv.slice(2);
const cwd = process.cwd();
const addonDirectory = 'BDS-Addons';
const requiredFiles = ['behavior_packs', 'resource_packs', 'development_behavior_packs', 'development_resource_packs'];
const useExample = ' bds-addon-installer <pathToServer> \n Example: bds-addon-installer "C:\\Program Files\\BedrockServer\\" \n';
console.log('\nRunning Bedrock Dedicated Server Addon Installer...');
// Check if the user has added the -r option. This is for removing old addons before installing the new addons.
let removeOldPacks = false;
if (args.includes('-r')) removeOldPacks = true;
// Check if the user has added the -v option. This is for enabling verbose mode.
let verboseMode = false;
if (args.includes('-v')) verboseMode = true;
// Remove options from the argument array
args = args.filter(arg => arg != '-r' && arg != '-v');
// If multiple arguments provided cancel execution. There may be a space in the path provided but no quotes.
if (args.length > 1) {
console.log('You provided too many arguments. Maybe you forgot to add "quotes" around your path?');
console.log(useExample);;
process.exit();
}
// If no arguments provided, assume current working directory is server location.
if (args.length == 0) args.push(cwd);
let serverPath = args[0];
// Check if user is asking for help
if (['help', '-h', '-H', '--help'].includes(serverPath)) {
console.log(useExample);
process.exit();
}
// Check if provided path is relative path & convert to absolute path if needed.
if (!serverPath.startsWith(cwd)) serverPath = path.join(cwd, serverPath);
// Validate provided path exists
if (!fs.existsSync(serverPath)) {
console.log('The provided path does not exist...');
console.log('path: ' + serverPath);;
process.exit();
}
// Validate that provided path contains bedrock server files
requiredFiles.forEach(file => {
let filePath = path.join(serverPath, file);
if (!fs.existsSync(filePath)) {
console.log('Required files/folders are missing. Please provide a path to the root of a Bedrock Server.');
console.log('Missing file: ' + file);
console.log('Provided path: ' + serverPath);
process.exit();
}
});
// Check if addon directory exists & create it if not.
const addonPath = path.join(serverPath, addonDirectory);
if (!fs.existsSync(addonPath)) {
fs.mkdirSync(addonPath);
console.log('It looks like this may be your first time using bds-addon-installer.');
console.log('Place all of you your packs in the addon folder and run the script again.');;
console.log('Addon Location: ' + addonPath);
process.exit();
}
// Install the addons.
const installer = new BDSAddonInstaller(serverPath, verboseMode);
installer.installAllAddons(removeOldPacks)