key-screen-framework 0.1.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.
Files changed (113) hide show
  1. package/chunks/store-txJwmrlO.js +281 -0
  2. package/chunks/useArduinoBuild-CVr4XAsL.js +152 -0
  3. package/cli/check-arduino-bundle.mjs +157 -0
  4. package/cli/doctor-project.mjs +554 -0
  5. package/cli/generate-screen.mjs +286 -0
  6. package/cli/migrate-project.mjs +679 -0
  7. package/cli/new-project.mjs +344 -0
  8. package/cli/remove-screen.mjs +83 -0
  9. package/cli/screen-generation-contract.mjs +127 -0
  10. package/cli/screen-generation-renderers.mjs +71 -0
  11. package/cli/screen-module-utils.mjs +148 -0
  12. package/cli/screen-script-utils.mjs +92 -0
  13. package/cli/setup-arduino-cli.mjs +515 -0
  14. package/cli/source-module-specifiers.mjs +89 -0
  15. package/cli/sync-screens.mjs +48 -0
  16. package/main/index.js +2003 -0
  17. package/package.json +108 -0
  18. package/preload/index.js +69 -0
  19. package/renderer/components/VideoSceneScreen.js +160 -0
  20. package/renderer/hooks/index.js +6 -0
  21. package/renderer/index.js +3092 -0
  22. package/renderer/store.js +6 -0
  23. package/renderer/styles.css +1395 -0
  24. package/shared/arduino-board.js +136 -0
  25. package/shared/arduino-keyboard-shortcut.js +77 -0
  26. package/shared/index.js +25 -0
  27. package/shared/screen-catalog.js +35 -0
  28. package/shared/screen-shortcuts.js +164 -0
  29. package/shared/types.js +1 -0
  30. package/templates/project/README.md +45 -0
  31. package/templates/project/build/favicon-mac.png +0 -0
  32. package/templates/project/build/favicon.ico +0 -0
  33. package/templates/project/build/favicon.png +0 -0
  34. package/templates/project/e2e/smoke.spec.ts +10 -0
  35. package/templates/project/electron.vite.config.ts +40 -0
  36. package/templates/project/eslint.config.js +23 -0
  37. package/templates/project/gitignore +19 -0
  38. package/templates/project/media/audio/.gitkeep +1 -0
  39. package/templates/project/media/font/.gitkeep +1 -0
  40. package/templates/project/media/image/.gitkeep +1 -0
  41. package/templates/project/media/video/.gitkeep +1 -0
  42. package/templates/project/media/video/external-sample-30s.mp4 +0 -0
  43. package/templates/project/package.json +117 -0
  44. package/templates/project/playwright.config.ts +7 -0
  45. package/templates/project/postcss.config.js +6 -0
  46. package/templates/project/src/arduino-output-signals.ts +19 -0
  47. package/templates/project/src/assets/audio/.gitkeep +1 -0
  48. package/templates/project/src/assets/font/PretendardVariable.woff2 +0 -0
  49. package/templates/project/src/assets/image/.gitkeep +1 -0
  50. package/templates/project/src/assets/image/key-icon.png +0 -0
  51. package/templates/project/src/assets/video/.gitkeep +1 -0
  52. package/templates/project/src/assets/video/sample-30s.mp4 +0 -0
  53. package/templates/project/src/device-signal-handlers.test.ts +9 -0
  54. package/templates/project/src/device-signal-handlers.ts +14 -0
  55. package/templates/project/src/device-signal-targets.ts +3 -0
  56. package/templates/project/src/main/index.ts +17 -0
  57. package/templates/project/src/preload/index.ts +4 -0
  58. package/templates/project/src/project.config.ts +11 -0
  59. package/templates/project/src/renderer/index.html +16 -0
  60. package/templates/project/src/renderer/main.tsx +20 -0
  61. package/templates/project/src/renderer/vite-env.d.ts +1 -0
  62. package/templates/project/src/screen-definitions.ts +75 -0
  63. package/templates/project/src/screens/Screen001Black.test.tsx +21 -0
  64. package/templates/project/src/screens/Screen001Black.tsx +38 -0
  65. package/templates/project/src/screens/Screen002Video.test.tsx +18 -0
  66. package/templates/project/src/screens/Screen002Video.tsx +22 -0
  67. package/templates/project/src/screens/Screen003ExternalVideo.test.tsx +26 -0
  68. package/templates/project/src/screens/Screen003ExternalVideo.tsx +22 -0
  69. package/templates/project/src/store.test.ts +21 -0
  70. package/templates/project/src/store.ts +32 -0
  71. package/templates/project/src/styles.css +60 -0
  72. package/templates/project/tailwind.config.ts +69 -0
  73. package/templates/project/tsconfig.json +4 -0
  74. package/templates/project/tsconfig.node.json +32 -0
  75. package/templates/project/vitest.config.ts +20 -0
  76. package/templates/project/vitest.setup.ts +1 -0
  77. package/types/main/app-keyboard-shortcuts.d.ts +4 -0
  78. package/types/main/arduino-cli.d.ts +55 -0
  79. package/types/main/arduino-sketch-generator.d.ts +10 -0
  80. package/types/main/device-controller.d.ts +39 -0
  81. package/types/main/device-log-writer.d.ts +21 -0
  82. package/types/main/dtoa-dispatcher.d.ts +17 -0
  83. package/types/main/dtoa-handler.d.ts +9 -0
  84. package/types/main/game-session.d.ts +12 -0
  85. package/types/main/kiosk-quit.d.ts +5 -0
  86. package/types/main/media-manager.d.ts +17 -0
  87. package/types/main/runtime-paths.d.ts +10 -0
  88. package/types/main/serial-protocol.d.ts +29 -0
  89. package/types/main/start.d.ts +2 -0
  90. package/types/main/window-mode.d.ts +18 -0
  91. package/types/main/windows-key-lock.d.ts +3 -0
  92. package/types/preload/bridge.d.ts +4 -0
  93. package/types/renderer/src/App.d.ts +3 -0
  94. package/types/renderer/src/KeyScreenApp.d.ts +3 -0
  95. package/types/renderer/src/bridge.d.ts +3 -0
  96. package/types/renderer/src/components/DeviceLogOverlay.d.ts +7 -0
  97. package/types/renderer/src/components/ScreenRenderer.d.ts +7 -0
  98. package/types/renderer/src/components/SplashScreen.d.ts +7 -0
  99. package/types/renderer/src/components/VideoSceneScreen.d.ts +16 -0
  100. package/types/renderer/src/framework/AdminScreen.d.ts +3 -0
  101. package/types/renderer/src/hooks/index.d.ts +4 -0
  102. package/types/renderer/src/hooks/useArduinoBuild.d.ts +14 -0
  103. package/types/renderer/src/hooks/useAtodSignal.d.ts +12 -0
  104. package/types/renderer/src/index.d.ts +9 -0
  105. package/types/renderer/src/project-runtime.d.ts +10 -0
  106. package/types/renderer/src/screen-types.d.ts +24 -0
  107. package/types/renderer/src/store.d.ts +33 -0
  108. package/types/shared/arduino-board.d.ts +11 -0
  109. package/types/shared/arduino-keyboard-shortcut.d.ts +14 -0
  110. package/types/shared/index.d.ts +5 -0
  111. package/types/shared/screen-catalog.d.ts +19 -0
  112. package/types/shared/screen-shortcuts.d.ts +10 -0
  113. package/types/shared/types.d.ts +272 -0
