unity-hub-cli 0.2.0 → 0.4.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 +38 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,22 +6,26 @@ import { render } from "ink";
|
|
|
6
6
|
|
|
7
7
|
// src/application/usecases.ts
|
|
8
8
|
var ListProjectsUseCase = class {
|
|
9
|
-
constructor(unityHubProjectsReader, gitRepositoryInfoReader, unityProjectOptionsReader) {
|
|
9
|
+
constructor(unityHubProjectsReader, gitRepositoryInfoReader, unityProjectOptionsReader, lockReader) {
|
|
10
10
|
this.unityHubProjectsReader = unityHubProjectsReader;
|
|
11
11
|
this.gitRepositoryInfoReader = gitRepositoryInfoReader;
|
|
12
12
|
this.unityProjectOptionsReader = unityProjectOptionsReader;
|
|
13
|
+
this.lockReader = lockReader;
|
|
13
14
|
}
|
|
14
15
|
async execute() {
|
|
15
16
|
const projects = await this.unityHubProjectsReader.listProjects();
|
|
16
|
-
const repositoryInfoResults = await Promise.
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const [repositoryInfoResults, lockResults] = await Promise.all([
|
|
18
|
+
Promise.allSettled(
|
|
19
|
+
projects.map((project) => this.gitRepositoryInfoReader.readRepositoryInfo(project.path))
|
|
20
|
+
),
|
|
21
|
+
Promise.allSettled(projects.map((project) => this.lockReader.isLocked(project.path)))
|
|
22
|
+
]);
|
|
19
23
|
return projects.map((project, index) => {
|
|
20
24
|
const repositoryResult = repositoryInfoResults[index];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return { project };
|
|
25
|
+
const lockResult = lockResults[index];
|
|
26
|
+
const repository = repositoryResult.status === "fulfilled" ? repositoryResult.value ?? void 0 : void 0;
|
|
27
|
+
const isLocked = lockResult.status === "fulfilled" ? Boolean(lockResult.value) : false;
|
|
28
|
+
return { project, repository, isLocked };
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
};
|
|
@@ -441,6 +445,12 @@ var UnityLockChecker = class {
|
|
|
441
445
|
return "allow";
|
|
442
446
|
}
|
|
443
447
|
};
|
|
448
|
+
var UnityLockStatusReader = class {
|
|
449
|
+
async isLocked(projectPath) {
|
|
450
|
+
const lockfilePath = join3(projectPath, "Temp", "UnityLockfile");
|
|
451
|
+
return await pathExists(lockfilePath);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
444
454
|
|
|
445
455
|
// src/presentation/App.tsx
|
|
446
456
|
import clipboard from "clipboardy";
|
|
@@ -530,10 +540,12 @@ var formatUpdatedText = (lastModified) => {
|
|
|
530
540
|
var homeDirectory = process.env.HOME ?? "";
|
|
531
541
|
var homePrefix = homeDirectory ? `${homeDirectory}/` : "";
|
|
532
542
|
var minimumVisibleProjectCount = 4;
|
|
533
|
-
var defaultHintMessage = "Move with arrows or j/k \xB7 Launch
|
|
543
|
+
var defaultHintMessage = "Move with arrows or j/k \xB7 Launch with o \xB7 Copy cd path with c \xB7 Exit with Ctrl+C";
|
|
534
544
|
var PROJECT_COLOR = "#abd8e7";
|
|
535
545
|
var BRANCH_COLOR = "#e3839c";
|
|
536
546
|
var PATH_COLOR = "#719bd8";
|
|
547
|
+
var LOCK_COLOR = "yellow";
|
|
548
|
+
var LOCK_LABEL = "[running]";
|
|
537
549
|
var shortenHomePath = (targetPath) => {
|
|
538
550
|
if (!homeDirectory) {
|
|
539
551
|
return targetPath;
|
|
@@ -562,7 +574,6 @@ var App = ({
|
|
|
562
574
|
const [visibleCount, setVisibleCount] = useState(minimumVisibleProjectCount);
|
|
563
575
|
const [index, setIndex] = useState(0);
|
|
564
576
|
const [hint, setHint] = useState(defaultHintMessage);
|
|
565
|
-
const [pendingExit, setPendingExit] = useState(false);
|
|
566
577
|
const [windowStart, setWindowStart] = useState(0);
|
|
567
578
|
const linesPerProject = (showBranch ? 1 : 0) + (showPath ? 1 : 0) + 2;
|
|
568
579
|
const sortedProjects = useMemo(() => {
|
|
@@ -596,22 +607,13 @@ var App = ({
|
|
|
596
607
|
}, [projects, useGitRootName]);
|
|
597
608
|
useEffect(() => {
|
|
598
609
|
const handleSigint = () => {
|
|
599
|
-
if (!pendingExit) {
|
|
600
|
-
setPendingExit(true);
|
|
601
|
-
setHint("Press Ctrl+C again to exit");
|
|
602
|
-
setTimeout(() => {
|
|
603
|
-
setPendingExit(false);
|
|
604
|
-
setHint(defaultHintMessage);
|
|
605
|
-
}, 2e3);
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
610
|
exit();
|
|
609
611
|
};
|
|
610
612
|
process.on("SIGINT", handleSigint);
|
|
611
613
|
return () => {
|
|
612
614
|
process.off("SIGINT", handleSigint);
|
|
613
615
|
};
|
|
614
|
-
}, [exit
|
|
616
|
+
}, [exit]);
|
|
615
617
|
useEffect(() => {
|
|
616
618
|
const updateVisibleCount = () => {
|
|
617
619
|
if (!stdout || typeof stdout.columns !== "number" || typeof stdout.rows !== "number") {
|
|
@@ -723,7 +725,7 @@ var App = ({
|
|
|
723
725
|
setHint(defaultHintMessage);
|
|
724
726
|
}, 2e3);
|
|
725
727
|
}, [index, sortedProjects]);
|
|
726
|
-
const
|
|
728
|
+
const launchSelected = useCallback(async () => {
|
|
727
729
|
const projectView = sortedProjects[index];
|
|
728
730
|
if (!projectView) {
|
|
729
731
|
setHint("No project to launch");
|
|
@@ -746,8 +748,10 @@ var App = ({
|
|
|
746
748
|
}
|
|
747
749
|
try {
|
|
748
750
|
await onLaunch(project);
|
|
749
|
-
|
|
750
|
-
|
|
751
|
+
setHint(`Launched: ${project.title}`);
|
|
752
|
+
setTimeout(() => {
|
|
753
|
+
setHint(defaultHintMessage);
|
|
754
|
+
}, 3e3);
|
|
751
755
|
} catch (error) {
|
|
752
756
|
if (error instanceof LaunchCancelledError) {
|
|
753
757
|
setHint("Launch cancelled");
|
|
@@ -762,7 +766,7 @@ var App = ({
|
|
|
762
766
|
setHint(defaultHintMessage);
|
|
763
767
|
}, 3e3);
|
|
764
768
|
}
|
|
765
|
-
}, [
|
|
769
|
+
}, [index, onLaunch, sortedProjects]);
|
|
766
770
|
useInput((input, key) => {
|
|
767
771
|
if (input === "j" || key.downArrow) {
|
|
768
772
|
move(1);
|
|
@@ -771,7 +775,7 @@ var App = ({
|
|
|
771
775
|
move(-1);
|
|
772
776
|
}
|
|
773
777
|
if (input === "o") {
|
|
774
|
-
void
|
|
778
|
+
void launchSelected();
|
|
775
779
|
}
|
|
776
780
|
if (input === "c") {
|
|
777
781
|
copyProjectPath();
|
|
@@ -820,7 +824,7 @@ var App = ({
|
|
|
820
824
|
});
|
|
821
825
|
}, [linesPerProject, projects.length, startIndex, visibleProjects]);
|
|
822
826
|
const rows = useMemo(() => {
|
|
823
|
-
return visibleProjects.map(({ project, repository }, offset) => {
|
|
827
|
+
return visibleProjects.map(({ project, repository, isLocked }, offset) => {
|
|
824
828
|
const rowIndex = startIndex + offset;
|
|
825
829
|
const isSelected = rowIndex === index;
|
|
826
830
|
const arrow = isSelected ? ">" : " ";
|
|
@@ -846,7 +850,8 @@ var App = ({
|
|
|
846
850
|
" ",
|
|
847
851
|
versionLabel
|
|
848
852
|
] }),
|
|
849
|
-
updatedText ? /* @__PURE__ */ jsx(Text, { color: isSelected ? "green" : void 0, children: ` ${updatedText}` }) : null
|
|
853
|
+
updatedText ? /* @__PURE__ */ jsx(Text, { color: isSelected ? "green" : void 0, children: ` ${updatedText}` }) : null,
|
|
854
|
+
isLocked ? /* @__PURE__ */ jsx(Text, { color: LOCK_COLOR, children: ` ${LOCK_LABEL}` }) : null
|
|
850
855
|
] }),
|
|
851
856
|
showBranch ? /* @__PURE__ */ jsxs(Text, { color: isSelected ? "green" : BRANCH_COLOR, children: [
|
|
852
857
|
" ",
|
|
@@ -878,10 +883,12 @@ import { jsx as jsx2 } from "react/jsx-runtime";
|
|
|
878
883
|
var bootstrap = async () => {
|
|
879
884
|
const unityHubReader = new UnityHubProjectsReader();
|
|
880
885
|
const gitRepositoryInfoReader = new GitRepositoryInfoReader();
|
|
886
|
+
const lockStatusReader = new UnityLockStatusReader();
|
|
881
887
|
const listProjectsUseCase = new ListProjectsUseCase(
|
|
882
888
|
unityHubReader,
|
|
883
889
|
gitRepositoryInfoReader,
|
|
884
|
-
unityHubReader
|
|
890
|
+
unityHubReader,
|
|
891
|
+
lockStatusReader
|
|
885
892
|
);
|
|
886
893
|
const editorPathResolver = new MacEditorPathResolver();
|
|
887
894
|
const processLauncher = new NodeProcessLauncher();
|
|
@@ -898,7 +905,7 @@ var bootstrap = async () => {
|
|
|
898
905
|
const showPath = !process2.argv.includes("--hide-path");
|
|
899
906
|
try {
|
|
900
907
|
const projects = await listProjectsUseCase.execute();
|
|
901
|
-
render(
|
|
908
|
+
const { waitUntilExit } = render(
|
|
902
909
|
/* @__PURE__ */ jsx2(
|
|
903
910
|
App,
|
|
904
911
|
{
|
|
@@ -910,6 +917,8 @@ var bootstrap = async () => {
|
|
|
910
917
|
}
|
|
911
918
|
)
|
|
912
919
|
);
|
|
920
|
+
await waitUntilExit();
|
|
921
|
+
process2.stdout.write("\x1B[2J\x1B[3J\x1B[H");
|
|
913
922
|
} catch (error) {
|
|
914
923
|
const message = error instanceof Error ? error.message : String(error);
|
|
915
924
|
console.error(message);
|