@powernukkitx/cli 0.0.1

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.
Files changed (41) hide show
  1. package/dist/bundle.js +18871 -0
  2. package/dist/commands/backup.d.ts +1 -0
  3. package/dist/commands/backup.js +74 -0
  4. package/dist/commands/config.d.ts +1 -0
  5. package/dist/commands/config.js +114 -0
  6. package/dist/commands/doctor.d.ts +1 -0
  7. package/dist/commands/doctor.js +119 -0
  8. package/dist/commands/info.d.ts +1 -0
  9. package/dist/commands/info.js +36 -0
  10. package/dist/commands/init.d.ts +4 -0
  11. package/dist/commands/init.js +73 -0
  12. package/dist/commands/plugin.d.ts +12 -0
  13. package/dist/commands/plugin.js +385 -0
  14. package/dist/commands/start.d.ts +7 -0
  15. package/dist/commands/start.js +108 -0
  16. package/dist/commands/update.d.ts +5 -0
  17. package/dist/commands/update.js +55 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +260 -0
  20. package/dist/lang/en.json +178 -0
  21. package/dist/lang/fr.json +178 -0
  22. package/dist/lang/index.d.ts +7 -0
  23. package/dist/lang/index.js +83 -0
  24. package/dist/plugins.json +66 -0
  25. package/dist/types.d.ts +61 -0
  26. package/dist/types.js +1 -0
  27. package/dist/utils/api.d.ts +18 -0
  28. package/dist/utils/api.js +74 -0
  29. package/dist/utils/github.d.ts +27 -0
  30. package/dist/utils/github.js +187 -0
  31. package/dist/utils/logger.d.ts +15 -0
  32. package/dist/utils/logger.js +72 -0
  33. package/dist/utils/pause.d.ts +1 -0
  34. package/dist/utils/pause.js +6 -0
  35. package/dist/utils/plugins.d.ts +4 -0
  36. package/dist/utils/plugins.js +34 -0
  37. package/dist/utils/server.d.ts +3 -0
  38. package/dist/utils/server.js +39 -0
  39. package/dist/utils/updater.d.ts +1 -0
  40. package/dist/utils/updater.js +86 -0
  41. package/package.json +63 -0
