-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRepoFormModal.tsx
More file actions
4163 lines (3860 loc) · 202 KB
/
RepoFormModal.tsx
File metadata and controls
4163 lines (3860 loc) · 202 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React, { useState, useEffect, useMemo, useCallback, useRef } from 'react';
import type { Repository, Task, TaskStep, ProjectSuggestion, GitRepository, SvnRepository, LaunchConfig, WebLinkConfig, Commit, BranchInfo, PythonCapabilities, ProjectInfo, DelphiCapabilities, NodejsCapabilities, LazarusCapabilities, ReleaseInfo, DockerCapabilities, GoCapabilities, RustCapabilities, MavenCapabilities, DotnetCapabilities } from '../../types';
import { RepoStatus, BuildHealth, TaskStepType, VcsType } from '../../types';
import { PlusIcon } from '../icons/PlusIcon';
import { TrashIcon } from '../icons/TrashIcon';
import { ArrowLeftIcon } from '../icons/ArrowLeftIcon';
import { ArrowUpIcon } from '../icons/ArrowUpIcon';
import { ArrowDownIcon } from '../icons/ArrowDownIcon';
import { ArrowDownTrayIcon } from '../icons/ArrowDownTrayIcon';
import { CloudArrowDownIcon } from '../icons/CloudArrowDownIcon';
import { ArrowRightOnRectangleIcon } from '../icons/ArrowRightOnRectangleIcon';
import { ArchiveBoxIcon } from '../icons/ArchiveBoxIcon';
import { BeakerIcon } from '../icons/BeakerIcon';
import { CubeTransparentIcon } from '../icons/CubeTransparentIcon';
import { CodeBracketIcon } from '../icons/CodeBracketIcon';
import { VariableIcon } from '../icons/VariableIcon';
import { DocumentTextIcon } from '../icons/DocumentTextIcon';
import { GitBranchIcon } from '../icons/GitBranchIcon';
import { ExclamationCircleIcon } from '../icons/ExclamationCircleIcon';
// FIX: Import the missing ExclamationTriangleIcon component.
import { ExclamationTriangleIcon } from '../icons/ExclamationTriangleIcon';
import { useTooltip } from '../../hooks/useTooltip';
import { useLogger } from '../../hooks/useLogger';
import { MagnifyingGlassIcon } from '../icons/MagnifyingGlassIcon';
import { PythonIcon } from '../icons/PythonIcon';
import { NodeIcon } from '../icons/NodeIcon';
import { DockerIcon } from '../icons/DockerIcon';
import { FolderOpenIcon } from '../icons/FolderOpenIcon';
import { DocumentDuplicateIcon } from '../icons/DocumentDuplicateIcon';
import { ServerIcon } from '../icons/ServerIcon';
import { TagIcon } from '../icons/TagIcon';
import { CubeIcon } from '../icons/CubeIcon';
import { ChevronsUpIcon } from '../icons/ChevronsUpIcon';
import { ChevronsDownIcon } from '../icons/ChevronsDownIcon';
import { ChevronDownIcon } from '../icons/ChevronDownIcon';
import { ChevronRightIcon } from '../icons/ChevronRightIcon';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { PencilIcon } from '../icons/PencilIcon';
import { ArrowPathIcon } from '../icons/ArrowPathIcon';
import type { StatusBarMessage } from '../StatusBar';
interface RepoEditViewProps {
onSave: (repository: Repository, categoryId?: string) => void;
onCancel: () => void;
repository: Repository | null;
onRefreshState: (repoId: string) => Promise<void>;
setToast: (toast: { message: string; type: 'success' | 'error' | 'info' } | null) => void;
setStatusBarMessage?: (message: StatusBarMessage | null) => void;
confirmAction: (options: {
title: string;
message: React.ReactNode;
onConfirm: () => void;
onCancel?: () => void;
confirmText?: string;
confirmButtonClass?: string;
icon?: React.ReactNode;
}) => void;
defaultCategoryId?: string;
onOpenWeblink: (url: string) => void;
detectedExecutables: Record<string, string[]>;
}
const NEW_REPO_TEMPLATE: Omit<GitRepository, 'id'> = {
name: '',
remoteUrl: '',
localPath: '',
webLinks: [],
branch: 'main',
status: RepoStatus.Idle,
lastUpdated: null,
buildHealth: BuildHealth.Unknown,
tasks: [],
vcs: VcsType.Git,
launchConfigs: [],
ignoreDirty: false,
};
const STEP_DEFINITIONS: Record<TaskStepType, { label: string; icon: React.ComponentType<{className: string}>; description: string }> = {
[TaskStepType.GitPull]: { label: 'Git Pull', icon: ArrowDownTrayIcon, description: 'Pull latest changes from remote.' },
[TaskStepType.GitFetch]: { label: 'Git Fetch', icon: CloudArrowDownIcon, description: 'Fetch updates from remote.' },
[TaskStepType.GitCheckout]: { label: 'Git Checkout', icon: ArrowRightOnRectangleIcon, description: 'Switch to a specific branch.' },
[TaskStepType.GitStash]: { label: 'Git Stash', icon: ArchiveBoxIcon, description: 'Stash uncommitted local changes.' },
[TaskStepType.SvnUpdate]: { label: 'SVN Update', icon: ArrowDownTrayIcon, description: 'Update working copy to latest revision.' },
[TaskStepType.SvnSwitch]: { label: 'SVN Switch', icon: ArrowRightOnRectangleIcon, description: 'Switch working copy to a different branch or URL.' },
[TaskStepType.RunCommand]: { label: 'Run Command', icon: CodeBracketIcon, description: 'Execute a custom shell command.' },
// Delphi
[TaskStepType.DelphiBuild]: { label: 'Delphi Build', icon: BeakerIcon, description: 'Build, rebuild, or clean a Delphi project.' },
[TaskStepType.DELPHI_BOSS_INSTALL]: { label: 'Delphi: Boss Install', icon: ArchiveBoxIcon, description: 'Install dependencies using the Boss package manager.' },
[TaskStepType.DELPHI_PACKAGE_INNO]: { label: 'Delphi: Package (Inno)', icon: ArchiveBoxIcon, description: 'Create an installer using an Inno Setup script.' },
[TaskStepType.DELPHI_PACKAGE_NSIS]: { label: 'Delphi: Package (NSIS)', icon: ArchiveBoxIcon, description: 'Create an installer using an NSIS script.' },
[TaskStepType.DELPHI_TEST_DUNITX]: { label: 'Delphi: Run DUnitX Tests', icon: BeakerIcon, description: 'Execute a DUnitX test application.' },
// Go
[TaskStepType.GO_MOD_TIDY]: { label: 'Go: Mod Tidy', icon: CodeBracketIcon, description: 'Run go mod tidy to sync module requirements.' },
[TaskStepType.GO_FMT]: { label: 'Go: Format', icon: CodeBracketIcon, description: 'Format Go sources with go fmt ./...' },
[TaskStepType.GO_TEST]: { label: 'Go: Test', icon: BeakerIcon, description: 'Execute go test ./... across the project.' },
[TaskStepType.GO_BUILD]: { label: 'Go: Build', icon: CodeBracketIcon, description: 'Compile all packages with go build ./...' },
// Rust
[TaskStepType.RUST_CARGO_FMT]: { label: 'Rust: Cargo Fmt', icon: CodeBracketIcon, description: 'Format the workspace with cargo fmt --all.' },
[TaskStepType.RUST_CARGO_CLIPPY]: { label: 'Rust: Cargo Clippy', icon: BeakerIcon, description: 'Run cargo clippy with --all-targets and fail on warnings.' },
[TaskStepType.RUST_CARGO_CHECK]: { label: 'Rust: Cargo Check', icon: CodeBracketIcon, description: 'Type-check the project with cargo check --all-targets.' },
[TaskStepType.RUST_CARGO_TEST]: { label: 'Rust: Cargo Test', icon: BeakerIcon, description: 'Run cargo test --all-targets --all-features.' },
[TaskStepType.RUST_CARGO_BUILD]: { label: 'Rust: Cargo Build', icon: CodeBracketIcon, description: 'Build the project with cargo build --release.' },
// Java / Maven
[TaskStepType.MAVEN_CLEAN]: { label: 'Maven: Clean', icon: DocumentTextIcon, description: 'Run mvn clean (or ./mvnw clean if available).' },
[TaskStepType.MAVEN_TEST]: { label: 'Maven: Test', icon: DocumentTextIcon, description: 'Run mvn test to execute the project test suite.' },
[TaskStepType.MAVEN_PACKAGE]: { label: 'Maven: Package', icon: DocumentTextIcon, description: 'Run mvn package to build distributables.' },
// .NET
[TaskStepType.DOTNET_RESTORE]: { label: '.NET: Restore', icon: CubeIcon, description: 'Restore NuGet dependencies with dotnet restore.' },
[TaskStepType.DOTNET_BUILD]: { label: '.NET: Build', icon: CubeIcon, description: 'Build the solution with dotnet build --configuration Release.' },
[TaskStepType.DOTNET_TEST]: { label: '.NET: Test', icon: CubeIcon, description: 'Run dotnet test with diagnostics-friendly output.' },
// Python
[TaskStepType.PYTHON_CREATE_VENV]: { label: 'Python: Create Venv', icon: PythonIcon, description: 'Create a .venv virtual environment.' },
[TaskStepType.PYTHON_INSTALL_DEPS]: { label: 'Python: Install Deps', icon: PythonIcon, description: 'Install dependencies using the detected manager.' },
[TaskStepType.PYTHON_RUN_LINT]: { label: 'Python: Run Linting', icon: PythonIcon, description: 'Run all detected linters (e.g., Ruff).' },
[TaskStepType.PYTHON_RUN_FORMAT]: { label: 'Python: Run Formatting', icon: PythonIcon, description: 'Run all detected formatters (e.g., Black, isort).' },
[TaskStepType.PYTHON_RUN_TYPECHECK]: { label: 'Python: Run Type Check', icon: PythonIcon, description: 'Run all detected type checkers (e.g., Mypy).' },
[TaskStepType.PYTHON_RUN_TESTS]: { label: 'Python: Run Tests', icon: PythonIcon, description: 'Run tests using the detected framework (e.g., Pytest).' },
[TaskStepType.PYTHON_RUN_BUILD]: { label: 'Python: Build Package', icon: PythonIcon, description: 'Build wheel and sdist using the detected backend.' },
// Node.js
[TaskStepType.NODE_INSTALL_DEPS]: { label: 'Node: Install Deps', icon: NodeIcon, description: 'Install dependencies using the detected package manager.' },
[TaskStepType.NODE_RUN_LINT]: { label: 'Node: Run Linting', icon: NodeIcon, description: 'Run ESLint and Prettier to find issues.' },
[TaskStepType.NODE_RUN_FORMAT]: { label: 'Node: Format Code', icon: NodeIcon, description: 'Format code using Prettier and ESLint.' },
[TaskStepType.NODE_RUN_TYPECHECK]: { label: 'Node: Type Check', icon: NodeIcon, description: 'Run the TypeScript compiler to check for type errors.' },
[TaskStepType.NODE_RUN_TESTS]: { label: 'Node: Run Tests', icon: NodeIcon, description: 'Run unit/integration tests with Jest or Vitest.' },
[TaskStepType.NODE_RUN_BUILD]: { label: 'Node: Build Project', icon: NodeIcon, description: 'Run the build script or detected bundler.' },
// Lazarus/FPC
[TaskStepType.LAZARUS_BUILD]: { label: 'Lazarus: Build Project', icon: BeakerIcon, description: 'Build a Lazarus project (.lpi) using lazbuild.' },
[TaskStepType.LAZARUS_BUILD_PACKAGE]: { label: 'Lazarus: Build Package', icon: BeakerIcon, description: 'Build a Lazarus package (.lpk) using lazbuild.' },
[TaskStepType.FPC_TEST_FPCUNIT]: { label: 'Lazarus: Run FPCUnit Tests', icon: BeakerIcon, description: 'Build and run an FPCUnit test project.' },
// Docker
[TaskStepType.DOCKER_BUILD_IMAGE]: { label: 'Docker: Build Image', icon: DockerIcon, description: 'Build a Docker image from a Dockerfile.' },
[TaskStepType.DOCKER_COMPOSE_UP]: { label: 'Docker: Compose Up', icon: DockerIcon, description: 'Create and start containers with Docker Compose.' },
[TaskStepType.DOCKER_COMPOSE_DOWN]: { label: 'Docker: Compose Down', icon: DockerIcon, description: 'Stop and remove containers with Docker Compose.' },
[TaskStepType.DOCKER_COMPOSE_BUILD]: { label: 'Docker: Compose Build', icon: DockerIcon, description: 'Build or rebuild services with Docker Compose.' },
};
const STEPS_WITH_DETAILS = new Set<TaskStepType>([
TaskStepType.GitCheckout,
TaskStepType.SvnSwitch,
TaskStepType.DelphiBuild,
TaskStepType.LAZARUS_BUILD,
TaskStepType.LAZARUS_BUILD_PACKAGE,
TaskStepType.FPC_TEST_FPCUNIT,
TaskStepType.DELPHI_PACKAGE_INNO,
TaskStepType.DELPHI_PACKAGE_NSIS,
TaskStepType.DELPHI_TEST_DUNITX,
TaskStepType.RunCommand,
]);
const STEP_CATEGORIES = [
{ name: 'General', types: [TaskStepType.RunCommand] },
{ name: 'Git', types: [TaskStepType.GitPull, TaskStepType.GitFetch, TaskStepType.GitCheckout, TaskStepType.GitStash] },
{ name: 'SVN', types: [TaskStepType.SvnUpdate, TaskStepType.SvnSwitch] },
{ name: 'Node.js', types: [TaskStepType.NODE_INSTALL_DEPS, TaskStepType.NODE_RUN_BUILD, TaskStepType.NODE_RUN_TESTS, TaskStepType.NODE_RUN_LINT, TaskStepType.NODE_RUN_FORMAT, TaskStepType.NODE_RUN_TYPECHECK] },
{ name: 'Go', types: [TaskStepType.GO_MOD_TIDY, TaskStepType.GO_FMT, TaskStepType.GO_TEST, TaskStepType.GO_BUILD] },
{ name: 'Rust', types: [TaskStepType.RUST_CARGO_FMT, TaskStepType.RUST_CARGO_CLIPPY, TaskStepType.RUST_CARGO_CHECK, TaskStepType.RUST_CARGO_TEST, TaskStepType.RUST_CARGO_BUILD] },
{ name: 'Java / Maven', types: [TaskStepType.MAVEN_CLEAN, TaskStepType.MAVEN_TEST, TaskStepType.MAVEN_PACKAGE] },
{ name: '.NET', types: [TaskStepType.DOTNET_RESTORE, TaskStepType.DOTNET_BUILD, TaskStepType.DOTNET_TEST] },
{ name: 'Python', types: [TaskStepType.PYTHON_CREATE_VENV, TaskStepType.PYTHON_INSTALL_DEPS, TaskStepType.PYTHON_RUN_BUILD, TaskStepType.PYTHON_RUN_TESTS, TaskStepType.PYTHON_RUN_LINT, TaskStepType.PYTHON_RUN_FORMAT, TaskStepType.PYTHON_RUN_TYPECHECK] },
{ name: 'Delphi', types: [TaskStepType.DelphiBuild, TaskStepType.DELPHI_BOSS_INSTALL, TaskStepType.DELPHI_PACKAGE_INNO, TaskStepType.DELPHI_PACKAGE_NSIS, TaskStepType.DELPHI_TEST_DUNITX] },
{ name: 'Lazarus/FPC', types: [TaskStepType.LAZARUS_BUILD, TaskStepType.LAZARUS_BUILD_PACKAGE, TaskStepType.FPC_TEST_FPCUNIT] },
{ name: 'Docker', types: [TaskStepType.DOCKER_BUILD_IMAGE, TaskStepType.DOCKER_COMPOSE_UP, TaskStepType.DOCKER_COMPOSE_DOWN, TaskStepType.DOCKER_COMPOSE_BUILD] },
];
const PROTECTED_BRANCH_IDENTIFIERS = new Set(['main', 'origin', 'origin/main']);
const parseRemoteBranchIdentifier = (fullBranchName: string): { remoteName: string; branchName: string } | null => {
const [remoteName, ...rest] = fullBranchName.split('/');
if (!remoteName || rest.length === 0) {
return null;
}
return { remoteName, branchName: rest.join('/') };
};
const formatBranchSelectionLabel = (selection: { name: string; scope: 'local' | 'remote' } | string, scopeOverride?: 'local' | 'remote'): string => {
if (typeof selection === 'string') {
const scope = scopeOverride ?? 'local';
if (scope === 'remote') {
const remoteDetails = parseRemoteBranchIdentifier(selection);
if (remoteDetails) {
return `${remoteDetails.remoteName}/${remoteDetails.branchName}`;
}
}
return selection;
}
if (selection.scope === 'remote') {
const remoteDetails = parseRemoteBranchIdentifier(selection.name);
if (remoteDetails) {
return `${remoteDetails.remoteName}/${remoteDetails.branchName}`;
}
}
return selection.name;
};
const isProtectedBranch = (branchIdentifier: string, scope: 'local' | 'remote'): boolean => {
const normalized = branchIdentifier.trim().toLowerCase();
if (PROTECTED_BRANCH_IDENTIFIERS.has(normalized)) {
return true;
}
if (scope === 'remote') {
const remoteDetails = parseRemoteBranchIdentifier(branchIdentifier);
if (remoteDetails) {
const remoteNormalized = remoteDetails.remoteName.trim().toLowerCase();
const branchNormalized = remoteDetails.branchName.trim().toLowerCase();
const composite = `${remoteNormalized}/${branchNormalized}`;
if (PROTECTED_BRANCH_IDENTIFIERS.has(composite)) {
return true;
}
if (remoteNormalized === 'origin' && PROTECTED_BRANCH_IDENTIFIERS.has(branchNormalized)) {
return true;
}
}
}
return false;
};
// Component for a single step in the TaskStepsEditor
const TaskStepItem: React.FC<{
step: TaskStep;
index: number;
totalSteps: number;
onStepChange: (id: string, updates: Partial<TaskStep>) => void;
onMoveStep: (index: number, direction: 'up' | 'down' | 'top' | 'bottom') => void;
onRemoveStep: (id: string) => void;
onDuplicateStep: (index: number) => void;
suggestions: ProjectSuggestion[];
projectInfo: ProjectInfo | null;
delphiVersions: { name: string; version: string }[];
collapsed: boolean;
onCollapsedChange: (id: string, collapsed: boolean) => void;
}> = ({
step,
index,
totalSteps,
onStepChange,
onMoveStep,
onRemoveStep,
onDuplicateStep,
suggestions,
projectInfo,
delphiVersions,
collapsed,
onCollapsedChange,
}) => {
const logger = useLogger();
const stepDef = STEP_DEFINITIONS[step.type];
const isEnabled = step.enabled ?? true;
const hasDetails = STEPS_WITH_DETAILS.has(step.type);
const detailsId = useMemo(() => `task-step-${step.id}-details`, [step.id]);
// --- HOOKS MOVED TO TOP ---
const toggleTooltip = useTooltip(isEnabled ? 'Disable Step' : 'Enable Step');
const duplicateTooltip = useTooltip('Duplicate Step');
const moveToTopTooltip = useTooltip('Move Step to Top');
const moveToBottomTooltip = useTooltip('Move Step to Bottom');
const canCollapse = hasDetails;
const isCollapsed = canCollapse ? collapsed : false;
useEffect(() => {
if (!canCollapse && collapsed) {
onCollapsedChange(step.id, false);
}
}, [canCollapse, collapsed, onCollapsedChange, step.id]);
const selectedDelphiProject = useMemo(() => {
return projectInfo?.delphi?.projects.find(p => p.path === step.delphiProjectFile);
}, [projectInfo?.delphi?.projects, step.delphiProjectFile]);
const allDelphiPlatforms = useMemo(() => {
const platformSet = new Set<string>();
(projectInfo?.delphi?.projects || []).forEach(p => {
p.platforms.forEach(platform => platformSet.add(platform));
});
return Array.from(platformSet).sort();
}, [projectInfo?.delphi?.projects]);
const allDelphiConfigs = useMemo(() => {
const configSet = new Set<string>();
(projectInfo?.delphi?.projects || []).forEach(p => {
p.configs.forEach(config => configSet.add(config));
});
return Array.from(configSet).sort();
}, [projectInfo?.delphi?.projects]);
// Log invalid steps inside a useEffect to prevent render loops.
useEffect(() => {
if (!stepDef) {
logger.error('Invalid step type encountered in TaskStepItem. This may be due to malformed data.', { step });
}
}, [step, stepDef, logger]);
useEffect(() => {
if (selectedDelphiProject) {
if (step.delphiConfiguration && !selectedDelphiProject.configs.includes(step.delphiConfiguration)) {
onStepChange(step.id, { delphiConfiguration: '' });
}
if (step.delphiPlatform && !selectedDelphiProject.platforms.includes(step.delphiPlatform)) {
onStepChange(step.id, { delphiPlatform: '' });
}
}
}, [selectedDelphiProject, step.delphiConfiguration, step.delphiPlatform, onStepChange, step.id]);
// --- END HOOKS MOVED TO TOP ---
if (!stepDef) {
return (
<div className="bg-red-50 dark:bg-red-900/40 p-3 rounded-lg border border-red-200 dark:border-red-700 space-y-2 text-red-700 dark:text-red-300">
<div className="flex items-center gap-3">
<ExclamationCircleIcon className="h-6 w-6"/>
<div>
<p className="font-semibold">Invalid Step Type</p>
<p className="text-xs">The step type '{step.type}' is not recognized. This step may be from an older version or corrupted. Please remove it.</p>
</div>
<button type="button" onClick={() => onRemoveStep(step.id)} className="ml-auto p-1.5 text-red-500 hover:bg-red-100 dark:hover:bg-red-900/50 rounded-full"><TrashIcon className="h-4 w-4" /></button>
</div>
</div>
);
}
const { label, icon: Icon } = stepDef;
const formInputStyle = "mt-1 block w-full bg-gray-50 dark:bg-gray-900 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm py-1.5 px-3 text-gray-900 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500";
const CUSTOM_COMMAND_VALUE = 'custom_command';
const availablePlatforms = selectedDelphiProject ? selectedDelphiProject.platforms : allDelphiPlatforms;
const availableConfigs = selectedDelphiProject ? selectedDelphiProject.configs : allDelphiConfigs;
const DelphiVersionSelector: React.FC = () => (
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Compiler Version</label>
<select
value={step.delphiVersion || ''}
onChange={(e) => onStepChange(step.id, { delphiVersion: e.target.value })}
className={formInputStyle}
>
<option value="">Default (from PATH)</option>
{delphiVersions.map(v => (
<option key={v.version} value={v.version}>{v.name}</option>
))}
</select>
</div>
);
const detailFields = (
<>
{(step.type === TaskStepType.GitCheckout || step.type === TaskStepType.SvnSwitch) && (
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">
{step.type === TaskStepType.GitCheckout ? 'Branch Name' : 'Switch Target'}
</label>
<input
type="text"
placeholder={step.type === TaskStepType.GitCheckout ? 'e.g., main' : 'e.g., ^/branches/release/1.2'}
value={step.branch || ''}
onChange={(e) => onStepChange(step.id, { branch: e.target.value })}
required
className={formInputStyle}
/>
</div>
)}
{step.type === TaskStepType.DelphiBuild && (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Project/Group File</label>
<select
value={step.delphiProjectFile || ''}
onChange={(e) => onStepChange(step.id, { delphiProjectFile: e.target.value })}
className={formInputStyle}
>
<option value="">Auto-detect</option>
<optgroup label="Projects">
{(projectInfo?.delphi?.projects || []).map(p => (
<option key={p.path} value={p.path}>{p.path}</option>
))}
</optgroup>
<optgroup label="Project Groups">
{/* FIX: Use Array.isArray as a type guard because the type from the Electron API might be unknown at compile time. */}
{Array.isArray(projectInfo?.delphi?.groups) && projectInfo?.delphi.groups.map(g => (
<option key={g} value={g}>{g}</option>
))}
</optgroup>
</select>
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Mode</label>
<select
value={step.delphiBuildMode || 'Build'}
onChange={(e) => onStepChange(step.id, { delphiBuildMode: e.target.value as any })}
className={formInputStyle}
>
<option>Build</option>
<option>Rebuild</option>
<option>Clean</option>
</select>
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Configuration</label>
<select
value={step.delphiConfiguration || ''}
onChange={(e) => onStepChange(step.id, { delphiConfiguration: e.target.value })}
className={formInputStyle}
disabled={availableConfigs.length === 0}
>
<option value="">Default</option>
{availableConfigs.map(config => (
<option key={config} value={config}>{config}</option>
))}
</select>
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Platform</label>
<select
value={step.delphiPlatform || ''}
onChange={(e) => onStepChange(step.id, { delphiPlatform: e.target.value })}
className={formInputStyle}
disabled={availablePlatforms.length === 0}
>
<option value="">Default</option>
{availablePlatforms.map(platform => (
<option key={platform} value={platform}>{platform}</option>
))}
</select>
</div>
<DelphiVersionSelector />
</div>
)}
{step.type === TaskStepType.LAZARUS_BUILD && (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4">
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Project File (.lpi)</label>
<select
value={step.lazarusProjectFile || ''}
onChange={(e) => onStepChange(step.id, { lazarusProjectFile: e.target.value })}
className={formInputStyle}
>
<option value="">Auto-detect</option>
{(projectInfo?.lazarus?.projects || []).map(p => (
<option key={p.path} value={p.path}>{p.path}</option>
))}
</select>
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Build Mode</label>
<input type="text" placeholder="e.g., Release" value={step.lazarusBuildMode || ''} onChange={(e) => onStepChange(step.id, { lazarusBuildMode: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Target CPU</label>
<input type="text" placeholder="e.g., x86_64" value={step.lazarusCpu || ''} onChange={(e) => onStepChange(step.id, { lazarusCpu: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Target OS</label>
<input type="text" placeholder="e.g., win64" value={step.lazarusOs || ''} onChange={(e) => onStepChange(step.id, { lazarusOs: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Widgetset</label>
<input type="text" placeholder="e.g., qt5" value={step.lazarusWidgetset || ''} onChange={(e) => onStepChange(step.id, { lazarusWidgetset: e.target.value })} className={formInputStyle} />
</div>
</div>
)}
{step.type === TaskStepType.LAZARUS_BUILD_PACKAGE && (
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Package File (.lpk)</label>
<select
value={step.lazarusPackageFile || ''}
onChange={(e) => onStepChange(step.id, { lazarusPackageFile: e.target.value })}
className={formInputStyle}
>
<option value="">Auto-detect</option>
{(projectInfo?.lazarus?.packages || []).map(p => (
<option key={p} value={p}>{p}</option>
))}
</select>
</div>
)}
{step.type === TaskStepType.FPC_TEST_FPCUNIT && (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Test Project File (.lpi)</label>
<input type="text" placeholder="e.g., tests/MyTests.lpi" value={step.lazarusProjectFile || ''} onChange={(e) => onStepChange(step.id, { lazarusProjectFile: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">JUnit XML Output File (optional)</label>
<input type="text" placeholder="e.g., reports/junit.xml" value={step.fpcTestOutputFile || ''} onChange={(e) => onStepChange(step.id, { fpcTestOutputFile: e.target.value })} className={formInputStyle} />
</div>
</div>
)}
{(step.type === TaskStepType.DELPHI_PACKAGE_INNO || step.type === TaskStepType.DELPHI_PACKAGE_NSIS) && (
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Installer Script File</label>
<input type="text" placeholder="e.g., scripts/installer.iss" value={step.delphiInstallerScript || ''} onChange={(e) => onStepChange(step.id, { delphiInstallerScript: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Defines (semicolon-separated)</label>
<input type="text" placeholder="e.g., AppVersion=1.0;Mode=PRO" value={step.delphiInstallerDefines || ''} onChange={(e) => onStepChange(step.id, { delphiInstallerDefines: e.target.value })} className={formInputStyle} />
</div>
<DelphiVersionSelector />
</div>
)}
{step.type === TaskStepType.DELPHI_TEST_DUNITX && (
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Test Executable Path</label>
<input type="text" placeholder="e.g., bin/Win32/Release/Tests.exe" value={step.delphiTestExecutable || ''} onChange={(e) => onStepChange(step.id, { delphiTestExecutable: e.target.value })} className={formInputStyle} />
</div>
<div>
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">JUnit XML Output File (optional)</label>
<input type="text" placeholder="e.g., reports/junit.xml" value={step.delphiTestOutputFile || ''} onChange={(e) => onStepChange(step.id, { delphiTestOutputFile: e.target.value })} className={formInputStyle} />
</div>
<DelphiVersionSelector />
</div>
)}
{step.type === TaskStepType.RunCommand && (() => {
const allPredefined = [...suggestions.map(s => s.value)];
const isCustom = !allPredefined.includes(step.command || '');
const selectValue = isCustom ? CUSTOM_COMMAND_VALUE : step.command;
const groupedSuggestions = suggestions.reduce((acc, suggestion) => {
(acc[suggestion.group] = acc[suggestion.group] || []).push(suggestion);
return acc;
}, {} as Record<string, ProjectSuggestion[]>);
const handleSelectChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newValue = e.target.value;
// When a predefined command is selected, update the step.
// When "Custom Command..." is selected, do nothing, preserving the current text for editing.
if (newValue !== CUSTOM_COMMAND_VALUE) {
onStepChange(step.id, { command: newValue });
}
};
return (
<div className="space-y-2">
<label className="text-xs font-medium text-gray-500 dark:text-gray-400">Command</label>
<select value={selectValue} onChange={handleSelectChange} className={formInputStyle}>
{Object.entries(groupedSuggestions).map(([groupName, suggestions]) => (
<optgroup key={groupName} label={groupName}>
{suggestions.map(s => <option key={s.value} value={s.value}>{s.label}</option>)}
</optgroup>
))}
<option value={CUSTOM_COMMAND_VALUE}>Custom Command...</option>
</select>
<textarea
placeholder={`e.g., npm run build -- --env=production\nUse \${VAR_NAME} for variables.`}
value={step.command || ''}
onChange={(e) => onStepChange(step.id, { command: e.target.value })}
required
className={`${formInputStyle} font-mono min-h-[5rem] text-sm`}
rows={3}
/>
</div>
);
})()}
</>
);
return (
<div className={`bg-white dark:bg-gray-800/50 px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 space-y-1.5 transition-opacity ${!isEnabled ? 'opacity-50' : ''}`}>
<div className="flex items-center justify-between gap-2.5">
<div className="flex items-center gap-1.5">
<div className="flex h-6 w-6 items-center justify-center">
{hasDetails ? (
<button
type="button"
onClick={() => onCollapsedChange(step.id, !isCollapsed)}
aria-label={`${isCollapsed ? 'Expand' : 'Collapse'} step details`}
aria-expanded={!isCollapsed}
aria-controls={detailsId}
className="p-0.5 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"
>
{isCollapsed ? <ChevronRightIcon className="h-4 w-4" /> : <ChevronDownIcon className="h-4 w-4" />}
</button>
) : null}
</div>
<Icon className="h-6 w-6 text-blue-500" />
<div>
<p className="font-semibold text-gray-800 dark:text-gray-200">{label}</p>
<p className="text-xs text-gray-500">Step {index + 1}</p>
</div>
</div>
<div className="flex items-center space-x-1.5">
<label {...toggleTooltip} className="relative inline-flex items-center cursor-pointer">
<input type="checkbox" checked={isEnabled} onChange={(e) => onStepChange(step.id, {enabled: e.target.checked})} className="sr-only peer" />
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-500/50 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
<button
{...moveToTopTooltip}
type="button"
onClick={() => onMoveStep(index, 'top')}
disabled={index === 0}
aria-label="Move step to top"
className="p-1 disabled:opacity-30 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"
>
<ChevronsUpIcon className="h-4 w-4" />
</button>
<button type="button" onClick={() => onMoveStep(index, 'up')} disabled={index === 0} className="p-1 disabled:opacity-30 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"><ArrowUpIcon className="h-4 w-4" /></button>
<button type="button" onClick={() => onMoveStep(index, 'down')} disabled={index === totalSteps - 1} className="p-1 disabled:opacity-30 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"><ArrowDownIcon className="h-4 w-4" /></button>
<button
{...moveToBottomTooltip}
type="button"
onClick={() => onMoveStep(index, 'bottom')}
disabled={index === totalSteps - 1}
aria-label="Move step to bottom"
className="p-1 disabled:opacity-30 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"
>
<ChevronsDownIcon className="h-4 w-4" />
</button>
<button {...duplicateTooltip} type="button" onClick={() => onDuplicateStep(index)} className="p-1 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full"><DocumentDuplicateIcon className="h-4 w-4" /></button>
<button type="button" onClick={() => onRemoveStep(step.id)} className="p-1 text-red-500 hover:bg-red-100 dark:hover:bg-red-900/50 rounded-full"><TrashIcon className="h-4 w-4" /></button>
</div>
</div>
{hasDetails ? (
<div id={detailsId} className={`mt-1.5 space-y-1.5 ${isCollapsed ? 'hidden' : ''}`}>
{detailFields}
</div>
) : (
detailFields
)}
</div>
);
};
// Component for managing task-level variables
const TaskVariablesEditor: React.FC<{
variables: Task['variables'];
onVariablesChange: (variables: Task['variables']) => void;
}> = ({ variables = [], onVariablesChange }) => {
const handleAddVariable = () => {
const newVar = { id: `var_${Date.now()}`, key: '', value: '' };
onVariablesChange([...variables, newVar]);
};
const handleUpdateVariable = (id: string, field: 'key' | 'value', fieldValue: string) => {
const newVariables = variables.map(v =>
v.id === id ? { ...v, [field]: fieldValue } : v
);
onVariablesChange(newVariables);
};
const handleRemoveVariable = (id: string) => {
onVariablesChange(variables.filter(v => v.id !== id));
};
const formInputStyle = "block w-full bg-gray-100 dark:bg-gray-900/50 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm py-1 px-2 text-sm text-gray-900 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500";
return (
<div className="p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<VariableIcon className="h-5 w-5 text-gray-500"/>
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Task Variables (Substitution)</h3>
</div>
<div className="space-y-2">
{variables.map((variable) => (
<div key={variable.id} className="flex items-center space-x-2">
<input
type="text"
placeholder="KEY"
value={variable.key}
onChange={(e) => handleUpdateVariable(variable.id, 'key', e.target.value)}
className={`${formInputStyle} font-mono uppercase`}
/>
<span className="text-gray-400">=</span>
<input
type="text"
placeholder="VALUE"
value={variable.value}
onChange={(e) => handleUpdateVariable(variable.id, 'value', e.target.value)}
className={formInputStyle}
/>
<button type="button" onClick={() => handleRemoveVariable(variable.id)} className="p-1.5 text-red-500 hover:bg-red-100 dark:hover:bg-red-900/50 rounded-full"><TrashIcon className="h-4 w-4" /></button>
</div>
))}
</div>
<button type="button" onClick={handleAddVariable} className="mt-3 flex items-center text-xs font-medium text-blue-600 dark:text-blue-400 hover:underline">
<PlusIcon className="h-3 w-3 mr-1"/> Add Variable
</button>
</div>
);
}
// Component for managing task-level environment variables
const TaskEnvironmentVariablesEditor: React.FC<{
variables: Task['environmentVariables'];
onVariablesChange: (variables: Task['environmentVariables']) => void;
}> = ({ variables = [], onVariablesChange }) => {
const handleAddVariable = () => {
const newVar = { id: `env_var_${Date.now()}`, key: '', value: '' };
onVariablesChange([...variables, newVar]);
};
const handleUpdateVariable = (id: string, field: 'key' | 'value', fieldValue: string) => {
const newVariables = variables.map(v =>
v.id === id ? { ...v, [field]: fieldValue } : v
);
onVariablesChange(newVariables);
};
const handleRemoveVariable = (id: string) => {
onVariablesChange(variables.filter(v => v.id !== id));
};
const formInputStyle = "block w-full bg-gray-100 dark:bg-gray-900/50 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm py-1 px-2 text-sm text-gray-900 dark:text-white focus:outline-none focus:ring-blue-500 focus:border-blue-500";
return (
<div className="p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<ServerIcon className="h-5 w-5 text-gray-500"/>
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Environment Variables</h3>
</div>
<p className="text-xs text-gray-500 mb-3">
These variables are set in the shell environment before step commands are executed. They can be accessed by scripts (e.g., as `process.env.VAR_NAME` in Node.js or `$VAR_NAME` in bash).
</p>
<div className="space-y-2">
{variables.map((variable) => (
<div key={variable.id} className="flex items-center space-x-2">
<input
type="text"
placeholder="KEY"
value={variable.key}
onChange={(e) => handleUpdateVariable(variable.id, 'key', e.target.value)}
className={`${formInputStyle} font-mono`}
/>
<span className="text-gray-400">=</span>
<input
type="text"
placeholder="VALUE (supports ${...} substitution)"
value={variable.value}
onChange={(e) => handleUpdateVariable(variable.id, 'value', e.target.value)}
className={formInputStyle}
/>
<button type="button" onClick={() => handleRemoveVariable(variable.id)} className="p-1.5 text-red-500 hover:bg-red-100 dark:hover:bg-red-900/50 rounded-full"><TrashIcon className="h-4 w-4" /></button>
</div>
))}
</div>
<button type="button" onClick={handleAddVariable} className="mt-3 flex items-center text-xs font-medium text-blue-600 dark:text-blue-400 hover:underline">
<PlusIcon className="h-3 w-3 mr-1"/> Add Environment Variable
</button>
</div>
);
}
const NodejsTaskGenerator: React.FC<{
nodejsCaps: NodejsCapabilities | undefined;
onAddTask: (task: Partial<Task>) => void;
}> = ({ nodejsCaps, onAddTask }) => {
if (!nodejsCaps) return null;
const createInstallTask = () => onAddTask({
name: 'Install Dependencies',
steps: [{ type: TaskStepType.NODE_INSTALL_DEPS, id: '', enabled: true }]
});
const createCiTask = () => {
const steps: Omit<TaskStep, 'id'>[] = [
{ type: TaskStepType.NODE_INSTALL_DEPS, enabled: true },
];
if (nodejsCaps.linters.includes('eslint') || nodejsCaps.linters.includes('prettier')) {
steps.push({ type: TaskStepType.NODE_RUN_LINT, enabled: true });
}
if (nodejsCaps.typescript) {
steps.push({ type: TaskStepType.NODE_RUN_TYPECHECK, enabled: true });
}
if (nodejsCaps.testFrameworks.length > 0) {
steps.push({ type: TaskStepType.NODE_RUN_TESTS, enabled: true });
}
steps.push({ type: TaskStepType.NODE_RUN_BUILD, enabled: true });
onAddTask({
name: 'CI Checks & Build',
steps: steps.map(s => ({...s, id: ''}))
});
};
let detectedManager = 'npm';
if (nodejsCaps.declaredManager) detectedManager = nodejsCaps.declaredManager.split('@')[0];
else if (nodejsCaps.packageManagers.pnpm) detectedManager = 'pnpm';
else if (nodejsCaps.packageManagers.yarn) detectedManager = 'yarn';
else if (nodejsCaps.packageManagers.bun) detectedManager = 'bun';
const detectedTools = [
`Manager: ${detectedManager}`,
...(nodejsCaps.typescript ? ['TypeScript'] : []),
...nodejsCaps.testFrameworks,
...nodejsCaps.linters,
...nodejsCaps.bundlers,
...(nodejsCaps.monorepo.turbo ? ['Turbo'] : []),
...(nodejsCaps.monorepo.nx ? ['NX'] : []),
].map(t => t.charAt(0).toUpperCase() + t.slice(1));
return (
<div className="p-3 mb-3 bg-green-50 dark:bg-gray-900/50 rounded-lg border border-green-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<NodeIcon className="h-5 w-5 text-green-500"/>
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Node.js Project Detected</h3>
</div>
<div className="text-xs text-gray-600 dark:text-gray-400 mb-3 flex flex-wrap gap-2">
{detectedTools.map(tool => (
<span key={tool} className="bg-green-100 dark:bg-green-900/50 text-green-800 dark:text-green-300 px-2 py-0.5 rounded-full">{tool}</span>
))}
</div>
<div className="flex gap-2">
<button type="button" onClick={createInstallTask} className="text-xs font-medium text-white bg-green-600 hover:bg-green-700 px-3 py-1.5 rounded-md">Add Install Task</button>
<button type="button" onClick={createCiTask} className="text-xs font-medium text-white bg-green-600 hover:bg-green-700 px-3 py-1.5 rounded-md">Add CI/Checks Task</button>
</div>
</div>
);
};
const GoTaskGenerator: React.FC<{
goCaps: GoCapabilities | undefined;
onAddTask: (task: Partial<Task>) => void;
}> = ({ goCaps, onAddTask }) => {
if (!goCaps) return null;
const getBasename = (p: string) => p.split(/[\\/]/).pop() || p;
const moduleBadges = goCaps.modules.map(m => `Module: ${m.module ?? getBasename(m.path)}`);
const versionBadges = Array.from(new Set(goCaps.modules.map(m => m.goVersion).filter((v): v is string => Boolean(v)))).map(v => `Go ${v}`);
const toolchainBadges = Array.from(new Set(goCaps.modules.map(m => m.toolchain).filter((v): v is string => Boolean(v)))).map(v => `Toolchain ${v}`);
const badges = [
...moduleBadges,
...versionBadges,
...toolchainBadges,
...(goCaps.hasGoWork ? ['go.work workspace'] : []),
...(goCaps.hasGoSum ? ['go.sum present'] : []),
...(goCaps.hasTests ? ['Tests detected'] : []),
];
const createTidyTask = () => onAddTask({
name: 'Go Mod Tidy',
steps: [{ type: TaskStepType.GO_MOD_TIDY, id: '', enabled: true }],
});
const createCiTask = () => {
const steps: Omit<TaskStep, 'id'>[] = [
{ type: TaskStepType.GO_MOD_TIDY, enabled: true },
{ type: TaskStepType.GO_FMT, enabled: true },
{ type: TaskStepType.GO_TEST, enabled: true },
{ type: TaskStepType.GO_BUILD, enabled: true },
];
onAddTask({
name: 'Go CI Checks',
steps: steps.map(step => ({ ...step, id: '' })),
});
};
return (
<div className="p-3 mb-3 bg-cyan-50 dark:bg-gray-900/50 rounded-lg border border-cyan-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<CodeBracketIcon className="h-5 w-5 text-cyan-500" />
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Go Project Detected</h3>
</div>
{badges.length > 0 && (
<div className="text-xs text-gray-600 dark:text-gray-400 mb-3 flex flex-wrap gap-2">
{badges.map(badge => (
<span key={badge} className="bg-cyan-100 dark:bg-cyan-900/50 text-cyan-800 dark:text-cyan-200 px-2 py-0.5 rounded-full">{badge}</span>
))}
</div>
)}
<div className="flex flex-wrap gap-2">
<button type="button" onClick={createTidyTask} className="text-xs font-medium text-white bg-cyan-600 hover:bg-cyan-700 px-3 py-1.5 rounded-md">Add Mod Tidy Task</button>
<button type="button" onClick={createCiTask} className="text-xs font-medium text-white bg-cyan-600 hover:bg-cyan-700 px-3 py-1.5 rounded-md">Add Go CI Task</button>
</div>
</div>
);
};
const RustTaskGenerator: React.FC<{
rustCaps: RustCapabilities | undefined;
onAddTask: (task: Partial<Task>) => void;
}> = ({ rustCaps, onAddTask }) => {
if (!rustCaps) return null;
const getBasename = (p: string) => p.split(/[\\/]/).pop() || p;
const packageBadges = rustCaps.packages.map(pkg => `Crate: ${pkg.name ?? getBasename(pkg.path)}`);
const editionBadges = Array.from(new Set(rustCaps.packages.map(pkg => pkg.edition).filter((v): v is string => Boolean(v)))).map(v => `Edition ${v}`);
const versionBadges = Array.from(new Set(rustCaps.packages.map(pkg => pkg.rustVersion).filter((v): v is string => Boolean(v)))).map(v => `Rust ${v}`);
const badges = [
...packageBadges,
...editionBadges,
...versionBadges,
...(rustCaps.hasWorkspace ? ['Workspace'] : []),
...(rustCaps.hasLockfile ? ['Cargo.lock'] : []),
...(rustCaps.hasTests ? ['Tests detected'] : []),
...(rustCaps.workspaceMembers.length > 0 ? [`Members: ${rustCaps.workspaceMembers.length}`] : []),
];
const createFmtTask = () => onAddTask({
name: 'Cargo Fmt',
steps: [{ type: TaskStepType.RUST_CARGO_FMT, id: '', enabled: true }],
});
const createClippyTask = () => onAddTask({
name: 'Cargo Clippy',
steps: [{ type: TaskStepType.RUST_CARGO_CLIPPY, id: '', enabled: true }],
});
const createCiTask = () => {
const steps: Omit<TaskStep, 'id'>[] = [
{ type: TaskStepType.RUST_CARGO_FMT, enabled: true },
{ type: TaskStepType.RUST_CARGO_CLIPPY, enabled: true },
{ type: TaskStepType.RUST_CARGO_CHECK, enabled: true },
{ type: TaskStepType.RUST_CARGO_TEST, enabled: true },
{ type: TaskStepType.RUST_CARGO_BUILD, enabled: true },
];
onAddTask({
name: 'Cargo CI Pipeline',
steps: steps.map(step => ({ ...step, id: '' })),
});
};
return (
<div className="p-3 mb-3 bg-amber-50 dark:bg-gray-900/50 rounded-lg border border-amber-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<CodeBracketIcon className="h-5 w-5 text-amber-500" />
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Rust Project Detected</h3>
</div>
{badges.length > 0 && (
<div className="text-xs text-gray-600 dark:text-gray-400 mb-3 flex flex-wrap gap-2">
{badges.map(badge => (
<span key={badge} className="bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-200 px-2 py-0.5 rounded-full">{badge}</span>
))}
</div>
)}
<div className="flex flex-wrap gap-2">
<button type="button" onClick={createFmtTask} className="text-xs font-medium text-white bg-amber-600 hover:bg-amber-700 px-3 py-1.5 rounded-md">Add Cargo Fmt Task</button>
<button type="button" onClick={createClippyTask} className="text-xs font-medium text-white bg-amber-600 hover:bg-amber-700 px-3 py-1.5 rounded-md">Add Cargo Clippy Task</button>
<button type="button" onClick={createCiTask} className="text-xs font-medium text-white bg-amber-600 hover:bg-amber-700 px-3 py-1.5 rounded-md">Add Cargo CI Task</button>
</div>
</div>
);
};
const MavenTaskGenerator: React.FC<{
mavenCaps: MavenCapabilities | undefined;
onAddTask: (task: Partial<Task>) => void;
}> = ({ mavenCaps, onAddTask }) => {
if (!mavenCaps) return null;
const getBasename = (p: string) => p.split(/[\\/]/).pop() || p;
const coordinates = mavenCaps.projects.map(project => {
if (project.groupId && project.artifactId) {
return `${project.groupId}:${project.artifactId}`;
}
return `POM: ${getBasename(project.path)}`;
});
const packagingBadges = Array.from(new Set(mavenCaps.projects.map(project => project.packaging).filter((v): v is string => Boolean(v)))).map(v => `Packaging: ${v}`);
const javaBadges = Array.from(new Set(mavenCaps.projects.map(project => project.javaVersion).filter((v): v is string => Boolean(v)))).map(v => `Java ${v}`);
const badges = [
...coordinates,
...packagingBadges,
...javaBadges,
...(mavenCaps.hasWrapper ? ['Maven Wrapper'] : []),
];
const createCleanTask = () => onAddTask({
name: 'Maven Clean',
steps: [{ type: TaskStepType.MAVEN_CLEAN, id: '', enabled: true }],
});
const createTestTask = () => onAddTask({
name: 'Maven Test',
steps: [{ type: TaskStepType.MAVEN_TEST, id: '', enabled: true }],
});
const createBuildTask = () => {
const steps: Omit<TaskStep, 'id'>[] = [
{ type: TaskStepType.MAVEN_CLEAN, enabled: true },
{ type: TaskStepType.MAVEN_TEST, enabled: true },
{ type: TaskStepType.MAVEN_PACKAGE, enabled: true },
];
onAddTask({
name: 'Maven Build Pipeline',
steps: steps.map(step => ({ ...step, id: '' })),
});
};
return (
<div className="p-3 mb-3 bg-orange-50 dark:bg-gray-900/50 rounded-lg border border-orange-200 dark:border-gray-700">
<div className="flex items-center gap-2 mb-2">
<DocumentTextIcon className="h-5 w-5 text-orange-500" />
<h3 className="text-md font-semibold text-gray-800 dark:text-gray-200">Maven Project Detected</h3>
</div>
{badges.length > 0 && (
<div className="text-xs text-gray-600 dark:text-gray-400 mb-3 flex flex-wrap gap-2">
{badges.map(badge => (
<span key={badge} className="bg-orange-100 dark:bg-orange-900/50 text-orange-800 dark:text-orange-200 px-2 py-0.5 rounded-full">{badge}</span>
))}
</div>
)}
<div className="flex flex-wrap gap-2">
<button type="button" onClick={createCleanTask} className="text-xs font-medium text-white bg-orange-600 hover:bg-orange-700 px-3 py-1.5 rounded-md">Add Maven Clean Task</button>
<button type="button" onClick={createTestTask} className="text-xs font-medium text-white bg-orange-600 hover:bg-orange-700 px-3 py-1.5 rounded-md">Add Maven Test Task</button>
<button type="button" onClick={createBuildTask} className="text-xs font-medium text-white bg-orange-600 hover:bg-orange-700 px-3 py-1.5 rounded-md">Add Maven Build Task</button>
</div>
</div>