moomodding 1.0.0 → 1.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.
- package/dist/commands/clone.js +17 -13
- package/dist/commands/dev.js +11 -12
- package/dist/commands/init.js +16 -16
- package/dist/commands/list.js +11 -11
- package/dist/commands/login.js +25 -25
- package/dist/commands/pull.js +14 -10
- package/dist/commands/push.js +13 -13
- package/dist/commands/whoami.js +8 -8
- package/dist/core/client.js +3 -3
- package/dist/index.js +20 -21
- package/package.json +1 -1
package/dist/commands/clone.js
CHANGED
|
@@ -4,18 +4,18 @@ import pc from "picocolors";
|
|
|
4
4
|
import { api } from "../core/client.js";
|
|
5
5
|
export async function cloneCommand(modSlug, targetDirName) {
|
|
6
6
|
if (!modSlug) {
|
|
7
|
-
console.log(pc.red("
|
|
8
|
-
console.log(pc.gray(
|
|
7
|
+
console.log(pc.red("[error] Mod slug is required."));
|
|
8
|
+
console.log(pc.gray(`Example: ${pc.cyan("moo clone elite-combat-suite")}`));
|
|
9
9
|
process.exit(1);
|
|
10
10
|
}
|
|
11
11
|
const cleanSlug = modSlug.trim().toLowerCase();
|
|
12
12
|
const destDir = path.resolve(process.cwd(), targetDirName || cleanSlug);
|
|
13
|
-
console.log(pc.
|
|
14
|
-
console.log(pc.gray(`
|
|
13
|
+
console.log(pc.cyan(`[clone] Downloading '${cleanSlug}'...`));
|
|
14
|
+
console.log(pc.gray(`Destination: ${destDir}`));
|
|
15
15
|
try {
|
|
16
16
|
const res = await api.get(`/api/developer/mods/${cleanSlug}/pull`);
|
|
17
17
|
if (!res.success || !res.files) {
|
|
18
|
-
console.log(pc.red(
|
|
18
|
+
console.log(pc.red(`[error] Failed to clone mod: ${res.message || "Unknown error"}`));
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
if (!fs.existsSync(destDir)) {
|
|
@@ -31,17 +31,21 @@ export async function cloneCommand(modSlug, targetDirName) {
|
|
|
31
31
|
is_active: res.mod.is_active ?? true
|
|
32
32
|
};
|
|
33
33
|
fs.writeFileSync(path.join(destDir, "mod.json"), JSON.stringify(modJson, null, 2), "utf-8");
|
|
34
|
-
// 2. Write all files and recreate directories
|
|
34
|
+
// 2. Write all files and recreate directories (with Path Traversal protection)
|
|
35
35
|
let writtenCount = 0;
|
|
36
36
|
for (const [relPath, content] of Object.entries(res.files)) {
|
|
37
37
|
if (typeof content !== "string")
|
|
38
38
|
continue;
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const resolvedPath = path.resolve(destDir, relPath);
|
|
40
|
+
if (!resolvedPath.startsWith(destDir + path.sep) && resolvedPath !== destDir) {
|
|
41
|
+
console.warn(pc.yellow(`[warn] Security: Skipped invalid path: ${relPath}`));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const parentDir = path.dirname(resolvedPath);
|
|
41
45
|
if (!fs.existsSync(parentDir)) {
|
|
42
46
|
fs.mkdirSync(parentDir, { recursive: true });
|
|
43
47
|
}
|
|
44
|
-
fs.writeFileSync(
|
|
48
|
+
fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
45
49
|
writtenCount++;
|
|
46
50
|
}
|
|
47
51
|
// 3. Write default .mooignore if missing
|
|
@@ -49,12 +53,12 @@ export async function cloneCommand(modSlug, targetDirName) {
|
|
|
49
53
|
if (!fs.existsSync(mooIgnorePath)) {
|
|
50
54
|
fs.writeFileSync(mooIgnorePath, `node_modules/\n.git/\n.vscode/\n.idea/\ndist/\nbuild/\n*.log\n.env\n.DS_Store\n`, "utf-8");
|
|
51
55
|
}
|
|
52
|
-
console.log(pc.green(
|
|
53
|
-
console.log(
|
|
54
|
-
console.log(pc.gray(
|
|
56
|
+
console.log(pc.green(`[success] Cloned '${res.mod.name}' successfully.`));
|
|
57
|
+
console.log(pc.gray(`Files written: ${writtenCount}`));
|
|
58
|
+
console.log(pc.gray(`Next steps:\n cd ${path.basename(destDir)}\n moo dev\n`));
|
|
55
59
|
}
|
|
56
60
|
catch (err) {
|
|
57
|
-
console.log(pc.red(
|
|
61
|
+
console.log(pc.red(`[error] Clone error: ${err.message}`));
|
|
58
62
|
process.exit(1);
|
|
59
63
|
}
|
|
60
64
|
}
|
package/dist/commands/dev.js
CHANGED
|
@@ -6,8 +6,8 @@ import { pushCommand } from "./push.js";
|
|
|
6
6
|
export function devCommand(rootDir = process.cwd()) {
|
|
7
7
|
const modConfigPath = path.join(rootDir, "mod.json");
|
|
8
8
|
if (!fs.existsSync(modConfigPath)) {
|
|
9
|
-
console.log(pc.red("
|
|
10
|
-
console.log(pc.gray(`
|
|
9
|
+
console.log(pc.red("[error] 'mod.json' not found."));
|
|
10
|
+
console.log(pc.gray(`Please run this command in a mod root directory or run 'moo init'.`));
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
let modConfig;
|
|
@@ -15,13 +15,12 @@ export function devCommand(rootDir = process.cwd()) {
|
|
|
15
15
|
modConfig = JSON.parse(fs.readFileSync(modConfigPath, "utf-8"));
|
|
16
16
|
}
|
|
17
17
|
catch {
|
|
18
|
-
console.log(pc.red("
|
|
18
|
+
console.log(pc.red("[error] Failed to parse 'mod.json'."));
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
|
-
console.log(pc.
|
|
22
|
-
console.log(
|
|
23
|
-
console.log(pc.gray(
|
|
24
|
-
console.log(pc.gray(`💡 İpucu: Kodunuzda Ctrl+S yaptığınız anda otomatik buluta aktarılır.\n`));
|
|
21
|
+
console.log(pc.cyan(`[watch] Starting live sync for '${modConfig.name || "Mod"}' (${modConfig.slug})`));
|
|
22
|
+
console.log(pc.gray(`Watching directory: ${rootDir}`));
|
|
23
|
+
console.log(pc.gray(`Changes will automatically sync to cloud on save. Press Ctrl+C to stop.\n`));
|
|
25
24
|
// Initial push to verify state
|
|
26
25
|
pushCommand({ rootDir, silent: false }).then(() => {
|
|
27
26
|
let debounceTimer = null;
|
|
@@ -47,7 +46,7 @@ export function devCommand(rootDir = process.cwd()) {
|
|
|
47
46
|
});
|
|
48
47
|
const handleChange = (filePath, eventType) => {
|
|
49
48
|
const rel = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
50
|
-
console.log(pc.gray(`[${new Date().toLocaleTimeString()}]
|
|
49
|
+
console.log(pc.gray(`[${new Date().toLocaleTimeString()}] [${eventType}] ${rel}`));
|
|
51
50
|
if (debounceTimer)
|
|
52
51
|
clearTimeout(debounceTimer);
|
|
53
52
|
debounceTimer = setTimeout(async () => {
|
|
@@ -62,11 +61,11 @@ export function devCommand(rootDir = process.cwd()) {
|
|
|
62
61
|
}
|
|
63
62
|
}, 300);
|
|
64
63
|
};
|
|
65
|
-
watcher.on("change", (fp) => handleChange(fp, "
|
|
66
|
-
watcher.on("add", (fp) => handleChange(fp, "
|
|
67
|
-
watcher.on("unlink", (fp) => handleChange(fp, "
|
|
64
|
+
watcher.on("change", (fp) => handleChange(fp, "change"));
|
|
65
|
+
watcher.on("add", (fp) => handleChange(fp, "add"));
|
|
66
|
+
watcher.on("unlink", (fp) => handleChange(fp, "delete"));
|
|
68
67
|
process.on("SIGINT", () => {
|
|
69
|
-
console.log(pc.yellow("\n
|
|
68
|
+
console.log(pc.yellow("\n[watch] Watcher stopped."));
|
|
70
69
|
watcher.close();
|
|
71
70
|
process.exit(0);
|
|
72
71
|
});
|
package/dist/commands/init.js
CHANGED
|
@@ -7,13 +7,13 @@ export async function initCommand(targetDirName, options = {}) {
|
|
|
7
7
|
const cleanSlug = path.basename(dir).toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
8
8
|
const modName = options.name || cleanSlug.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase());
|
|
9
9
|
const modType = options.type || "hook";
|
|
10
|
-
console.log(pc.
|
|
10
|
+
console.log(pc.cyan(`[init] Initializing mod project: ${modName}`));
|
|
11
11
|
if (!fs.existsSync(dir)) {
|
|
12
12
|
fs.mkdirSync(dir, { recursive: true });
|
|
13
13
|
}
|
|
14
14
|
const modJsonPath = path.join(dir, "mod.json");
|
|
15
15
|
if (fs.existsSync(modJsonPath)) {
|
|
16
|
-
console.log(pc.yellow(
|
|
16
|
+
console.log(pc.yellow(`[warn] Directory already contains 'mod.json'.`));
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
// 1. Write minimal mod.json (Notice: NO file list here, auto-scanned!)
|
|
@@ -36,15 +36,15 @@ export async function initCommand(targetDirName, options = {}) {
|
|
|
36
36
|
* Entry point: src/index.ts
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
console.log("[${modName}] Mod
|
|
39
|
+
console.log("[${modName}] Mod loaded.");
|
|
40
40
|
|
|
41
|
-
// MooMoo WebSocket
|
|
41
|
+
// MooMoo WebSocket packet hook example
|
|
42
42
|
if (typeof window !== "undefined") {
|
|
43
43
|
// @ts-ignore
|
|
44
44
|
window.__myMooModLoaded = true;
|
|
45
45
|
|
|
46
|
-
//
|
|
47
|
-
console.log("[${modName}]
|
|
46
|
+
// Example: Chat or packet listener
|
|
47
|
+
console.log("[${modName}] Ready.");
|
|
48
48
|
}
|
|
49
49
|
`;
|
|
50
50
|
fs.writeFileSync(path.join(srcDir, "index.ts"), indexTsContent, "utf-8");
|
|
@@ -64,18 +64,18 @@ build/
|
|
|
64
64
|
// 4. Create README.md
|
|
65
65
|
const readmeContent = `# ${modName}
|
|
66
66
|
|
|
67
|
-
MooMoo.io
|
|
67
|
+
MooMoo.io mod - Built with MooModding.io developer tools.
|
|
68
68
|
|
|
69
|
-
##
|
|
69
|
+
## Commands
|
|
70
70
|
|
|
71
|
-
- \`moo push\`:
|
|
72
|
-
- \`moo dev\`:
|
|
73
|
-
- \`moo pull\`:
|
|
71
|
+
- \`moo push\`: Push files to MooModding cloud storage.
|
|
72
|
+
- \`moo dev\`: Start watcher mode (auto-sync on save).
|
|
73
|
+
- \`moo pull\`: Pull latest files from cloud.
|
|
74
74
|
`;
|
|
75
75
|
fs.writeFileSync(path.join(dir, "README.md"), readmeContent, "utf-8");
|
|
76
|
-
console.log(pc.green(
|
|
77
|
-
console.log(
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
80
|
-
console.log(pc.gray(
|
|
76
|
+
console.log(pc.green(`[success] Mod project scaffolded successfully.`));
|
|
77
|
+
console.log(pc.gray(`Directory: ${dir}`));
|
|
78
|
+
console.log(pc.gray(`Config: mod.json`));
|
|
79
|
+
console.log(pc.gray(`Entry point: src/index.ts`));
|
|
80
|
+
console.log(pc.gray(`Next steps:\n ${targetDirName ? `cd ${targetDirName}\n ` : ""}moo dev\n`));
|
|
81
81
|
}
|
package/dist/commands/list.js
CHANGED
|
@@ -2,33 +2,33 @@ import pc from "picocolors";
|
|
|
2
2
|
import { api } from "../core/client.js";
|
|
3
3
|
export async function listCommand() {
|
|
4
4
|
try {
|
|
5
|
-
console.log(pc.bold(pc.
|
|
6
|
-
console.log(pc.gray("
|
|
5
|
+
console.log(pc.bold(pc.cyan("\nMooModding Cloud Mods")));
|
|
6
|
+
console.log(pc.gray("Fetching mod list...\n"));
|
|
7
7
|
const res = await api.get("/api/developer/mods/list");
|
|
8
8
|
if (!res.success || !res.mods || res.mods.length === 0) {
|
|
9
|
-
console.log(pc.yellow("
|
|
10
|
-
console.log(pc.gray(`
|
|
9
|
+
console.log(pc.yellow("[info] You have no saved mods yet."));
|
|
10
|
+
console.log(pc.gray(`Scaffold a new mod: ${pc.cyan("moo init <mod-name>")}\n`));
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
console.log(pc.bold(` ${"
|
|
13
|
+
console.log(pc.bold(` ${"NAME".padEnd(28)} ${"TYPE".padEnd(14)} ${"SIZE".padEnd(10)} ${"STATUS".padEnd(10)} ${"VERSION"}`));
|
|
14
14
|
console.log(pc.gray("─".repeat(70)));
|
|
15
15
|
for (const m of res.mods) {
|
|
16
16
|
const kb = (m.storage_size_bytes / 1024).toFixed(1) + " KB";
|
|
17
|
-
const status = m.is_active ? pc.green("
|
|
17
|
+
const status = m.is_active ? pc.green("active") : pc.gray("inactive");
|
|
18
18
|
const slug = pc.cyan(m.slug);
|
|
19
|
-
const type = m.type === "bundle_replacement" ? "
|
|
19
|
+
const type = m.type === "bundle_replacement" ? "bundle" : "hook";
|
|
20
20
|
console.log(` ${m.name.padEnd(28)} ${type.padEnd(14)} ${kb.padEnd(10)} ${status.padEnd(18)} v${m.version || "1.0.0"}`);
|
|
21
|
-
console.log(pc.gray(` ↳
|
|
21
|
+
console.log(pc.gray(` ↳ slug: ${slug} (${m.file_count || 1} files)`));
|
|
22
22
|
}
|
|
23
23
|
console.log(pc.gray("─".repeat(70)));
|
|
24
24
|
if (res.quota) {
|
|
25
25
|
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
26
26
|
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
27
|
-
console.log(pc.gray(`
|
|
27
|
+
console.log(pc.gray(`Storage Quota: ${usedMb} MB / ${maxMb} MB\n`));
|
|
28
28
|
}
|
|
29
|
-
console.log(pc.gray(`
|
|
29
|
+
console.log(pc.gray(`Clone into local folder: ${pc.cyan("moo clone <slug>")}\n`));
|
|
30
30
|
}
|
|
31
31
|
catch (err) {
|
|
32
|
-
console.log(pc.red(
|
|
32
|
+
console.log(pc.red(`[error] Failed to list mods: ${err.message}`));
|
|
33
33
|
}
|
|
34
34
|
}
|
package/dist/commands/login.js
CHANGED
|
@@ -57,39 +57,39 @@ function askQuestion(query, hideInput = false) {
|
|
|
57
57
|
}
|
|
58
58
|
export async function loginCommand(explicitToken) {
|
|
59
59
|
const apiUrl = getApiUrl();
|
|
60
|
-
console.log(pc.bold(pc.
|
|
61
|
-
console.log(pc.gray(`
|
|
60
|
+
console.log(pc.bold(pc.cyan("\nMooModding Developer CLI Login")));
|
|
61
|
+
console.log(pc.gray(`Server: ${apiUrl}\n`));
|
|
62
62
|
// Case 1: Direct token passed via command line (moo login moo_pat_...)
|
|
63
63
|
if (explicitToken && explicitToken.trim()) {
|
|
64
64
|
await verifyAndSaveToken(explicitToken.trim());
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
console.log(pc.cyan("
|
|
68
|
-
console.log(` 1)
|
|
69
|
-
console.log(` 2)
|
|
70
|
-
const choice = await askQuestion(pc.bold("
|
|
67
|
+
console.log(pc.cyan("Select authentication method:"));
|
|
68
|
+
console.log(` 1) Username and Password ${pc.green("(Recommended)")}`);
|
|
69
|
+
console.log(` 2) Personal Access Token (PAT)\n`);
|
|
70
|
+
const choice = await askQuestion(pc.bold("Choice (1 or 2, default 1): "));
|
|
71
71
|
if (choice === "2") {
|
|
72
|
-
console.log(pc.yellow(`\
|
|
73
|
-
const token = await askQuestion(pc.bold("
|
|
72
|
+
console.log(pc.yellow(`\nGenerate token in settings: ${apiUrl}/settings?tab=developer-tokens`));
|
|
73
|
+
const token = await askQuestion(pc.bold("Paste your Personal Access Token: "));
|
|
74
74
|
if (!token) {
|
|
75
|
-
console.log(pc.red("
|
|
75
|
+
console.log(pc.red("[error] Login cancelled: Empty token."));
|
|
76
76
|
process.exit(1);
|
|
77
77
|
}
|
|
78
78
|
await verifyAndSaveToken(token);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
81
|
// Direct credential login
|
|
82
|
-
const username = await askQuestion(pc.bold("
|
|
82
|
+
const username = await askQuestion(pc.bold("Username or Email: "));
|
|
83
83
|
if (!username) {
|
|
84
|
-
console.log(pc.red("
|
|
84
|
+
console.log(pc.red("[error] Username cannot be empty."));
|
|
85
85
|
process.exit(1);
|
|
86
86
|
}
|
|
87
|
-
const password = await askQuestion(pc.bold("
|
|
87
|
+
const password = await askQuestion(pc.bold("Password: "), true);
|
|
88
88
|
if (!password) {
|
|
89
|
-
console.log(pc.red("
|
|
89
|
+
console.log(pc.red("[error] Password cannot be empty."));
|
|
90
90
|
process.exit(1);
|
|
91
91
|
}
|
|
92
|
-
console.log(pc.gray("\
|
|
92
|
+
console.log(pc.gray("\nAuthenticating..."));
|
|
93
93
|
try {
|
|
94
94
|
const res = await api.post("/api/developer/auth/login", {
|
|
95
95
|
username,
|
|
@@ -98,43 +98,43 @@ export async function loginCommand(explicitToken) {
|
|
|
98
98
|
}, { requiresAuth: false });
|
|
99
99
|
if (res.success && res.token) {
|
|
100
100
|
setAuth(res.token, res.user);
|
|
101
|
-
console.log(pc.green(
|
|
102
|
-
console.log(
|
|
103
|
-
console.log(pc.gray(
|
|
101
|
+
console.log(pc.green(`[success] Successfully authenticated.`));
|
|
102
|
+
console.log(pc.gray(`User: ${res.user.username} (${res.user.email})`));
|
|
103
|
+
console.log(pc.gray(`You can now use 'moo init', 'moo clone', or 'moo dev'.\n`));
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
console.log(pc.red(
|
|
106
|
+
console.log(pc.red(`[error] Login failed: ${res.message || "Unknown error"}`));
|
|
107
107
|
process.exit(1);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
catch (err) {
|
|
111
|
-
console.log(pc.red(
|
|
111
|
+
console.log(pc.red(`[error] Login failed: ${err.message}`));
|
|
112
112
|
process.exit(1);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
async function verifyAndSaveToken(token) {
|
|
117
|
-
console.log(pc.gray("
|
|
117
|
+
console.log(pc.gray("Verifying token..."));
|
|
118
118
|
try {
|
|
119
119
|
setAuth(token);
|
|
120
120
|
const res = await api.get("/api/developer/whoami");
|
|
121
121
|
if (res.success && res.user) {
|
|
122
122
|
setAuth(token, res.user);
|
|
123
|
-
console.log(pc.green(
|
|
124
|
-
console.log(
|
|
123
|
+
console.log(pc.green(`[success] Token verified and saved.`));
|
|
124
|
+
console.log(pc.gray(`User: ${res.user.username} (${res.user.email})`));
|
|
125
125
|
if (res.quota) {
|
|
126
126
|
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
127
127
|
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
128
|
-
console.log(
|
|
128
|
+
console.log(pc.gray(`Storage Quota: ${usedMb} MB / ${maxMb} MB\n`));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
console.log(pc.red("
|
|
132
|
+
console.log(pc.red("[error] Token verification failed."));
|
|
133
133
|
process.exit(1);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
catch (err) {
|
|
137
|
-
console.log(pc.red(
|
|
137
|
+
console.log(pc.red(`[error] Verification error: ${err.message}`));
|
|
138
138
|
process.exit(1);
|
|
139
139
|
}
|
|
140
140
|
}
|
package/dist/commands/pull.js
CHANGED
|
@@ -5,7 +5,7 @@ import { api } from "../core/client.js";
|
|
|
5
5
|
export async function pullCommand(rootDir = process.cwd()) {
|
|
6
6
|
const modConfigPath = path.join(rootDir, "mod.json");
|
|
7
7
|
if (!fs.existsSync(modConfigPath)) {
|
|
8
|
-
console.log(pc.red("
|
|
8
|
+
console.log(pc.red("[error] 'mod.json' not found. Please run this command inside a mod root directory."));
|
|
9
9
|
process.exit(1);
|
|
10
10
|
}
|
|
11
11
|
let modConfig;
|
|
@@ -13,37 +13,41 @@ export async function pullCommand(rootDir = process.cwd()) {
|
|
|
13
13
|
modConfig = JSON.parse(fs.readFileSync(modConfigPath, "utf-8"));
|
|
14
14
|
}
|
|
15
15
|
catch {
|
|
16
|
-
console.log(pc.red("
|
|
16
|
+
console.log(pc.red("[error] Failed to parse 'mod.json'."));
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
19
|
const slug = modConfig.slug;
|
|
20
20
|
if (!slug) {
|
|
21
|
-
console.log(pc.red("
|
|
21
|
+
console.log(pc.red("[error] Missing 'slug' field in 'mod.json'."));
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
|
-
console.log(pc.
|
|
24
|
+
console.log(pc.cyan(`[pull] Pulling latest files for '${slug}' from cloud...`));
|
|
25
25
|
try {
|
|
26
26
|
const res = await api.get(`/api/developer/mods/${slug}/pull`);
|
|
27
27
|
if (!res.success || !res.files) {
|
|
28
|
-
console.log(pc.red(
|
|
28
|
+
console.log(pc.red(`[error] Pull failed: ${res.message || "Unknown error"}`));
|
|
29
29
|
process.exit(1);
|
|
30
30
|
}
|
|
31
31
|
let updatedCount = 0;
|
|
32
32
|
for (const [relPath, content] of Object.entries(res.files)) {
|
|
33
33
|
if (typeof content !== "string")
|
|
34
34
|
continue;
|
|
35
|
-
const
|
|
36
|
-
|
|
35
|
+
const resolvedPath = path.resolve(rootDir, relPath);
|
|
36
|
+
if (!resolvedPath.startsWith(rootDir + path.sep) && resolvedPath !== rootDir) {
|
|
37
|
+
console.warn(pc.yellow(`[warn] Security: Skipped invalid path: ${relPath}`));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const parent = path.dirname(resolvedPath);
|
|
37
41
|
if (!fs.existsSync(parent)) {
|
|
38
42
|
fs.mkdirSync(parent, { recursive: true });
|
|
39
43
|
}
|
|
40
|
-
fs.writeFileSync(
|
|
44
|
+
fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
41
45
|
updatedCount++;
|
|
42
46
|
}
|
|
43
|
-
console.log(pc.green(
|
|
47
|
+
console.log(pc.green(`[success] Synced ${updatedCount} files from cloud.\n`));
|
|
44
48
|
}
|
|
45
49
|
catch (err) {
|
|
46
|
-
console.log(pc.red(
|
|
50
|
+
console.log(pc.red(`[error] Pull error: ${err.message}`));
|
|
47
51
|
process.exit(1);
|
|
48
52
|
}
|
|
49
53
|
}
|
package/dist/commands/push.js
CHANGED
|
@@ -8,8 +8,8 @@ export async function pushCommand(options = {}) {
|
|
|
8
8
|
const modConfigPath = path.join(rootDir, "mod.json");
|
|
9
9
|
if (!fs.existsSync(modConfigPath)) {
|
|
10
10
|
if (!options.silent) {
|
|
11
|
-
console.log(pc.red("
|
|
12
|
-
console.log(pc.gray(`
|
|
11
|
+
console.log(pc.red("[error] 'mod.json' not found."));
|
|
12
|
+
console.log(pc.gray(`Run 'moo init' to scaffold a new project or navigate to your mod directory.`));
|
|
13
13
|
}
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
@@ -19,17 +19,17 @@ export async function pushCommand(options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
21
|
if (!options.silent) {
|
|
22
|
-
console.log(pc.red("
|
|
22
|
+
console.log(pc.red("[error] 'mod.json' is not valid JSON."));
|
|
23
23
|
}
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
if (!options.silent) {
|
|
27
|
-
console.log(pc.gray(
|
|
27
|
+
console.log(pc.gray(`[push] Scanning '${modConfig.name || "Mod"}' directory...`));
|
|
28
28
|
}
|
|
29
29
|
const { files, fileCount, totalBytes } = scanModDirectory(rootDir);
|
|
30
30
|
if (fileCount === 0) {
|
|
31
31
|
if (!options.silent) {
|
|
32
|
-
console.log(pc.yellow("
|
|
32
|
+
console.log(pc.yellow("[warn] No files found to synchronize."));
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
@@ -37,12 +37,12 @@ export async function pushCommand(options = {}) {
|
|
|
37
37
|
const totalMb = totalBytes / (1024 * 1024);
|
|
38
38
|
if (totalMb > 15) {
|
|
39
39
|
if (!options.silent) {
|
|
40
|
-
console.log(pc.red(
|
|
40
|
+
console.log(pc.red(`[error] Mod size (${totalMb.toFixed(1)} MB) exceeds allowed 15 MB limit.`));
|
|
41
41
|
}
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
if (!options.silent) {
|
|
45
|
-
console.log(pc.gray(
|
|
45
|
+
console.log(pc.gray(`[push] Uploading ${fileCount} files (${(totalBytes / 1024).toFixed(1)} KB) to cloud...`));
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
48
|
const payload = {
|
|
@@ -57,24 +57,24 @@ export async function pushCommand(options = {}) {
|
|
|
57
57
|
const res = await api.post("/api/developer/mods/sync", payload);
|
|
58
58
|
if (res.success) {
|
|
59
59
|
if (!options.silent) {
|
|
60
|
-
console.log(pc.green(
|
|
61
|
-
console.log(
|
|
60
|
+
console.log(pc.green(`[success] Mod '${modConfig.name}' synced successfully.`));
|
|
61
|
+
console.log(pc.gray(`Slug: ${res.mod.slug} (${res.mod.size_bytes} bytes)`));
|
|
62
62
|
if (res.play_url) {
|
|
63
|
-
console.log(
|
|
63
|
+
console.log(pc.cyan(`Test in-game: ${res.play_url}\n`));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
|
-
console.log(pc.green(`[${new Date().toLocaleTimeString()}]
|
|
67
|
+
console.log(pc.green(`[${new Date().toLocaleTimeString()}] [synced] ${modConfig.name}`));
|
|
68
68
|
}
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
console.log(pc.red(
|
|
72
|
+
console.log(pc.red(`[error] Sync failed: ${res.message || "Unknown error"}`));
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
|
-
console.log(pc.red(
|
|
77
|
+
console.log(pc.red(`[error] Sync error: ${err.message}`));
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
}
|
package/dist/commands/whoami.js
CHANGED
|
@@ -4,27 +4,27 @@ import { api } from "../core/client.js";
|
|
|
4
4
|
export async function whoamiCommand() {
|
|
5
5
|
const config = loadConfig();
|
|
6
6
|
if (!config.token) {
|
|
7
|
-
console.log(pc.yellow("
|
|
8
|
-
console.log(pc.gray(`
|
|
7
|
+
console.log(pc.yellow("[warn] Not authenticated."));
|
|
8
|
+
console.log(pc.gray(`Run: ${pc.cyan("moo login")}`));
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
try {
|
|
12
12
|
const res = await api.get("/api/developer/whoami");
|
|
13
13
|
if (res.success && res.user) {
|
|
14
|
-
console.log(pc.bold(pc.
|
|
15
|
-
console.log(
|
|
16
|
-
console.log(
|
|
17
|
-
console.log(
|
|
14
|
+
console.log(pc.bold(pc.cyan("\nMooModding CLI Account Info")));
|
|
15
|
+
console.log(`Username : ${pc.bold(pc.white(res.user.username))}`);
|
|
16
|
+
console.log(`Email : ${res.user.email}`);
|
|
17
|
+
console.log(`API URL : ${getApiUrl()}`);
|
|
18
18
|
if (res.quota) {
|
|
19
19
|
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
20
20
|
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
21
21
|
const percent = ((res.quota.used_bytes / res.quota.max_bytes) * 100).toFixed(1);
|
|
22
|
-
console.log(
|
|
22
|
+
console.log(`Storage : ${usedMb} MB / ${maxMb} MB (${percent}%)`);
|
|
23
23
|
}
|
|
24
24
|
console.log("");
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
catch (err) {
|
|
28
|
-
console.log(pc.red(
|
|
28
|
+
console.log(pc.red(`[error] Authentication failed: ${err.message}`));
|
|
29
29
|
}
|
|
30
30
|
}
|
package/dist/core/client.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function request(endpoint, options = {}) {
|
|
|
24
24
|
if (requiresAuth) {
|
|
25
25
|
const token = getToken();
|
|
26
26
|
if (!token) {
|
|
27
|
-
throw new ApiError(`
|
|
27
|
+
throw new ApiError(`Not authenticated. Please run ${pc.bold(pc.cyan("moo login"))} or set the MOOMODDING_TOKEN environment variable.`, 401);
|
|
28
28
|
}
|
|
29
29
|
headers["Authorization"] = `Bearer ${token}`;
|
|
30
30
|
}
|
|
@@ -44,7 +44,7 @@ export async function request(endpoint, options = {}) {
|
|
|
44
44
|
}
|
|
45
45
|
if (!res.ok) {
|
|
46
46
|
const errorMsg = responseData?.message ||
|
|
47
|
-
`API
|
|
47
|
+
`API request failed (${res.status} ${res.statusText})`;
|
|
48
48
|
throw new ApiError(errorMsg, res.status, responseData);
|
|
49
49
|
}
|
|
50
50
|
return responseData;
|
|
@@ -53,7 +53,7 @@ export async function request(endpoint, options = {}) {
|
|
|
53
53
|
if (err instanceof ApiError) {
|
|
54
54
|
throw err;
|
|
55
55
|
}
|
|
56
|
-
throw new ApiError(`
|
|
56
|
+
throw new ApiError(`Connection error (${url}): ${err.message}`, 0);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
export const api = {
|
package/dist/index.js
CHANGED
|
@@ -12,78 +12,77 @@ import { clearAuth, loadConfig, saveConfig } from "./core/config.js";
|
|
|
12
12
|
const program = new Command();
|
|
13
13
|
program
|
|
14
14
|
.name("moo")
|
|
15
|
-
.description(
|
|
16
|
-
|
|
17
|
-
.version("1.0.0");
|
|
15
|
+
.description("MooModding Developer CLI — Build, test, and sync MooMoo.io mods with zero friction.")
|
|
16
|
+
.version("1.0.1");
|
|
18
17
|
// 1. Auth Commands
|
|
19
18
|
program
|
|
20
19
|
.command("login [token]")
|
|
21
|
-
.description("
|
|
20
|
+
.description("Log in to your MooModding account")
|
|
22
21
|
.action(async (token) => {
|
|
23
22
|
await loginCommand(token);
|
|
24
23
|
});
|
|
25
24
|
program
|
|
26
25
|
.command("logout")
|
|
27
|
-
.description("
|
|
26
|
+
.description("Log out and clear local credentials")
|
|
28
27
|
.action(() => {
|
|
29
28
|
clearAuth();
|
|
30
|
-
console.log(pc.green("
|
|
29
|
+
console.log(pc.green("[success] Logged out successfully."));
|
|
31
30
|
});
|
|
32
31
|
program
|
|
33
32
|
.command("whoami")
|
|
34
|
-
.description("
|
|
33
|
+
.description("Display current user and storage quota")
|
|
35
34
|
.action(async () => {
|
|
36
35
|
await whoamiCommand();
|
|
37
36
|
});
|
|
38
37
|
// 2. Project Lifecycle Commands
|
|
39
38
|
program
|
|
40
39
|
.command("init [dir]")
|
|
41
|
-
.description("
|
|
42
|
-
.option("-n, --name <name>", "
|
|
43
|
-
.option("-t, --type <type>", "Mod
|
|
40
|
+
.description("Scaffold a new MooMoo mod project")
|
|
41
|
+
.option("-n, --name <name>", "Mod display name")
|
|
42
|
+
.option("-t, --type <type>", "Mod type ('hook' or 'bundle_replacement')", "hook")
|
|
44
43
|
.action(async (dir, options) => {
|
|
45
44
|
await initCommand(dir, options);
|
|
46
45
|
});
|
|
47
46
|
program
|
|
48
47
|
.command("list")
|
|
49
48
|
.alias("ls")
|
|
50
|
-
.description("
|
|
49
|
+
.description("List your cloud mods and storage usage")
|
|
51
50
|
.action(async () => {
|
|
52
51
|
await listCommand();
|
|
53
52
|
});
|
|
54
53
|
program
|
|
55
54
|
.command("clone <slug> [dir]")
|
|
56
|
-
.description("
|
|
55
|
+
.description("Clone a cloud mod into a local directory")
|
|
57
56
|
.action(async (slug, dir) => {
|
|
58
57
|
await cloneCommand(slug, dir);
|
|
59
58
|
});
|
|
60
59
|
program
|
|
61
60
|
.command("push")
|
|
62
|
-
.description("
|
|
61
|
+
.description("Scan directory and push mod files to cloud")
|
|
63
62
|
.action(async () => {
|
|
64
63
|
await pushCommand();
|
|
65
64
|
});
|
|
66
65
|
program
|
|
67
66
|
.command("pull")
|
|
68
|
-
.description("
|
|
67
|
+
.description("Pull latest mod files from cloud")
|
|
69
68
|
.action(async () => {
|
|
70
69
|
await pullCommand();
|
|
71
70
|
});
|
|
72
71
|
program
|
|
73
72
|
.command("dev")
|
|
74
|
-
.description("
|
|
73
|
+
.description("Start file watcher for live cloud sync on save")
|
|
75
74
|
.action(() => {
|
|
76
75
|
devCommand();
|
|
77
76
|
});
|
|
78
77
|
// 3. Configuration command
|
|
79
78
|
program
|
|
80
79
|
.command("config <action> [key] [value]")
|
|
81
|
-
.description("
|
|
80
|
+
.description("View or update CLI config (e.g. moo config set api https://moomodding.io)")
|
|
82
81
|
.action((action, key, value) => {
|
|
83
82
|
const config = loadConfig();
|
|
84
83
|
if (action === "get") {
|
|
85
84
|
if (key) {
|
|
86
|
-
console.log(config[key] || pc.gray("(
|
|
85
|
+
console.log(config[key] || pc.gray("(undefined)"));
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
88
|
console.log(JSON.stringify(config, null, 2));
|
|
@@ -91,22 +90,22 @@ program
|
|
|
91
90
|
}
|
|
92
91
|
else if (action === "set") {
|
|
93
92
|
if (!key || value === undefined) {
|
|
94
|
-
console.log(pc.red("
|
|
93
|
+
console.log(pc.red("Usage: moo config set <key> <value>"));
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
if (key === "api" || key === "apiUrl") {
|
|
98
97
|
config.apiUrl = value;
|
|
99
98
|
saveConfig(config);
|
|
100
|
-
console.log(pc.green(
|
|
99
|
+
console.log(pc.green(`[success] API URL updated: ${value}`));
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
103
102
|
config[key] = value;
|
|
104
103
|
saveConfig(config);
|
|
105
|
-
console.log(pc.green(
|
|
104
|
+
console.log(pc.green(`[success] '${key}' updated.`));
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
|
-
console.log(pc.red("
|
|
108
|
+
console.log(pc.red("Invalid action. Usage: moo config get [key] | moo config set <key> <value>"));
|
|
110
109
|
}
|
|
111
110
|
});
|
|
112
111
|
program.parse(process.argv);
|