@@ -0,0 +1,39 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join, dirname, resolve } from 'node:path';
3
+ import { cwd } from 'node:process';
4
+ import { select } from '@inquirer/prompts';
5
+ import { highlight } from './logger.js';
6
+ export function detectServer(startPath) {
7
+ const all = detectAllServers(startPath);
8
+ return all[0] || null;
9
+ }
10
+ export function detectAllServers(startPath) {
11
+ const found = [];
12
+ const checkPaths = [
13
+ startPath || cwd(),
14
+ join(startPath || cwd(), 'pnx-server'),
15
+ startPath ? dirname(resolve(startPath)) : dirname(cwd()),
16
+ ];
17
+ for (const dir of checkPaths) {
18
+ if (existsSync(join(dir, 'powernukkitx.jar')) && !found.includes(dir)) {
19
+ found.push(dir);
20
+ }
21
+ }
22
+ return found;
23
+ }
24
+ export async function resolveServerDir(label) {
25
+ const servers = detectAllServers();
26
+ if (servers.length === 0)
27
+ return null;
28
+ if (servers.length === 1)
29
+ return servers[0];
30
+ const choice = await select({
31
+ message: label || 'Multiple servers found. Which one to manage?',
32
+ pageSize: 10,
33
+ choices: servers.map((s) => ({
34
+ name: highlight(s),
35
+ value: s,
36
+ })),
37
+ });
38
+ return choice;
39
+ }
@@ -0,0 +1 @@
1
+ export declare function checkForUpdates(force?: boolean): Promise<void>;
@@ -0,0 +1,86 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile, writeFile, mkdir } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import chalk from 'chalk';
6
+ import { warn, dim } from './logger.js';
7
+ import { getLatestRelease, findAsset } from './github.js';
8
+ import { fetchPluginDetail } from './api.js';
9
+ import { getInstalledPlugins } from './plugins.js';
10
+ import { detectServer } from './server.js';
11
+ import { t } from '../lang/index.js';
12
+ const CACHE_DIR = join(homedir(), '.pnx-cli');
13
+ const CHECK_FILE = join(CACHE_DIR, 'last-update-check.json');
14
+ const CHECK_TTL = 3_600_000; // 1h
15
+ async function getLastCheck() {
16
+ try {
17
+ if (existsSync(CHECK_FILE)) {
18
+ const raw = await readFile(CHECK_FILE, 'utf-8');
19
+ return JSON.parse(raw);
20
+ }
21
+ }
22
+ catch { /* ignore */ }
23
+ return null;
24
+ }
25
+ async function saveCheck(data) {
26
+ try {
27
+ await mkdir(CACHE_DIR, { recursive: true });
28
+ await writeFile(CHECK_FILE, JSON.stringify(data), 'utf-8');
29
+ }
30
+ catch { /* ignore */ }
31
+ }
32
+ let notifsShown = false;
33
+ export async function checkForUpdates(force) {
34
+ if (notifsShown && !force)
35
+ return;
36
+ const last = await getLastCheck();
37
+ if (last && !force && Date.now() - last.timestamp < CHECK_TTL) {
38
+ notifsShown = true;
39
+ return;
40
+ }
41
+ const notifications = [];
42
+ // Check core update
43
+ try {
44
+ const serverPath = detectServer();
45
+ if (serverPath && existsSync(join(serverPath, 'powernukkitx.jar'))) {
46
+ const release = await getLatestRelease();
47
+ const tag = release.tag_name.replace(/^v/, '');
48
+ const asset = await findAsset(release, 'powernukkitx.jar');
49
+ if (asset) {
50
+ // Read current version from jar name or release cache
51
+ const cachedVersion = last?.coreVersion;
52
+ if (cachedVersion && cachedVersion !== tag) {
53
+ notifications.push(`${chalk.yellow('⟳')} ${t('updater.coreUpdate')} ${chalk.bold('v' + tag)} ${dim('(current: v' + cachedVersion + ')')} ${chalk.cyan('pnx update')}`);
54
+ }
55
+ }
56
+ await saveCheck({ timestamp: Date.now(), coreVersion: tag });
57
+ }
58
+ }
59
+ catch { /* silent */ }
60
+ // Check plugin updates
61
+ try {
62
+ const serverPath = detectServer();
63
+ const pluginsDir = serverPath ? join(serverPath, 'plugins') : join(process.cwd(), 'plugins');
64
+ if (existsSync(pluginsDir)) {
65
+ const installed = await getInstalledPlugins();
66
+ for (const p of installed) {
67
+ try {
68
+ const detail = await fetchPluginDetail(p.slug);
69
+ if (detail.latest_version !== p.version) {
70
+ notifications.push(`${chalk.yellow('⟳')} ${t('updater.pluginUpdate', detail.name, chalk.bold('v' + detail.latest_version), dim('(current: v' + p.version + ')'))} ${chalk.cyan(`pnx plugin update ${p.slug}`)}`);
71
+ }
72
+ }
73
+ catch { /* skip if plugin not found on marketplace */ }
74
+ }
75
+ }
76
+ }
77
+ catch { /* silent */ }
78
+ if (notifications.length > 0) {
79
+ console.log();
80
+ for (const n of notifications) {
81
+ warn(n);
82
+ }
83
+ console.log();
84
+ }
85
+ notifsShown = true;
86
+ }
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@powernukkitx/cli",
3
+ "version": "0.0.1",
4
+ "description": "PowerNukkitX CLI — Manage your Minecraft Bedrock servers with style",
5
+ "keywords": [
6
+ "powernukkitx",
7
+ "pnx",
8
+ "minecraft",
9
+ "bedrock",
10
+ "server",
11
+ "cli"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "AzaleeX",
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "bin": {
18
+ "pnx": "dist/index.js"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "start": "node dist/index.js",
26
+ "prepublishOnly": "npm run build",
27
+ "dev": "tsc --watch",
28
+ "generate-icon": "node scripts/generate-icon.js",
29
+ "set-icon": "node scripts/apply-icon.js",
30
+ "bundle": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/bundle.js --tsconfig=tsconfig.json --external:@yao-pkg/pkg",
31
+ "build:exe": "npm run bundle && pkg dist/bundle.js --targets node18-win-x64,node18-linux-x64,node18-macos-x64 --output pnx-cli",
32
+ "build:exe:win": "npm run generate-icon && npm run bundle && pkg dist/bundle.js --targets node18-win-x64 --output pnx-cli.exe && npm run set-icon",
33
+ "build:exe:linux": "npm run bundle && pkg dist/bundle.js --targets node18-linux-x64 --output pnx-cli-linux",
34
+ "build:exe:mac": "npm run bundle && pkg dist/bundle.js --targets node18-macos-x64 --output pnx-cli-macos"
35
+ },
36
+ "dependencies": {
37
+ "@inquirer/prompts": "^7.10.1",
38
+ "chalk": "^5.6.2",
39
+ "commander": "^12.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^22.19.19",
43
+ "@yao-pkg/pkg": "^6.19.0",
44
+ "esbuild": "^0.28.0",
45
+ "rcedit": "^5.0.2",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "pkg": {
52
+ "assets": [
53
+ "dist/lang/*.json",
54
+ "dist/plugins.json"
55
+ ],
56
+ "targets": [
57
+ "node18-win-x64",
58
+ "node18-linux-x64",
59
+ "node18-macos-x64"
60
+ ],
61
+ "public": true
62
+ }
63
+ }