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,148 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, extname, join } from 'node:path'
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
import { assertValidId, toPascalCase } from './screen-script-utils.mjs'
|
|
5
|
+
|
|
6
|
+
function hasModifier(node, kind) {
|
|
7
|
+
return Boolean(node.modifiers?.some((modifier) => modifier.kind === kind))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getStringLiteralValue(node) {
|
|
11
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
12
|
+
return node.text
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function toImportIdentifier(fileBaseName) {
|
|
19
|
+
const pascal = toPascalCase(fileBaseName)
|
|
20
|
+
if (!pascal) {
|
|
21
|
+
throw new Error(`Invalid screen filename: ${fileBaseName}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return /^[0-9]/.test(pascal) ? `Screen${pascal}` : pascal
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseScreenMetadata(sourceText, filePath) {
|
|
28
|
+
const sourceFile = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX)
|
|
29
|
+
let hasDefaultExport = false
|
|
30
|
+
let metadata
|
|
31
|
+
|
|
32
|
+
for (const statement of sourceFile.statements) {
|
|
33
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
|
|
34
|
+
hasDefaultExport = true
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
(ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&
|
|
40
|
+
hasModifier(statement, ts.SyntaxKind.ExportKeyword) &&
|
|
41
|
+
hasModifier(statement, ts.SyntaxKind.DefaultKeyword)
|
|
42
|
+
) {
|
|
43
|
+
hasDefaultExport = true
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!ts.isVariableStatement(statement) || !hasModifier(statement, ts.SyntaxKind.ExportKeyword)) {
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
52
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'screen') {
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!declaration.initializer || !ts.isObjectLiteralExpression(declaration.initializer)) {
|
|
57
|
+
throw new Error(`"screen" export must be an object literal: ${filePath}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const values = {}
|
|
61
|
+
for (const property of declaration.initializer.properties) {
|
|
62
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
|
|
63
|
+
throw new Error(`Unsupported "screen" property in ${filePath}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const literalValue = getStringLiteralValue(property.initializer)
|
|
67
|
+
if (literalValue === undefined) {
|
|
68
|
+
throw new Error(`"screen.${property.name.text}" must be a string literal in ${filePath}`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
values[property.name.text] = literalValue
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
metadata = values
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!hasDefaultExport) {
|
|
79
|
+
throw new Error(`Screen module must default export a component: ${filePath}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!metadata) {
|
|
83
|
+
throw new Error(`Screen module must export "screen": ${filePath}`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { id, title, description, kind, shortcut, componentKey, isInitial, ...unknown } = metadata
|
|
87
|
+
if (componentKey || isInitial) {
|
|
88
|
+
throw new Error(`"screen" export cannot define componentKey or isInitial: ${filePath}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const unknownKeys = Object.keys(unknown)
|
|
92
|
+
if (unknownKeys.length > 0) {
|
|
93
|
+
throw new Error(`Unsupported "screen" keys in ${filePath}: ${unknownKeys.join(', ')}`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!id || !title || !kind) {
|
|
97
|
+
throw new Error(`"screen" export must define id, title, and kind: ${filePath}`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
assertValidId(id)
|
|
101
|
+
|
|
102
|
+
if (kind !== 'scene') {
|
|
103
|
+
throw new Error(`"screen.kind" must be "scene": ${filePath}`)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
id,
|
|
108
|
+
title,
|
|
109
|
+
description,
|
|
110
|
+
kind,
|
|
111
|
+
shortcut
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function loadSceneScreenModules(screenDirectory) {
|
|
116
|
+
const entries = await readdir(screenDirectory, { withFileTypes: true })
|
|
117
|
+
const modules = []
|
|
118
|
+
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
if (!entry.isFile()) {
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const extension = extname(entry.name)
|
|
125
|
+
if (extension !== '.tsx') {
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
if (entry.name === 'AdminScreen.tsx' || entry.name.endsWith('.test.tsx')) {
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const filePath = join(screenDirectory, entry.name)
|
|
133
|
+
const sourceText = await readFile(filePath, 'utf8')
|
|
134
|
+
const fileBaseName = basename(entry.name, extension)
|
|
135
|
+
const screen = parseScreenMetadata(sourceText, filePath)
|
|
136
|
+
|
|
137
|
+
modules.push({
|
|
138
|
+
fileBaseName,
|
|
139
|
+
filePath,
|
|
140
|
+
importIdentifier: toImportIdentifier(fileBaseName),
|
|
141
|
+
componentKey: `${screen.id}-screen`,
|
|
142
|
+
screen
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
modules.sort((left, right) => left.screen.id.localeCompare(right.screen.id))
|
|
147
|
+
return modules
|
|
148
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
4
|
+
|
|
5
|
+
export function parseArgs(argv) {
|
|
6
|
+
const result = {}
|
|
7
|
+
|
|
8
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
9
|
+
const token = argv[index]
|
|
10
|
+
if (!token.startsWith('--')) {
|
|
11
|
+
throw new Error(`Unexpected argument: ${token}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const [key, inlineValue] = token.slice(2).split(/=(.*)/s, 2)
|
|
15
|
+
if (!key) {
|
|
16
|
+
throw new Error('Option name is required after "--".')
|
|
17
|
+
}
|
|
18
|
+
if (Object.hasOwn(result, key)) {
|
|
19
|
+
throw new Error(`Option may only be provided once: --${key}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (inlineValue !== undefined) {
|
|
23
|
+
if (!inlineValue) {
|
|
24
|
+
throw new Error(`Option --${key} requires a value.`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
result[key] = inlineValue
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const value = argv[index + 1]
|
|
32
|
+
if (!value || value.startsWith('--')) {
|
|
33
|
+
throw new Error(`Option --${key} requires a value.`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
result[key] = value
|
|
37
|
+
index += 1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function assertKnownArgs(args, allowedKeys) {
|
|
44
|
+
for (const key of Object.keys(args)) {
|
|
45
|
+
if (!allowedKeys.includes(key)) {
|
|
46
|
+
throw new Error(`Unknown option: --${key}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isDirectExecution(moduleUrl, entryPath) {
|
|
52
|
+
if (typeof entryPath !== 'string') {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
const absoluteEntryPath = resolve(entryPath)
|
|
56
|
+
if (moduleUrl === pathToFileURL(absoluteEntryPath).href) {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
return realpathSync(fileURLToPath(moduleUrl)) === realpathSync(absoluteEntryPath)
|
|
62
|
+
} catch {
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function toPascalCase(value) {
|
|
68
|
+
return value
|
|
69
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
72
|
+
.join('')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function toComponentBaseName(id) {
|
|
76
|
+
const pascal = toPascalCase(id)
|
|
77
|
+
if (!pascal) {
|
|
78
|
+
throw new Error('Screen id must contain at least one alphanumeric character.')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return /^[0-9]/.test(pascal) ? `Screen${pascal}` : `${pascal}Screen`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function assertValidId(id) {
|
|
85
|
+
if (!id) {
|
|
86
|
+
throw new Error('Missing required --id argument.')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!/^[a-z0-9-]+$/.test(id)) {
|
|
90
|
+
throw new Error('Screen id must use lowercase letters, numbers, and hyphens only.')
|
|
91
|
+
}
|
|
92
|
+
}
|