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,344 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { execFileSync } from 'node:child_process'
|
|
4
|
+
import {
|
|
5
|
+
cpSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
renameSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
statSync,
|
|
13
|
+
writeFileSync
|
|
14
|
+
} from 'node:fs'
|
|
15
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
import { confirm, input } from '@inquirer/prompts'
|
|
18
|
+
import { isDirectExecution, parseArgs } from './screen-script-utils.mjs'
|
|
19
|
+
|
|
20
|
+
const cliDirectory = dirname(fileURLToPath(import.meta.url))
|
|
21
|
+
const frameworkRoot = resolve(cliDirectory, '..')
|
|
22
|
+
const projectTemplateDirectory = join(frameworkRoot, 'templates/project')
|
|
23
|
+
|
|
24
|
+
export const PROJECT_COPY_PATHS = ['.gitignore', 'build', 'e2e', 'media', 'src']
|
|
25
|
+
|
|
26
|
+
const EXCLUDED_NAMES = new Set(['.DS_Store', 'node_modules', 'out', 'release', 'dist', 'coverage'])
|
|
27
|
+
|
|
28
|
+
const CONSUMER_IMPORT_REPLACEMENTS = new Map([
|
|
29
|
+
['@shared/types', 'key-screen-framework/shared/types'],
|
|
30
|
+
['@shared/screens', '@project/screen-definitions'],
|
|
31
|
+
['@framework/renderer/src/screen-types', 'key-screen-framework/renderer'],
|
|
32
|
+
['@framework/renderer/src/hooks', 'key-screen-framework/renderer/hooks'],
|
|
33
|
+
[
|
|
34
|
+
'@renderer/components/VideoSceneScreen',
|
|
35
|
+
'key-screen-framework/renderer/components/VideoSceneScreen'
|
|
36
|
+
]
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
function parseBooleanFlag(value) {
|
|
40
|
+
if (value === undefined) return undefined
|
|
41
|
+
if (value === 'true') return true
|
|
42
|
+
if (value === 'false') return false
|
|
43
|
+
throw new Error(`Boolean flag must be "true" or "false": ${value}`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function slugifyPackageName(value) {
|
|
47
|
+
return (
|
|
48
|
+
value
|
|
49
|
+
.trim()
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
52
|
+
.replace(/^-+|-+$/g, '') || 'new-electron-app'
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function toAppId(packageName) {
|
|
57
|
+
return `com.example.${packageName.replace(/[^a-z0-9]+/g, '') || 'app'}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function ensureTargetAvailable(targetDirectory) {
|
|
61
|
+
if (!existsSync(targetDirectory)) return
|
|
62
|
+
const stats = statSync(targetDirectory)
|
|
63
|
+
if (!stats.isDirectory()) {
|
|
64
|
+
throw new Error(`Target path is not a directory: ${targetDirectory}`)
|
|
65
|
+
}
|
|
66
|
+
if (readdirSync(targetDirectory).length > 0) {
|
|
67
|
+
throw new Error(`Target directory must be empty: ${targetDirectory}`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function shouldCopy(sourcePath) {
|
|
72
|
+
return !EXCLUDED_NAMES.has(sourcePath.split(sep).at(-1))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function copyPathIfPresent(sourceRoot, targetRoot, projectPath) {
|
|
76
|
+
const sourcePath = join(sourceRoot, projectPath)
|
|
77
|
+
if (!existsSync(sourcePath)) return
|
|
78
|
+
cpSync(sourcePath, join(targetRoot, projectPath), {
|
|
79
|
+
recursive: true,
|
|
80
|
+
dereference: false,
|
|
81
|
+
filter: shouldCopy
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function copyProjectTemplate(sourceRoot, templateDirectory, targetDirectory) {
|
|
86
|
+
mkdirSync(targetDirectory, { recursive: true })
|
|
87
|
+
for (const projectPath of PROJECT_COPY_PATHS) {
|
|
88
|
+
copyPathIfPresent(sourceRoot, targetDirectory, projectPath)
|
|
89
|
+
}
|
|
90
|
+
cpSync(templateDirectory, targetDirectory, {
|
|
91
|
+
recursive: true,
|
|
92
|
+
dereference: false,
|
|
93
|
+
filter: shouldCopy
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const packedGitignorePath = join(targetDirectory, 'gitignore')
|
|
97
|
+
if (existsSync(packedGitignorePath)) {
|
|
98
|
+
renameSync(packedGitignorePath, join(targetDirectory, '.gitignore'))
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function replaceFile(path, transform) {
|
|
103
|
+
writeFileSync(path, transform(readFileSync(path, 'utf8')))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function updatePackageJson(
|
|
107
|
+
targetDirectory,
|
|
108
|
+
{ packageName, productName, appId, frameworkDependency }
|
|
109
|
+
) {
|
|
110
|
+
const packageJsonPath = join(targetDirectory, 'package.json')
|
|
111
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
112
|
+
packageJson.name = packageName
|
|
113
|
+
packageJson.build.appId = appId
|
|
114
|
+
packageJson.build.productName = productName
|
|
115
|
+
packageJson.dependencies['key-screen-framework'] = frameworkDependency
|
|
116
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function updateProjectConfig(targetDirectory, appName) {
|
|
120
|
+
replaceFile(join(targetDirectory, 'src/project.config.ts'), (source) =>
|
|
121
|
+
source.replace("appName: 'KEYESCAPE'", `appName: ${JSON.stringify(appName)}`)
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function updateReadme(targetDirectory, appName) {
|
|
126
|
+
replaceFile(join(targetDirectory, 'README.md'), (source) =>
|
|
127
|
+
source.replace('# New Key Screen Project', `# ${appName}`)
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function enableProjectTailwindUtilities(targetDirectory) {
|
|
132
|
+
const stylesPath = join(targetDirectory, 'src/styles.css')
|
|
133
|
+
replaceFile(stylesPath, (source) =>
|
|
134
|
+
source.includes('@tailwind utilities;') ? source : `@tailwind utilities;\n\n${source}`
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function updateGeneratedIgnore(targetDirectory) {
|
|
139
|
+
const ignorePath = join(targetDirectory, '.gitignore')
|
|
140
|
+
if (!existsSync(ignorePath)) return
|
|
141
|
+
replaceFile(ignorePath, (source) => source.replaceAll('framework/generated', 'src/generated'))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function rewriteSourceImports(directory) {
|
|
145
|
+
if (!existsSync(directory)) return
|
|
146
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
147
|
+
const path = join(directory, entry.name)
|
|
148
|
+
if (entry.isDirectory()) {
|
|
149
|
+
rewriteSourceImports(path)
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
if (!entry.isFile() || !/\.[cm]?[jt]sx?$/.test(entry.name)) continue
|
|
153
|
+
|
|
154
|
+
replaceFile(path, (source) => {
|
|
155
|
+
let result = source
|
|
156
|
+
for (const [internalPath, publicPath] of CONSUMER_IMPORT_REPLACEMENTS) {
|
|
157
|
+
result = result.replaceAll(internalPath, publicPath)
|
|
158
|
+
}
|
|
159
|
+
return result
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function readFrameworkPackageManifest(sourceRoot) {
|
|
165
|
+
const distributionManifest = join(sourceRoot, 'dist/package/package.json')
|
|
166
|
+
const manifestPath = existsSync(distributionManifest)
|
|
167
|
+
? distributionManifest
|
|
168
|
+
: join(sourceRoot, 'package.json')
|
|
169
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
170
|
+
if (typeof manifest.version !== 'string' || !manifest.version.trim()) {
|
|
171
|
+
throw new Error(`Framework package version is missing: ${manifestPath}`)
|
|
172
|
+
}
|
|
173
|
+
return manifest
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function resolveFrameworkDependency(sourceRoot, override) {
|
|
177
|
+
return override || `^${readFrameworkPackageManifest(sourceRoot).version}`
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function resolveNpmCommand(
|
|
181
|
+
args,
|
|
182
|
+
{ env = process.env, platform = process.platform, execPath = process.execPath } = {}
|
|
183
|
+
) {
|
|
184
|
+
const npmExecPath = env.npm_execpath
|
|
185
|
+
if (typeof npmExecPath === 'string' && npmExecPath.trim()) {
|
|
186
|
+
return { command: execPath, args: [npmExecPath, ...args] }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (platform === 'win32') {
|
|
190
|
+
return {
|
|
191
|
+
command: env.ComSpec || env.COMSPEC || 'cmd.exe',
|
|
192
|
+
args: ['/d', '/s', '/c', 'npm.cmd', ...args]
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return { command: 'npm', args }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function scaffoldProject({
|
|
200
|
+
sourceRoot = frameworkRoot,
|
|
201
|
+
templateDirectory = projectTemplateDirectory,
|
|
202
|
+
targetDirectory,
|
|
203
|
+
packageName,
|
|
204
|
+
appName,
|
|
205
|
+
appId,
|
|
206
|
+
frameworkDependency
|
|
207
|
+
}) {
|
|
208
|
+
ensureTargetAvailable(targetDirectory)
|
|
209
|
+
copyProjectTemplate(sourceRoot, templateDirectory, targetDirectory)
|
|
210
|
+
rewriteSourceImports(join(targetDirectory, 'src'))
|
|
211
|
+
updatePackageJson(targetDirectory, {
|
|
212
|
+
packageName,
|
|
213
|
+
productName: appName,
|
|
214
|
+
appId,
|
|
215
|
+
frameworkDependency: resolveFrameworkDependency(sourceRoot, frameworkDependency)
|
|
216
|
+
})
|
|
217
|
+
updateProjectConfig(targetDirectory, appName)
|
|
218
|
+
enableProjectTailwindUtilities(targetDirectory)
|
|
219
|
+
updateGeneratedIgnore(targetDirectory)
|
|
220
|
+
updateReadme(targetDirectory, appName)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function runCommand(command, args, cwd) {
|
|
224
|
+
execFileSync(command, args, { cwd, stdio: 'inherit' })
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function main() {
|
|
228
|
+
const args = parseArgs(process.argv.slice(2))
|
|
229
|
+
const interactive = process.stdout.isTTY
|
|
230
|
+
const appName =
|
|
231
|
+
args.name ??
|
|
232
|
+
(!interactive
|
|
233
|
+
? (() => {
|
|
234
|
+
throw new Error('Missing required --name argument.')
|
|
235
|
+
})()
|
|
236
|
+
: await input({
|
|
237
|
+
message: '앱 이름 (프로그램 이름으로 표시될 이름)',
|
|
238
|
+
default: 'New Electron App',
|
|
239
|
+
validate: (value) => (value.trim() ? true : '앱 이름은 필수입니다.')
|
|
240
|
+
}))
|
|
241
|
+
const packageName =
|
|
242
|
+
args['package-name'] ??
|
|
243
|
+
(interactive
|
|
244
|
+
? await input({
|
|
245
|
+
message: '패키지 이름',
|
|
246
|
+
default: slugifyPackageName(appName),
|
|
247
|
+
validate: (value) =>
|
|
248
|
+
/^[a-z0-9-]+$/.test(value.trim())
|
|
249
|
+
? true
|
|
250
|
+
: '소문자, 숫자, 하이픈만 사용할 수 있습니다.'
|
|
251
|
+
})
|
|
252
|
+
: slugifyPackageName(appName))
|
|
253
|
+
const appId =
|
|
254
|
+
args['app-id'] ??
|
|
255
|
+
(interactive
|
|
256
|
+
? await input({
|
|
257
|
+
message: 'appId',
|
|
258
|
+
default: toAppId(packageName),
|
|
259
|
+
validate: (value) =>
|
|
260
|
+
/^[a-zA-Z0-9.-]+$/.test(value.trim())
|
|
261
|
+
? true
|
|
262
|
+
: '영문, 숫자, 점, 하이픈만 사용할 수 있습니다.'
|
|
263
|
+
})
|
|
264
|
+
: toAppId(packageName))
|
|
265
|
+
const targetDirectoryInput =
|
|
266
|
+
args.dir ??
|
|
267
|
+
(!interactive
|
|
268
|
+
? (() => {
|
|
269
|
+
throw new Error('Missing required --dir argument.')
|
|
270
|
+
})()
|
|
271
|
+
: await input({
|
|
272
|
+
message: '프로젝트 디렉토리',
|
|
273
|
+
default: `../${packageName}`,
|
|
274
|
+
validate: (value) => (value.trim() ? true : '디렉토리 경로는 필수입니다.')
|
|
275
|
+
}))
|
|
276
|
+
const targetDirectory = isAbsolute(targetDirectoryInput)
|
|
277
|
+
? targetDirectoryInput
|
|
278
|
+
: resolve(process.cwd(), targetDirectoryInput)
|
|
279
|
+
const frameworkDependency = resolveFrameworkDependency(
|
|
280
|
+
frameworkRoot,
|
|
281
|
+
args['framework-dependency']
|
|
282
|
+
)
|
|
283
|
+
const installFlag = parseBooleanFlag(args.install)
|
|
284
|
+
const shouldInstall =
|
|
285
|
+
installFlag ??
|
|
286
|
+
(interactive
|
|
287
|
+
? await confirm({ message: '생성 후 npm install을 실행할까요?', default: true })
|
|
288
|
+
: false)
|
|
289
|
+
const gitFlag = parseBooleanFlag(args.git)
|
|
290
|
+
const shouldInitGit =
|
|
291
|
+
gitFlag ??
|
|
292
|
+
(interactive
|
|
293
|
+
? await confirm({
|
|
294
|
+
message: '새 프로젝트 디렉토리에서 git 저장소를 초기화할까요?',
|
|
295
|
+
default: true
|
|
296
|
+
})
|
|
297
|
+
: false)
|
|
298
|
+
|
|
299
|
+
ensureTargetAvailable(targetDirectory)
|
|
300
|
+
if (interactive) {
|
|
301
|
+
const shouldProceed = await confirm({
|
|
302
|
+
message: `새 프로젝트를 ${targetDirectory} 에 생성할까요?`,
|
|
303
|
+
default: true
|
|
304
|
+
})
|
|
305
|
+
if (!shouldProceed) throw new Error('프로젝트 생성이 취소되었습니다.')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
scaffoldProject({
|
|
309
|
+
targetDirectory,
|
|
310
|
+
packageName,
|
|
311
|
+
appName,
|
|
312
|
+
appId,
|
|
313
|
+
frameworkDependency
|
|
314
|
+
})
|
|
315
|
+
runCommand(process.execPath, [join(cliDirectory, 'sync-screens.mjs')], targetDirectory)
|
|
316
|
+
|
|
317
|
+
if (shouldInitGit) {
|
|
318
|
+
rmSync(join(targetDirectory, '.git'), { recursive: true, force: true })
|
|
319
|
+
runCommand('git', ['init', '-b', 'main'], targetDirectory)
|
|
320
|
+
}
|
|
321
|
+
if (shouldInstall) {
|
|
322
|
+
const npmCommand = resolveNpmCommand(['install'])
|
|
323
|
+
runCommand(npmCommand.command, npmCommand.args, targetDirectory)
|
|
324
|
+
} else {
|
|
325
|
+
process.stdout.write(
|
|
326
|
+
'npm install을 아직 실행하지 않았습니다. 의존성 설치 후 npm run sync:screens 를 실행하세요.\n'
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
if (shouldInitGit) {
|
|
330
|
+
runCommand('git', ['add', '.'], targetDirectory)
|
|
331
|
+
runCommand('git', ['commit', '-m', '초기 프로젝트 생성'], targetDirectory)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
process.stdout.write(
|
|
335
|
+
`새 프로젝트를 생성했습니다: ${relative(process.cwd(), targetDirectory) || '.'}\n`
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (isDirectExecution(import.meta.url, process.argv[1])) {
|
|
340
|
+
main().catch((error) => {
|
|
341
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
|
|
342
|
+
process.exitCode = 1
|
|
343
|
+
})
|
|
344
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { rm } from 'node:fs/promises'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { confirm, select } from '@inquirer/prompts'
|
|
6
|
+
import {
|
|
7
|
+
pickScreenGenerationArgs,
|
|
8
|
+
resolveScreenGenerationContract,
|
|
9
|
+
SCREEN_GENERATION_OPTION_KEYS
|
|
10
|
+
} from './screen-generation-contract.mjs'
|
|
11
|
+
import { assertKnownArgs, assertValidId, isDirectExecution, parseArgs } from './screen-script-utils.mjs'
|
|
12
|
+
import { loadSceneScreenModules } from './screen-module-utils.mjs'
|
|
13
|
+
import { syncScreens } from './sync-screens.mjs'
|
|
14
|
+
|
|
15
|
+
const REMOVE_SCREEN_OPTION_KEYS = [...SCREEN_GENERATION_OPTION_KEYS, 'id']
|
|
16
|
+
|
|
17
|
+
async function removeFileIfExists(path) {
|
|
18
|
+
await rm(path, { force: true })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function removeScreen(args, { cwd = process.cwd(), interactive = process.stdout.isTTY } = {}) {
|
|
22
|
+
assertKnownArgs(args, REMOVE_SCREEN_OPTION_KEYS)
|
|
23
|
+
const contract = resolveScreenGenerationContract(args, { cwd })
|
|
24
|
+
const screenDirectory = contract.screenDirectory
|
|
25
|
+
const registeredScreens = await loadSceneScreenModules(screenDirectory)
|
|
26
|
+
if (registeredScreens.length === 0) {
|
|
27
|
+
throw new Error('No removable screens found.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const id =
|
|
31
|
+
args.id ??
|
|
32
|
+
(!interactive
|
|
33
|
+
? (() => {
|
|
34
|
+
throw new Error('Missing required --id argument.')
|
|
35
|
+
})()
|
|
36
|
+
: await select({
|
|
37
|
+
message: 'Select a screen to remove',
|
|
38
|
+
choices: registeredScreens.map((screenModule) => ({
|
|
39
|
+
name: `${screenModule.screen.id} (${screenModule.screen.title})`,
|
|
40
|
+
value: screenModule.screen.id
|
|
41
|
+
}))
|
|
42
|
+
}))
|
|
43
|
+
|
|
44
|
+
assertValidId(id)
|
|
45
|
+
|
|
46
|
+
const matchedScreen = registeredScreens.find((screenModule) => screenModule.screen.id === id)
|
|
47
|
+
if (!matchedScreen) {
|
|
48
|
+
throw new Error(`Screen id not found: ${id}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const shouldRemove = interactive
|
|
52
|
+
? await confirm({
|
|
53
|
+
message: `Remove screen "${id}"?`,
|
|
54
|
+
default: false
|
|
55
|
+
})
|
|
56
|
+
: true
|
|
57
|
+
if (!shouldRemove) {
|
|
58
|
+
throw new Error('Screen removal cancelled.')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const componentFilePath = join(screenDirectory, `${matchedScreen.fileBaseName}.tsx`)
|
|
62
|
+
const testFilePath = join(screenDirectory, `${matchedScreen.fileBaseName}.test.tsx`)
|
|
63
|
+
|
|
64
|
+
await Promise.all([
|
|
65
|
+
removeFileIfExists(componentFilePath),
|
|
66
|
+
removeFileIfExists(testFilePath)
|
|
67
|
+
])
|
|
68
|
+
await syncScreens(pickScreenGenerationArgs(args), { cwd })
|
|
69
|
+
|
|
70
|
+
return { contract, id }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function main() {
|
|
74
|
+
const result = await removeScreen(parseArgs(process.argv.slice(2)))
|
|
75
|
+
process.stdout.write(`Removed screen "${result.id}"\n`)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (isDirectExecution(import.meta.url, process.argv[1])) {
|
|
79
|
+
main().catch((error) => {
|
|
80
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
|
|
81
|
+
process.exitCode = 1
|
|
82
|
+
})
|
|
83
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isAbsolute, join, relative, resolve } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_GENERATED_DIRECTORY = 'framework/generated'
|
|
5
|
+
export const CONSUMER_GENERATED_DIRECTORY = 'src/generated'
|
|
6
|
+
|
|
7
|
+
const FRAMEWORK_ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
8
|
+
|
|
9
|
+
const LEGACY_IMPORT_PATHS = {
|
|
10
|
+
definitionsTypes: '@shared/types',
|
|
11
|
+
registryScreenTypes: '@framework/renderer/src/screen-types',
|
|
12
|
+
screens: '@screens',
|
|
13
|
+
videoSceneScreen: '@renderer/components/VideoSceneScreen'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const CONSUMER_IMPORT_PATHS = {
|
|
17
|
+
definitionsTypes: 'key-screen-framework/shared/types',
|
|
18
|
+
registryScreenTypes: 'key-screen-framework/renderer',
|
|
19
|
+
screens: '@screens',
|
|
20
|
+
videoSceneScreen: 'key-screen-framework/renderer/components/VideoSceneScreen'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const SCREEN_GENERATION_OPTION_KEYS = [
|
|
24
|
+
'project-root',
|
|
25
|
+
'output-dir',
|
|
26
|
+
'definitions-types-import',
|
|
27
|
+
'registry-screen-types-import',
|
|
28
|
+
'screens-import',
|
|
29
|
+
'video-scene-screen-import'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
function assertNonEmptyString(value, optionName) {
|
|
33
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
34
|
+
throw new Error(`Option --${optionName} must be a non-empty string.`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return value.trim()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertProjectRelativeDirectory(value, optionName) {
|
|
41
|
+
const directory = assertNonEmptyString(value, optionName)
|
|
42
|
+
if (isAbsolute(directory)) {
|
|
43
|
+
throw new Error(`Option --${optionName} must be relative to --project-root.`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const normalized = directory.replaceAll('\\', '/')
|
|
47
|
+
if (normalized === '.' || normalized.split('/').includes('..')) {
|
|
48
|
+
throw new Error(`Option --${optionName} must not escape --project-root.`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return directory
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function assertProjectContained(projectRoot, targetPath, optionName) {
|
|
55
|
+
const pathFromProjectRoot = relative(projectRoot, targetPath)
|
|
56
|
+
if (
|
|
57
|
+
pathFromProjectRoot === '' ||
|
|
58
|
+
pathFromProjectRoot === '..' ||
|
|
59
|
+
pathFromProjectRoot.startsWith('..\\') ||
|
|
60
|
+
isAbsolute(pathFromProjectRoot)
|
|
61
|
+
) {
|
|
62
|
+
throw new Error(`Option --${optionName} must resolve inside --project-root.`)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function resolveScreenGenerationContract(
|
|
67
|
+
args,
|
|
68
|
+
{ cwd = process.cwd(), frameworkRoot = FRAMEWORK_ROOT } = {}
|
|
69
|
+
) {
|
|
70
|
+
const projectRootInput = args['project-root']
|
|
71
|
+
? assertNonEmptyString(args['project-root'], 'project-root')
|
|
72
|
+
: cwd
|
|
73
|
+
const projectRoot = resolve(cwd, projectRootInput)
|
|
74
|
+
const usesLegacyFrameworkLayout = projectRoot === resolve(frameworkRoot)
|
|
75
|
+
const defaultImports = usesLegacyFrameworkLayout ? LEGACY_IMPORT_PATHS : CONSUMER_IMPORT_PATHS
|
|
76
|
+
const outputDirectoryInput = assertProjectRelativeDirectory(
|
|
77
|
+
args['output-dir'] ??
|
|
78
|
+
(usesLegacyFrameworkLayout ? DEFAULT_GENERATED_DIRECTORY : CONSUMER_GENERATED_DIRECTORY),
|
|
79
|
+
'output-dir'
|
|
80
|
+
)
|
|
81
|
+
const outputDirectory = resolve(projectRoot, outputDirectoryInput)
|
|
82
|
+
assertProjectContained(projectRoot, outputDirectory, 'output-dir')
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
projectRoot,
|
|
86
|
+
screenDirectory: join(projectRoot, 'src/screens'),
|
|
87
|
+
outputDirectory,
|
|
88
|
+
generatedDefinitionsPath: join(outputDirectory, 'scene-screen-definitions.ts'),
|
|
89
|
+
generatedRegistryPath: join(outputDirectory, 'scene-screen-registry.tsx'),
|
|
90
|
+
importPaths: {
|
|
91
|
+
definitionsTypes: args['definitions-types-import']
|
|
92
|
+
? assertNonEmptyString(args['definitions-types-import'], 'definitions-types-import')
|
|
93
|
+
: defaultImports.definitionsTypes,
|
|
94
|
+
registryScreenTypes: args['registry-screen-types-import']
|
|
95
|
+
? assertNonEmptyString(args['registry-screen-types-import'], 'registry-screen-types-import')
|
|
96
|
+
: defaultImports.registryScreenTypes,
|
|
97
|
+
screens: args['screens-import']
|
|
98
|
+
? assertNonEmptyString(args['screens-import'], 'screens-import')
|
|
99
|
+
: defaultImports.screens,
|
|
100
|
+
videoSceneScreen: args['video-scene-screen-import']
|
|
101
|
+
? assertNonEmptyString(
|
|
102
|
+
args['video-scene-screen-import'],
|
|
103
|
+
'video-scene-screen-import'
|
|
104
|
+
)
|
|
105
|
+
: defaultImports.videoSceneScreen
|
|
106
|
+
},
|
|
107
|
+
usesLegacyFrameworkLayout
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function toScreenGenerationCliArgs(args, { includeImportPaths = false } = {}) {
|
|
112
|
+
const keys = includeImportPaths
|
|
113
|
+
? SCREEN_GENERATION_OPTION_KEYS
|
|
114
|
+
: SCREEN_GENERATION_OPTION_KEYS.slice(0, 2)
|
|
115
|
+
|
|
116
|
+
return keys.flatMap((key) => (args[key] === undefined ? [] : [`--${key}`, args[key]]))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function pickScreenGenerationArgs(args, { includeImportPaths = true } = {}) {
|
|
120
|
+
const keys = includeImportPaths
|
|
121
|
+
? SCREEN_GENERATION_OPTION_KEYS
|
|
122
|
+
: SCREEN_GENERATION_OPTION_KEYS.slice(0, 2)
|
|
123
|
+
|
|
124
|
+
return Object.fromEntries(
|
|
125
|
+
keys.flatMap((key) => (args[key] === undefined ? [] : [[key, args[key]]]))
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export function renderGeneratedDefinitions(modules, importPaths) {
|
|
2
|
+
const definitions = modules
|
|
3
|
+
.map(({ componentKey, screen }) => {
|
|
4
|
+
const descriptionLine = screen.description ? ` description: ${JSON.stringify(screen.description)},\n` : ''
|
|
5
|
+
const shortcutLine = screen.shortcut ? ` shortcut: ${JSON.stringify(screen.shortcut)},\n` : ''
|
|
6
|
+
|
|
7
|
+
return ` {\n id: ${JSON.stringify(screen.id)},\n title: ${JSON.stringify(screen.title)},\n${descriptionLine} kind: 'scene',\n${shortcutLine} componentKey: ${JSON.stringify(componentKey)}\n }`
|
|
8
|
+
})
|
|
9
|
+
.join(',\n')
|
|
10
|
+
|
|
11
|
+
return `import type { ScreenDefinition } from ${JSON.stringify(importPaths.definitionsTypes)}\n\nexport const GENERATED_SCENE_SCREEN_DEFINITIONS = [\n${definitions}\n] as const satisfies readonly ScreenDefinition[]\n`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function renderGeneratedRegistry(modules, importPaths) {
|
|
15
|
+
const imports = modules
|
|
16
|
+
.map(({ fileBaseName }, index) => `import * as SceneScreenModule${index} from ${JSON.stringify(`${importPaths.screens}/${fileBaseName}`)}`)
|
|
17
|
+
.join('\n')
|
|
18
|
+
|
|
19
|
+
const moduleEntries = modules
|
|
20
|
+
.map(({ componentKey }, index) => ` ${JSON.stringify(componentKey)}: SceneScreenModule${index}`)
|
|
21
|
+
.join(',\n')
|
|
22
|
+
|
|
23
|
+
return `/* eslint-disable react-refresh/only-export-components */
|
|
24
|
+
import type { ComponentType } from 'react'
|
|
25
|
+
import type {
|
|
26
|
+
ScreenComponentProps,
|
|
27
|
+
ScreenComponentType,
|
|
28
|
+
ScreenPreloadFunction
|
|
29
|
+
} from ${JSON.stringify(importPaths.registryScreenTypes)}
|
|
30
|
+
${imports}
|
|
31
|
+
|
|
32
|
+
type SceneScreenModule = {
|
|
33
|
+
default: ComponentType<ScreenComponentProps>
|
|
34
|
+
preload?: ScreenPreloadFunction
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const SCENE_SCREEN_MODULES: Record<string, SceneScreenModule> = {
|
|
38
|
+
${moduleEntries}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const SCENE_SCREEN_COMPONENTS = Object.fromEntries(
|
|
42
|
+
Object.entries(SCENE_SCREEN_MODULES).map(([componentKey, module]) => [componentKey, module.default])
|
|
43
|
+
) as Record<string, ScreenComponentType>
|
|
44
|
+
|
|
45
|
+
const sceneScreenPreloadPromises = new Map<string, Promise<void>>()
|
|
46
|
+
|
|
47
|
+
export async function preloadSceneScreenComponent(componentKey: string): Promise<void> {
|
|
48
|
+
const module = SCENE_SCREEN_MODULES[componentKey]
|
|
49
|
+
if (!module?.preload) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const existingPreload = sceneScreenPreloadPromises.get(componentKey)
|
|
54
|
+
if (existingPreload) {
|
|
55
|
+
await existingPreload
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const preloadPromise = Promise.resolve()
|
|
60
|
+
.then(() => module.preload?.())
|
|
61
|
+
.then(() => undefined)
|
|
62
|
+
.catch((error: unknown) => {
|
|
63
|
+
sceneScreenPreloadPromises.delete(componentKey)
|
|
64
|
+
throw error
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
sceneScreenPreloadPromises.set(componentKey, preloadPromise)
|
|
68
|
+
await preloadPromise
|
|
69
|
+
}
|
|
70
|
+
`
|
|
71
|
+
}
|