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.
- package/chunks/store-txJwmrlO.js +281 -0
- package/chunks/useArduinoBuild-CVr4XAsL.js +152 -0
- package/cli/check-arduino-bundle.mjs +157 -0
- package/cli/doctor-project.mjs +554 -0
- package/cli/generate-screen.mjs +286 -0
- package/cli/migrate-project.mjs +679 -0
- package/cli/new-project.mjs +344 -0
- package/cli/remove-screen.mjs +83 -0
- package/cli/screen-generation-contract.mjs +127 -0
- package/cli/screen-generation-renderers.mjs +71 -0
- package/cli/screen-module-utils.mjs +148 -0
- package/cli/screen-script-utils.mjs +92 -0
- package/cli/setup-arduino-cli.mjs +515 -0
- package/cli/source-module-specifiers.mjs +89 -0
- package/cli/sync-screens.mjs +48 -0
- package/main/index.js +2003 -0
- package/package.json +108 -0
- package/preload/index.js +69 -0
- package/renderer/components/VideoSceneScreen.js +160 -0
- package/renderer/hooks/index.js +6 -0
- package/renderer/index.js +3092 -0
- package/renderer/store.js +6 -0
- package/renderer/styles.css +1395 -0
- package/shared/arduino-board.js +136 -0
- package/shared/arduino-keyboard-shortcut.js +77 -0
- package/shared/index.js +25 -0
- package/shared/screen-catalog.js +35 -0
- package/shared/screen-shortcuts.js +164 -0
- package/shared/types.js +1 -0
- package/templates/project/README.md +45 -0
- package/templates/project/build/favicon-mac.png +0 -0
- package/templates/project/build/favicon.ico +0 -0
- package/templates/project/build/favicon.png +0 -0
- package/templates/project/e2e/smoke.spec.ts +10 -0
- package/templates/project/electron.vite.config.ts +40 -0
- package/templates/project/eslint.config.js +23 -0
- package/templates/project/gitignore +19 -0
- package/templates/project/media/audio/.gitkeep +1 -0
- package/templates/project/media/font/.gitkeep +1 -0
- package/templates/project/media/image/.gitkeep +1 -0
- package/templates/project/media/video/.gitkeep +1 -0
- package/templates/project/media/video/external-sample-30s.mp4 +0 -0
- package/templates/project/package.json +117 -0
- package/templates/project/playwright.config.ts +7 -0
- package/templates/project/postcss.config.js +6 -0
- package/templates/project/src/arduino-output-signals.ts +19 -0
- package/templates/project/src/assets/audio/.gitkeep +1 -0
- package/templates/project/src/assets/font/PretendardVariable.woff2 +0 -0
- package/templates/project/src/assets/image/.gitkeep +1 -0
- package/templates/project/src/assets/image/key-icon.png +0 -0
- package/templates/project/src/assets/video/.gitkeep +1 -0
- package/templates/project/src/assets/video/sample-30s.mp4 +0 -0
- package/templates/project/src/device-signal-handlers.test.ts +9 -0
- package/templates/project/src/device-signal-handlers.ts +14 -0
- package/templates/project/src/device-signal-targets.ts +3 -0
- package/templates/project/src/main/index.ts +17 -0
- package/templates/project/src/preload/index.ts +4 -0
- package/templates/project/src/project.config.ts +11 -0
- package/templates/project/src/renderer/index.html +16 -0
- package/templates/project/src/renderer/main.tsx +20 -0
- package/templates/project/src/renderer/vite-env.d.ts +1 -0
- package/templates/project/src/screen-definitions.ts +75 -0
- package/templates/project/src/screens/Screen001Black.test.tsx +21 -0
- package/templates/project/src/screens/Screen001Black.tsx +38 -0
- package/templates/project/src/screens/Screen002Video.test.tsx +18 -0
- package/templates/project/src/screens/Screen002Video.tsx +22 -0
- package/templates/project/src/screens/Screen003ExternalVideo.test.tsx +26 -0
- package/templates/project/src/screens/Screen003ExternalVideo.tsx +22 -0
- package/templates/project/src/store.test.ts +21 -0
- package/templates/project/src/store.ts +32 -0
- package/templates/project/src/styles.css +60 -0
- package/templates/project/tailwind.config.ts +69 -0
- package/templates/project/tsconfig.json +4 -0
- package/templates/project/tsconfig.node.json +32 -0
- package/templates/project/vitest.config.ts +20 -0
- package/templates/project/vitest.setup.ts +1 -0
- package/types/main/app-keyboard-shortcuts.d.ts +4 -0
- package/types/main/arduino-cli.d.ts +55 -0
- package/types/main/arduino-sketch-generator.d.ts +10 -0
- package/types/main/device-controller.d.ts +39 -0
- package/types/main/device-log-writer.d.ts +21 -0
- package/types/main/dtoa-dispatcher.d.ts +17 -0
- package/types/main/dtoa-handler.d.ts +9 -0
- package/types/main/game-session.d.ts +12 -0
- package/types/main/kiosk-quit.d.ts +5 -0
- package/types/main/media-manager.d.ts +17 -0
- package/types/main/runtime-paths.d.ts +10 -0
- package/types/main/serial-protocol.d.ts +29 -0
- package/types/main/start.d.ts +2 -0
- package/types/main/window-mode.d.ts +18 -0
- package/types/main/windows-key-lock.d.ts +3 -0
- package/types/preload/bridge.d.ts +4 -0
- package/types/renderer/src/App.d.ts +3 -0
- package/types/renderer/src/KeyScreenApp.d.ts +3 -0
- package/types/renderer/src/bridge.d.ts +3 -0
- package/types/renderer/src/components/DeviceLogOverlay.d.ts +7 -0
- package/types/renderer/src/components/ScreenRenderer.d.ts +7 -0
- package/types/renderer/src/components/SplashScreen.d.ts +7 -0
- package/types/renderer/src/components/VideoSceneScreen.d.ts +16 -0
- package/types/renderer/src/framework/AdminScreen.d.ts +3 -0
- package/types/renderer/src/hooks/index.d.ts +4 -0
- package/types/renderer/src/hooks/useArduinoBuild.d.ts +14 -0
- package/types/renderer/src/hooks/useAtodSignal.d.ts +12 -0
- package/types/renderer/src/index.d.ts +9 -0
- package/types/renderer/src/project-runtime.d.ts +10 -0
- package/types/renderer/src/screen-types.d.ts +24 -0
- package/types/renderer/src/store.d.ts +33 -0
- package/types/shared/arduino-board.d.ts +11 -0
- package/types/shared/arduino-keyboard-shortcut.d.ts +14 -0
- package/types/shared/index.d.ts +5 -0
- package/types/shared/screen-catalog.d.ts +19 -0
- package/types/shared/screen-shortcuts.d.ts +10 -0
- package/types/shared/types.d.ts +272 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { mkdir, stat, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { confirm, input, select } from '@inquirer/prompts'
|
|
6
|
+
import {
|
|
7
|
+
pickScreenGenerationArgs,
|
|
8
|
+
resolveScreenGenerationContract,
|
|
9
|
+
SCREEN_GENERATION_OPTION_KEYS
|
|
10
|
+
} from './screen-generation-contract.mjs'
|
|
11
|
+
import {
|
|
12
|
+
assertKnownArgs,
|
|
13
|
+
assertValidId,
|
|
14
|
+
isDirectExecution,
|
|
15
|
+
parseArgs,
|
|
16
|
+
toComponentBaseName
|
|
17
|
+
} from './screen-script-utils.mjs'
|
|
18
|
+
import { syncScreens } from './sync-screens.mjs'
|
|
19
|
+
|
|
20
|
+
const GENERATE_SCREEN_OPTION_KEYS = [
|
|
21
|
+
...SCREEN_GENERATION_OPTION_KEYS,
|
|
22
|
+
'id',
|
|
23
|
+
'title',
|
|
24
|
+
'description',
|
|
25
|
+
'template',
|
|
26
|
+
'video-src'
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
async function ensureMissing(path) {
|
|
30
|
+
try {
|
|
31
|
+
await stat(path)
|
|
32
|
+
throw new Error(`Refusing to overwrite existing file: ${path}`)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw error
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toAssetImportPath(source) {
|
|
43
|
+
if (source.startsWith('/src/assets/')) {
|
|
44
|
+
return `@assets/${source.slice('/src/assets/'.length)}?url`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (source.startsWith('@assets/')) {
|
|
48
|
+
return source.includes('?') ? source : `${source}?url`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function generateScreen(args, { cwd = process.cwd(), interactive = process.stdout.isTTY } = {}) {
|
|
55
|
+
assertKnownArgs(args, GENERATE_SCREEN_OPTION_KEYS)
|
|
56
|
+
const contract = resolveScreenGenerationContract(args, { cwd })
|
|
57
|
+
const screenDirectory = contract.screenDirectory
|
|
58
|
+
const id =
|
|
59
|
+
args.id ??
|
|
60
|
+
(!interactive
|
|
61
|
+
? (() => {
|
|
62
|
+
throw new Error('Missing required --id argument.')
|
|
63
|
+
})()
|
|
64
|
+
:
|
|
65
|
+
(await input({
|
|
66
|
+
message: 'Screen id',
|
|
67
|
+
default: 'puzzle-1',
|
|
68
|
+
validate: (value) => {
|
|
69
|
+
try {
|
|
70
|
+
assertValidId(value.trim())
|
|
71
|
+
return true
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return error instanceof Error ? error.message : String(error)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})))
|
|
77
|
+
const title =
|
|
78
|
+
args.title ??
|
|
79
|
+
(!interactive
|
|
80
|
+
? (() => {
|
|
81
|
+
throw new Error('Missing required --title argument.')
|
|
82
|
+
})()
|
|
83
|
+
:
|
|
84
|
+
(await input({
|
|
85
|
+
message: 'Screen title',
|
|
86
|
+
validate: (value) => (value.trim() ? true : 'Screen title is required.')
|
|
87
|
+
})))
|
|
88
|
+
const description =
|
|
89
|
+
args.description ??
|
|
90
|
+
(interactive
|
|
91
|
+
? await input({
|
|
92
|
+
message: 'Description (optional)'
|
|
93
|
+
})
|
|
94
|
+
: '')
|
|
95
|
+
const template =
|
|
96
|
+
args.template ??
|
|
97
|
+
(interactive
|
|
98
|
+
? await select({
|
|
99
|
+
message: 'Screen template',
|
|
100
|
+
choices: [
|
|
101
|
+
{ name: '기본 scene 화면', value: 'basic' },
|
|
102
|
+
{ name: '영상 자동재생 scene 화면', value: 'video' }
|
|
103
|
+
],
|
|
104
|
+
default: 'basic'
|
|
105
|
+
})
|
|
106
|
+
: 'basic')
|
|
107
|
+
|
|
108
|
+
if (!['basic', 'video'].includes(template)) {
|
|
109
|
+
throw new Error('Screen template must be either "basic" or "video".')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const videoSrc =
|
|
113
|
+
template === 'video'
|
|
114
|
+
? args['video-src'] ??
|
|
115
|
+
(!interactive
|
|
116
|
+
? (() => {
|
|
117
|
+
throw new Error('Missing required --video-src argument for video template.')
|
|
118
|
+
})()
|
|
119
|
+
: await input({
|
|
120
|
+
message: 'Video src',
|
|
121
|
+
default: '/src/assets/video/intro.mp4',
|
|
122
|
+
validate: (value) => (value.trim() ? true : 'Video src is required.')
|
|
123
|
+
}))
|
|
124
|
+
: undefined
|
|
125
|
+
|
|
126
|
+
assertValidId(id)
|
|
127
|
+
|
|
128
|
+
if (interactive && !args.id && !args.title && !args.description) {
|
|
129
|
+
const shouldProceed = await confirm({
|
|
130
|
+
message: `Create screen "${id}" with title "${title}"?`,
|
|
131
|
+
default: true
|
|
132
|
+
})
|
|
133
|
+
if (!shouldProceed) {
|
|
134
|
+
throw new Error('Screen generation cancelled.')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const componentBaseName = toComponentBaseName(id)
|
|
139
|
+
const componentKey = `${id}-screen`
|
|
140
|
+
const componentFilePath = join(screenDirectory, `${componentBaseName}.tsx`)
|
|
141
|
+
const testFilePath = join(screenDirectory, `${componentBaseName}.test.tsx`)
|
|
142
|
+
|
|
143
|
+
await ensureMissing(componentFilePath)
|
|
144
|
+
await ensureMissing(testFilePath)
|
|
145
|
+
const idLiteral = JSON.stringify(id)
|
|
146
|
+
const titleLiteral = JSON.stringify(title)
|
|
147
|
+
const descriptionLiteral = description ? JSON.stringify(description) : undefined
|
|
148
|
+
const videoSrcLiteral = videoSrc ? JSON.stringify(videoSrc) : undefined
|
|
149
|
+
const videoAssetImportPath = videoSrc ? toAssetImportPath(videoSrc) : undefined
|
|
150
|
+
const componentSource =
|
|
151
|
+
template === 'video'
|
|
152
|
+
? `/* eslint-disable react-refresh/only-export-components */
|
|
153
|
+
import type { SceneScreenDefinition } from ${JSON.stringify(contract.importPaths.definitionsTypes)}
|
|
154
|
+
import VideoSceneScreen, { preloadVideoSource } from ${JSON.stringify(contract.importPaths.videoSceneScreen)}
|
|
155
|
+
import type { ScreenPreloadFunction } from ${JSON.stringify(contract.importPaths.registryScreenTypes)}
|
|
156
|
+
${videoAssetImportPath ? `import videoSourceUrl from ${JSON.stringify(videoAssetImportPath)}\n` : ''}
|
|
157
|
+
|
|
158
|
+
const VIDEO_SRC = ${videoAssetImportPath ? 'videoSourceUrl' : videoSrcLiteral}
|
|
159
|
+
|
|
160
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
161
|
+
export const screen: SceneScreenDefinition = {
|
|
162
|
+
id: ${idLiteral},
|
|
163
|
+
title: ${titleLiteral},
|
|
164
|
+
${descriptionLiteral ? ` description: ${descriptionLiteral},\n` : ''} kind: 'scene'
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const preload: ScreenPreloadFunction = () => preloadVideoSource(VIDEO_SRC)
|
|
168
|
+
|
|
169
|
+
function ${componentBaseName}() {
|
|
170
|
+
return <VideoSceneScreen src={VIDEO_SRC} />
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default ${componentBaseName}
|
|
174
|
+
`
|
|
175
|
+
: `import type { SceneScreenDefinition } from ${JSON.stringify(contract.importPaths.definitionsTypes)}
|
|
176
|
+
import type {
|
|
177
|
+
ScreenComponentProps,
|
|
178
|
+
ScreenPreloadFunction
|
|
179
|
+
} from ${JSON.stringify(contract.importPaths.registryScreenTypes)}
|
|
180
|
+
|
|
181
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
182
|
+
export const screen: SceneScreenDefinition = {
|
|
183
|
+
id: ${idLiteral},
|
|
184
|
+
title: ${titleLiteral},
|
|
185
|
+
${descriptionLiteral ? ` description: ${descriptionLiteral},\n` : ''} kind: 'scene'
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const preload: ScreenPreloadFunction = () => {
|
|
189
|
+
// 이미지, 영상, 오디오처럼 mount 전에 준비할 리소스가 있으면 여기에서 로드하세요.
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function ${componentBaseName}({ gameState, screen }: ScreenComponentProps) {
|
|
193
|
+
return (
|
|
194
|
+
<main className="flex min-h-screen flex-col justify-between bg-app-bg p-8 text-text">
|
|
195
|
+
<div>
|
|
196
|
+
<p className="text-xs uppercase tracking-[0.25em] text-text-subtle">
|
|
197
|
+
{screen.kind} screen
|
|
198
|
+
</p>
|
|
199
|
+
<h1 className="mt-3 font-display text-4xl text-text">{screen.title}</h1>
|
|
200
|
+
<p className="mt-4 max-w-2xl text-sm leading-7 text-text-muted">
|
|
201
|
+
{screen.description ?? '${title} 화면용 보일러플레이트입니다. 이 컴포넌트는 다른 화면과 완전히 독립적인 레이아웃을 가지므로, 여기에서 장면 전용 UI와 로직을 자유롭게 구성하세요.'}
|
|
202
|
+
</p>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<div className="mt-10 grid gap-4 md:grid-cols-3">
|
|
206
|
+
<div className="rounded-xl border border-border-soft bg-surface-soft p-4">
|
|
207
|
+
<p className="text-xs uppercase tracking-[0.25em] text-text-subtle">Screen Id</p>
|
|
208
|
+
<p className="mt-2 text-sm text-text">{screen.id}</p>
|
|
209
|
+
</div>
|
|
210
|
+
<div className="rounded-xl border border-border-soft bg-surface-soft p-4">
|
|
211
|
+
<p className="text-xs uppercase tracking-[0.25em] text-text-subtle">Game Mode</p>
|
|
212
|
+
<p className="mt-2 text-sm text-text">{gameState.mode}</p>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
</main>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default ${componentBaseName}
|
|
220
|
+
`
|
|
221
|
+
|
|
222
|
+
const testSource =
|
|
223
|
+
template === 'video'
|
|
224
|
+
? `import { render, screen } from '@testing-library/react'
|
|
225
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
226
|
+
import ${componentBaseName} from './${componentBaseName}'
|
|
227
|
+
|
|
228
|
+
describe('${componentBaseName}', () => {
|
|
229
|
+
afterEach(() => {
|
|
230
|
+
vi.restoreAllMocks()
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('renders video scene template', () => {
|
|
234
|
+
vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue(undefined)
|
|
235
|
+
vi.spyOn(HTMLMediaElement.prototype, 'load').mockImplementation(() => undefined)
|
|
236
|
+
|
|
237
|
+
render(<${componentBaseName} />)
|
|
238
|
+
|
|
239
|
+
expect(screen.getByLabelText('video scene')).toHaveAttribute('src', ${videoSrcLiteral})
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
`
|
|
243
|
+
: `import { render, screen } from '@testing-library/react'
|
|
244
|
+
import { describe, expect, it } from 'vitest'
|
|
245
|
+
import ${componentBaseName}, { screen as screenDefinition } from './${componentBaseName}'
|
|
246
|
+
|
|
247
|
+
describe('${componentBaseName}', () => {
|
|
248
|
+
it('renders registered screen metadata', () => {
|
|
249
|
+
render(
|
|
250
|
+
<${componentBaseName}
|
|
251
|
+
gameState={{
|
|
252
|
+
mode: 'running',
|
|
253
|
+
currentStepId: '${id}',
|
|
254
|
+
updatedAt: new Date().toISOString()
|
|
255
|
+
}}
|
|
256
|
+
screen={{ ...screenDefinition, componentKey: '${componentKey}' }}
|
|
257
|
+
/>
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
expect(screen.getByRole('heading', { name: ${titleLiteral} })).toBeInTheDocument()
|
|
261
|
+
expect(screen.getByText(${idLiteral})).toBeInTheDocument()
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
`
|
|
265
|
+
|
|
266
|
+
await mkdir(dirname(componentFilePath), { recursive: true })
|
|
267
|
+
await Promise.all([
|
|
268
|
+
writeFile(componentFilePath, componentSource),
|
|
269
|
+
writeFile(testFilePath, testSource)
|
|
270
|
+
])
|
|
271
|
+
await syncScreens(pickScreenGenerationArgs(args), { cwd })
|
|
272
|
+
|
|
273
|
+
return { componentFilePath, contract, id }
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function main() {
|
|
277
|
+
const result = await generateScreen(parseArgs(process.argv.slice(2)))
|
|
278
|
+
process.stdout.write(`Created screen "${result.id}" at ${result.componentFilePath}\n`)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (isDirectExecution(import.meta.url, process.argv[1])) {
|
|
282
|
+
main().catch((error) => {
|
|
283
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
|
|
284
|
+
process.exitCode = 1
|
|
285
|
+
})
|
|
286
|
+
}
|