moomodding 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -2
- package/bin/moo.js +3 -0
- package/dist/commands/clone.d.ts +1 -0
- package/dist/commands/clone.js +60 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +74 -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 +49 -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 +112 -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,60 @@
|
|
|
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("❌ Hata: İndirilecek mod slug'ı belirtilmedi."));
|
|
8
|
+
console.log(pc.gray(`Örnek kullanım: ${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.bold(pc.green(`\n📥 Mod İndiriliyor: ${cleanSlug}`)));
|
|
14
|
+
console.log(pc.gray(`Hedef: ${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(`❌ Mod indirilemedi: ${res.message || "Bilinmeyen hata"}`));
|
|
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
|
|
35
|
+
let writtenCount = 0;
|
|
36
|
+
for (const [relPath, content] of Object.entries(res.files)) {
|
|
37
|
+
if (typeof content !== "string")
|
|
38
|
+
continue;
|
|
39
|
+
const filePath = path.join(destDir, relPath);
|
|
40
|
+
const parentDir = path.dirname(filePath);
|
|
41
|
+
if (!fs.existsSync(parentDir)) {
|
|
42
|
+
fs.mkdirSync(parentDir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
45
|
+
writtenCount++;
|
|
46
|
+
}
|
|
47
|
+
// 3. Write default .mooignore if missing
|
|
48
|
+
const mooIgnorePath = path.join(destDir, ".mooignore");
|
|
49
|
+
if (!fs.existsSync(mooIgnorePath)) {
|
|
50
|
+
fs.writeFileSync(mooIgnorePath, `node_modules/\n.git/\n.vscode/\n.idea/\ndist/\nbuild/\n*.log\n.env\n.DS_Store\n`, "utf-8");
|
|
51
|
+
}
|
|
52
|
+
console.log(pc.green(`\n✅ '${res.mod.name}' başarıyla indirildi!`));
|
|
53
|
+
console.log(`📄 Toplam ${writtenCount} dosya yerel dizine yazıldı.`);
|
|
54
|
+
console.log(pc.gray(`\nGeliştirmeye başlamak için:\n cd ${path.basename(destDir)}\n moo dev\n`));
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.log(pc.red(`❌ İndirme hatası: ${err.message}`));
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function devCommand(rootDir?: string): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
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("❌ 'mod.json' bulunamadı."));
|
|
10
|
+
console.log(pc.gray(`Lütfen mod kök dizininde çalıştırın veya yeni başlatmak için: ${pc.cyan("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("❌ 'mod.json' okunamadı."));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
console.log(pc.bold(pc.green(`\n⚡ MooModding Canlı İzleme Modu (Hot-Sync)`)));
|
|
22
|
+
console.log(`📦 Mod: ${pc.bold(pc.white(modConfig.name || "Mod"))} (${pc.cyan(modConfig.slug)})`);
|
|
23
|
+
console.log(pc.gray(`👀 Dizin izleniyor: ${rootDir}`));
|
|
24
|
+
console.log(pc.gray(`💡 İpucu: Kodunuzda Ctrl+S yaptığınız anda otomatik buluta aktarılır.\n`));
|
|
25
|
+
// Initial push to verify state
|
|
26
|
+
pushCommand({ rootDir, silent: false }).then(() => {
|
|
27
|
+
let debounceTimer = null;
|
|
28
|
+
let isSyncing = false;
|
|
29
|
+
const watcher = chokidar.watch(rootDir, {
|
|
30
|
+
ignored: [
|
|
31
|
+
"**/node_modules/**",
|
|
32
|
+
"**/.git/**",
|
|
33
|
+
"**/.vscode/**",
|
|
34
|
+
"**/.idea/**",
|
|
35
|
+
"**/dist/**",
|
|
36
|
+
"**/build/**",
|
|
37
|
+
"**/*.log",
|
|
38
|
+
"**/.env*",
|
|
39
|
+
"**/.DS_Store"
|
|
40
|
+
],
|
|
41
|
+
persistent: true,
|
|
42
|
+
ignoreInitial: true,
|
|
43
|
+
awaitWriteFinish: {
|
|
44
|
+
stabilityThreshold: 150,
|
|
45
|
+
pollInterval: 50
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const handleChange = (filePath, eventType) => {
|
|
49
|
+
const rel = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
50
|
+
console.log(pc.gray(`[${new Date().toLocaleTimeString()}] 📝 ${eventType.toUpperCase()}: ${rel}`));
|
|
51
|
+
if (debounceTimer)
|
|
52
|
+
clearTimeout(debounceTimer);
|
|
53
|
+
debounceTimer = setTimeout(async () => {
|
|
54
|
+
if (isSyncing)
|
|
55
|
+
return;
|
|
56
|
+
isSyncing = true;
|
|
57
|
+
try {
|
|
58
|
+
await pushCommand({ rootDir, silent: true });
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
isSyncing = false;
|
|
62
|
+
}
|
|
63
|
+
}, 300);
|
|
64
|
+
};
|
|
65
|
+
watcher.on("change", (fp) => handleChange(fp, "değişti"));
|
|
66
|
+
watcher.on("add", (fp) => handleChange(fp, "eklendi"));
|
|
67
|
+
watcher.on("unlink", (fp) => handleChange(fp, "silindi"));
|
|
68
|
+
process.on("SIGINT", () => {
|
|
69
|
+
console.log(pc.yellow("\n🛑 Canlı izleme modu sonlandırıldı."));
|
|
70
|
+
watcher.close();
|
|
71
|
+
process.exit(0);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -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.bold(pc.green(`\n🌱 MooModding Mod Projesi Başlatılıyor: ${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(`⚠️ Dikkat: Bu dizinde zaten bir 'mod.json' mevcut.`));
|
|
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 yüklendi!");
|
|
40
|
+
|
|
41
|
+
// MooMoo WebSocket paket kancası örneği
|
|
42
|
+
if (typeof window !== "undefined") {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
window.__myMooModLoaded = true;
|
|
45
|
+
|
|
46
|
+
// Örnek: Chat veya paket dinleyici
|
|
47
|
+
console.log("[${modName}] Hazır.");
|
|
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 modu - MooModding.io ile geliştirilmektedir.
|
|
68
|
+
|
|
69
|
+
## Komutlar
|
|
70
|
+
|
|
71
|
+
- \`moo push\`: Mod dosyalarını MooModding bulutuna senkronize eder.
|
|
72
|
+
- \`moo dev\`: Canlı izleme modu (her \`Ctrl+S\` kaydedildiğinde anında buluta gönderir).
|
|
73
|
+
- \`moo pull\`: Buluttaki en son sürümü yerel dizine çeker.
|
|
74
|
+
`;
|
|
75
|
+
fs.writeFileSync(path.join(dir, "README.md"), readmeContent, "utf-8");
|
|
76
|
+
console.log(pc.green(`✅ Mod şablonu başarıyla oluşturuldu!\n`));
|
|
77
|
+
console.log(`📁 Dizin: ${pc.cyan(dir)}`);
|
|
78
|
+
console.log(`📄 Yapılandırma: ${pc.bold("mod.json")}`);
|
|
79
|
+
console.log(`📝 Giriş Dosyası: ${pc.bold("src/index.ts")}`);
|
|
80
|
+
console.log(pc.gray(`\nBaşlamak için:\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.green("\n🐄 MooModding.io — Bulut Modlarınız")));
|
|
6
|
+
console.log(pc.gray("Modlar yükleniyor...\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("Henüz kayıtlı bir modunuz bulunmuyor."));
|
|
10
|
+
console.log(pc.gray(`Yeni mod başlatmak için: ${pc.cyan("moo init <mod-adi>")}\n`));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.log(pc.bold(` ${"AD / SLUG".padEnd(28)} ${"TÜR".padEnd(14)} ${"BOYUT".padEnd(10)} ${"DURUM".padEnd(10)} ${"SÜRÜM"}`));
|
|
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("Aktif") : pc.gray("Pasif");
|
|
18
|
+
const slug = pc.cyan(m.slug);
|
|
19
|
+
const type = m.type === "bundle_replacement" ? "Tam Paket" : "Kanca (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} dosya)`));
|
|
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(`Toplam Kullanım: ${usedMb} MB / ${maxMb} MB\n`));
|
|
28
|
+
}
|
|
29
|
+
console.log(pc.gray(`Yerel dizine indirmek için: ${pc.cyan("moo clone <slug>")}\n`));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
console.log(pc.red(`❌ Mod listesi alınamadı: ${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.green("\n🐄 MooModding.io — Developer CLI Girişi")));
|
|
61
|
+
console.log(pc.gray(`Bağlanılan Sunucu: ${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("Giriş yöntemi seçin:"));
|
|
68
|
+
console.log(` 1) Kullanıcı Adı ve Şifre ile Hızlı Giriş ${pc.green("(Önerilen)")}`);
|
|
69
|
+
console.log(` 2) Kişisel Erişim Belirteci (Personal Access Token) ile Giriş\n`);
|
|
70
|
+
const choice = await askQuestion(pc.bold("Seçiminiz (1 veya 2, varsayılan 1): "));
|
|
71
|
+
if (choice === "2") {
|
|
72
|
+
console.log(pc.yellow(`\nWeb arayüzünden token oluşturun: ${apiUrl}/settings?tab=developer-tokens`));
|
|
73
|
+
const token = await askQuestion(pc.bold("Kişisel Erişim Belirtecinizi (PAT) yapıştırın: "));
|
|
74
|
+
if (!token) {
|
|
75
|
+
console.log(pc.red("❌ Giriş iptal edildi: Boş token."));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
await verifyAndSaveToken(token);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Direct credential login
|
|
82
|
+
const username = await askQuestion(pc.bold("Kullanıcı Adı veya E-posta: "));
|
|
83
|
+
if (!username) {
|
|
84
|
+
console.log(pc.red("❌ Kullanıcı adı boş olamaz."));
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
const password = await askQuestion(pc.bold("Şifre: "), true);
|
|
88
|
+
if (!password) {
|
|
89
|
+
console.log(pc.red("❌ Şifre boş olamaz."));
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
console.log(pc.gray("\nGiriş yapılıyor..."));
|
|
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(`\n✅ Başarıyla giriş yapıldı!`));
|
|
102
|
+
console.log(`👤 Hoş geldin, ${pc.bold(pc.white(res.user.username))} (${res.user.email})`);
|
|
103
|
+
console.log(pc.gray(`\nArtık 'moo init', 'moo clone' veya 'moo dev' komutlarını kullanabilirsiniz.\n`));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.log(pc.red(`❌ Giriş başarısız: ${res.message || "Bilinmeyen hata"}`));
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
console.log(pc.red(`❌ Giriş başarısız: ${err.message}`));
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function verifyAndSaveToken(token) {
|
|
117
|
+
console.log(pc.gray("Token doğrulanıyor..."));
|
|
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(`\n✅ Token onaylandı ve kaydedildi!`));
|
|
124
|
+
console.log(`👤 Kullanıcı: ${pc.bold(pc.white(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(`💾 Depolama Kotası: ${usedMb} MB / ${maxMb} MB\n`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log(pc.red("❌ Token doğrulanamadı."));
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.log(pc.red(`❌ Hata: ${err.message}`));
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pullCommand(rootDir?: string): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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("❌ 'mod.json' bulunamadı. Lütfen mod kök dizininde çalıştırın."));
|
|
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("❌ 'mod.json' dosyası okunamadı."));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const slug = modConfig.slug;
|
|
20
|
+
if (!slug) {
|
|
21
|
+
console.log(pc.red("❌ 'mod.json' içinde 'slug' alanı tanımlı değil."));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
console.log(pc.gray(`📥 '${slug}' için buluttan en son dosyalar çekiliyor...`));
|
|
25
|
+
try {
|
|
26
|
+
const res = await api.get(`/api/developer/mods/${slug}/pull`);
|
|
27
|
+
if (!res.success || !res.files) {
|
|
28
|
+
console.log(pc.red(`❌ Çekme başarısız: ${res.message || "Bilinmeyen hata"}`));
|
|
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 destPath = path.join(rootDir, relPath);
|
|
36
|
+
const parent = path.dirname(destPath);
|
|
37
|
+
if (!fs.existsSync(parent)) {
|
|
38
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
fs.writeFileSync(destPath, content, "utf-8");
|
|
41
|
+
updatedCount++;
|
|
42
|
+
}
|
|
43
|
+
console.log(pc.green(`✅ ${updatedCount} dosya buluttan yerel dizine eşitlendi!\n`));
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.log(pc.red(`❌ Hata: ${err.message}`));
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -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("❌ 'mod.json' bulunamadı."));
|
|
12
|
+
console.log(pc.gray(`Lütfen modun kök dizininde olduğunuzdan emin olun veya yeni başlatmak için: ${pc.cyan("moo init")}`));
|
|
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("❌ 'mod.json' dosyası geçerli bir JSON değil."));
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!options.silent) {
|
|
27
|
+
console.log(pc.gray(`📦 '${modConfig.name || "Mod"}' dizini taranıyor...`));
|
|
28
|
+
}
|
|
29
|
+
const { files, fileCount, totalBytes } = scanModDirectory(rootDir);
|
|
30
|
+
if (fileCount === 0) {
|
|
31
|
+
if (!options.silent) {
|
|
32
|
+
console.log(pc.yellow("⚠️ Senkronize edilecek dosya bulunamadı."));
|
|
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(`❌ Hata: Mod boyutu (${totalMb.toFixed(1)} MB) izin verilen 15 MB sınırını aşıyor!`));
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!options.silent) {
|
|
45
|
+
console.log(pc.gray(`🚀 ${fileCount} dosya paketlendi (${(totalBytes / 1024).toFixed(1)} KB). Buluta aktarılıyor...`));
|
|
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(`\n✅ '${modConfig.name}' başarıyla senkronize edildi!`));
|
|
61
|
+
console.log(`📡 Mod Slug: ${pc.cyan(res.mod.slug)} (${res.mod.size_bytes} bayt)`);
|
|
62
|
+
if (res.play_url) {
|
|
63
|
+
console.log(`🎮 Oyunda test et: ${pc.bold(pc.white(res.play_url))}\n`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log(pc.green(`[${new Date().toLocaleTimeString()}] ✅ Senkronize edildi: ${modConfig.name}`));
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(pc.red(`❌ Senkronizasyon başarısız: ${res.message || "Bilinmeyen hata"}`));
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.log(pc.red(`❌ Senkronizasyon hatası: ${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("⚠️ Giriş yapılmamış."));
|
|
8
|
+
console.log(pc.gray(`Giriş yapmak için: ${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.green("\n🐄 MooModding.io — Oturum Bilgisi")));
|
|
15
|
+
console.log(`👤 Kullanıcı Adı : ${pc.bold(pc.white(res.user.username))}`);
|
|
16
|
+
console.log(`📧 E-posta : ${res.user.email}`);
|
|
17
|
+
console.log(`🌐 Sunucu API : ${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(`💾 Depolama : ${usedMb} MB / ${maxMb} MB (%${percent})`);
|
|
23
|
+
}
|
|
24
|
+
console.log("");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.log(pc.red(`❌ Kimlik doğrulama başarısız: ${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(`Giriş yapılmamış. Lütfen önce ${pc.bold(pc.cyan("moo login"))} çalıştırın veya MOOMODDING_TOKEN çevre değişkeni ayarlayın.`, 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 isteği başarısız oldu (${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(`Bağlantı hatası (${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,112 @@
|
|
|
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(pc.bold(pc.green("🐄 MooModding Developer CLI")) +
|
|
16
|
+
pc.gray(" — Build, test, and sync MooMoo.io mods with zero friction."))
|
|
17
|
+
.version("1.0.0");
|
|
18
|
+
// 1. Auth Commands
|
|
19
|
+
program
|
|
20
|
+
.command("login [token]")
|
|
21
|
+
.description("MooModding hesabınıza giriş yapın (Kişisel Erişim Belirteci ile)")
|
|
22
|
+
.action(async (token) => {
|
|
23
|
+
await loginCommand(token);
|
|
24
|
+
});
|
|
25
|
+
program
|
|
26
|
+
.command("logout")
|
|
27
|
+
.description("Yerel oturum belirtecini temizler")
|
|
28
|
+
.action(() => {
|
|
29
|
+
clearAuth();
|
|
30
|
+
console.log(pc.green("✅ Başarıyla çıkış yapıldı."));
|
|
31
|
+
});
|
|
32
|
+
program
|
|
33
|
+
.command("whoami")
|
|
34
|
+
.description("Aktif oturum ve depolama kotası bilgilerini gösterir")
|
|
35
|
+
.action(async () => {
|
|
36
|
+
await whoamiCommand();
|
|
37
|
+
});
|
|
38
|
+
// 2. Project Lifecycle Commands
|
|
39
|
+
program
|
|
40
|
+
.command("init [dir]")
|
|
41
|
+
.description("Yeni bir MooMoo mod şablonu oluşturur")
|
|
42
|
+
.option("-n, --name <name>", "Modun görünen adı")
|
|
43
|
+
.option("-t, --type <type>", "Mod türü ('hook' veya 'bundle_replacement')", "hook")
|
|
44
|
+
.action(async (dir, options) => {
|
|
45
|
+
await initCommand(dir, options);
|
|
46
|
+
});
|
|
47
|
+
program
|
|
48
|
+
.command("list")
|
|
49
|
+
.alias("ls")
|
|
50
|
+
.description("Buluttaki kayıtlı modlarınızı ve durumlarını listeler")
|
|
51
|
+
.action(async () => {
|
|
52
|
+
await listCommand();
|
|
53
|
+
});
|
|
54
|
+
program
|
|
55
|
+
.command("clone <slug> [dir]")
|
|
56
|
+
.description("Buluttaki bir modu yerel klasöre indirir")
|
|
57
|
+
.action(async (slug, dir) => {
|
|
58
|
+
await cloneCommand(slug, dir);
|
|
59
|
+
});
|
|
60
|
+
program
|
|
61
|
+
.command("push")
|
|
62
|
+
.description("Geçerli dizindeki mod dosyalarını otomatik tarayıp buluta aktarır")
|
|
63
|
+
.action(async () => {
|
|
64
|
+
await pushCommand();
|
|
65
|
+
});
|
|
66
|
+
program
|
|
67
|
+
.command("pull")
|
|
68
|
+
.description("Buluttaki en güncel dosyaları yerel dizine çeker")
|
|
69
|
+
.action(async () => {
|
|
70
|
+
await pullCommand();
|
|
71
|
+
});
|
|
72
|
+
program
|
|
73
|
+
.command("dev")
|
|
74
|
+
.description("Canlı izleme modu (dosyalar kaydedildikçe anında buluta senkronize eder)")
|
|
75
|
+
.action(() => {
|
|
76
|
+
devCommand();
|
|
77
|
+
});
|
|
78
|
+
// 3. Configuration command
|
|
79
|
+
program
|
|
80
|
+
.command("config <action> [key] [value]")
|
|
81
|
+
.description("CLI ayarlarını görüntüleyin veya değiştirin (ör: moo config set api http://localhost:8000)")
|
|
82
|
+
.action((action, key, value) => {
|
|
83
|
+
const config = loadConfig();
|
|
84
|
+
if (action === "get") {
|
|
85
|
+
if (key) {
|
|
86
|
+
console.log(config[key] || pc.gray("(tanımsız)"));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log(JSON.stringify(config, null, 2));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (action === "set") {
|
|
93
|
+
if (!key || value === undefined) {
|
|
94
|
+
console.log(pc.red("Kullanım: moo config set <key> <value>"));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (key === "api" || key === "apiUrl") {
|
|
98
|
+
config.apiUrl = value;
|
|
99
|
+
saveConfig(config);
|
|
100
|
+
console.log(pc.green(`✅ API adresi güncellendi: ${value}`));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
config[key] = value;
|
|
104
|
+
saveConfig(config);
|
|
105
|
+
console.log(pc.green(`✅ '${key}' güncellendi.`));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.log(pc.red("Geçersiz eylem. Kullanım: moo config get [key] | moo config set <key> <value>"));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
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.0",
|
|
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
|
+
}
|