@jlcpcb/cli 0.1.1 → 0.3.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/CHANGELOG.md +72 -0
- package/dist/assets/search.html +528 -0
- package/dist/index.js +5432 -1442
- package/package.json +3 -2
- package/src/app/App.tsx +7 -3
- package/src/app/components/DetailView.tsx +2 -2
- package/src/app/components/EasyEDADetailView.tsx +132 -0
- package/src/app/navigation/NavigationContext.tsx +5 -1
- package/src/app/navigation/types.ts +8 -2
- package/src/app/screens/EasyEDAInfoScreen.tsx +150 -0
- package/src/app/screens/InfoScreen.tsx +23 -28
- package/src/commands/easyeda.ts +149 -0
- package/src/commands/info.ts +1 -1
- package/src/commands/install.ts +22 -15
- package/src/commands/library.ts +51 -2
- package/src/commands/search.ts +1 -1
- package/src/commands/validate.ts +287 -0
- package/src/index.ts +72 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jlcpcb/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "CLI for JLC/EasyEDA component sourcing and KiCad library management",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target node",
|
|
21
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node && mkdir -p ./dist/assets && cp ../core/dist/assets/search.html ./dist/assets/",
|
|
22
22
|
"dev": "bun --watch ./src/index.ts",
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
24
|
"test": "bun test",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"ink-select-input": "6.2.0",
|
|
45
45
|
"@jlcpcb/core": "workspace:*",
|
|
46
46
|
"open": "11.0.0",
|
|
47
|
+
"react": "^19.0.0",
|
|
47
48
|
"react-devtools-core": "7.0.1"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
package/src/app/App.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { InstallScreen } from './screens/InstallScreen.js';
|
|
|
8
8
|
import { InstalledScreen } from './screens/InstalledScreen.js';
|
|
9
9
|
import { LibraryScreen } from './screens/LibraryScreen.js';
|
|
10
10
|
import { LibrarySetupScreen } from './screens/LibrarySetupScreen.js';
|
|
11
|
+
import { EasyEDAInfoScreen } from './screens/EasyEDAInfoScreen.js';
|
|
11
12
|
import type { ScreenName, ScreenParams } from './navigation/types.js';
|
|
12
13
|
|
|
13
14
|
function ScreenRouter() {
|
|
@@ -26,6 +27,8 @@ function ScreenRouter() {
|
|
|
26
27
|
return <LibraryScreen />;
|
|
27
28
|
case 'library-setup':
|
|
28
29
|
return <LibrarySetupScreen />;
|
|
30
|
+
case 'easyeda-info':
|
|
31
|
+
return <EasyEDAInfoScreen />;
|
|
29
32
|
default:
|
|
30
33
|
return null;
|
|
31
34
|
}
|
|
@@ -77,9 +80,10 @@ export function App<T extends ScreenName>({ initialScreen, initialParams }: AppP
|
|
|
77
80
|
);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
export function renderApp<T extends ScreenName>(
|
|
83
|
+
export async function renderApp<T extends ScreenName>(
|
|
81
84
|
initialScreen: T,
|
|
82
85
|
initialParams: ScreenParams[T]
|
|
83
|
-
): void {
|
|
84
|
-
render(<App initialScreen={initialScreen} initialParams={initialParams} />);
|
|
86
|
+
): Promise<void> {
|
|
87
|
+
const instance = render(<App initialScreen={initialScreen} initialParams={initialParams} />);
|
|
88
|
+
await instance.waitUntilExit();
|
|
85
89
|
}
|
|
@@ -142,8 +142,8 @@ export function DetailView({ component, terminalWidth, isInstalled, installedInf
|
|
|
142
142
|
|
|
143
143
|
// Footer text based on installation status
|
|
144
144
|
const footerText = isInstalled
|
|
145
|
-
? '
|
|
146
|
-
: 'Enter Install •
|
|
145
|
+
? 'R Regenerate • D Delete • O Datasheet • Esc Back'
|
|
146
|
+
: 'Enter Install • O Datasheet • Esc Back';
|
|
147
147
|
|
|
148
148
|
return (
|
|
149
149
|
<Box flexDirection="column" width="100%">
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import type { EasyEDACommunityComponent } from '@jlcpcb/core';
|
|
4
|
+
import { Divider } from './Divider.js';
|
|
5
|
+
|
|
6
|
+
interface EasyEDADetailViewProps {
|
|
7
|
+
component: EasyEDACommunityComponent;
|
|
8
|
+
terminalWidth: number;
|
|
9
|
+
isInstalled?: boolean;
|
|
10
|
+
statusMessage?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function truncate(str: string, len: number): string {
|
|
14
|
+
if (!str) return '';
|
|
15
|
+
return str.length > len ? str.slice(0, len - 1) + '…' : str;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function formatDate(timestamp: number): string {
|
|
19
|
+
if (!timestamp) return 'N/A';
|
|
20
|
+
const date = new Date(timestamp * 1000);
|
|
21
|
+
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function EasyEDADetailView({ component, terminalWidth, isInstalled, statusMessage }: EasyEDADetailViewProps) {
|
|
25
|
+
const isWide = terminalWidth >= 80;
|
|
26
|
+
const labelWidth = 16;
|
|
27
|
+
const colWidth = isWide ? Math.floor((terminalWidth - 4) / 2) : terminalWidth - 2;
|
|
28
|
+
const valueWidth = colWidth - labelWidth - 1;
|
|
29
|
+
|
|
30
|
+
const description = (
|
|
31
|
+
<Box flexDirection="column" marginBottom={1} width={terminalWidth - 2}>
|
|
32
|
+
<Text dimColor>Description</Text>
|
|
33
|
+
<Text wrap="wrap">{component.description || 'No description'}</Text>
|
|
34
|
+
</Box>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const partInfo = (
|
|
38
|
+
<Box flexDirection="column" width={colWidth}>
|
|
39
|
+
<Text bold underline color="cyan">Component Info</Text>
|
|
40
|
+
<Box marginTop={1} flexDirection="column">
|
|
41
|
+
<Box>
|
|
42
|
+
<Text dimColor>{'Title'.padEnd(labelWidth)}</Text>
|
|
43
|
+
<Text bold>{truncate(component.title || 'N/A', valueWidth)}</Text>
|
|
44
|
+
</Box>
|
|
45
|
+
<Box>
|
|
46
|
+
<Text dimColor>{'UUID'.padEnd(labelWidth)}</Text>
|
|
47
|
+
<Text color="cyan">{truncate(component.uuid, valueWidth)}</Text>
|
|
48
|
+
</Box>
|
|
49
|
+
<Box>
|
|
50
|
+
<Text dimColor>{'Package'.padEnd(labelWidth)}</Text>
|
|
51
|
+
<Text>{truncate(component.footprint?.name || 'N/A', valueWidth)}</Text>
|
|
52
|
+
</Box>
|
|
53
|
+
<Box>
|
|
54
|
+
<Text dimColor>{'Pins'.padEnd(labelWidth)}</Text>
|
|
55
|
+
<Text>{component.symbol?.pins?.length || 0}</Text>
|
|
56
|
+
</Box>
|
|
57
|
+
<Box>
|
|
58
|
+
<Text dimColor>{'Pads'.padEnd(labelWidth)}</Text>
|
|
59
|
+
<Text>{component.footprint?.pads?.length || 0}</Text>
|
|
60
|
+
</Box>
|
|
61
|
+
<Box>
|
|
62
|
+
<Text dimColor>{'3D Model'.padEnd(labelWidth)}</Text>
|
|
63
|
+
<Text color={component.model3d ? 'green' : 'yellow'}>
|
|
64
|
+
{component.model3d ? 'Yes' : 'No'}
|
|
65
|
+
</Text>
|
|
66
|
+
</Box>
|
|
67
|
+
<Box>
|
|
68
|
+
<Text dimColor>{'Verified'.padEnd(labelWidth)}</Text>
|
|
69
|
+
<Text color={component.verify ? 'green' : 'yellow'}>
|
|
70
|
+
{component.verify ? 'Yes' : 'No'}
|
|
71
|
+
</Text>
|
|
72
|
+
</Box>
|
|
73
|
+
</Box>
|
|
74
|
+
</Box>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const communityInfo = (
|
|
78
|
+
<Box flexDirection="column" marginLeft={isWide ? 2 : 0} marginTop={isWide ? 0 : 1} width={colWidth}>
|
|
79
|
+
<Text bold underline color="cyan">Community</Text>
|
|
80
|
+
<Box marginTop={1} flexDirection="column">
|
|
81
|
+
<Box>
|
|
82
|
+
<Text dimColor>{'Owner'.padEnd(labelWidth)}</Text>
|
|
83
|
+
<Text>{truncate(component.owner?.nickname || component.owner?.username || 'N/A', valueWidth)}</Text>
|
|
84
|
+
</Box>
|
|
85
|
+
{component.creator && component.creator.uuid !== component.owner?.uuid && (
|
|
86
|
+
<Box>
|
|
87
|
+
<Text dimColor>{'Creator'.padEnd(labelWidth)}</Text>
|
|
88
|
+
<Text>{truncate(component.creator.nickname || component.creator.username || 'N/A', valueWidth)}</Text>
|
|
89
|
+
</Box>
|
|
90
|
+
)}
|
|
91
|
+
<Box>
|
|
92
|
+
<Text dimColor>{'Updated'.padEnd(labelWidth)}</Text>
|
|
93
|
+
<Text>{formatDate(component.updateTime)}</Text>
|
|
94
|
+
</Box>
|
|
95
|
+
{component.tags && component.tags.length > 0 && (
|
|
96
|
+
<Box>
|
|
97
|
+
<Text dimColor>{'Tags'.padEnd(labelWidth)}</Text>
|
|
98
|
+
<Text>{truncate(component.tags.slice(0, 3).join(', '), valueWidth)}</Text>
|
|
99
|
+
</Box>
|
|
100
|
+
)}
|
|
101
|
+
</Box>
|
|
102
|
+
</Box>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const footerText = isInstalled
|
|
106
|
+
? 'R Regenerate • Esc Back'
|
|
107
|
+
: 'Enter Install • Esc Back';
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Box flexDirection="column" width="100%">
|
|
111
|
+
{description}
|
|
112
|
+
<Box flexDirection={isWide ? 'row' : 'column'} width="100%">
|
|
113
|
+
{partInfo}
|
|
114
|
+
{communityInfo}
|
|
115
|
+
</Box>
|
|
116
|
+
<Box marginTop={1} flexDirection="column" width="100%">
|
|
117
|
+
<Divider width={terminalWidth} />
|
|
118
|
+
{statusMessage && (
|
|
119
|
+
<Box paddingY={0}>
|
|
120
|
+
<Text color={statusMessage.startsWith('✓') ? 'green' : statusMessage.startsWith('✗') ? 'red' : 'yellow'}>
|
|
121
|
+
{statusMessage}
|
|
122
|
+
</Text>
|
|
123
|
+
</Box>
|
|
124
|
+
)}
|
|
125
|
+
<Box paddingY={0}>
|
|
126
|
+
<Text dimColor>{footerText}</Text>
|
|
127
|
+
</Box>
|
|
128
|
+
<Divider width={terminalWidth} />
|
|
129
|
+
</Box>
|
|
130
|
+
</Box>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
@@ -83,5 +83,9 @@ export function useNavigation(): NavigationContextValue {
|
|
|
83
83
|
|
|
84
84
|
export function useCurrentScreen(): HistoryEntry {
|
|
85
85
|
const { history, currentIndex } = useNavigation();
|
|
86
|
-
|
|
86
|
+
const entry = history[currentIndex];
|
|
87
|
+
if (!entry) {
|
|
88
|
+
throw new Error(`Invalid navigation state: currentIndex=${currentIndex}, history.length=${history.length}`);
|
|
89
|
+
}
|
|
90
|
+
return entry;
|
|
87
91
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ComponentSearchResult, ComponentDetails, InstallResult, InstalledComponent, LibraryStatus } from '@jlcpcb/core';
|
|
1
|
+
import type { ComponentSearchResult, ComponentDetails, InstallResult, InstalledComponent, LibraryStatus, EasyEDACommunityComponent } from '@jlcpcb/core';
|
|
2
2
|
|
|
3
|
-
export type ScreenName = 'search' | 'info' | 'install' | 'library' | 'library-setup' | 'installed';
|
|
3
|
+
export type ScreenName = 'search' | 'info' | 'install' | 'library' | 'library-setup' | 'installed' | 'easyeda-info';
|
|
4
4
|
|
|
5
5
|
// Common component type that works across screens
|
|
6
6
|
export type ComponentInfo = ComponentSearchResult | ComponentDetails;
|
|
@@ -37,6 +37,11 @@ export interface InstalledParams {
|
|
|
37
37
|
error?: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export interface EasyEDAInfoParams {
|
|
41
|
+
uuid: string;
|
|
42
|
+
component?: EasyEDACommunityComponent;
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
export interface ScreenParams {
|
|
41
46
|
search: SearchParams;
|
|
42
47
|
info: InfoParams;
|
|
@@ -44,6 +49,7 @@ export interface ScreenParams {
|
|
|
44
49
|
library: LibraryParams;
|
|
45
50
|
'library-setup': LibrarySetupParams;
|
|
46
51
|
installed: InstalledParams;
|
|
52
|
+
'easyeda-info': EasyEDAInfoParams;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
export interface HistoryEntry<T extends ScreenName = ScreenName> {
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import { createComponentService, createLibraryService, type EasyEDACommunityComponent } from '@jlcpcb/core';
|
|
4
|
+
import { useNavigation, useCurrentScreen } from '../navigation/NavigationContext.js';
|
|
5
|
+
import type { EasyEDAInfoParams } from '../navigation/types.js';
|
|
6
|
+
import { useTerminalSize } from '../hooks/useTerminalSize.js';
|
|
7
|
+
import { EasyEDADetailView } from '../components/EasyEDADetailView.js';
|
|
8
|
+
|
|
9
|
+
const componentService = createComponentService();
|
|
10
|
+
const libraryService = createLibraryService();
|
|
11
|
+
|
|
12
|
+
export function EasyEDAInfoScreen() {
|
|
13
|
+
const { replace } = useNavigation();
|
|
14
|
+
const { params } = useCurrentScreen() as { screen: 'easyeda-info'; params: EasyEDAInfoParams };
|
|
15
|
+
const { columns: terminalWidth } = useTerminalSize();
|
|
16
|
+
|
|
17
|
+
const [component, setComponent] = useState<EasyEDACommunityComponent | null>(null);
|
|
18
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
19
|
+
const [error, setError] = useState<string | null>(null);
|
|
20
|
+
const [isInstalling, setIsInstalling] = useState(false);
|
|
21
|
+
const [statusMessage, setStatusMessage] = useState<string | null>(null);
|
|
22
|
+
const [isInstalled, setIsInstalled] = useState(false);
|
|
23
|
+
const installingRef = useRef(false);
|
|
24
|
+
|
|
25
|
+
// Always fetch component to keep the process alive
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const init = async () => {
|
|
28
|
+
if (!params.uuid) {
|
|
29
|
+
setError('No UUID provided');
|
|
30
|
+
setIsLoading(false);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
// Ensure global tables are set up
|
|
36
|
+
await libraryService.ensureGlobalTables();
|
|
37
|
+
|
|
38
|
+
// Fetch component
|
|
39
|
+
const fetched = await componentService.fetchCommunity(params.uuid);
|
|
40
|
+
if (fetched) {
|
|
41
|
+
setComponent(fetched);
|
|
42
|
+
// Check if already installed
|
|
43
|
+
const installed = await libraryService.isEasyEDAInstalled(fetched.title);
|
|
44
|
+
setIsInstalled(installed);
|
|
45
|
+
} else {
|
|
46
|
+
setError('Component not found');
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch component');
|
|
50
|
+
} finally {
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
init();
|
|
56
|
+
}, [params.uuid]);
|
|
57
|
+
|
|
58
|
+
useInput((input, key) => {
|
|
59
|
+
if (isLoading || !component || isInstalling) return;
|
|
60
|
+
|
|
61
|
+
const lowerInput = input.toLowerCase();
|
|
62
|
+
|
|
63
|
+
// R - Regenerate (force reinstall)
|
|
64
|
+
if (lowerInput === 'r') {
|
|
65
|
+
if (installingRef.current) return;
|
|
66
|
+
installingRef.current = true;
|
|
67
|
+
setIsInstalling(true);
|
|
68
|
+
setStatusMessage('Regenerating symbol and footprint...');
|
|
69
|
+
|
|
70
|
+
libraryService.install(params.uuid, { force: true })
|
|
71
|
+
.then((result) => {
|
|
72
|
+
setStatusMessage(`✓ Reinstalled: ${result.symbolRef}`);
|
|
73
|
+
setIsInstalled(true);
|
|
74
|
+
setTimeout(() => setStatusMessage(null), 3000);
|
|
75
|
+
})
|
|
76
|
+
.catch((err) => {
|
|
77
|
+
setStatusMessage(`✗ Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
78
|
+
setTimeout(() => setStatusMessage(null), 3000);
|
|
79
|
+
})
|
|
80
|
+
.finally(() => {
|
|
81
|
+
setIsInstalling(false);
|
|
82
|
+
installingRef.current = false;
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Enter - Install
|
|
88
|
+
if (key.return) {
|
|
89
|
+
if (installingRef.current) return;
|
|
90
|
+
installingRef.current = true;
|
|
91
|
+
setIsInstalling(true);
|
|
92
|
+
setStatusMessage('Installing component...');
|
|
93
|
+
|
|
94
|
+
// Ensure libraries are set up
|
|
95
|
+
libraryService.ensureGlobalTables()
|
|
96
|
+
.then(() => libraryService.install(params.uuid, {}))
|
|
97
|
+
.then((result) => {
|
|
98
|
+
if (result.symbolAction === 'exists') {
|
|
99
|
+
setStatusMessage(`⚡ Already installed (use R to reinstall)`);
|
|
100
|
+
} else {
|
|
101
|
+
setStatusMessage(`✓ Installed: ${result.symbolRef}`);
|
|
102
|
+
setIsInstalled(true);
|
|
103
|
+
}
|
|
104
|
+
setTimeout(() => setStatusMessage(null), 3000);
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => {
|
|
107
|
+
setStatusMessage(`✗ Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
108
|
+
setTimeout(() => setStatusMessage(null), 3000);
|
|
109
|
+
})
|
|
110
|
+
.finally(() => {
|
|
111
|
+
setIsInstalling(false);
|
|
112
|
+
installingRef.current = false;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (isLoading) {
|
|
118
|
+
return (
|
|
119
|
+
<Box flexDirection="column">
|
|
120
|
+
<Text color="yellow">⏳ Loading component {params.uuid}...</Text>
|
|
121
|
+
</Box>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (error || !component) {
|
|
126
|
+
return (
|
|
127
|
+
<Box flexDirection="column">
|
|
128
|
+
<Text color="red">✗ {error || 'Component not found'}</Text>
|
|
129
|
+
<Text dimColor>Press Esc to go back</Text>
|
|
130
|
+
</Box>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<Box flexDirection="column">
|
|
136
|
+
<Box marginBottom={1}>
|
|
137
|
+
<Text bold>
|
|
138
|
+
Component: <Text color="cyan">{component.title}</Text>
|
|
139
|
+
{isInstalled && <Text color="green"> ✓ Installed</Text>}
|
|
140
|
+
</Text>
|
|
141
|
+
</Box>
|
|
142
|
+
<EasyEDADetailView
|
|
143
|
+
component={component}
|
|
144
|
+
terminalWidth={terminalWidth}
|
|
145
|
+
isInstalled={isInstalled}
|
|
146
|
+
statusMessage={statusMessage}
|
|
147
|
+
/>
|
|
148
|
+
</Box>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -73,38 +73,14 @@ export function InfoScreen() {
|
|
|
73
73
|
const datasheetUrl = component && ('datasheetPdf' in component ? component.datasheetPdf : 'datasheet' in component ? component.datasheet : undefined);
|
|
74
74
|
|
|
75
75
|
const [isRegenerating, setIsRegenerating] = useState(false);
|
|
76
|
+
const [isDeleting, setIsDeleting] = useState(false);
|
|
76
77
|
const [regenerateMessage, setRegenerateMessage] = useState<string | null>(null);
|
|
77
78
|
|
|
78
79
|
useInput((input, key) => {
|
|
79
|
-
if (isLoading || !component || isCheckingLibrary || isRegenerating) return;
|
|
80
|
+
if (isLoading || !component || isCheckingLibrary || isRegenerating || isDeleting) return;
|
|
80
81
|
|
|
81
82
|
const lowerInput = input.toLowerCase();
|
|
82
83
|
|
|
83
|
-
// S - Open Symbol in KiCad
|
|
84
|
-
if (lowerInput === 's' && installedInfo && libraryStatus) {
|
|
85
|
-
const symbolPath = `${libraryStatus.paths.symbolsDir}/JLC-MCP-${installedInfo.category}.kicad_sym`;
|
|
86
|
-
open(symbolPath);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// F - Open Footprint in KiCad
|
|
91
|
-
if (lowerInput === 'f' && installedInfo && libraryStatus) {
|
|
92
|
-
if (installedInfo.footprintRef?.startsWith('JLC-MCP:')) {
|
|
93
|
-
const fpName = installedInfo.footprintRef.split(':')[1];
|
|
94
|
-
const footprintPath = `${libraryStatus.paths.footprintsDir}/JLC-MCP.pretty/${fpName}.kicad_mod`;
|
|
95
|
-
open(footprintPath);
|
|
96
|
-
}
|
|
97
|
-
// Standard KiCad footprints can't be opened directly
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// M - Open 3D Model
|
|
102
|
-
if (lowerInput === 'm' && installedInfo && libraryStatus && installedInfo.has3dModel) {
|
|
103
|
-
const modelPath = `${libraryStatus.paths.models3dDir}/${installedInfo.name}.step`;
|
|
104
|
-
open(modelPath);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
84
|
// R - Regenerate symbol and footprint
|
|
109
85
|
if (lowerInput === 'r' && installedInfo) {
|
|
110
86
|
setIsRegenerating(true);
|
|
@@ -124,8 +100,27 @@ export function InfoScreen() {
|
|
|
124
100
|
return;
|
|
125
101
|
}
|
|
126
102
|
|
|
127
|
-
// D -
|
|
128
|
-
if (lowerInput === 'd' &&
|
|
103
|
+
// D - Delete component
|
|
104
|
+
if (lowerInput === 'd' && installedInfo) {
|
|
105
|
+
setIsDeleting(true);
|
|
106
|
+
setRegenerateMessage('Deleting component...');
|
|
107
|
+
|
|
108
|
+
libraryService.remove(installedInfo.lcscId)
|
|
109
|
+
.then(() => {
|
|
110
|
+
setRegenerateMessage('✓ Component deleted');
|
|
111
|
+
setInstalledInfo(null);
|
|
112
|
+
setTimeout(() => setRegenerateMessage(null), 2000);
|
|
113
|
+
})
|
|
114
|
+
.catch((err) => {
|
|
115
|
+
setRegenerateMessage(`✗ Delete failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
116
|
+
setTimeout(() => setRegenerateMessage(null), 3000);
|
|
117
|
+
})
|
|
118
|
+
.finally(() => setIsDeleting(false));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// O - Open Datasheet
|
|
123
|
+
if (lowerInput === 'o' && datasheetUrl) {
|
|
129
124
|
open(datasheetUrl);
|
|
130
125
|
return;
|
|
131
126
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EasyEDA subcommands
|
|
3
|
+
* Browser-based component search and exploration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import open from 'open'
|
|
7
|
+
import * as p from '@clack/prompts'
|
|
8
|
+
import chalk from 'chalk'
|
|
9
|
+
import {
|
|
10
|
+
startHttpServer,
|
|
11
|
+
stopHttpServer,
|
|
12
|
+
createComponentService,
|
|
13
|
+
createLibraryService,
|
|
14
|
+
type SearchOptions,
|
|
15
|
+
} from '@jlcpcb/core'
|
|
16
|
+
import { renderApp } from '../app/App.js'
|
|
17
|
+
|
|
18
|
+
const componentService = createComponentService()
|
|
19
|
+
const libraryService = createLibraryService()
|
|
20
|
+
|
|
21
|
+
interface EasyedaSearchOptions {
|
|
22
|
+
port?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Launch the EasyEDA component browser with an optional search query
|
|
27
|
+
*/
|
|
28
|
+
export async function easyedaSearchCommand(
|
|
29
|
+
query: string,
|
|
30
|
+
options: EasyedaSearchOptions
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
const port = options.port ?? 3847
|
|
33
|
+
|
|
34
|
+
console.log('Starting component browser...')
|
|
35
|
+
|
|
36
|
+
startHttpServer({
|
|
37
|
+
port,
|
|
38
|
+
onReady: async (url) => {
|
|
39
|
+
// Append query to URL if provided
|
|
40
|
+
const searchUrl = query ? `${url}?q=${encodeURIComponent(query)}` : url
|
|
41
|
+
|
|
42
|
+
console.log(`Browser opened at ${searchUrl}`)
|
|
43
|
+
|
|
44
|
+
// Open browser
|
|
45
|
+
await open(searchUrl)
|
|
46
|
+
|
|
47
|
+
console.log('Press Ctrl+C to stop the server and exit')
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Keep running until Ctrl+C
|
|
52
|
+
await new Promise<void>((resolve) => {
|
|
53
|
+
process.on('SIGINT', () => {
|
|
54
|
+
console.log('\nShutting down server...')
|
|
55
|
+
stopHttpServer()
|
|
56
|
+
resolve()
|
|
57
|
+
process.exit(0)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface EasyedaInstallOptions {
|
|
63
|
+
projectPath?: string
|
|
64
|
+
include3d?: boolean
|
|
65
|
+
force?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Install an EasyEDA community component to KiCad libraries
|
|
70
|
+
*/
|
|
71
|
+
export async function easyedaInstallCommand(
|
|
72
|
+
uuid: string | undefined,
|
|
73
|
+
options: EasyedaInstallOptions
|
|
74
|
+
): Promise<void> {
|
|
75
|
+
// If UUID provided with --force, do direct install (non-interactive)
|
|
76
|
+
if (uuid && options.force) {
|
|
77
|
+
const spinner = p.spinner()
|
|
78
|
+
spinner.start(`Installing EasyEDA component ${uuid}...`)
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
// Ensure libraries are set up
|
|
82
|
+
await libraryService.ensureGlobalTables()
|
|
83
|
+
|
|
84
|
+
// Install the component
|
|
85
|
+
const result = await libraryService.install(uuid, {
|
|
86
|
+
projectPath: options.projectPath,
|
|
87
|
+
include3d: options.include3d,
|
|
88
|
+
force: true,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
spinner.stop(chalk.green('✓ Component installed'))
|
|
92
|
+
|
|
93
|
+
// Display result
|
|
94
|
+
console.log()
|
|
95
|
+
console.log(chalk.cyan('Symbol: '), result.symbolRef)
|
|
96
|
+
console.log(chalk.cyan('Footprint: '), result.footprintRef)
|
|
97
|
+
console.log(chalk.cyan('Action: '), result.symbolAction)
|
|
98
|
+
if (result.files.model3d) {
|
|
99
|
+
console.log(chalk.cyan('3D Model: '), result.files.model3d)
|
|
100
|
+
}
|
|
101
|
+
console.log()
|
|
102
|
+
console.log(chalk.dim(`Library: ${result.files.symbolLibrary}`))
|
|
103
|
+
} catch (error) {
|
|
104
|
+
spinner.stop(chalk.red('✗ Installation failed'))
|
|
105
|
+
p.log.error(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
|
106
|
+
process.exit(1)
|
|
107
|
+
}
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// If UUID provided (without --force), launch TUI to fetch and display
|
|
112
|
+
if (uuid) {
|
|
113
|
+
// Launch TUI at EasyEDA info screen - let it fetch the component
|
|
114
|
+
await renderApp('easyeda-info', { uuid })
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// No UUID provided - interactive search mode
|
|
119
|
+
const query = await p.text({
|
|
120
|
+
message: 'Search EasyEDA community library:',
|
|
121
|
+
placeholder: 'e.g., STM32F103, ESP32, Arduino Nano',
|
|
122
|
+
validate: (value) => {
|
|
123
|
+
if (!value) return 'Please enter a search term'
|
|
124
|
+
return undefined
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
if (p.isCancel(query)) {
|
|
129
|
+
p.cancel('Installation cancelled')
|
|
130
|
+
process.exit(0)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
console.log(`Searching EasyEDA community for "${query}"...`)
|
|
134
|
+
|
|
135
|
+
const searchOptions: SearchOptions = {
|
|
136
|
+
limit: 20,
|
|
137
|
+
source: 'easyeda-community',
|
|
138
|
+
}
|
|
139
|
+
const results = await componentService.search(query as string, searchOptions)
|
|
140
|
+
|
|
141
|
+
if (results.length === 0) {
|
|
142
|
+
console.log('No components found. Try a different search term.')
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Clear the "Searching..." line and launch interactive UI
|
|
147
|
+
process.stdout.write('\x1b[1A\x1b[2K')
|
|
148
|
+
await renderApp('search', { query: query as string, results })
|
|
149
|
+
}
|
package/src/commands/info.ts
CHANGED