@powernukkitx/cli 1.0.0 → 1.0.2
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/LICENSE +21 -0
- package/README.md +186 -203
- package/dist/cli.js +34 -46
- package/dist/commands/backup.d.ts +2 -2
- package/dist/commands/backup.js +23 -24
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +60 -61
- package/dist/commands/console.d.ts +2 -2
- package/dist/commands/console.js +98 -99
- package/dist/commands/doctor.d.ts +2 -2
- package/dist/commands/doctor.js +97 -98
- package/dist/commands/info.d.ts +2 -2
- package/dist/commands/info.js +41 -42
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +87 -66
- package/dist/commands/install.js +45 -0
- package/dist/commands/logs.d.ts +2 -2
- package/dist/commands/logs.js +60 -61
- package/dist/commands/menu.js +94 -86
- package/dist/commands/plugin/index.d.ts +2 -2
- package/dist/commands/plugin/index.js +13 -13
- package/dist/commands/plugin/info.d.ts +2 -2
- package/dist/commands/plugin/info.js +39 -40
- package/dist/commands/plugin/install.d.ts +2 -2
- package/dist/commands/plugin/install.js +56 -57
- package/dist/commands/plugin/installed.d.ts +2 -2
- package/dist/commands/plugin/installed.js +41 -42
- package/dist/commands/plugin/list.d.ts +2 -2
- package/dist/commands/plugin/list.js +47 -49
- package/dist/commands/plugin/remove.d.ts +2 -2
- package/dist/commands/plugin/remove.js +44 -45
- package/dist/commands/plugin/search.d.ts +2 -2
- package/dist/commands/plugin/search.js +11 -12
- package/dist/commands/plugin/update.d.ts +2 -2
- package/dist/commands/plugin/update.js +52 -53
- package/dist/commands/start.d.ts +2 -2
- package/dist/commands/start.js +74 -75
- package/dist/commands/stop.d.ts +2 -2
- package/dist/commands/stop.js +26 -27
- package/dist/commands/update.d.ts +2 -2
- package/dist/commands/update.js +34 -35
- package/dist/commands/use.d.ts +2 -2
- package/dist/commands/use.js +39 -40
- package/dist/infra/http.js +119 -121
- package/dist/infra/paths.js +15 -20
- package/dist/infra/store.js +24 -27
- package/dist/services/backup.js +34 -40
- package/dist/services/plugins.js +139 -111
- package/dist/services/process.js +41 -43
- package/dist/services/release.js +51 -38
- package/dist/services/server.js +81 -89
- package/dist/ui/output.js +67 -71
- package/dist/ui/prompts.js +26 -30
- package/dist/ui/theme.js +16 -18
- package/package.json +44 -46
- package/dist/bundle.js +0 -18
- package/dist/commands/cfg.d.ts +0 -2
- package/dist/commands/cfg.js +0 -61
- package/dist/commands/lang.d.ts +0 -2
- package/dist/commands/lang.js +0 -28
- package/dist/commands/plugin.d.ts +0 -1
- package/dist/commands/plugin.js +0 -1
- package/dist/core/config.d.ts +0 -13
- package/dist/core/config.js +0 -31
- package/dist/core/network.d.ts +0 -13
- package/dist/core/network.js +0 -139
- package/dist/core/output.d.ts +0 -33
- package/dist/core/output.js +0 -75
- package/dist/core/process.d.ts +0 -10
- package/dist/core/process.js +0 -53
- package/dist/i18n/en.json +0 -174
- package/dist/i18n/fr.json +0 -174
- package/dist/i18n/index.js +0 -58
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lang/en.json +0 -146
- package/dist/lang/fr.json +0 -146
- package/dist/lang/index.d.ts +0 -7
- package/dist/lang/index.js +0 -83
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -28
- package/dist/plugins.json +0 -66
- package/dist/types.d.ts +0 -61
- package/dist/types.js +0 -1
- package/dist/utils/api.d.ts +0 -9
- package/dist/utils/api.js +0 -24
- package/dist/utils/github.d.ts +0 -20
- package/dist/utils/github.js +0 -60
- package/dist/utils/logger.d.ts +0 -15
- package/dist/utils/logger.js +0 -72
- package/dist/utils/pause.d.ts +0 -1
- package/dist/utils/pause.js +0 -6
- package/dist/utils/plugins.d.ts +0 -4
- package/dist/utils/plugins.js +0 -34
- package/dist/utils/server.d.ts +0 -3
- package/dist/utils/server.js +0 -32
- package/dist/utils/updater.d.ts +0 -1
- package/dist/utils/updater.js +0 -86
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { readdir } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { defineCommand } from 'citty';
|
|
5
|
-
import { intro, outro, log, spin, progress } from '../../ui/output.js';
|
|
6
|
-
import { promptMulti } from '../../ui/prompts.js';
|
|
7
|
-
import { resolveServerDir } from '../../services/server.js';
|
|
8
|
-
import { getInstalled, updatePlugin } from '../../services/plugins.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { defineCommand } from 'citty';
|
|
5
|
+
import { intro, outro, log, spin, progress } from '../../ui/output.js';
|
|
6
|
+
import { promptMulti } from '../../ui/prompts.js';
|
|
7
|
+
import { resolveServerDir } from '../../services/server.js';
|
|
8
|
+
import { getInstalled, updatePlugin } from '../../services/plugins.js';
|
|
9
|
+
export const updateCmd = defineCommand({
|
|
10
|
+
meta: { description: 'Update installed plugins' },
|
|
11
|
+
args: { names: { type: 'positional', description: 'Plugin slugs', required: false } },
|
|
12
|
+
async run({ args }) {
|
|
13
|
+
const serverPath = (await resolveServerDir()) ?? '.';
|
|
14
|
+
const pluginsDir = join(serverPath, 'plugins');
|
|
15
|
+
if (!existsSync(pluginsDir)) {
|
|
16
|
+
log.error("No plugins/ directory");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const jars = (await readdir(pluginsDir)).filter(f => f.endsWith('.jar'));
|
|
20
|
+
let names = args.names ? [args.names] : [];
|
|
21
|
+
if (names.length === 0) {
|
|
22
|
+
names = await promptMulti("Select plugins to update:", jars.map(j => ({ value: j.replace('.jar', ''), label: j.replace('.jar', '') })));
|
|
23
|
+
}
|
|
24
|
+
intro(`🔄 ${"Update plugins"}`);
|
|
25
|
+
const tracked = await getInstalled();
|
|
26
|
+
for (const slug of names) {
|
|
27
|
+
const sp = spin(slug);
|
|
28
|
+
try {
|
|
29
|
+
const meta = tracked.find(p => p.slug === slug);
|
|
30
|
+
const existingJar = jars.find(j => j.toLowerCase().startsWith(slug.toLowerCase()));
|
|
31
|
+
const entry = await updatePlugin(slug, pluginsDir, meta?.version, existingJar, (pct, f) => progress(pct, f));
|
|
32
|
+
if (!entry) {
|
|
33
|
+
sp.stop(`${slug} is already up to date (v${meta?.version ?? '?'})`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
sp.stop(`${entry.name} v${entry.version}`);
|
|
37
|
+
log.success(`${entry.name} updated to v${entry.version}`);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
const msg = e.message;
|
|
41
|
+
if (msg.startsWith('no-release'))
|
|
42
|
+
sp.fail(`No release available for ${slug}`);
|
|
43
|
+
else if (msg.startsWith('no-file'))
|
|
44
|
+
sp.fail(`No file for ${slug}`);
|
|
45
|
+
else
|
|
46
|
+
sp.fail(`Error installing ${slug}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
log.info("Restart the server to load plugins");
|
|
50
|
+
outro('');
|
|
51
|
+
},
|
|
52
|
+
});
|
package/dist/commands/start.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandDef } from 'citty';
|
|
2
|
-
export declare const startCmd: CommandDef;
|
|
1
|
+
import type { CommandDef } from 'citty';
|
|
2
|
+
export declare const startCmd: CommandDef;
|
package/dist/commands/start.js
CHANGED
|
@@ -1,75 +1,74 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { cwd } from 'node:process';
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
5
|
-
import { defineCommand } from 'citty';
|
|
6
|
-
import { intro, outro, log, spin } from '../ui/output.js';
|
|
7
|
-
import { promptConfirm } from '../ui/prompts.js';
|
|
8
|
-
import { resolveServerDir, checkJava, findJava, buildLaunchArgs, javaEnv } from '../services/server.js';
|
|
9
|
-
import { savePid } from '../services/process.js';
|
|
10
|
-
import { JAR_NAME } from '../infra/paths.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
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
|
-
});
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { cwd } from 'node:process';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { defineCommand } from 'citty';
|
|
6
|
+
import { intro, outro, log, spin } from '../ui/output.js';
|
|
7
|
+
import { promptConfirm } from '../ui/prompts.js';
|
|
8
|
+
import { resolveServerDir, checkJava, findJava, buildLaunchArgs, javaEnv } from '../services/server.js';
|
|
9
|
+
import { savePid } from '../services/process.js';
|
|
10
|
+
import { JAR_NAME } from '../infra/paths.js';
|
|
11
|
+
export async function runStart(opts) {
|
|
12
|
+
const serverPath = opts.dir
|
|
13
|
+
? (opts.dir.includes(':') || opts.dir.startsWith('/') ? opts.dir : join(cwd(), opts.dir))
|
|
14
|
+
: (await resolveServerDir()) ?? cwd();
|
|
15
|
+
if (!existsSync(join(serverPath, JAR_NAME))) {
|
|
16
|
+
log.warn("No server found here");
|
|
17
|
+
if (!(await promptConfirm("Create a server now?", true)))
|
|
18
|
+
process.exit(0);
|
|
19
|
+
const { initCmd } = await import('./init.js');
|
|
20
|
+
await initCmd.run({ args: { dir: serverPath } });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
intro(`🚀 ${"Start server"}`);
|
|
24
|
+
const sp = spin("Checking Java...");
|
|
25
|
+
const java = await checkJava();
|
|
26
|
+
if (!java.ok) {
|
|
27
|
+
sp.fail("Java 21+ required — https://adoptium.net/");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
sp.stop(`Java ${String(java.version)} detected`);
|
|
31
|
+
const mem = opts.memory ?? '2G';
|
|
32
|
+
const cmdArgs = buildLaunchArgs(mem);
|
|
33
|
+
const javaExe = findJava();
|
|
34
|
+
if (opts.dryRun) {
|
|
35
|
+
log.info(`${javaExe} ${cmdArgs.join(' ')}`);
|
|
36
|
+
outro("Command generated");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
log.step(`${"Starting..."} (memory: ${mem})`);
|
|
40
|
+
const run = () => {
|
|
41
|
+
const child = spawn(javaExe, cmdArgs, { stdio: 'inherit', env: javaEnv(), cwd: serverPath });
|
|
42
|
+
if (child.pid)
|
|
43
|
+
savePid(child.pid, serverPath);
|
|
44
|
+
log.success(`Server running (PID ${String(child.pid)})`);
|
|
45
|
+
child.on('exit', code => {
|
|
46
|
+
if (code !== 0 && opts.restart) {
|
|
47
|
+
log.warn("Restarting...");
|
|
48
|
+
run();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
log.info(`Server stopped (code ${String(code ?? '?')})`);
|
|
52
|
+
process.exit(code ?? 0);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
run();
|
|
57
|
+
}
|
|
58
|
+
export const startCmd = defineCommand({
|
|
59
|
+
meta: { description: 'Start the PowerNukkitX server' },
|
|
60
|
+
args: {
|
|
61
|
+
dir: { type: 'string', description: 'Server directory' },
|
|
62
|
+
memory: { type: 'string', description: 'Memory (e.g. 2G)', default: '2G' },
|
|
63
|
+
restart: { type: 'boolean', description: 'Auto-restart on crash', default: false },
|
|
64
|
+
'dry-run': { type: 'boolean', description: 'Print command without running', default: false },
|
|
65
|
+
},
|
|
66
|
+
async run({ args }) {
|
|
67
|
+
await runStart({
|
|
68
|
+
dir: args.dir,
|
|
69
|
+
memory: args.memory,
|
|
70
|
+
restart: args.restart,
|
|
71
|
+
dryRun: args['dry-run'],
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
});
|
package/dist/commands/stop.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandDef } from 'citty';
|
|
2
|
-
export declare const stopCmd: CommandDef;
|
|
1
|
+
import type { CommandDef } from 'citty';
|
|
2
|
+
export declare const stopCmd: CommandDef;
|
package/dist/commands/stop.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { defineCommand } from 'citty';
|
|
2
|
-
import { intro, outro, log, spin } from '../ui/output.js';
|
|
3
|
-
import { loadPid, clearPid, killProcess, isAlive } from '../services/process.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { intro, outro, log, spin } from '../ui/output.js';
|
|
3
|
+
import { loadPid, clearPid, killProcess, isAlive } from '../services/process.js';
|
|
4
|
+
export async function runStop() {
|
|
5
|
+
intro(`⏹ ${"Stop server"}`);
|
|
6
|
+
const pid = await loadPid();
|
|
7
|
+
if (!pid || !isAlive(pid.pid)) {
|
|
8
|
+
log.warn("No server running");
|
|
9
|
+
await clearPid();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const sp = spin(`Stopping server (PID ${String(pid.pid)})...`);
|
|
13
|
+
const ok = await killProcess(pid.pid);
|
|
14
|
+
await clearPid();
|
|
15
|
+
if (ok) {
|
|
16
|
+
sp.stop("Server stopped");
|
|
17
|
+
outro("Server stopped");
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
sp.fail("Failed to stop");
|
|
21
|
+
}
|
|
22
|
+
export const stopCmd = defineCommand({
|
|
23
|
+
meta: { description: 'Stop the running PowerNukkitX server' },
|
|
24
|
+
args: {},
|
|
25
|
+
run: () => runStop(),
|
|
26
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandDef } from 'citty';
|
|
2
|
-
export declare const updateCmd: CommandDef;
|
|
1
|
+
import type { CommandDef } from 'citty';
|
|
2
|
+
export declare const updateCmd: CommandDef;
|
package/dist/commands/update.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import { rename } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { defineCommand } from 'citty';
|
|
4
|
-
import { intro, outro, log, spin, progress } from '../ui/output.js';
|
|
5
|
-
import { resolveServerDir } from '../services/server.js';
|
|
6
|
-
import { getLatestRelease, downloadCore } from '../services/release.js';
|
|
7
|
-
import { JAR_NAME } from '../infra/paths.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
log.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
});
|
|
1
|
+
import { rename } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { intro, outro, log, spin, progress } from '../ui/output.js';
|
|
5
|
+
import { resolveServerDir } from '../services/server.js';
|
|
6
|
+
import { getLatestRelease, downloadCore } from '../services/release.js';
|
|
7
|
+
import { JAR_NAME } from '../infra/paths.js';
|
|
8
|
+
export async function runUpdate(force = false) {
|
|
9
|
+
intro(`🔄 ${"Update PowerNukkitX"}`);
|
|
10
|
+
const serverPath = await resolveServerDir();
|
|
11
|
+
if (!serverPath) {
|
|
12
|
+
log.error("No server found");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const sp = spin("Checking for updates...");
|
|
16
|
+
const release = await getLatestRelease(force);
|
|
17
|
+
sp.stop(`New version available: ${release.tag}`);
|
|
18
|
+
const jarPath = join(serverPath, JAR_NAME);
|
|
19
|
+
log.step("Backing up old version...");
|
|
20
|
+
await rename(jarPath, `${jarPath}.old`).catch(() => { });
|
|
21
|
+
log.step("Downloading...");
|
|
22
|
+
await downloadCore(release, jarPath, pct => progress(pct, JAR_NAME));
|
|
23
|
+
log.success("Update complete!");
|
|
24
|
+
log.info("Restart the server to apply changes");
|
|
25
|
+
outro("Update complete!");
|
|
26
|
+
}
|
|
27
|
+
export const updateCmd = defineCommand({
|
|
28
|
+
meta: { description: 'Update PowerNukkitX to the latest version' },
|
|
29
|
+
args: {
|
|
30
|
+
force: { type: 'boolean', description: 'Force update', default: false },
|
|
31
|
+
dev: { type: 'boolean', description: 'Dev version', default: false },
|
|
32
|
+
},
|
|
33
|
+
run: ({ args }) => runUpdate(args.force),
|
|
34
|
+
});
|
package/dist/commands/use.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandDef } from 'citty';
|
|
2
|
-
export declare const useCmd: CommandDef;
|
|
1
|
+
import type { CommandDef } from 'citty';
|
|
2
|
+
export declare const useCmd: CommandDef;
|
package/dist/commands/use.js
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join, resolve } from 'node:path';
|
|
3
|
-
import { cwd } from 'node:process';
|
|
4
|
-
import { defineCommand } from 'citty';
|
|
5
|
-
import { intro, outro, log } from '../ui/output.js';
|
|
6
|
-
import { promptSelect, promptText } from '../ui/prompts.js';
|
|
7
|
-
import { detectServers, setDefaultServer } from '../services/server.js';
|
|
8
|
-
import { JAR_NAME } from '../infra/paths.js';
|
|
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
|
-
});
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { cwd } from 'node:process';
|
|
4
|
+
import { defineCommand } from 'citty';
|
|
5
|
+
import { intro, outro, log } from '../ui/output.js';
|
|
6
|
+
import { promptSelect, promptText } from '../ui/prompts.js';
|
|
7
|
+
import { detectServers, setDefaultServer } from '../services/server.js';
|
|
8
|
+
import { JAR_NAME } from '../infra/paths.js';
|
|
9
|
+
export const useCmd = defineCommand({
|
|
10
|
+
meta: { description: 'Set the default PowerNukkitX server directory' },
|
|
11
|
+
args: {
|
|
12
|
+
dir: { type: 'positional', description: 'Server path', required: false },
|
|
13
|
+
clear: { type: 'boolean', description: 'Remove default server', default: false },
|
|
14
|
+
},
|
|
15
|
+
async run({ args }) {
|
|
16
|
+
intro(`📌 ${"Default server"}`);
|
|
17
|
+
if (args.clear) {
|
|
18
|
+
await setDefaultServer(null);
|
|
19
|
+
log.success("Default server cleared");
|
|
20
|
+
outro("Default server cleared");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let target = args.dir;
|
|
24
|
+
if (!target) {
|
|
25
|
+
const servers = detectServers();
|
|
26
|
+
target = servers.length > 0
|
|
27
|
+
? await promptSelect("Select a server:", servers.map(s => ({ value: s, label: s })))
|
|
28
|
+
: await promptText({ message: "Server path:", defaultValue: cwd() });
|
|
29
|
+
}
|
|
30
|
+
const absPath = resolve(cwd(), target);
|
|
31
|
+
if (!existsSync(join(absPath, JAR_NAME))) {
|
|
32
|
+
log.error(`powernukkitx.jar not found in: ${absPath}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
await setDefaultServer(absPath);
|
|
36
|
+
log.success(`Default server set: ${absPath}`);
|
|
37
|
+
outro(`Default server set: ${absPath}`);
|
|
38
|
+
},
|
|
39
|
+
});
|