@bobschlowinskii/clicraft 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +191 -0
- package/CONTRIBUTING.md +261 -0
- package/LICENSE.md +7 -0
- package/README.md +55 -0
- package/commands/auth.js +427 -0
- package/commands/config.js +356 -0
- package/commands/create.js +534 -0
- package/commands/info.js +113 -0
- package/commands/install.js +130 -0
- package/commands/launch.js +296 -0
- package/commands/search.js +50 -0
- package/commands/uninstall.js +94 -0
- package/commands/upgrade.js +343 -0
- package/commands/version.js +21 -0
- package/docs/README.md +119 -0
- package/docs/_config.yml +63 -0
- package/docs/commands/auth.md +376 -0
- package/docs/commands/config.md +294 -0
- package/docs/commands/create.md +276 -0
- package/docs/commands/info.md +460 -0
- package/docs/commands/install.md +320 -0
- package/docs/commands/launch.md +427 -0
- package/docs/commands/search.md +276 -0
- package/docs/commands/uninstall.md +128 -0
- package/docs/commands/upgrade.md +515 -0
- package/docs/commands.md +266 -0
- package/docs/configuration.md +410 -0
- package/docs/contributing.md +114 -0
- package/docs/index.md +82 -0
- package/docs/installation.md +162 -0
- package/helpers/auth/index.js +20 -0
- package/helpers/auth/microsoft.js +329 -0
- package/helpers/auth/storage.js +260 -0
- package/helpers/config.js +258 -0
- package/helpers/constants.js +38 -0
- package/helpers/getv.js +5 -0
- package/helpers/minecraft.js +308 -0
- package/helpers/modrinth.js +141 -0
- package/helpers/utils.js +334 -0
- package/helpers/versions.js +21 -0
- package/index.js +89 -0
- package/package.json +30 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import {
|
|
6
|
+
getConfigDir,
|
|
7
|
+
loadSettings,
|
|
8
|
+
saveSettings,
|
|
9
|
+
loadGameSettingsIgnore,
|
|
10
|
+
saveGameSettingsIgnore,
|
|
11
|
+
loadDefaultGameSettings,
|
|
12
|
+
saveDefaultGameSettings,
|
|
13
|
+
extractGameSettings
|
|
14
|
+
} from '../helpers/config.js';
|
|
15
|
+
import {
|
|
16
|
+
loadConfig,
|
|
17
|
+
saveConfig,
|
|
18
|
+
getInstancePath,
|
|
19
|
+
requireConfig,
|
|
20
|
+
parseValue
|
|
21
|
+
} from '../helpers/utils.js';
|
|
22
|
+
|
|
23
|
+
// Show current CLI settings
|
|
24
|
+
async function showSettings() {
|
|
25
|
+
const settings = loadSettings();
|
|
26
|
+
const configDir = getConfigDir();
|
|
27
|
+
|
|
28
|
+
console.log(chalk.cyan('\n⚙️ CLI Settings\n'));
|
|
29
|
+
console.log(chalk.gray(` Config directory: ${configDir}`));
|
|
30
|
+
console.log('');
|
|
31
|
+
|
|
32
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
33
|
+
const displayValue = value === null ? chalk.gray('(auto)') : chalk.white(value);
|
|
34
|
+
console.log(` ${chalk.cyan(key)}: ${displayValue}`);
|
|
35
|
+
}
|
|
36
|
+
console.log('');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Edit a CLI setting
|
|
40
|
+
async function editSetting(key, value) {
|
|
41
|
+
const settings = loadSettings();
|
|
42
|
+
|
|
43
|
+
if (!(key in settings)) {
|
|
44
|
+
console.log(chalk.red(`\nError: Unknown setting "${key}"`));
|
|
45
|
+
console.log(chalk.gray('Available settings:'));
|
|
46
|
+
for (const k of Object.keys(settings)) {
|
|
47
|
+
console.log(chalk.gray(` - ${k}`));
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let parsedValue = value === 'null' || value === 'auto' ? null : parseValue(value);
|
|
53
|
+
settings[key] = parsedValue;
|
|
54
|
+
saveSettings(settings);
|
|
55
|
+
|
|
56
|
+
console.log(chalk.green(`\n✓ Set ${key} = ${parsedValue === null ? '(auto)' : parsedValue}`));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Show game settings ignore list
|
|
60
|
+
async function showIgnoreList() {
|
|
61
|
+
const ignoreList = loadGameSettingsIgnore();
|
|
62
|
+
const configDir = getConfigDir();
|
|
63
|
+
|
|
64
|
+
console.log(chalk.cyan('\n🚫 Game Settings Ignore List\n'));
|
|
65
|
+
console.log(chalk.gray(` File: ${path.join(configDir, 'game-settings-ignore.json')}`));
|
|
66
|
+
console.log(chalk.gray(' These settings are excluded when saving game settings to mcconfig.json\n'));
|
|
67
|
+
|
|
68
|
+
for (const pattern of ignoreList) {
|
|
69
|
+
console.log(` ${chalk.gray('-')} ${pattern}`);
|
|
70
|
+
}
|
|
71
|
+
console.log('');
|
|
72
|
+
console.log(chalk.gray(' Tip: Use * as wildcard (e.g., key_* ignores all keybinds)'));
|
|
73
|
+
console.log('');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Add to ignore list
|
|
77
|
+
async function addToIgnoreList(pattern) {
|
|
78
|
+
const ignoreList = loadGameSettingsIgnore();
|
|
79
|
+
|
|
80
|
+
if (ignoreList.includes(pattern)) {
|
|
81
|
+
console.log(chalk.yellow(`\n"${pattern}" is already in the ignore list`));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
ignoreList.push(pattern);
|
|
86
|
+
saveGameSettingsIgnore(ignoreList);
|
|
87
|
+
|
|
88
|
+
console.log(chalk.green(`\n✓ Added "${pattern}" to ignore list`));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Remove from ignore list
|
|
92
|
+
async function removeFromIgnoreList(pattern) {
|
|
93
|
+
const ignoreList = loadGameSettingsIgnore();
|
|
94
|
+
|
|
95
|
+
const index = ignoreList.indexOf(pattern);
|
|
96
|
+
if (index === -1) {
|
|
97
|
+
console.log(chalk.yellow(`\n"${pattern}" is not in the ignore list`));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
ignoreList.splice(index, 1);
|
|
102
|
+
saveGameSettingsIgnore(ignoreList);
|
|
103
|
+
|
|
104
|
+
console.log(chalk.green(`\n✓ Removed "${pattern}" from ignore list`));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Capture game settings from an instance's options.txt
|
|
108
|
+
export async function captureGameSettings(options, autoSaveToConfig = false) {
|
|
109
|
+
const instancePath = getInstancePath(options);
|
|
110
|
+
|
|
111
|
+
const config = loadConfig(instancePath);
|
|
112
|
+
if (!config) {
|
|
113
|
+
console.log(chalk.red('Error: No mcconfig.json found.'));
|
|
114
|
+
console.log(chalk.gray('Make sure you are in a Minecraft instance directory or use --instance <path>'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const optionsPath = path.join(instancePath, 'options.txt');
|
|
119
|
+
if (!fs.existsSync(optionsPath)) {
|
|
120
|
+
console.log(chalk.red('Error: No options.txt found.'));
|
|
121
|
+
console.log(chalk.gray('Launch Minecraft at least once to generate options.txt'));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const gameSettings = extractGameSettings(optionsPath);
|
|
126
|
+
|
|
127
|
+
if (!gameSettings || Object.keys(gameSettings).length === 0) {
|
|
128
|
+
console.log(chalk.yellow('No game settings to capture (all settings are in ignore list)'));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const message = autoSaveToConfig
|
|
133
|
+
? chalk.gray('(auto-saved to mcconfig.json)\nDisable this by setting autoSaveToConfig to false in ~/.clicraft/settings.json')
|
|
134
|
+
: '';
|
|
135
|
+
console.log(chalk.cyan(`\n⚙️ Captured ${Object.keys(gameSettings).length} game settings\n ${message}\n`));
|
|
136
|
+
|
|
137
|
+
if (options.verbose) {
|
|
138
|
+
for (const [key, value] of Object.entries(gameSettings)) {
|
|
139
|
+
console.log(chalk.gray(` ${key}: ${value}`));
|
|
140
|
+
}
|
|
141
|
+
console.log('');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!autoSaveToConfig) {
|
|
145
|
+
const { confirm } = await inquirer.prompt([{
|
|
146
|
+
type: 'confirm',
|
|
147
|
+
name: 'confirm',
|
|
148
|
+
message: 'Save these settings to mcconfig.json?',
|
|
149
|
+
default: true
|
|
150
|
+
}]);
|
|
151
|
+
|
|
152
|
+
if (!confirm) {
|
|
153
|
+
console.log(chalk.yellow('\nCancelled.'));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
config.gameSettings = gameSettings;
|
|
159
|
+
saveConfig(instancePath, config);
|
|
160
|
+
|
|
161
|
+
console.log(chalk.green(`\n✓ Saved ${Object.keys(gameSettings).length} game settings to mcconfig.json`));
|
|
162
|
+
console.log(chalk.gray(' These settings will be applied when creating an instance from this config'));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Show game settings from mcconfig
|
|
166
|
+
async function showGameSettings(options) {
|
|
167
|
+
const instancePath = getInstancePath(options);
|
|
168
|
+
|
|
169
|
+
const config = loadConfig(instancePath);
|
|
170
|
+
if (!config) {
|
|
171
|
+
console.log(chalk.red('Error: No mcconfig.json found.'));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!config.gameSettings || Object.keys(config.gameSettings).length === 0) {
|
|
176
|
+
console.log(chalk.yellow('\nNo game settings saved in this instance.'));
|
|
177
|
+
console.log(chalk.gray('Use "clicraft config capture" to capture settings from options.txt'));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.log(chalk.cyan(`\n⚙️ Game Settings (${Object.keys(config.gameSettings).length} saved)\n`));
|
|
182
|
+
|
|
183
|
+
for (const [key, value] of Object.entries(config.gameSettings)) {
|
|
184
|
+
console.log(` ${chalk.cyan(key)}: ${value}`);
|
|
185
|
+
}
|
|
186
|
+
console.log('');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Clear game settings from mcconfig
|
|
190
|
+
async function clearGameSettings(options) {
|
|
191
|
+
const instancePath = getInstancePath(options);
|
|
192
|
+
|
|
193
|
+
const config = loadConfig(instancePath);
|
|
194
|
+
if (!config) {
|
|
195
|
+
console.log(chalk.red('Error: No mcconfig.json found.'));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!config.gameSettings || Object.keys(config.gameSettings).length === 0) {
|
|
200
|
+
console.log(chalk.yellow('\nNo game settings to clear.'));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const count = Object.keys(config.gameSettings).length;
|
|
205
|
+
delete config.gameSettings;
|
|
206
|
+
saveConfig(instancePath, config);
|
|
207
|
+
|
|
208
|
+
console.log(chalk.green(`\n✓ Cleared ${count} game settings from mcconfig.json`));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Show default game settings
|
|
212
|
+
async function showDefaultGameSettings() {
|
|
213
|
+
const configDir = getConfigDir();
|
|
214
|
+
const defaults = loadDefaultGameSettings();
|
|
215
|
+
|
|
216
|
+
console.log(chalk.cyan('\n🎮 Default Game Settings\n'));
|
|
217
|
+
console.log(chalk.gray(` File: ${path.join(configDir, 'default-game-settings.json')}`));
|
|
218
|
+
console.log(chalk.gray(' These settings are applied to all new instances\n'));
|
|
219
|
+
|
|
220
|
+
if (Object.keys(defaults).length === 0) {
|
|
221
|
+
console.log(chalk.gray(' (No default settings configured)'));
|
|
222
|
+
console.log('');
|
|
223
|
+
console.log(chalk.gray(' Add settings with: clicraft config defaults-set <key> <value>'));
|
|
224
|
+
console.log(chalk.gray(' Example: clicraft config defaults-set renderDistance 16'));
|
|
225
|
+
} else {
|
|
226
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
227
|
+
console.log(` ${chalk.cyan(key)}: ${value}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
console.log('');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Set a default game setting
|
|
234
|
+
async function setDefaultGameSetting(key, value) {
|
|
235
|
+
const defaults = loadDefaultGameSettings();
|
|
236
|
+
defaults[key] = parseValue(value);
|
|
237
|
+
saveDefaultGameSettings(defaults);
|
|
238
|
+
|
|
239
|
+
console.log(chalk.green(`\n✓ Set default ${key} = ${defaults[key]}`));
|
|
240
|
+
console.log(chalk.gray(' This will be applied to all new instances'));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Remove a default game setting
|
|
244
|
+
async function removeDefaultGameSetting(key) {
|
|
245
|
+
const defaults = loadDefaultGameSettings();
|
|
246
|
+
|
|
247
|
+
if (!(key in defaults)) {
|
|
248
|
+
console.log(chalk.yellow(`\n"${key}" is not in default settings`));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
delete defaults[key];
|
|
253
|
+
saveDefaultGameSettings(defaults);
|
|
254
|
+
|
|
255
|
+
console.log(chalk.green(`\n✓ Removed "${key}" from default settings`));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Clear all default game settings
|
|
259
|
+
async function clearDefaultGameSettings() {
|
|
260
|
+
saveDefaultGameSettings({});
|
|
261
|
+
console.log(chalk.green('\n✓ Cleared all default game settings'));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Main config command handler
|
|
265
|
+
export async function configCommand(action, args, options) {
|
|
266
|
+
switch (action) {
|
|
267
|
+
case 'show':
|
|
268
|
+
case undefined:
|
|
269
|
+
await showSettings();
|
|
270
|
+
break;
|
|
271
|
+
|
|
272
|
+
case 'set':
|
|
273
|
+
if (!args || args.length < 2) {
|
|
274
|
+
console.log(chalk.red('Usage: clicraft config set <key> <value>'));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
await editSetting(args[0], args[1]);
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case 'ignore':
|
|
281
|
+
await showIgnoreList();
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case 'ignore-add':
|
|
285
|
+
if (!args || args.length < 1) {
|
|
286
|
+
console.log(chalk.red('Usage: clicraft config ignore-add <pattern>'));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
await addToIgnoreList(args[0]);
|
|
290
|
+
break;
|
|
291
|
+
|
|
292
|
+
case 'ignore-remove':
|
|
293
|
+
if (!args || args.length < 1) {
|
|
294
|
+
console.log(chalk.red('Usage: clicraft config ignore-remove <pattern>'));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
await removeFromIgnoreList(args[0]);
|
|
298
|
+
break;
|
|
299
|
+
|
|
300
|
+
case 'capture':
|
|
301
|
+
await captureGameSettings(options);
|
|
302
|
+
break;
|
|
303
|
+
|
|
304
|
+
case 'game-settings':
|
|
305
|
+
await showGameSettings(options);
|
|
306
|
+
break;
|
|
307
|
+
|
|
308
|
+
case 'clear-game-settings':
|
|
309
|
+
await clearGameSettings(options);
|
|
310
|
+
break;
|
|
311
|
+
|
|
312
|
+
case 'defaults':
|
|
313
|
+
await showDefaultGameSettings();
|
|
314
|
+
break;
|
|
315
|
+
|
|
316
|
+
case 'defaults-set':
|
|
317
|
+
if (!args || args.length < 2) {
|
|
318
|
+
console.log(chalk.red('Usage: clicraft config defaults-set <key> <value>'));
|
|
319
|
+
console.log(chalk.gray('\nExample: clicraft config defaults-set renderDistance 16'));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
await setDefaultGameSetting(args[0], args[1]);
|
|
323
|
+
break;
|
|
324
|
+
|
|
325
|
+
case 'defaults-remove':
|
|
326
|
+
if (!args || args.length < 1) {
|
|
327
|
+
console.log(chalk.red('Usage: clicraft config defaults-remove <key>'));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
await removeDefaultGameSetting(args[0]);
|
|
331
|
+
break;
|
|
332
|
+
|
|
333
|
+
case 'defaults-clear':
|
|
334
|
+
await clearDefaultGameSettings();
|
|
335
|
+
break;
|
|
336
|
+
|
|
337
|
+
default:
|
|
338
|
+
console.log(chalk.red(`Unknown action: ${action}`));
|
|
339
|
+
console.log(chalk.gray('\nAvailable actions:'));
|
|
340
|
+
console.log(chalk.gray(' show - Show CLI settings'));
|
|
341
|
+
console.log(chalk.gray(' set <key> <value> - Set a CLI setting'));
|
|
342
|
+
console.log(chalk.gray(' ignore - Show game settings ignore list'));
|
|
343
|
+
console.log(chalk.gray(' ignore-add <pattern> - Add to ignore list'));
|
|
344
|
+
console.log(chalk.gray(' ignore-remove <pattern> - Remove from ignore list'));
|
|
345
|
+
console.log(chalk.gray(' defaults - Show default game settings'));
|
|
346
|
+
console.log(chalk.gray(' defaults-set <key> <value> - Set a default game setting'));
|
|
347
|
+
console.log(chalk.gray(' defaults-remove <key> - Remove a default game setting'));
|
|
348
|
+
console.log(chalk.gray(' defaults-clear - Clear all default game settings'));
|
|
349
|
+
console.log(chalk.gray(' capture - Capture game settings from options.txt'));
|
|
350
|
+
console.log(chalk.gray(' game-settings - Show saved game settings'));
|
|
351
|
+
console.log(chalk.gray(' clear-game-settings - Clear saved game settings'));
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export default { configCommand };
|