unity-hub-cli 0.18.0 → 0.19.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/dist/index.js +121 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { homedir } from "os";
|
|
|
7
7
|
import { dirname as dirname2, join as join9 } from "path";
|
|
8
8
|
import process3 from "process";
|
|
9
9
|
import { createInterface as createInterface2 } from "readline";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
10
11
|
import chalk from "chalk";
|
|
11
12
|
import { render } from "ink";
|
|
12
13
|
|
|
@@ -784,6 +785,38 @@ var MacUnityHubProjectsReader = class {
|
|
|
784
785
|
};
|
|
785
786
|
await writeFile(HUB_PROJECTS_PATH, JSON.stringify(json, void 0, 2), "utf8");
|
|
786
787
|
}
|
|
788
|
+
async toggleFavorite(projectPath) {
|
|
789
|
+
let content;
|
|
790
|
+
try {
|
|
791
|
+
content = await readFile2(HUB_PROJECTS_PATH, "utf8");
|
|
792
|
+
} catch {
|
|
793
|
+
throw new Error(`Unity Hub project list not found (${HUB_PROJECTS_PATH}).`);
|
|
794
|
+
}
|
|
795
|
+
let json;
|
|
796
|
+
try {
|
|
797
|
+
json = JSON.parse(content);
|
|
798
|
+
} catch {
|
|
799
|
+
throw new Error("Unable to read the Unity Hub project list (permissions/format error).");
|
|
800
|
+
}
|
|
801
|
+
if (!json.data) {
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
const projectKey = Object.keys(json.data).find((key) => json.data?.[key]?.path === projectPath);
|
|
805
|
+
if (!projectKey) {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
const original = json.data[projectKey];
|
|
809
|
+
if (!original) {
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
const newFavorite = original.isFavorite !== true;
|
|
813
|
+
json.data[projectKey] = {
|
|
814
|
+
...original,
|
|
815
|
+
isFavorite: newFavorite
|
|
816
|
+
};
|
|
817
|
+
await writeFile(HUB_PROJECTS_PATH, JSON.stringify(json, void 0, 2), "utf8");
|
|
818
|
+
return newFavorite;
|
|
819
|
+
}
|
|
787
820
|
async readCliArgs(projectPath) {
|
|
788
821
|
const infoPath = `${process.env.HOME ?? ""}/Library/Application Support/UnityHub/projectsInfo.json`;
|
|
789
822
|
let content;
|
|
@@ -915,6 +948,38 @@ var WinUnityHubProjectsReader = class {
|
|
|
915
948
|
};
|
|
916
949
|
await writeFile2(HUB_PROJECTS_PATH2, JSON.stringify(json, void 0, 2), "utf8");
|
|
917
950
|
}
|
|
951
|
+
async toggleFavorite(projectPath) {
|
|
952
|
+
let content;
|
|
953
|
+
try {
|
|
954
|
+
content = await readFile3(HUB_PROJECTS_PATH2, "utf8");
|
|
955
|
+
} catch {
|
|
956
|
+
throw new Error(`Unity Hub project list not found (${HUB_PROJECTS_PATH2}).`);
|
|
957
|
+
}
|
|
958
|
+
let json;
|
|
959
|
+
try {
|
|
960
|
+
json = JSON.parse(content);
|
|
961
|
+
} catch {
|
|
962
|
+
throw new Error("Unable to read the Unity Hub project list (permissions/format error).");
|
|
963
|
+
}
|
|
964
|
+
if (!json.data) {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
const projectKey = Object.keys(json.data).find((key) => json.data?.[key]?.path === projectPath);
|
|
968
|
+
if (!projectKey) {
|
|
969
|
+
return false;
|
|
970
|
+
}
|
|
971
|
+
const original = json.data[projectKey];
|
|
972
|
+
if (!original) {
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
const newFavorite = original.isFavorite !== true;
|
|
976
|
+
json.data[projectKey] = {
|
|
977
|
+
...original,
|
|
978
|
+
isFavorite: newFavorite
|
|
979
|
+
};
|
|
980
|
+
await writeFile2(HUB_PROJECTS_PATH2, JSON.stringify(json, void 0, 2), "utf8");
|
|
981
|
+
return newFavorite;
|
|
982
|
+
}
|
|
918
983
|
async readCliArgs(projectPath) {
|
|
919
984
|
const infoPath = join6(HUB_DIR, "projectsInfo.json");
|
|
920
985
|
let content;
|
|
@@ -1673,7 +1738,8 @@ var ProjectList = ({
|
|
|
1673
1738
|
const rowIndex = startIndex + offset;
|
|
1674
1739
|
const isSelected = rowIndex === selectedIndex;
|
|
1675
1740
|
const selectionBar = isSelected ? "\u2503" : " ";
|
|
1676
|
-
const
|
|
1741
|
+
const baseName = formatProjectName(project.title, repository, useGitRootName);
|
|
1742
|
+
const projectName = project.favorite ? `\u2B51 ${baseName}` : baseName;
|
|
1677
1743
|
const versionLabel = `(${project.version.value})`;
|
|
1678
1744
|
const updatedText = formatUpdatedText(project.lastModified);
|
|
1679
1745
|
const pathLine = shortenHomePath(project.path);
|
|
@@ -1993,7 +2059,7 @@ var extractRootFolder2 = (repository) => {
|
|
|
1993
2059
|
return base || void 0;
|
|
1994
2060
|
};
|
|
1995
2061
|
var minimumVisibleProjectCount = 4;
|
|
1996
|
-
var defaultHintMessage = `j/k Select \xB7 [o]pen [O]+Editor [i]de [q]uit [r]efresh [c]opy [s]ort [v]isibility \xB7 ^C Exit`;
|
|
2062
|
+
var defaultHintMessage = `j/k Select \xB7 [o]pen [O]+Editor [i]de [q]uit [r]efresh [c]opy [f]av [s]ort [v]isibility \xB7 ^C Exit`;
|
|
1997
2063
|
var getCopyTargetPath = (view) => {
|
|
1998
2064
|
const root = view.repository?.root;
|
|
1999
2065
|
return root && root.length > 0 ? root : view.project.path;
|
|
@@ -2005,6 +2071,7 @@ var App = ({
|
|
|
2005
2071
|
onLaunchEditorOnly,
|
|
2006
2072
|
onTerminate,
|
|
2007
2073
|
onRefresh,
|
|
2074
|
+
onToggleFavorite,
|
|
2008
2075
|
useGitRootName = true,
|
|
2009
2076
|
outputPathOnExit = false,
|
|
2010
2077
|
onSetExitPath
|
|
@@ -2443,6 +2510,43 @@ var App = ({
|
|
|
2443
2510
|
setIsRefreshing(false);
|
|
2444
2511
|
}
|
|
2445
2512
|
}, [isRefreshing, onRefresh, sortedProjects]);
|
|
2513
|
+
const toggleFavoriteSelected = useCallback(async () => {
|
|
2514
|
+
if (!onToggleFavorite) {
|
|
2515
|
+
setHint("Toggle favorite not available");
|
|
2516
|
+
setTimeout(() => {
|
|
2517
|
+
setHint(defaultHintMessage);
|
|
2518
|
+
}, 2e3);
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
const projectView = sortedProjects[index];
|
|
2522
|
+
if (!projectView) {
|
|
2523
|
+
setHint("No project to toggle favorite");
|
|
2524
|
+
setTimeout(() => {
|
|
2525
|
+
setHint(defaultHintMessage);
|
|
2526
|
+
}, 2e3);
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
const { project } = projectView;
|
|
2530
|
+
try {
|
|
2531
|
+
const newFavorite = await onToggleFavorite(project);
|
|
2532
|
+
setProjectViews(
|
|
2533
|
+
(prev) => prev.map(
|
|
2534
|
+
(pv) => pv.project.id === project.id ? { ...pv, project: { ...pv.project, favorite: newFavorite } } : pv
|
|
2535
|
+
)
|
|
2536
|
+
);
|
|
2537
|
+
const status = newFavorite ? "added to" : "removed from";
|
|
2538
|
+
setHint(`${project.title} ${status} favorites`);
|
|
2539
|
+
setTimeout(() => {
|
|
2540
|
+
setHint(defaultHintMessage);
|
|
2541
|
+
}, 2e3);
|
|
2542
|
+
} catch (error) {
|
|
2543
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2544
|
+
setHint(`Failed to toggle favorite: ${message}`);
|
|
2545
|
+
setTimeout(() => {
|
|
2546
|
+
setHint(defaultHintMessage);
|
|
2547
|
+
}, 3e3);
|
|
2548
|
+
}
|
|
2549
|
+
}, [index, onToggleFavorite, sortedProjects]);
|
|
2446
2550
|
useInput((input, key) => {
|
|
2447
2551
|
if (isSortMenuOpen) {
|
|
2448
2552
|
if (key.escape || input === "\x1B") {
|
|
@@ -2563,6 +2667,10 @@ var App = ({
|
|
|
2563
2667
|
}
|
|
2564
2668
|
if (input === "c") {
|
|
2565
2669
|
copyProjectPath();
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
if (input === "f" || input === "F") {
|
|
2673
|
+
void toggleFavoriteSelected();
|
|
2566
2674
|
}
|
|
2567
2675
|
});
|
|
2568
2676
|
const { startIndex, visibleProjects } = useMemo2(() => {
|
|
@@ -2642,6 +2750,12 @@ var App = ({
|
|
|
2642
2750
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
2643
2751
|
var SHELL_INIT_MARKER_START = "# >>> unity-hub-cli >>>";
|
|
2644
2752
|
var SHELL_INIT_MARKER_END = "# <<< unity-hub-cli <<<";
|
|
2753
|
+
var getVersion = () => {
|
|
2754
|
+
const currentDir = dirname2(fileURLToPath(import.meta.url));
|
|
2755
|
+
const packageJsonPath = join9(currentDir, "..", "package.json");
|
|
2756
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
2757
|
+
return packageJson.version;
|
|
2758
|
+
};
|
|
2645
2759
|
var getShellConfigPath = () => {
|
|
2646
2760
|
const shell = process3.env["SHELL"] ?? "";
|
|
2647
2761
|
const home = homedir();
|
|
@@ -2793,6 +2907,10 @@ end`;
|
|
|
2793
2907
|
};
|
|
2794
2908
|
var bootstrap = async () => {
|
|
2795
2909
|
const args = process3.argv.slice(2);
|
|
2910
|
+
if (args.includes("-v") || args.includes("--version")) {
|
|
2911
|
+
console.log(getVersion());
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2796
2914
|
if (args.includes("--shell-init")) {
|
|
2797
2915
|
const isDryRun = args.includes("--dry-run");
|
|
2798
2916
|
if (isDryRun) {
|
|
@@ -2896,6 +3014,7 @@ var bootstrap = async () => {
|
|
|
2896
3014
|
onLaunchEditorOnly: (project) => launchEditorOnlyUseCase.execute(project),
|
|
2897
3015
|
onTerminate: (project) => terminateProjectUseCase.execute(project),
|
|
2898
3016
|
onRefresh: () => listProjectsUseCase.execute(),
|
|
3017
|
+
onToggleFavorite: (project) => unityHubReader.toggleFavorite(project.path),
|
|
2899
3018
|
useGitRootName,
|
|
2900
3019
|
outputPathOnExit,
|
|
2901
3020
|
onSetExitPath: (path) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unity-hub-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A CLI tool that reads Unity Hub's projects and launches Unity Editor with an interactive TUI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"eslint-config-prettier": "10.1.8",
|
|
65
65
|
"eslint-import-resolver-typescript": "4.4.4",
|
|
66
66
|
"eslint-plugin-import": "2.32.0",
|
|
67
|
-
"prettier": "3.7.
|
|
67
|
+
"prettier": "3.7.4",
|
|
68
68
|
"tsup": "8.5.1",
|
|
69
69
|
"tsx": "4.21.0",
|
|
70
70
|
"typescript": "5.9.3",
|