@@ -0,0 +1,281 @@
1
+ import { create } from "zustand";
2
+ import { validateArduinoBoardConfig, defaultArduinoBoardConfig } from "../shared/arduino-board.js";
3
+ import { buildDefaultGlobalShortcuts, normalizeShortcutAccelerator, mergeGlobalShortcuts } from "../shared/screen-shortcuts.js";
4
+ const now = () => (/* @__PURE__ */ new Date()).toISOString();
5
+ const FALLBACK_ADMIN_SCREEN = {
6
+ id: "admin",
7
+ title: "관리자",
8
+ description: "디바이스 연결과 화면 제어를 위한 운영 대시보드",
9
+ kind: "admin",
10
+ isInitial: true,
11
+ componentKey: "admin-screen",
12
+ shortcut: "CmdOrCtrl+Shift+Alt+S"
13
+ };
14
+ let fallbackScreenDefinitions = [FALLBACK_ADMIN_SCREEN];
15
+ let fallbackDefaultGlobalShortcuts = buildDefaultGlobalShortcuts(fallbackScreenDefinitions);
16
+ function configureRendererPreview(screenDefinitions) {
17
+ fallbackScreenDefinitions = screenDefinitions.length > 0 ? screenDefinitions.map((screen) => ({ ...screen })) : [FALLBACK_ADMIN_SCREEN];
18
+ fallbackDefaultGlobalShortcuts = buildDefaultGlobalShortcuts(fallbackScreenDefinitions);
19
+ fallbackGlobalShortcuts = [];
20
+ }
21
+ const fallbackDeviceState = () => ({
22
+ status: "disconnected",
23
+ availablePorts: [],
24
+ lastMessage: "Electron 브리지 없이 미리보기 모드로 실행 중입니다.",
25
+ messageLog: [],
26
+ updatedAt: now()
27
+ });
28
+ const fallbackGameState = () => ({
29
+ mode: "idle",
30
+ currentStepId: fallbackScreenDefinitions.find((screen) => screen.isInitial)?.id ?? fallbackScreenDefinitions[0]?.id,
31
+ updatedAt: now()
32
+ });
33
+ const fallbackPerformanceSnapshot = () => ({
34
+ capturedAt: now(),
35
+ appVersion: "preview",
36
+ platform: typeof navigator === "undefined" ? "unknown" : navigator.platform,
37
+ arch: "unknown",
38
+ processMemory: {
39
+ privateKb: 0,
40
+ sharedKb: 0
41
+ },
42
+ appMetrics: []
43
+ });
44
+ let fallbackGlobalShortcuts = [];
45
+ let fallbackArduinoBoardConfig = defaultArduinoBoardConfig();
46
+ const fallbackArduinoBuildStatus = {
47
+ phase: "idle",
48
+ updatedAt: now()
49
+ };
50
+ let fallbackWindowMode = "windowed";
51
+ const fallbackApi = {
52
+ listPorts: async () => [],
53
+ listDeviceLogArchives: async () => [],
54
+ getDeviceLogArchive: async () => [],
55
+ connectDevice: async () => fallbackDeviceState(),
56
+ disconnectDevice: async () => fallbackDeviceState(),
57
+ sendCommand: async () => ({
58
+ ok: true,
59
+ message: "Preview mode: command ignored.",
60
+ receivedAt: now()
61
+ }),
62
+ getDeviceState: async () => fallbackDeviceState(),
63
+ getGameState: async () => fallbackGameState(),
64
+ getAvailableScreens: async () => fallbackScreenDefinitions.map((screen) => ({ ...screen })),
65
+ getMediaLibrary: async () => ({
66
+ rootPath: "preview",
67
+ assets: []
68
+ }),
69
+ resolveMediaUrl: async (ref) => `media://${ref.type}/${encodeURIComponent(ref.name)}`,
70
+ openMediaFolder: async () => ({
71
+ ok: false,
72
+ path: "preview",
73
+ message: "Preview mode: media folder is unavailable."
74
+ }),
75
+ getPerformanceSnapshot: async () => fallbackPerformanceSnapshot(),
76
+ quitApp: () => void 0,
77
+ getGlobalShortcuts: async () => mergeGlobalShortcuts(fallbackGlobalShortcuts, fallbackDefaultGlobalShortcuts),
78
+ updateGlobalShortcuts: async (shortcuts) => {
79
+ fallbackGlobalShortcuts = shortcuts.map((shortcut) => ({
80
+ ...shortcut,
81
+ accelerator: normalizeShortcutAccelerator(shortcut.accelerator)
82
+ })).filter(
83
+ (shortcut) => !fallbackDefaultGlobalShortcuts.some(
84
+ (defaultShortcut) => defaultShortcut.accelerator === shortcut.accelerator && defaultShortcut.target === shortcut.target
85
+ )
86
+ ).map((shortcut) => ({ ...shortcut }));
87
+ return mergeGlobalShortcuts(fallbackGlobalShortcuts, fallbackDefaultGlobalShortcuts);
88
+ },
89
+ getArduinoBoardConfig: async () => fallbackArduinoBoardConfig,
90
+ updateArduinoBoardConfig: async (config) => {
91
+ fallbackArduinoBoardConfig = validateArduinoBoardConfig(config);
92
+ return fallbackArduinoBoardConfig;
93
+ },
94
+ previewArduinoSketch: async () => ({
95
+ source: "// Preview mode: Arduino sketch generation is unavailable.",
96
+ warnings: []
97
+ }),
98
+ compileArduinoSketch: async () => ({
99
+ ok: false,
100
+ action: "compile",
101
+ exitCode: null,
102
+ message: "Preview mode: Arduino compile is unavailable.",
103
+ warnings: [],
104
+ durationMs: 0,
105
+ completedAt: now()
106
+ }),
107
+ uploadArduinoSketch: async () => ({
108
+ ok: false,
109
+ action: "upload",
110
+ exitCode: null,
111
+ message: "Preview mode: Arduino upload is unavailable.",
112
+ warnings: [],
113
+ durationMs: 0,
114
+ completedAt: now()
115
+ }),
116
+ cancelArduinoBuild: () => void 0,
117
+ getArduinoBuildStatus: async () => fallbackArduinoBuildStatus,
118
+ getDeviceSignalTargets: async () => [],
119
+ getWindowMode: async () => fallbackWindowMode,
120
+ isWindowModeLocked: async () => false,
121
+ setWindowMode: async (mode) => {
122
+ fallbackWindowMode = mode;
123
+ return fallbackWindowMode;
124
+ },
125
+ moveToScreen: async (target) => ({
126
+ mode: "running",
127
+ currentStepId: target,
128
+ startedAt: now(),
129
+ updatedAt: now()
130
+ }),
131
+ logPreload: (entry) => {
132
+ if (entry.phase === "error") {
133
+ console.error("[preload]", entry);
134
+ return;
135
+ }
136
+ console.info("[preload]", entry);
137
+ },
138
+ logShortcutTransition: (entry) => console.info("[shortcut]", entry),
139
+ onArduinoLog: () => () => void 0,
140
+ onArduinoStatus: () => () => void 0,
141
+ onDeviceState: () => () => void 0,
142
+ onDeviceSignal: () => () => void 0,
143
+ onGameState: () => () => void 0
144
+ };
145
+ function getGameApi() {
146
+ return window.gameApi ?? fallbackApi;
147
+ }
148
+ const emptyDeviceState = {
149
+ status: "disconnected",
150
+ availablePorts: [],
151
+ messageLog: [],
152
+ updatedAt: (/* @__PURE__ */ new Date(0)).toISOString()
153
+ };
154
+ const emptyGameState = {
155
+ mode: "idle",
156
+ updatedAt: (/* @__PURE__ */ new Date(0)).toISOString()
157
+ };
158
+ const useAppStore = create((set) => ({
159
+ deviceState: emptyDeviceState,
160
+ gameState: emptyGameState,
161
+ ports: [],
162
+ screens: [],
163
+ shortcuts: [],
164
+ arduinoBoardConfig: defaultArduinoBoardConfig(),
165
+ deviceSignalTargets: [],
166
+ windowMode: "windowed",
167
+ windowModeLocked: false,
168
+ loading: false,
169
+ setLoading: (loading) => set({ loading }),
170
+ setPorts: (ports) => set({ ports }),
171
+ setDeviceState: (deviceState) => set({ deviceState, ports: deviceState.availablePorts }),
172
+ setGameState: (gameState) => set({ gameState }),
173
+ setScreens: (screens) => set({ screens }),
174
+ setShortcuts: (shortcuts) => set({ shortcuts }),
175
+ setArduinoBoardConfig: (arduinoBoardConfig) => set({ arduinoBoardConfig }),
176
+ setDeviceSignalTargets: (deviceSignalTargets) => set({ deviceSignalTargets }),
177
+ setWindowMode: (windowMode) => set({ windowMode }),
178
+ setWindowModeLocked: (windowModeLocked) => set({ windowModeLocked }),
179
+ bootstrap: async () => {
180
+ set({ loading: true });
181
+ const gameApi = getGameApi();
182
+ const [
183
+ ports,
184
+ deviceState,
185
+ gameState,
186
+ screens,
187
+ shortcuts,
188
+ arduinoBoardConfig,
189
+ deviceSignalTargets,
190
+ windowMode,
191
+ windowModeLocked
192
+ ] = await Promise.all([
193
+ gameApi.listPorts(),
194
+ gameApi.getDeviceState(),
195
+ gameApi.getGameState(),
196
+ gameApi.getAvailableScreens(),
197
+ gameApi.getGlobalShortcuts(),
198
+ gameApi.getArduinoBoardConfig(),
199
+ gameApi.getDeviceSignalTargets(),
200
+ gameApi.getWindowMode(),
201
+ gameApi.isWindowModeLocked()
202
+ ]);
203
+ set({
204
+ ports,
205
+ screens,
206
+ shortcuts,
207
+ arduinoBoardConfig,
208
+ deviceSignalTargets,
209
+ windowMode,
210
+ windowModeLocked,
211
+ deviceState,
212
+ gameState,
213
+ loading: false
214
+ });
215
+ },
216
+ connect: async (portPath) => {
217
+ set({ loading: true });
218
+ const state = await getGameApi().connectDevice(portPath);
219
+ set({ deviceState: state, ports: state.availablePorts, loading: false });
220
+ },
221
+ disconnect: async () => {
222
+ set({ loading: true });
223
+ const state = await getGameApi().disconnectDevice();
224
+ set({ deviceState: state, loading: false });
225
+ },
226
+ send: async (command) => {
227
+ set({ loading: true });
228
+ const gameApi = getGameApi();
229
+ await gameApi.sendCommand(command);
230
+ const state = await gameApi.getDeviceState();
231
+ set({ deviceState: state, loading: false });
232
+ },
233
+ updateGlobalShortcuts: async (shortcuts) => {
234
+ set({ loading: true });
235
+ try {
236
+ const nextShortcuts = await getGameApi().updateGlobalShortcuts(shortcuts);
237
+ set({ shortcuts: nextShortcuts, loading: false });
238
+ } catch {
239
+ const nextShortcuts = await getGameApi().getGlobalShortcuts();
240
+ set({ shortcuts: nextShortcuts, loading: false });
241
+ throw new Error("Failed to update global shortcuts.");
242
+ }
243
+ },
244
+ updateArduinoBoardConfig: async (config) => {
245
+ set({ loading: true });
246
+ try {
247
+ const arduinoBoardConfig = await getGameApi().updateArduinoBoardConfig(config);
248
+ set({ arduinoBoardConfig, loading: false });
249
+ } catch {
250
+ const arduinoBoardConfig = await getGameApi().getArduinoBoardConfig();
251
+ set({ arduinoBoardConfig, loading: false });
252
+ throw new Error("Failed to update Arduino board config.");
253
+ }
254
+ },
255
+ updateWindowMode: async (mode) => {
256
+ set({ loading: true });
257
+ try {
258
+ const windowMode = await getGameApi().setWindowMode(mode);
259
+ set({ windowMode, loading: false });
260
+ } catch {
261
+ const windowMode = await getGameApi().getWindowMode();
262
+ set({ windowMode, loading: false });
263
+ throw new Error("Failed to update window mode.");
264
+ }
265
+ },
266
+ moveToScreen: async (target) => {
267
+ set({ loading: true });
268
+ try {
269
+ const gameState = await getGameApi().moveToScreen(target);
270
+ set({ gameState, loading: false });
271
+ } catch {
272
+ const gameState = await getGameApi().getGameState();
273
+ set({ gameState, loading: false });
274
+ }
275
+ }
276
+ }));
277
+ export {
278
+ configureRendererPreview as c,
279
+ getGameApi as g,
280
+ useAppStore as u
281
+ };
@@ -0,0 +1,152 @@
1
+ import { useState, useCallback, useEffect } from "react";
2
+ import { u as useAppStore, g as getGameApi } from "./store-txJwmrlO.js";
3
+ function normalizeAtodPart(value, label) {
4
+ const normalized = value.trim();
5
+ if (!normalized) {
6
+ throw new Error(`ATOD ${label} is required.`);
7
+ }
8
+ return normalized;
9
+ }
10
+ function useAtodSignalForDefinitions(defaultTarget) {
11
+ const setDeviceState = useAppStore((state) => state.setDeviceState);
12
+ const [sending, setSending] = useState(false);
13
+ const [error, setError] = useState(null);
14
+ const [lastResponse, setLastResponse] = useState(null);
15
+ const sendAtod = useCallback(
16
+ async (target, action) => {
17
+ const normalizedTarget = normalizeAtodPart(target, "target");
18
+ const normalizedAction = normalizeAtodPart(action, "action");
19
+ const gameApi = getGameApi();
20
+ setSending(true);
21
+ setError(null);
22
+ try {
23
+ const response = await gameApi.sendCommand({
24
+ type: "atod",
25
+ target: normalizedTarget,
26
+ action: normalizedAction
27
+ });
28
+ setLastResponse(response);
29
+ if (!response.ok) {
30
+ setError(new Error(response.message));
31
+ }
32
+ setDeviceState(await gameApi.getDeviceState());
33
+ return response;
34
+ } catch (caughtError) {
35
+ const nextError = caughtError instanceof Error ? caughtError : new Error("Failed to send ATOD signal.");
36
+ setError(nextError);
37
+ throw nextError;
38
+ } finally {
39
+ setSending(false);
40
+ }
41
+ },
42
+ [setDeviceState]
43
+ );
44
+ const sendAction = useCallback(
45
+ async (action) => {
46
+ return sendAtod(
47
+ normalizeAtodPart(defaultTarget ?? "", "target"),
48
+ action
49
+ );
50
+ },
51
+ [defaultTarget, sendAtod]
52
+ );
53
+ return {
54
+ sending,
55
+ error,
56
+ lastResponse,
57
+ sendAtod,
58
+ sendAction
59
+ };
60
+ }
61
+ function useAtodSignal(defaultTarget) {
62
+ return useAtodSignalForDefinitions(defaultTarget);
63
+ }
64
+ function createUseAtodSignal(_signalDefinitions) {
65
+ return function useConfiguredAtodSignal(defaultTarget) {
66
+ return useAtodSignalForDefinitions(defaultTarget);
67
+ };
68
+ }
69
+ const idleStatus = () => ({
70
+ phase: "idle",
71
+ updatedAt: (/* @__PURE__ */ new Date(0)).toISOString()
72
+ });
73
+ function useArduinoBuild() {
74
+ const [status, setStatus] = useState(idleStatus);
75
+ const [logs, setLogs] = useState([]);
76
+ const [error, setError] = useState(null);
77
+ useEffect(() => {
78
+ const gameApi = getGameApi();
79
+ let mounted = true;
80
+ void gameApi.getArduinoBuildStatus().then((nextStatus) => {
81
+ if (mounted) {
82
+ setStatus(nextStatus);
83
+ }
84
+ });
85
+ const disposeLog = gameApi.onArduinoLog((entry) => {
86
+ setLogs((current) => [...current, entry].slice(-500));
87
+ });
88
+ const disposeStatus = gameApi.onArduinoStatus((nextStatus) => {
89
+ setStatus(nextStatus);
90
+ });
91
+ return () => {
92
+ mounted = false;
93
+ disposeLog();
94
+ disposeStatus();
95
+ };
96
+ }, []);
97
+ const preview = useCallback(async () => {
98
+ setError(null);
99
+ return getGameApi().previewArduinoSketch();
100
+ }, []);
101
+ const compile = useCallback(async () => {
102
+ setError(null);
103
+ try {
104
+ const result = await getGameApi().compileArduinoSketch();
105
+ if (!result.ok) {
106
+ setError(new Error(result.message));
107
+ }
108
+ return result;
109
+ } catch (caughtError) {
110
+ const nextError = caughtError instanceof Error ? caughtError : new Error("Failed to compile Arduino sketch.");
111
+ setError(nextError);
112
+ throw nextError;
113
+ }
114
+ }, []);
115
+ const upload = useCallback(async (portPath) => {
116
+ setError(null);
117
+ try {
118
+ const result = await getGameApi().uploadArduinoSketch(portPath);
119
+ if (!result.ok) {
120
+ setError(new Error(result.message));
121
+ }
122
+ return result;
123
+ } catch (caughtError) {
124
+ const nextError = caughtError instanceof Error ? caughtError : new Error("Failed to upload Arduino sketch.");
125
+ setError(nextError);
126
+ throw nextError;
127
+ }
128
+ }, []);
129
+ const cancel = useCallback(() => {
130
+ getGameApi().cancelArduinoBuild();
131
+ }, []);
132
+ const clearLogs = useCallback(() => {
133
+ setLogs([]);
134
+ }, []);
135
+ return {
136
+ status,
137
+ logs,
138
+ compiling: status.phase === "compiling" || status.phase === "generating",
139
+ uploading: status.phase === "uploading" || status.phase === "reconnecting-device" || status.phase === "generating",
140
+ error,
141
+ preview,
142
+ compile,
143
+ upload,
144
+ cancel,
145
+ clearLogs
146
+ };
147
+ }
148
+ export {
149
+ useAtodSignal as a,
150
+ createUseAtodSignal as c,
151
+ useArduinoBuild as u
152
+ };
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import process from 'node:process'
3
+ import { stat } from 'node:fs/promises'
4
+ import { join, resolve } from 'node:path'
5
+ import { execFile } from 'node:child_process'
6
+ import { isDirectExecution } from './screen-script-utils.mjs'
7
+
8
+ const projectRootInput = getOptionValue('--project-root')
9
+ const targetBundleId = getTargetBundleId()
10
+ const { bundleRoot, projectRoot, target } = resolveArduinoBundlePaths({
11
+ projectRootInput,
12
+ targetBundleId
13
+ })
14
+
15
+ export function resolveArduinoBundlePaths({
16
+ cwd = process.cwd(),
17
+ projectRootInput,
18
+ targetBundleId = getBundleId(process.platform, process.arch)
19
+ } = {}) {
20
+ const projectRoot = resolve(cwd, projectRootInput ?? '.')
21
+ const target = parseBundleId(targetBundleId)
22
+ return {
23
+ projectRoot,
24
+ targetBundleId,
25
+ target,
26
+ bundleRoot: join(projectRoot, 'resources', 'arduino', targetBundleId)
27
+ }
28
+ }
29
+
30
+ async function main() {
31
+ const requiredPaths = [
32
+ join(bundleRoot, 'bin', target.platform === 'win32' ? 'arduino-cli.exe' : 'arduino-cli'),
33
+ join(bundleRoot, 'data', 'packages', 'arduino', 'hardware', 'avr'),
34
+ join(bundleRoot, 'data', 'packages', 'arduino', 'tools', 'avr-gcc'),
35
+ join(bundleRoot, 'data', 'packages', 'arduino', 'tools', 'avrdude'),
36
+ join(bundleRoot, 'data', 'packages', 'builtin', 'tools', 'ctags'),
37
+ join(bundleRoot, 'data', 'packages', 'builtin', 'tools', 'dfu-discovery'),
38
+ join(bundleRoot, 'data', 'packages', 'builtin', 'tools', 'mdns-discovery'),
39
+ join(bundleRoot, 'data', 'packages', 'builtin', 'tools', 'serial-discovery'),
40
+ join(bundleRoot, 'data', 'packages', 'builtin', 'tools', 'serial-monitor'),
41
+ join(bundleRoot, 'libraries', 'KeyescapeSerialProtocolBridge'),
42
+ join(bundleRoot, 'libraries', 'Keyboard')
43
+ ]
44
+
45
+ const missingPaths = []
46
+ for (const path of requiredPaths) {
47
+ if (!(await exists(path))) {
48
+ missingPaths.push(path)
49
+ }
50
+ }
51
+
52
+ if (missingPaths.length > 0) {
53
+ console.error(`Arduino bundle is missing for ${targetBundleId}.`)
54
+ for (const path of missingPaths) {
55
+ console.error(`- ${path}`)
56
+ }
57
+ console.error(`Run: npm run setup:arduino-cli -- --target ${targetBundleId}`)
58
+ process.exitCode = 1
59
+ return
60
+ }
61
+
62
+ const trackedFiles = await listTrackedBundleFiles()
63
+ if (trackedFiles.length > 0) {
64
+ console.error(`Arduino bundle files must not be committed: ${targetBundleId}`)
65
+ for (const file of trackedFiles.slice(0, 20)) {
66
+ console.error(`- ${file}`)
67
+ }
68
+ if (trackedFiles.length > 20) {
69
+ console.error(`...and ${trackedFiles.length - 20} more`)
70
+ }
71
+ process.exitCode = 1
72
+ return
73
+ }
74
+
75
+ console.log(`Arduino bundle verified: ${targetBundleId}`)
76
+ }
77
+
78
+ function getOptionValue(optionName) {
79
+ const inlinePrefix = `${optionName}=`
80
+ const inlineArgument = process.argv.find((argument) => argument.startsWith(inlinePrefix))
81
+ if (inlineArgument) {
82
+ const value = inlineArgument.slice(inlinePrefix.length)
83
+ if (!value) throw new Error(`${optionName} requires a value.`)
84
+ return value
85
+ }
86
+
87
+ const optionIndex = process.argv.indexOf(optionName)
88
+ const value = optionIndex >= 0 ? process.argv[optionIndex + 1] : undefined
89
+ if (optionIndex >= 0 && (!value || value.startsWith('--'))) {
90
+ throw new Error(`${optionName} requires a value.`)
91
+ }
92
+ return value
93
+ }
94
+
95
+ function getTargetBundleId() {
96
+ return getOptionValue('--target') ?? getBundleId(process.platform, process.arch)
97
+ }
98
+
99
+ function parseBundleId(value) {
100
+ const separatorIndex = value.indexOf('-')
101
+ if (separatorIndex < 0) {
102
+ throw new Error(`Invalid target bundle: ${value}`)
103
+ }
104
+
105
+ const platform = value.slice(0, separatorIndex)
106
+ const arch = value.slice(separatorIndex + 1)
107
+ if (getBundleId(platform, arch) !== value) {
108
+ throw new Error(`Unsupported target bundle: ${value}`)
109
+ }
110
+
111
+ return { platform, arch }
112
+ }
113
+
114
+ function getBundleId(platform, arch) {
115
+ if (platform === 'win32' && arch === 'x64') return 'win32-x64'
116
+ if (platform === 'darwin' && arch === 'arm64') return 'darwin-arm64'
117
+ if (platform === 'darwin' && arch === 'x64') return 'darwin-x64'
118
+ if (platform === 'linux' && arch === 'x64') return 'linux-x64'
119
+ if (platform === 'linux' && arch === 'arm64') return 'linux-arm64'
120
+ throw new Error(`Unsupported Arduino bundle target: ${platform}-${arch}`)
121
+ }
122
+
123
+ async function exists(path) {
124
+ return Boolean(await stat(path).catch(() => undefined))
125
+ }
126
+
127
+ export async function listTrackedBundleFiles({
128
+ projectRoot: root = projectRoot,
129
+ targetBundleId: bundleId = targetBundleId,
130
+ execFileImpl = execFile
131
+ } = {}) {
132
+ return new Promise((resolvePromise, rejectPromise) => {
133
+ execFileImpl(
134
+ 'git',
135
+ ['ls-files', `resources/arduino/${bundleId}`],
136
+ { cwd: root },
137
+ (error, stdout, stderr) => {
138
+ if (error) {
139
+ if (error.code === 128 || /not a git repository/i.test(stderr || error.message)) {
140
+ resolvePromise([])
141
+ return
142
+ }
143
+ rejectPromise(error)
144
+ return
145
+ }
146
+ resolvePromise(stdout.split('\n').filter(Boolean))
147
+ }
148
+ )
149
+ })
150
+ }
151
+
152
+ if (isDirectExecution(import.meta.url, process.argv[1])) {
153
+ main().catch((error) => {
154
+ console.error(error instanceof Error ? error.message : error)
155
+ process.exitCode = 1
156
+ })
157
+ }