@jlcpcb/cli 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jlcpcb/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.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",
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
  }
@@ -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
+ }
@@ -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
+ }
@@ -0,0 +1,151 @@
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
+ 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
+ const spinner = p.spinner()
134
+ spinner.start(`Searching EasyEDA community for "${query}"...`)
135
+
136
+ const searchOptions: SearchOptions = {
137
+ limit: 20,
138
+ source: 'easyeda-community',
139
+ }
140
+ const results = await componentService.search(query as string, searchOptions)
141
+
142
+ spinner.stop(`Found ${results.length} results`)
143
+
144
+ if (results.length === 0) {
145
+ p.log.warn('No components found. Try a different search term.')
146
+ return
147
+ }
148
+
149
+ // Launch TUI for selection and install
150
+ renderApp('search', { query: query as string, results })
151
+ }
@@ -11,6 +11,11 @@ import { renderApp } from '../app/App.js';
11
11
  const componentService = createComponentService();
12
12
  const libraryService = createLibraryService();
13
13
 
14
+ // LCSC IDs match pattern: C followed by digits (e.g., C2040, C5446)
15
+ function isLcscId(id: string): boolean {
16
+ return /^C\d+$/i.test(id);
17
+ }
18
+
14
19
  interface InstallOptions {
15
20
  projectPath?: string;
16
21
  include3d?: boolean;
@@ -18,6 +23,13 @@ interface InstallOptions {
18
23
  }
19
24
 
20
25
  export async function installCommand(id: string | undefined, options: InstallOptions): Promise<void> {
26
+ // Check if ID looks like an EasyEDA UUID (not an LCSC ID)
27
+ if (id && !isLcscId(id)) {
28
+ p.log.error(`"${id}" is not an LCSC part number (e.g., C2040).`);
29
+ p.log.info(`For EasyEDA community components, use: ${chalk.cyan(`jlc easyeda install ${id}`)}`);
30
+ process.exit(1);
31
+ }
32
+
21
33
  // If ID provided with --force, do direct install (non-interactive)
22
34
  if (id && options.force) {
23
35
  const spinner = p.spinner();
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ import { searchCommand } from './commands/search.js';
10
10
  import { infoCommand } from './commands/info.js';
11
11
  import { installCommand } from './commands/install.js';
12
12
  import { libraryCommand } from './commands/library.js';
13
+ import { easyedaSearchCommand, easyedaInstallCommand } from './commands/easyeda.js';
13
14
 
14
15
  const program = new Command();
15
16
 
@@ -67,4 +68,34 @@ program
67
68
  });
68
69
  });
69
70
 
71
+ // EasyEDA subcommand group
72
+ const easyeda = program
73
+ .command('easyeda')
74
+ .description('EasyEDA community component browser');
75
+
76
+ easyeda
77
+ .command('search <query...>')
78
+ .description('Open browser-based component search')
79
+ .option('-p, --port <number>', 'HTTP server port', '3847')
80
+ .action(async (queryParts: string[], options) => {
81
+ const query = queryParts.join(' ');
82
+ await easyedaSearchCommand(query, {
83
+ port: options.port ? parseInt(options.port, 10) : undefined,
84
+ });
85
+ });
86
+
87
+ easyeda
88
+ .command('install [uuid]')
89
+ .description('Install EasyEDA community component to KiCad libraries')
90
+ .option('-p, --project <path>', 'Install to project-local library')
91
+ .option('--with-3d', 'Include 3D model')
92
+ .option('-f, --force', 'Force reinstall (regenerate symbol and footprint)')
93
+ .action(async (uuid, options) => {
94
+ await easyedaInstallCommand(uuid, {
95
+ projectPath: options.project,
96
+ include3d: options.with3d,
97
+ force: options.force,
98
+ });
99
+ });
100
+
70
101
  program.parse();