moomodding 0.0.0-stage → 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/README.md +80 -2
- package/bin/moo.js +3 -0
- package/dist/commands/clone.d.ts +1 -0
- package/dist/commands/clone.js +64 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +73 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.js +81 -0
- package/dist/commands/list.d.ts +1 -0
- package/dist/commands/list.js +34 -0
- package/dist/commands/login.d.ts +1 -0
- package/dist/commands/login.js +140 -0
- package/dist/commands/pull.d.ts +1 -0
- package/dist/commands/pull.js +53 -0
- package/dist/commands/push.d.ts +5 -0
- package/dist/commands/push.js +80 -0
- package/dist/commands/whoami.d.ts +1 -0
- package/dist/commands/whoami.js +30 -0
- package/dist/core/client.d.ts +30 -0
- package/dist/core/client.js +64 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/config.js +54 -0
- package/dist/core/scanner.d.ts +7 -0
- package/dist/core/scanner.js +83 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +111 -0
- package/package.json +43 -4
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MooModding Developer CLI (`moo`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> The official Node.js command-line tool for building, testing, and hot-syncing MooMoo.io mods with the **MooModding.io** ecosystem.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⚡ Features
|
|
8
|
+
|
|
9
|
+
- **Zero-Friction Setup:** Use with `npx moomodding` or install globally via `npm i -g moomodding`.
|
|
10
|
+
- **Directory-First Auto-Walk:** No manual file lists in `mod.json`. Add, remove, and nest folders (`src/combat/`, `assets/`, `utils/`) freely.
|
|
11
|
+
- **Instant Hot-Sync (`moo dev`):** Automatically pushes changes to the cloud on every `Ctrl + S`.
|
|
12
|
+
- **Reconciliation:** Deleted local files are cleaned up from the cloud mirror automatically.
|
|
13
|
+
- **Smart Ignore:** Built-in `.mooignore` ignores `node_modules`, `.git`, `.env`, and build artifacts.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 Quick Start
|
|
18
|
+
|
|
19
|
+
### 1. Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Global install (recommended for quick 'moo' alias)
|
|
23
|
+
npm install -g moomodding
|
|
24
|
+
|
|
25
|
+
# Or run directly without installation
|
|
26
|
+
npx moomodding --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Login to Your MooModding Account
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
moo login
|
|
33
|
+
```
|
|
34
|
+
*Generates or prompts for your Personal Access Token from `https://moomodding.io/settings`.*
|
|
35
|
+
|
|
36
|
+
### 3. Create or Clone a Mod
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Start a fresh TypeScript mod project
|
|
40
|
+
moo init my-combat-mod
|
|
41
|
+
cd my-combat-mod
|
|
42
|
+
|
|
43
|
+
# Or clone an existing mod from your cloud storage
|
|
44
|
+
moo clone elite-combat-suite
|
|
45
|
+
cd elite-combat-suite
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 4. Develop & Test Live
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Run watch mode
|
|
52
|
+
moo dev
|
|
53
|
+
```
|
|
54
|
+
Open `https://sandbox.moomodding.io/` in your browser. Refresh the page whenever you save code to test your updates live in-game!
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📋 Commands Reference
|
|
59
|
+
|
|
60
|
+
| Command | Shortcut | Description |
|
|
61
|
+
| :--- | :--- | :--- |
|
|
62
|
+
| `moomodding login [token]` | `moo login` | Authenticate with your MooModding Personal Access Token |
|
|
63
|
+
| `moomodding whoami` | `moo whoami` | Display active user, email, and storage quota |
|
|
64
|
+
| `moomodding list` | `moo ls` | List all your cloud mods and their storage sizes |
|
|
65
|
+
| `moomodding init [name]` | `moo init` | Scaffold a new mod with template files |
|
|
66
|
+
| `moomodding clone <slug>` | `moo clone` | Clone a cloud mod into a local directory |
|
|
67
|
+
| `moomodding push` | `moo push` | Auto-scan directory and push files to cloud |
|
|
68
|
+
| `moomodding pull` | `moo pull` | Pull latest files from cloud into current folder |
|
|
69
|
+
| `moomodding dev` | `moo dev` | Start file watcher (hot-sync on save) |
|
|
70
|
+
| `moomodding logout` | `moo logout` | Clear local auth credentials |
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🛠️ Local Development (Developing this CLI)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cd moomodding-cli
|
|
78
|
+
npm install
|
|
79
|
+
npm run build
|
|
80
|
+
npm link # links 'moo' globally on your machine for testing
|
|
81
|
+
```
|
package/bin/moo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cloneCommand(modSlug: string, targetDirName?: string): Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { api } from "../core/client.js";
|
|
5
|
+
export async function cloneCommand(modSlug, targetDirName) {
|
|
6
|
+
if (!modSlug) {
|
|
7
|
+
console.log(pc.red("[error] Mod slug is required."));
|
|
8
|
+
console.log(pc.gray(`Example: ${pc.cyan("moo clone elite-combat-suite")}`));
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
const cleanSlug = modSlug.trim().toLowerCase();
|
|
12
|
+
const destDir = path.resolve(process.cwd(), targetDirName || cleanSlug);
|
|
13
|
+
console.log(pc.cyan(`[clone] Downloading '${cleanSlug}'...`));
|
|
14
|
+
console.log(pc.gray(`Destination: ${destDir}`));
|
|
15
|
+
try {
|
|
16
|
+
const res = await api.get(`/api/developer/mods/${cleanSlug}/pull`);
|
|
17
|
+
if (!res.success || !res.files) {
|
|
18
|
+
console.log(pc.red(`[error] Failed to clone mod: ${res.message || "Unknown error"}`));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
if (!fs.existsSync(destDir)) {
|
|
22
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
// 1. Write mod.json
|
|
25
|
+
const modJson = {
|
|
26
|
+
name: res.mod.name,
|
|
27
|
+
slug: res.mod.slug,
|
|
28
|
+
type: res.mod.type || "hook",
|
|
29
|
+
version: res.mod.version || "1.0.0",
|
|
30
|
+
entry: res.mod.entry_point || "src/index.ts",
|
|
31
|
+
is_active: res.mod.is_active ?? true
|
|
32
|
+
};
|
|
33
|
+
fs.writeFileSync(path.join(destDir, "mod.json"), JSON.stringify(modJson, null, 2), "utf-8");
|
|
34
|
+
// 2. Write all files and recreate directories (with Path Traversal protection)
|
|
35
|
+
let writtenCount = 0;
|
|
36
|
+
for (const [relPath, content] of Object.entries(res.files)) {
|
|
37
|
+
if (typeof content !== "string")
|
|
38
|
+
continue;
|
|
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);
|
|
45
|
+
if (!fs.existsSync(parentDir)) {
|
|
46
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
49
|
+
writtenCount++;
|
|
50
|
+
}
|
|
51
|
+
// 3. Write default .mooignore if missing
|
|
52
|
+
const mooIgnorePath = path.join(destDir, ".mooignore");
|
|
53
|
+
if (!fs.existsSync(mooIgnorePath)) {
|
|
54
|
+
fs.writeFileSync(mooIgnorePath, `node_modules/\n.git/\n.vscode/\n.idea/\ndist/\nbuild/\n*.log\n.env\n.DS_Store\n`, "utf-8");
|
|
55
|
+
}
|
|
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`));
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.log(pc.red(`[error] Clone error: ${err.message}`));
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function devCommand(rootDir?: string): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import chokidar from "chokidar";
|
|
5
|
+
import { pushCommand } from "./push.js";
|
|
6
|
+
export function devCommand(rootDir = process.cwd()) {
|
|
7
|
+
const modConfigPath = path.join(rootDir, "mod.json");
|
|
8
|
+
if (!fs.existsSync(modConfigPath)) {
|
|
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
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
let modConfig;
|
|
14
|
+
try {
|
|
15
|
+
modConfig = JSON.parse(fs.readFileSync(modConfigPath, "utf-8"));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
console.log(pc.red("[error] Failed to parse 'mod.json'."));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
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`));
|
|
24
|
+
// Initial push to verify state
|
|
25
|
+
pushCommand({ rootDir, silent: false }).then(() => {
|
|
26
|
+
let debounceTimer = null;
|
|
27
|
+
let isSyncing = false;
|
|
28
|
+
const watcher = chokidar.watch(rootDir, {
|
|
29
|
+
ignored: [
|
|
30
|
+
"**/node_modules/**",
|
|
31
|
+
"**/.git/**",
|
|
32
|
+
"**/.vscode/**",
|
|
33
|
+
"**/.idea/**",
|
|
34
|
+
"**/dist/**",
|
|
35
|
+
"**/build/**",
|
|
36
|
+
"**/*.log",
|
|
37
|
+
"**/.env*",
|
|
38
|
+
"**/.DS_Store"
|
|
39
|
+
],
|
|
40
|
+
persistent: true,
|
|
41
|
+
ignoreInitial: true,
|
|
42
|
+
awaitWriteFinish: {
|
|
43
|
+
stabilityThreshold: 150,
|
|
44
|
+
pollInterval: 50
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const handleChange = (filePath, eventType) => {
|
|
48
|
+
const rel = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
49
|
+
console.log(pc.gray(`[${new Date().toLocaleTimeString()}] [${eventType}] ${rel}`));
|
|
50
|
+
if (debounceTimer)
|
|
51
|
+
clearTimeout(debounceTimer);
|
|
52
|
+
debounceTimer = setTimeout(async () => {
|
|
53
|
+
if (isSyncing)
|
|
54
|
+
return;
|
|
55
|
+
isSyncing = true;
|
|
56
|
+
try {
|
|
57
|
+
await pushCommand({ rootDir, silent: true });
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
isSyncing = false;
|
|
61
|
+
}
|
|
62
|
+
}, 300);
|
|
63
|
+
};
|
|
64
|
+
watcher.on("change", (fp) => handleChange(fp, "change"));
|
|
65
|
+
watcher.on("add", (fp) => handleChange(fp, "add"));
|
|
66
|
+
watcher.on("unlink", (fp) => handleChange(fp, "delete"));
|
|
67
|
+
process.on("SIGINT", () => {
|
|
68
|
+
console.log(pc.yellow("\n[watch] Watcher stopped."));
|
|
69
|
+
watcher.close();
|
|
70
|
+
process.exit(0);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
export async function initCommand(targetDirName, options = {}) {
|
|
5
|
+
const rawName = targetDirName || options.name || "my-moo-mod";
|
|
6
|
+
const dir = targetDirName ? path.resolve(process.cwd(), targetDirName) : process.cwd();
|
|
7
|
+
const cleanSlug = path.basename(dir).toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
8
|
+
const modName = options.name || cleanSlug.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase());
|
|
9
|
+
const modType = options.type || "hook";
|
|
10
|
+
console.log(pc.cyan(`[init] Initializing mod project: ${modName}`));
|
|
11
|
+
if (!fs.existsSync(dir)) {
|
|
12
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
const modJsonPath = path.join(dir, "mod.json");
|
|
15
|
+
if (fs.existsSync(modJsonPath)) {
|
|
16
|
+
console.log(pc.yellow(`[warn] Directory already contains 'mod.json'.`));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// 1. Write minimal mod.json (Notice: NO file list here, auto-scanned!)
|
|
20
|
+
const modConfig = {
|
|
21
|
+
name: modName,
|
|
22
|
+
slug: cleanSlug,
|
|
23
|
+
type: modType,
|
|
24
|
+
version: "1.0.0",
|
|
25
|
+
entry: "src/index.ts"
|
|
26
|
+
};
|
|
27
|
+
fs.writeFileSync(modJsonPath, JSON.stringify(modConfig, null, 2), "utf-8");
|
|
28
|
+
// 2. Create src folder and src/index.ts
|
|
29
|
+
const srcDir = path.join(dir, "src");
|
|
30
|
+
if (!fs.existsSync(srcDir)) {
|
|
31
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
const indexTsContent = `/**
|
|
34
|
+
* ${modName}
|
|
35
|
+
* Created with MooModding Developer CLI
|
|
36
|
+
* Entry point: src/index.ts
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
console.log("[${modName}] Mod loaded.");
|
|
40
|
+
|
|
41
|
+
// MooMoo WebSocket packet hook example
|
|
42
|
+
if (typeof window !== "undefined") {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
window.__myMooModLoaded = true;
|
|
45
|
+
|
|
46
|
+
// Example: Chat or packet listener
|
|
47
|
+
console.log("[${modName}] Ready.");
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
fs.writeFileSync(path.join(srcDir, "index.ts"), indexTsContent, "utf-8");
|
|
51
|
+
// 3. Create .mooignore
|
|
52
|
+
const mooIgnoreContent = `# MooModding CLI Ignore List
|
|
53
|
+
node_modules/
|
|
54
|
+
.git/
|
|
55
|
+
.vscode/
|
|
56
|
+
.idea/
|
|
57
|
+
dist/
|
|
58
|
+
build/
|
|
59
|
+
*.log
|
|
60
|
+
.env
|
|
61
|
+
.DS_Store
|
|
62
|
+
`;
|
|
63
|
+
fs.writeFileSync(path.join(dir, ".mooignore"), mooIgnoreContent, "utf-8");
|
|
64
|
+
// 4. Create README.md
|
|
65
|
+
const readmeContent = `# ${modName}
|
|
66
|
+
|
|
67
|
+
MooMoo.io mod - Built with MooModding.io developer tools.
|
|
68
|
+
|
|
69
|
+
## Commands
|
|
70
|
+
|
|
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
|
+
`;
|
|
75
|
+
fs.writeFileSync(path.join(dir, "README.md"), readmeContent, "utf-8");
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listCommand(): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { api } from "../core/client.js";
|
|
3
|
+
export async function listCommand() {
|
|
4
|
+
try {
|
|
5
|
+
console.log(pc.bold(pc.cyan("\nMooModding Cloud Mods")));
|
|
6
|
+
console.log(pc.gray("Fetching mod list...\n"));
|
|
7
|
+
const res = await api.get("/api/developer/mods/list");
|
|
8
|
+
if (!res.success || !res.mods || res.mods.length === 0) {
|
|
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
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.log(pc.bold(` ${"NAME".padEnd(28)} ${"TYPE".padEnd(14)} ${"SIZE".padEnd(10)} ${"STATUS".padEnd(10)} ${"VERSION"}`));
|
|
14
|
+
console.log(pc.gray("─".repeat(70)));
|
|
15
|
+
for (const m of res.mods) {
|
|
16
|
+
const kb = (m.storage_size_bytes / 1024).toFixed(1) + " KB";
|
|
17
|
+
const status = m.is_active ? pc.green("active") : pc.gray("inactive");
|
|
18
|
+
const slug = pc.cyan(m.slug);
|
|
19
|
+
const type = m.type === "bundle_replacement" ? "bundle" : "hook";
|
|
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(` ↳ slug: ${slug} (${m.file_count || 1} files)`));
|
|
22
|
+
}
|
|
23
|
+
console.log(pc.gray("─".repeat(70)));
|
|
24
|
+
if (res.quota) {
|
|
25
|
+
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
26
|
+
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
27
|
+
console.log(pc.gray(`Storage Quota: ${usedMb} MB / ${maxMb} MB\n`));
|
|
28
|
+
}
|
|
29
|
+
console.log(pc.gray(`Clone into local folder: ${pc.cyan("moo clone <slug>")}\n`));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
console.log(pc.red(`[error] Failed to list mods: ${err.message}`));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loginCommand(explicitToken?: string): Promise<void>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import readline from "readline";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { setAuth, getApiUrl } from "../core/config.js";
|
|
4
|
+
import { api } from "../core/client.js";
|
|
5
|
+
function askQuestion(query, hideInput = false) {
|
|
6
|
+
const rl = readline.createInterface({
|
|
7
|
+
input: process.stdin,
|
|
8
|
+
output: process.stdout
|
|
9
|
+
});
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
if (!hideInput) {
|
|
12
|
+
rl.question(query, (answer) => {
|
|
13
|
+
rl.close();
|
|
14
|
+
resolve(answer.trim());
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// Mask password typing
|
|
19
|
+
process.stdout.write(query);
|
|
20
|
+
const stdin = process.stdin;
|
|
21
|
+
let input = "";
|
|
22
|
+
const onData = (char) => {
|
|
23
|
+
const c = char.toString("utf-8");
|
|
24
|
+
switch (c) {
|
|
25
|
+
case "\n":
|
|
26
|
+
case "\r":
|
|
27
|
+
case "\u0004":
|
|
28
|
+
stdin.removeListener("data", onData);
|
|
29
|
+
if (stdin.isTTY)
|
|
30
|
+
stdin.setRawMode(false);
|
|
31
|
+
rl.close();
|
|
32
|
+
process.stdout.write("\n");
|
|
33
|
+
resolve(input.trim());
|
|
34
|
+
break;
|
|
35
|
+
case "\u0003": // Ctrl+C
|
|
36
|
+
process.exit(1);
|
|
37
|
+
break;
|
|
38
|
+
case "\u007f": // Backspace
|
|
39
|
+
case "\b":
|
|
40
|
+
if (input.length > 0) {
|
|
41
|
+
input = input.slice(0, -1);
|
|
42
|
+
process.stdout.write("\b \b");
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
input += c;
|
|
47
|
+
process.stdout.write("*");
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (stdin.isTTY)
|
|
52
|
+
stdin.setRawMode(true);
|
|
53
|
+
stdin.resume();
|
|
54
|
+
stdin.on("data", onData);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export async function loginCommand(explicitToken) {
|
|
59
|
+
const apiUrl = getApiUrl();
|
|
60
|
+
console.log(pc.bold(pc.cyan("\nMooModding Developer CLI Login")));
|
|
61
|
+
console.log(pc.gray(`Server: ${apiUrl}\n`));
|
|
62
|
+
// Case 1: Direct token passed via command line (moo login moo_pat_...)
|
|
63
|
+
if (explicitToken && explicitToken.trim()) {
|
|
64
|
+
await verifyAndSaveToken(explicitToken.trim());
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
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
|
+
if (choice === "2") {
|
|
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
|
+
if (!token) {
|
|
75
|
+
console.log(pc.red("[error] Login cancelled: Empty token."));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
await verifyAndSaveToken(token);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Direct credential login
|
|
82
|
+
const username = await askQuestion(pc.bold("Username or Email: "));
|
|
83
|
+
if (!username) {
|
|
84
|
+
console.log(pc.red("[error] Username cannot be empty."));
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
const password = await askQuestion(pc.bold("Password: "), true);
|
|
88
|
+
if (!password) {
|
|
89
|
+
console.log(pc.red("[error] Password cannot be empty."));
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
console.log(pc.gray("\nAuthenticating..."));
|
|
93
|
+
try {
|
|
94
|
+
const res = await api.post("/api/developer/auth/login", {
|
|
95
|
+
username,
|
|
96
|
+
password,
|
|
97
|
+
device_name: "moo-cli"
|
|
98
|
+
}, { requiresAuth: false });
|
|
99
|
+
if (res.success && res.token) {
|
|
100
|
+
setAuth(res.token, res.user);
|
|
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
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.log(pc.red(`[error] Login failed: ${res.message || "Unknown error"}`));
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
console.log(pc.red(`[error] Login failed: ${err.message}`));
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function verifyAndSaveToken(token) {
|
|
117
|
+
console.log(pc.gray("Verifying token..."));
|
|
118
|
+
try {
|
|
119
|
+
setAuth(token);
|
|
120
|
+
const res = await api.get("/api/developer/whoami");
|
|
121
|
+
if (res.success && res.user) {
|
|
122
|
+
setAuth(token, res.user);
|
|
123
|
+
console.log(pc.green(`[success] Token verified and saved.`));
|
|
124
|
+
console.log(pc.gray(`User: ${res.user.username} (${res.user.email})`));
|
|
125
|
+
if (res.quota) {
|
|
126
|
+
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
127
|
+
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
128
|
+
console.log(pc.gray(`Storage Quota: ${usedMb} MB / ${maxMb} MB\n`));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log(pc.red("[error] Token verification failed."));
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.log(pc.red(`[error] Verification error: ${err.message}`));
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pullCommand(rootDir?: string): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { api } from "../core/client.js";
|
|
5
|
+
export async function pullCommand(rootDir = process.cwd()) {
|
|
6
|
+
const modConfigPath = path.join(rootDir, "mod.json");
|
|
7
|
+
if (!fs.existsSync(modConfigPath)) {
|
|
8
|
+
console.log(pc.red("[error] 'mod.json' not found. Please run this command inside a mod root directory."));
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
let modConfig;
|
|
12
|
+
try {
|
|
13
|
+
modConfig = JSON.parse(fs.readFileSync(modConfigPath, "utf-8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
console.log(pc.red("[error] Failed to parse 'mod.json'."));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const slug = modConfig.slug;
|
|
20
|
+
if (!slug) {
|
|
21
|
+
console.log(pc.red("[error] Missing 'slug' field in 'mod.json'."));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
console.log(pc.cyan(`[pull] Pulling latest files for '${slug}' from cloud...`));
|
|
25
|
+
try {
|
|
26
|
+
const res = await api.get(`/api/developer/mods/${slug}/pull`);
|
|
27
|
+
if (!res.success || !res.files) {
|
|
28
|
+
console.log(pc.red(`[error] Pull failed: ${res.message || "Unknown error"}`));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
let updatedCount = 0;
|
|
32
|
+
for (const [relPath, content] of Object.entries(res.files)) {
|
|
33
|
+
if (typeof content !== "string")
|
|
34
|
+
continue;
|
|
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);
|
|
41
|
+
if (!fs.existsSync(parent)) {
|
|
42
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
45
|
+
updatedCount++;
|
|
46
|
+
}
|
|
47
|
+
console.log(pc.green(`[success] Synced ${updatedCount} files from cloud.\n`));
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.log(pc.red(`[error] Pull error: ${err.message}`));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { scanModDirectory } from "../core/scanner.js";
|
|
5
|
+
import { api } from "../core/client.js";
|
|
6
|
+
export async function pushCommand(options = {}) {
|
|
7
|
+
const rootDir = options.rootDir || process.cwd();
|
|
8
|
+
const modConfigPath = path.join(rootDir, "mod.json");
|
|
9
|
+
if (!fs.existsSync(modConfigPath)) {
|
|
10
|
+
if (!options.silent) {
|
|
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
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
let modConfig;
|
|
17
|
+
try {
|
|
18
|
+
modConfig = JSON.parse(fs.readFileSync(modConfigPath, "utf-8"));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
if (!options.silent) {
|
|
22
|
+
console.log(pc.red("[error] 'mod.json' is not valid JSON."));
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!options.silent) {
|
|
27
|
+
console.log(pc.gray(`[push] Scanning '${modConfig.name || "Mod"}' directory...`));
|
|
28
|
+
}
|
|
29
|
+
const { files, fileCount, totalBytes } = scanModDirectory(rootDir);
|
|
30
|
+
if (fileCount === 0) {
|
|
31
|
+
if (!options.silent) {
|
|
32
|
+
console.log(pc.yellow("[warn] No files found to synchronize."));
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Safety check: local size check before sending
|
|
37
|
+
const totalMb = totalBytes / (1024 * 1024);
|
|
38
|
+
if (totalMb > 15) {
|
|
39
|
+
if (!options.silent) {
|
|
40
|
+
console.log(pc.red(`[error] Mod size (${totalMb.toFixed(1)} MB) exceeds allowed 15 MB limit.`));
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!options.silent) {
|
|
45
|
+
console.log(pc.gray(`[push] Uploading ${fileCount} files (${(totalBytes / 1024).toFixed(1)} KB) to cloud...`));
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const payload = {
|
|
49
|
+
name: modConfig.name || path.basename(rootDir),
|
|
50
|
+
slug: modConfig.slug,
|
|
51
|
+
type: modConfig.type || "hook",
|
|
52
|
+
version: modConfig.version || "1.0.0",
|
|
53
|
+
entry_point: modConfig.entry || "src/index.ts",
|
|
54
|
+
is_active: modConfig.is_active ?? true,
|
|
55
|
+
files: files
|
|
56
|
+
};
|
|
57
|
+
const res = await api.post("/api/developer/mods/sync", payload);
|
|
58
|
+
if (res.success) {
|
|
59
|
+
if (!options.silent) {
|
|
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
|
+
if (res.play_url) {
|
|
63
|
+
console.log(pc.cyan(`Test in-game: ${res.play_url}\n`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log(pc.green(`[${new Date().toLocaleTimeString()}] [synced] ${modConfig.name}`));
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(pc.red(`[error] Sync failed: ${res.message || "Unknown error"}`));
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.log(pc.red(`[error] Sync error: ${err.message}`));
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function whoamiCommand(): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { loadConfig, getApiUrl } from "../core/config.js";
|
|
3
|
+
import { api } from "../core/client.js";
|
|
4
|
+
export async function whoamiCommand() {
|
|
5
|
+
const config = loadConfig();
|
|
6
|
+
if (!config.token) {
|
|
7
|
+
console.log(pc.yellow("[warn] Not authenticated."));
|
|
8
|
+
console.log(pc.gray(`Run: ${pc.cyan("moo login")}`));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const res = await api.get("/api/developer/whoami");
|
|
13
|
+
if (res.success && res.user) {
|
|
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
|
+
if (res.quota) {
|
|
19
|
+
const usedMb = (res.quota.used_bytes / (1024 * 1024)).toFixed(2);
|
|
20
|
+
const maxMb = (res.quota.max_bytes / (1024 * 1024)).toFixed(0);
|
|
21
|
+
const percent = ((res.quota.used_bytes / res.quota.max_bytes) * 100).toFixed(1);
|
|
22
|
+
console.log(`Storage : ${usedMb} MB / ${maxMb} MB (${percent}%)`);
|
|
23
|
+
}
|
|
24
|
+
console.log("");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.log(pc.red(`[error] Authentication failed: ${err.message}`));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ApiResponse<T = any> {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message?: string;
|
|
4
|
+
data?: T;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class ApiError extends Error {
|
|
8
|
+
status: number;
|
|
9
|
+
data: any;
|
|
10
|
+
constructor(message: string, status: number, data?: any);
|
|
11
|
+
}
|
|
12
|
+
export declare function request<T = any>(endpoint: string, options?: {
|
|
13
|
+
method?: string;
|
|
14
|
+
body?: any;
|
|
15
|
+
requiresAuth?: boolean;
|
|
16
|
+
}): Promise<T>;
|
|
17
|
+
export declare const api: {
|
|
18
|
+
get: <T = any>(endpoint: string, options?: {
|
|
19
|
+
requiresAuth?: boolean;
|
|
20
|
+
}) => Promise<T>;
|
|
21
|
+
post: <T = any>(endpoint: string, body: any, options?: {
|
|
22
|
+
requiresAuth?: boolean;
|
|
23
|
+
}) => Promise<T>;
|
|
24
|
+
put: <T = any>(endpoint: string, body: any, options?: {
|
|
25
|
+
requiresAuth?: boolean;
|
|
26
|
+
}) => Promise<T>;
|
|
27
|
+
delete: <T = any>(endpoint: string, options?: {
|
|
28
|
+
requiresAuth?: boolean;
|
|
29
|
+
}) => Promise<T>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getApiUrl, getToken } from "./config.js";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
export class ApiError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
data;
|
|
6
|
+
constructor(message, status, data) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "ApiError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function request(endpoint, options = {}) {
|
|
14
|
+
const { method = "GET", body, requiresAuth = true } = options;
|
|
15
|
+
const baseUrl = getApiUrl().replace(/\/+$/, "");
|
|
16
|
+
const cleanEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
17
|
+
const url = `${baseUrl}${cleanEndpoint}`;
|
|
18
|
+
const headers = {
|
|
19
|
+
"Accept": "application/json"
|
|
20
|
+
};
|
|
21
|
+
if (body) {
|
|
22
|
+
headers["Content-Type"] = "application/json";
|
|
23
|
+
}
|
|
24
|
+
if (requiresAuth) {
|
|
25
|
+
const token = getToken();
|
|
26
|
+
if (!token) {
|
|
27
|
+
throw new ApiError(`Not authenticated. Please run ${pc.bold(pc.cyan("moo login"))} or set the MOOMODDING_TOKEN environment variable.`, 401);
|
|
28
|
+
}
|
|
29
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const res = await fetch(url, {
|
|
33
|
+
method,
|
|
34
|
+
headers,
|
|
35
|
+
body: body ? JSON.stringify(body) : undefined
|
|
36
|
+
});
|
|
37
|
+
const contentType = res.headers.get("content-type") || "";
|
|
38
|
+
let responseData = null;
|
|
39
|
+
if (contentType.includes("application/json")) {
|
|
40
|
+
responseData = await res.json();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
responseData = { message: await res.text() };
|
|
44
|
+
}
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const errorMsg = responseData?.message ||
|
|
47
|
+
`API request failed (${res.status} ${res.statusText})`;
|
|
48
|
+
throw new ApiError(errorMsg, res.status, responseData);
|
|
49
|
+
}
|
|
50
|
+
return responseData;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (err instanceof ApiError) {
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
throw new ApiError(`Connection error (${url}): ${err.message}`, 0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const api = {
|
|
60
|
+
get: (endpoint, options) => request(endpoint, { method: "GET", ...options }),
|
|
61
|
+
post: (endpoint, body, options) => request(endpoint, { method: "POST", body, ...options }),
|
|
62
|
+
put: (endpoint, body, options) => request(endpoint, { method: "PUT", body, ...options }),
|
|
63
|
+
delete: (endpoint, options) => request(endpoint, { method: "DELETE", ...options })
|
|
64
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface MooConfig {
|
|
2
|
+
token?: string;
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
user?: {
|
|
5
|
+
id: number;
|
|
6
|
+
username: string;
|
|
7
|
+
email: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare function getConfigPath(): string;
|
|
11
|
+
export declare function loadConfig(): MooConfig;
|
|
12
|
+
export declare function saveConfig(config: MooConfig): void;
|
|
13
|
+
export declare function getApiUrl(): string;
|
|
14
|
+
export declare function getToken(): string | undefined;
|
|
15
|
+
export declare function setAuth(token: string, user?: MooConfig["user"]): void;
|
|
16
|
+
export declare function clearAuth(): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import os from "os";
|
|
4
|
+
const CONFIG_DIR = path.join(os.homedir(), ".moomodding");
|
|
5
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
6
|
+
const DEFAULT_API_URL = "https://moomodding.io";
|
|
7
|
+
export function getConfigPath() {
|
|
8
|
+
return CONFIG_FILE;
|
|
9
|
+
}
|
|
10
|
+
export function loadConfig() {
|
|
11
|
+
try {
|
|
12
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
13
|
+
const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
|
|
14
|
+
return JSON.parse(raw);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Return blank config on parse failure
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
apiUrl: process.env.MOOMODDING_API_URL || DEFAULT_API_URL
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function saveConfig(config) {
|
|
25
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
26
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
|
|
29
|
+
}
|
|
30
|
+
export function getApiUrl() {
|
|
31
|
+
const config = loadConfig();
|
|
32
|
+
return process.env.MOOMODDING_API_URL || config.apiUrl || DEFAULT_API_URL;
|
|
33
|
+
}
|
|
34
|
+
export function getToken() {
|
|
35
|
+
if (process.env.MOOMODDING_TOKEN) {
|
|
36
|
+
return process.env.MOOMODDING_TOKEN;
|
|
37
|
+
}
|
|
38
|
+
const config = loadConfig();
|
|
39
|
+
return config.token;
|
|
40
|
+
}
|
|
41
|
+
export function setAuth(token, user) {
|
|
42
|
+
const config = loadConfig();
|
|
43
|
+
config.token = token.trim();
|
|
44
|
+
if (user) {
|
|
45
|
+
config.user = user;
|
|
46
|
+
}
|
|
47
|
+
saveConfig(config);
|
|
48
|
+
}
|
|
49
|
+
export function clearAuth() {
|
|
50
|
+
const config = loadConfig();
|
|
51
|
+
delete config.token;
|
|
52
|
+
delete config.user;
|
|
53
|
+
saveConfig(config);
|
|
54
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const DEFAULT_IGNORES = new Set([
|
|
4
|
+
"node_modules",
|
|
5
|
+
".git",
|
|
6
|
+
".vscode",
|
|
7
|
+
".idea",
|
|
8
|
+
"dist",
|
|
9
|
+
"build",
|
|
10
|
+
".env",
|
|
11
|
+
".env.local",
|
|
12
|
+
".DS_Store",
|
|
13
|
+
"Thumbs.db",
|
|
14
|
+
"package-lock.json",
|
|
15
|
+
"yarn.lock",
|
|
16
|
+
"pnpm-lock.yaml"
|
|
17
|
+
]);
|
|
18
|
+
export function scanModDirectory(rootDir = process.cwd()) {
|
|
19
|
+
const files = {};
|
|
20
|
+
let totalBytes = 0;
|
|
21
|
+
let ignoredCount = 0;
|
|
22
|
+
const ignorePatterns = new Set(DEFAULT_IGNORES);
|
|
23
|
+
const mooIgnoreFile = path.join(rootDir, ".mooignore");
|
|
24
|
+
if (fs.existsSync(mooIgnoreFile)) {
|
|
25
|
+
try {
|
|
26
|
+
const content = fs.readFileSync(mooIgnoreFile, "utf-8");
|
|
27
|
+
content.split(/\r?\n/).forEach(line => {
|
|
28
|
+
const clean = line.trim();
|
|
29
|
+
if (clean && !clean.startsWith("#")) {
|
|
30
|
+
ignorePatterns.add(clean.replace(/\/+$/, ""));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Ignore parse errors on custom ignore file
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isIgnored(name, relPath) {
|
|
39
|
+
if (ignorePatterns.has(name))
|
|
40
|
+
return true;
|
|
41
|
+
const normalizedRel = relPath.replace(/\\/g, "/");
|
|
42
|
+
for (const pattern of ignorePatterns) {
|
|
43
|
+
if (pattern.includes("/")) {
|
|
44
|
+
if (normalizedRel === pattern || normalizedRel.startsWith(`${pattern}/`)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
function walk(currentDir) {
|
|
52
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
55
|
+
const relPath = path.relative(rootDir, fullPath);
|
|
56
|
+
if (isIgnored(entry.name, relPath)) {
|
|
57
|
+
ignoredCount++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (entry.isDirectory()) {
|
|
61
|
+
walk(fullPath);
|
|
62
|
+
}
|
|
63
|
+
else if (entry.isFile()) {
|
|
64
|
+
try {
|
|
65
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
66
|
+
const normalizedRelPath = relPath.replace(/\\/g, "/");
|
|
67
|
+
files[normalizedRelPath] = content;
|
|
68
|
+
totalBytes += Buffer.byteLength(content, "utf-8");
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Binary or unreadable files can be handled or skipped
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
walk(rootDir);
|
|
77
|
+
return {
|
|
78
|
+
files,
|
|
79
|
+
fileCount: Object.keys(files).length,
|
|
80
|
+
totalBytes,
|
|
81
|
+
ignoredCount
|
|
82
|
+
};
|
|
83
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { loginCommand } from "./commands/login.js";
|
|
4
|
+
import { whoamiCommand } from "./commands/whoami.js";
|
|
5
|
+
import { initCommand } from "./commands/init.js";
|
|
6
|
+
import { listCommand } from "./commands/list.js";
|
|
7
|
+
import { cloneCommand } from "./commands/clone.js";
|
|
8
|
+
import { pushCommand } from "./commands/push.js";
|
|
9
|
+
import { pullCommand } from "./commands/pull.js";
|
|
10
|
+
import { devCommand } from "./commands/dev.js";
|
|
11
|
+
import { clearAuth, loadConfig, saveConfig } from "./core/config.js";
|
|
12
|
+
const program = new Command();
|
|
13
|
+
program
|
|
14
|
+
.name("moo")
|
|
15
|
+
.description("MooModding Developer CLI — Build, test, and sync MooMoo.io mods with zero friction.")
|
|
16
|
+
.version("1.0.1");
|
|
17
|
+
// 1. Auth Commands
|
|
18
|
+
program
|
|
19
|
+
.command("login [token]")
|
|
20
|
+
.description("Log in to your MooModding account")
|
|
21
|
+
.action(async (token) => {
|
|
22
|
+
await loginCommand(token);
|
|
23
|
+
});
|
|
24
|
+
program
|
|
25
|
+
.command("logout")
|
|
26
|
+
.description("Log out and clear local credentials")
|
|
27
|
+
.action(() => {
|
|
28
|
+
clearAuth();
|
|
29
|
+
console.log(pc.green("[success] Logged out successfully."));
|
|
30
|
+
});
|
|
31
|
+
program
|
|
32
|
+
.command("whoami")
|
|
33
|
+
.description("Display current user and storage quota")
|
|
34
|
+
.action(async () => {
|
|
35
|
+
await whoamiCommand();
|
|
36
|
+
});
|
|
37
|
+
// 2. Project Lifecycle Commands
|
|
38
|
+
program
|
|
39
|
+
.command("init [dir]")
|
|
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")
|
|
43
|
+
.action(async (dir, options) => {
|
|
44
|
+
await initCommand(dir, options);
|
|
45
|
+
});
|
|
46
|
+
program
|
|
47
|
+
.command("list")
|
|
48
|
+
.alias("ls")
|
|
49
|
+
.description("List your cloud mods and storage usage")
|
|
50
|
+
.action(async () => {
|
|
51
|
+
await listCommand();
|
|
52
|
+
});
|
|
53
|
+
program
|
|
54
|
+
.command("clone <slug> [dir]")
|
|
55
|
+
.description("Clone a cloud mod into a local directory")
|
|
56
|
+
.action(async (slug, dir) => {
|
|
57
|
+
await cloneCommand(slug, dir);
|
|
58
|
+
});
|
|
59
|
+
program
|
|
60
|
+
.command("push")
|
|
61
|
+
.description("Scan directory and push mod files to cloud")
|
|
62
|
+
.action(async () => {
|
|
63
|
+
await pushCommand();
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command("pull")
|
|
67
|
+
.description("Pull latest mod files from cloud")
|
|
68
|
+
.action(async () => {
|
|
69
|
+
await pullCommand();
|
|
70
|
+
});
|
|
71
|
+
program
|
|
72
|
+
.command("dev")
|
|
73
|
+
.description("Start file watcher for live cloud sync on save")
|
|
74
|
+
.action(() => {
|
|
75
|
+
devCommand();
|
|
76
|
+
});
|
|
77
|
+
// 3. Configuration command
|
|
78
|
+
program
|
|
79
|
+
.command("config <action> [key] [value]")
|
|
80
|
+
.description("View or update CLI config (e.g. moo config set api https://moomodding.io)")
|
|
81
|
+
.action((action, key, value) => {
|
|
82
|
+
const config = loadConfig();
|
|
83
|
+
if (action === "get") {
|
|
84
|
+
if (key) {
|
|
85
|
+
console.log(config[key] || pc.gray("(undefined)"));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.log(JSON.stringify(config, null, 2));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (action === "set") {
|
|
92
|
+
if (!key || value === undefined) {
|
|
93
|
+
console.log(pc.red("Usage: moo config set <key> <value>"));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (key === "api" || key === "apiUrl") {
|
|
97
|
+
config.apiUrl = value;
|
|
98
|
+
saveConfig(config);
|
|
99
|
+
console.log(pc.green(`[success] API URL updated: ${value}`));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
config[key] = value;
|
|
103
|
+
saveConfig(config);
|
|
104
|
+
console.log(pc.green(`[success] '${key}' updated.`));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(pc.red("Invalid action. Usage: moo config get [key] | moo config set <key> <value>"));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moomodding",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Official MooModding.io Developer CLI - Build, test, and sync MooMoo.io mods seamlessly.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"moomodding": "bin/moo.js",
|
|
9
|
+
"moo": "bin/moo.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"watch": "tsc -w",
|
|
15
|
+
"start": "node bin/moo.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://moomodding.io",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"moomoo",
|
|
25
|
+
"moomodding",
|
|
26
|
+
"mod",
|
|
27
|
+
"userscript",
|
|
28
|
+
"cli",
|
|
29
|
+
"developer-tools"
|
|
30
|
+
],
|
|
31
|
+
"author": "MooModding.io Team",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"chokidar": "^4.0.3",
|
|
35
|
+
"commander": "^13.1.0",
|
|
36
|
+
"picocolors": "^1.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.13.10",
|
|
40
|
+
"typescript": "^5.8.2"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|