@magicpixelart/cli 0.5.36 → 0.6.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/CHANGELOG.md +54 -5
- package/README.md +26 -0
- package/dist/commands/add.js +2 -1
- package/dist/commands/cleanStrays.js +92 -0
- package/dist/commands/connect.js +7 -4
- package/dist/commands/consolidate.js +308 -0
- package/dist/commands/doctor.js +3 -2
- package/dist/commands/init.js +6 -5
- package/dist/commands/login.js +2 -1
- package/dist/commands/logout.js +2 -1
- package/dist/commands/push.js +51 -17
- package/dist/commands/remove.js +2 -1
- package/dist/commands/repair.js +13 -23
- package/dist/commands/resync.js +11 -20
- package/dist/commands/search.js +2 -2
- package/dist/commands/start.js +97 -16
- package/dist/commands/sync.js +149 -66
- package/dist/commands/whoami.js +4 -3
- package/dist/commands/why.js +91 -0
- package/dist/config.js +3 -0
- package/dist/index.js +47 -4
- package/dist/util/framework.js +20 -2
- package/dist/util/gameScan.js +94 -11
- package/dist/util/projectRoots.js +73 -0
- package/dist/util/prompt.js +15 -0
- package/dist/util/strayGuard.js +76 -0
- package/dist/util/ui.js +156 -0
- package/dist/util/watchCopy.js +0 -16
- package/dist/util/workspace.js +82 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monorepo workspaces: one `magicpixel.json` at the root syncs several game
|
|
3
|
+
* folders (Unity projects / packages). Each folder keeps the sprite names it
|
|
4
|
+
* would have on its own, so moving to a workspace never re-uploads anything.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readdirSync, realpathSync } from 'node:fs';
|
|
7
|
+
import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
8
|
+
import { detectEngineKind, isEngineKind, readWorkspaceMembers } from './framework.js';
|
|
9
|
+
const NOT_MEMBERS = new Set(['node_modules', 'library', 'temp', 'build', 'builds', 'logs', 'obj']);
|
|
10
|
+
/** Child folders of `root` that are game folders on their own. Sorted. */
|
|
11
|
+
export function detectWorkspaceMembers(root) {
|
|
12
|
+
try {
|
|
13
|
+
return readdirSync(root, { withFileTypes: true })
|
|
14
|
+
.filter((e) => e.isDirectory() && !e.isSymbolicLink() && !e.name.startsWith('.') && !NOT_MEMBERS.has(e.name.toLowerCase()))
|
|
15
|
+
.filter((e) => isEngineKind(detectEngineKind(resolve(root, e.name))))
|
|
16
|
+
.map((e) => e.name)
|
|
17
|
+
.sort((a, b) => a.localeCompare(b));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Nearest ancestor (excluding `cwd`) that is a workspace root, or null. */
|
|
24
|
+
export function findWorkspaceRoot(cwd) {
|
|
25
|
+
let dir = dirname(resolve(cwd));
|
|
26
|
+
for (let i = 0; i < 32; i++) {
|
|
27
|
+
if (existsSync(resolve(dir, 'magicpixel.json')) && readWorkspaceMembers(dir))
|
|
28
|
+
return dir;
|
|
29
|
+
const parent = dirname(dir);
|
|
30
|
+
if (parent === dir)
|
|
31
|
+
return null;
|
|
32
|
+
dir = parent;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
/** Re-anchor a game-folder glob at the workspace root. */
|
|
37
|
+
export function anchorGlob(member, glob) {
|
|
38
|
+
const g = glob.trim().replace(/^\.\//, '');
|
|
39
|
+
return `${member}/${g}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A path typed by the user, made relative to the setup folder. Commands run
|
|
43
|
+
* inside a game folder of a monorepo work from the root, so `Runtime` typed in
|
|
44
|
+
* `kr-core` means `kr-core/Runtime`.
|
|
45
|
+
*/
|
|
46
|
+
/** Resolve symlinks on the existing prefix so `/var` and `/private/var` compare equal. */
|
|
47
|
+
function canonical(p) {
|
|
48
|
+
const abs = resolve(p);
|
|
49
|
+
const missing = [];
|
|
50
|
+
let dir = abs;
|
|
51
|
+
while (!existsSync(dir)) {
|
|
52
|
+
const parent = dirname(dir);
|
|
53
|
+
if (parent === dir)
|
|
54
|
+
return abs;
|
|
55
|
+
missing.push(basename(dir));
|
|
56
|
+
dir = parent;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const real = realpathSync(dir);
|
|
60
|
+
return missing.length === 0 ? real : resolve(real, ...missing.reverse());
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return abs;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function resolveInvokedPath(typed, cwd = process.cwd()) {
|
|
67
|
+
const from = process.env.MAGICPIXEL_INVOKED_FROM;
|
|
68
|
+
if (!from || isAbsolute(typed))
|
|
69
|
+
return typed;
|
|
70
|
+
return relative(canonical(cwd), canonical(resolve(from, typed))).replace(/\\/g, '/') || '.';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Library folders don't include the game-folder name, so drop a leading
|
|
74
|
+
* monorepo member (`kr-core/Runtime` → `Runtime`) before matching them.
|
|
75
|
+
*/
|
|
76
|
+
export function stripMemberSegment(segments, cwd = process.cwd()) {
|
|
77
|
+
const members = readWorkspaceMembers(cwd);
|
|
78
|
+
if (!members || segments.length < 2)
|
|
79
|
+
return segments;
|
|
80
|
+
const first = segments[0];
|
|
81
|
+
return members.some((m) => m.toLowerCase() === first) ? segments.slice(1) : segments;
|
|
82
|
+
}
|