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,554 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import {
|
|
5
|
+
existsSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
realpathSync,
|
|
9
|
+
statSync
|
|
10
|
+
} from 'node:fs'
|
|
11
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
12
|
+
import { fileURLToPath } from 'node:url'
|
|
13
|
+
import semver from 'semver'
|
|
14
|
+
import { collectModuleSpecifiers } from './source-module-specifiers.mjs'
|
|
15
|
+
import { isDirectExecution } from './screen-script-utils.mjs'
|
|
16
|
+
|
|
17
|
+
const cliDirectory = dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
const sourcePackageRoot = resolve(cliDirectory, '..')
|
|
19
|
+
const builtPackageRoot = join(sourcePackageRoot, 'dist/package')
|
|
20
|
+
const defaultTargetPackageRoot = existsSync(join(builtPackageRoot, 'package.json'))
|
|
21
|
+
? builtPackageRoot
|
|
22
|
+
: sourcePackageRoot
|
|
23
|
+
|
|
24
|
+
const SOURCE_EXTENSION_PATTERN = /\.[cm]?[jt]sx?$/i
|
|
25
|
+
const LEGACY_ALIAS_PATTERN = /^@(shared|framework|renderer|main|preload)(?:\/.*)?$/
|
|
26
|
+
const SCANNED_DIRECTORIES = ['src', 'e2e']
|
|
27
|
+
const CONFIG_FILE_PATTERN = /(?:^|\.)config\.[cm]?[jt]s$/i
|
|
28
|
+
|
|
29
|
+
function diagnostic(id, status, message, details = {}) {
|
|
30
|
+
return { id, status, message, ...details }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readJson(path, label) {
|
|
34
|
+
let source
|
|
35
|
+
try {
|
|
36
|
+
source = readFileSync(path, 'utf8')
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`${label}을 읽을 수 없습니다: ${path} (${error.message})`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(source)
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(`${label} JSON이 올바르지 않습니다: ${path} (${error.message})`)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function packageInfo(packageRoot, label) {
|
|
49
|
+
const manifestPath = join(packageRoot, 'package.json')
|
|
50
|
+
const manifest = readJson(manifestPath, label)
|
|
51
|
+
if (manifest.name !== 'key-screen-framework') {
|
|
52
|
+
throw new Error(`${label} name이 key-screen-framework가 아닙니다: ${manifest.name ?? '(없음)'}`)
|
|
53
|
+
}
|
|
54
|
+
if (typeof manifest.version !== 'string' || !semver.valid(manifest.version)) {
|
|
55
|
+
throw new Error(`${label} version이 유효한 SemVer가 아닙니다: ${manifest.version ?? '(없음)'}`)
|
|
56
|
+
}
|
|
57
|
+
return { path: realpathSync(packageRoot), manifestPath, manifest, version: manifest.version }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveInstalledPackage(projectRoot) {
|
|
61
|
+
const requireFromProject = createRequire(join(projectRoot, '__key_screen_doctor__.cjs'))
|
|
62
|
+
try {
|
|
63
|
+
const manifestPath = requireFromProject.resolve('key-screen-framework/package.json')
|
|
64
|
+
return packageInfo(dirname(manifestPath), '설치된 framework manifest')
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error?.code === 'MODULE_NOT_FOUND' || error?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
throw error
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function resolveDependencyPackage(projectRoot, packageName) {
|
|
74
|
+
const requireFromProject = createRequire(join(projectRoot, '__key_screen_doctor__.cjs'))
|
|
75
|
+
try {
|
|
76
|
+
const manifestPath = requireFromProject.resolve(`${packageName}/package.json`)
|
|
77
|
+
return readJson(manifestPath, `${packageName} manifest`)
|
|
78
|
+
} catch (initialError) {
|
|
79
|
+
try {
|
|
80
|
+
let current = dirname(requireFromProject.resolve(packageName))
|
|
81
|
+
while (true) {
|
|
82
|
+
const manifestPath = join(current, 'package.json')
|
|
83
|
+
if (existsSync(manifestPath)) {
|
|
84
|
+
const manifest = readJson(manifestPath, `${packageName} manifest`)
|
|
85
|
+
if (manifest.name === packageName) return manifest
|
|
86
|
+
}
|
|
87
|
+
const parent = dirname(current)
|
|
88
|
+
if (parent === current) return undefined
|
|
89
|
+
current = parent
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
if (
|
|
93
|
+
initialError?.code === 'MODULE_NOT_FOUND' ||
|
|
94
|
+
initialError?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
|
|
95
|
+
) {
|
|
96
|
+
return undefined
|
|
97
|
+
}
|
|
98
|
+
throw initialError
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function comparableRange(value) {
|
|
104
|
+
if (typeof value !== 'string') return undefined
|
|
105
|
+
try {
|
|
106
|
+
return semver.validRange(value) ?? undefined
|
|
107
|
+
} catch {
|
|
108
|
+
return undefined
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function pathInside(root, path) {
|
|
113
|
+
const fromRoot = relative(root, path)
|
|
114
|
+
return fromRoot === '' || (!isAbsolute(fromRoot) && fromRoot !== '..' && !fromRoot.startsWith(`..${sep}`))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function listSourceFiles(directory, projectRoot) {
|
|
118
|
+
if (!existsSync(directory)) return []
|
|
119
|
+
const files = []
|
|
120
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
121
|
+
const path = join(directory, entry.name)
|
|
122
|
+
if (entry.isSymbolicLink()) continue
|
|
123
|
+
if (entry.isDirectory()) {
|
|
124
|
+
files.push(...listSourceFiles(path, projectRoot))
|
|
125
|
+
} else if (entry.isFile() && SOURCE_EXTENSION_PATTERN.test(entry.name) && pathInside(projectRoot, path)) {
|
|
126
|
+
files.push(path)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return files
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function projectSourceFiles(projectRoot) {
|
|
133
|
+
const files = SCANNED_DIRECTORIES.flatMap((directory) =>
|
|
134
|
+
listSourceFiles(join(projectRoot, directory), projectRoot)
|
|
135
|
+
)
|
|
136
|
+
for (const entry of readdirSync(projectRoot, { withFileTypes: true })) {
|
|
137
|
+
if (entry.isFile() && CONFIG_FILE_PATTERN.test(entry.name)) files.push(join(projectRoot, entry.name))
|
|
138
|
+
}
|
|
139
|
+
return files.sort()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function scanImports(projectRoot) {
|
|
143
|
+
const imports = []
|
|
144
|
+
const warnings = []
|
|
145
|
+
for (const path of projectSourceFiles(projectRoot)) {
|
|
146
|
+
try {
|
|
147
|
+
const source = readFileSync(path, 'utf8')
|
|
148
|
+
for (const { value, kind } of collectModuleSpecifiers(source, path)) {
|
|
149
|
+
imports.push({ path: relative(projectRoot, path).split(sep).join('/'), specifier: value, kind })
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
warnings.push({ path: relative(projectRoot, path).split(sep).join('/'), error: error.message })
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { imports, warnings }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function matchExport(exportsField, exportName) {
|
|
159
|
+
if (!exportsField || typeof exportsField !== 'object' || Array.isArray(exportsField)) return undefined
|
|
160
|
+
if (Object.hasOwn(exportsField, exportName)) {
|
|
161
|
+
return { key: exportName, value: exportsField[exportName], wildcard: undefined }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const [key, value] of Object.entries(exportsField)) {
|
|
165
|
+
if (!key.includes('*')) continue
|
|
166
|
+
const [prefix, suffix] = key.split('*')
|
|
167
|
+
if (!exportName.startsWith(prefix) || !exportName.endsWith(suffix)) continue
|
|
168
|
+
return {
|
|
169
|
+
key,
|
|
170
|
+
value,
|
|
171
|
+
wildcard: exportName.slice(prefix.length, exportName.length - suffix.length)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function collectExportTargets(value, wildcard, result = [], conditions = []) {
|
|
178
|
+
if (typeof value === 'string') {
|
|
179
|
+
result.push({
|
|
180
|
+
path: wildcard === undefined ? value : value.replaceAll('*', wildcard),
|
|
181
|
+
conditions
|
|
182
|
+
})
|
|
183
|
+
} else if (Array.isArray(value)) {
|
|
184
|
+
for (const item of value) collectExportTargets(item, wildcard, result, conditions)
|
|
185
|
+
} else if (value && typeof value === 'object') {
|
|
186
|
+
for (const [condition, item] of Object.entries(value)) {
|
|
187
|
+
collectExportTargets(item, wildcard, result, [...conditions, condition])
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function targetSupportsUsage(target, kind) {
|
|
194
|
+
const conditions = new Set(target.conditions)
|
|
195
|
+
const declarationTarget = /\.d\.[cm]?ts$/i.test(target.path)
|
|
196
|
+
if (kind === 'type') {
|
|
197
|
+
return conditions.has('types') || (conditions.size === 0 && declarationTarget)
|
|
198
|
+
}
|
|
199
|
+
if (conditions.has('types') || declarationTarget) return false
|
|
200
|
+
if (kind === 'require') {
|
|
201
|
+
return !conditions.has('import')
|
|
202
|
+
}
|
|
203
|
+
return !conditions.has('require')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function checkExportFiles(target, diagnostics) {
|
|
207
|
+
const exportsField = target.manifest.exports
|
|
208
|
+
if (!exportsField || typeof exportsField !== 'object') {
|
|
209
|
+
diagnostics.push(
|
|
210
|
+
diagnostic('KSF020', 'ERROR', '검사 대상 패키지에 exports map이 없습니다.')
|
|
211
|
+
)
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const missing = []
|
|
216
|
+
let checked = 0
|
|
217
|
+
for (const [key, value] of Object.entries(exportsField)) {
|
|
218
|
+
for (const { path: targetPath } of collectExportTargets(value)) {
|
|
219
|
+
if (!targetPath.startsWith('./') || targetPath.includes('*')) continue
|
|
220
|
+
checked += 1
|
|
221
|
+
const absolutePath = resolve(target.path, targetPath)
|
|
222
|
+
if (!pathInside(target.path, absolutePath) || !existsSync(absolutePath) || !statSync(absolutePath).isFile()) {
|
|
223
|
+
missing.push({ export: key, target: targetPath })
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
diagnostics.push(
|
|
229
|
+
missing.length === 0
|
|
230
|
+
? diagnostic('KSF020', 'PASS', `공개 export target ${checked}개가 존재합니다.`)
|
|
231
|
+
: diagnostic('KSF020', 'ERROR', `공개 export target ${missing.length}개가 없습니다.`, {
|
|
232
|
+
items: missing
|
|
233
|
+
})
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function checkUsedExports(target, imports, diagnostics) {
|
|
238
|
+
const used = imports.filter(
|
|
239
|
+
({ specifier }) => specifier === 'key-screen-framework' || specifier.startsWith('key-screen-framework/')
|
|
240
|
+
)
|
|
241
|
+
if (used.length === 0) {
|
|
242
|
+
diagnostics.push(diagnostic('KSF021', 'SKIP', '프로젝트 source에서 framework import를 찾지 못했습니다.'))
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const unsupported = []
|
|
247
|
+
for (const item of used) {
|
|
248
|
+
const exportName = item.specifier === 'key-screen-framework'
|
|
249
|
+
? '.'
|
|
250
|
+
: `./${item.specifier.slice('key-screen-framework/'.length)}`
|
|
251
|
+
const matched = matchExport(target.manifest.exports, exportName)
|
|
252
|
+
if (!matched) {
|
|
253
|
+
unsupported.push(item)
|
|
254
|
+
continue
|
|
255
|
+
}
|
|
256
|
+
const targets = collectExportTargets(matched.value, matched.wildcard).filter((targetPath) =>
|
|
257
|
+
targetSupportsUsage(targetPath, item.kind)
|
|
258
|
+
)
|
|
259
|
+
if (
|
|
260
|
+
targets.length === 0 ||
|
|
261
|
+
targets.every((targetPath) => {
|
|
262
|
+
if (!targetPath.path.startsWith('./')) return false
|
|
263
|
+
const absolutePath = resolve(target.path, targetPath.path)
|
|
264
|
+
return !pathInside(target.path, absolutePath) || !existsSync(absolutePath)
|
|
265
|
+
})
|
|
266
|
+
) {
|
|
267
|
+
unsupported.push(item)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
diagnostics.push(
|
|
272
|
+
unsupported.length === 0
|
|
273
|
+
? diagnostic('KSF021', 'PASS', `사용 중인 공개 import ${used.length}개를 대상 버전이 제공합니다.`)
|
|
274
|
+
: diagnostic('KSF021', 'ERROR', `대상 버전에 없는 framework import ${unsupported.length}개가 있습니다.`, {
|
|
275
|
+
items: unsupported
|
|
276
|
+
})
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function checkLegacyAliases(projectRoot, imports, diagnostics) {
|
|
281
|
+
const legacy = imports.filter(({ specifier }) => LEGACY_ALIAS_PATTERN.test(specifier))
|
|
282
|
+
if (legacy.length === 0) {
|
|
283
|
+
diagnostics.push(diagnostic('KSF030', 'PASS', '복제형 framework alias import가 없습니다.'))
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
const hasFrameworkDirectory = existsSync(join(projectRoot, 'framework'))
|
|
287
|
+
diagnostics.push(
|
|
288
|
+
diagnostic(
|
|
289
|
+
'KSF030',
|
|
290
|
+
hasFrameworkDirectory ? 'WARN' : 'ERROR',
|
|
291
|
+
hasFrameworkDirectory
|
|
292
|
+
? `복제형 framework를 우회 참조하는 alias import ${legacy.length}개가 있습니다.`
|
|
293
|
+
: `resolve할 수 없는 복제형 framework alias import ${legacy.length}개가 있습니다.`,
|
|
294
|
+
{ items: legacy }
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function checkScripts(manifest, diagnostics) {
|
|
300
|
+
const scripts = manifest.scripts ?? {}
|
|
301
|
+
const lifecycleNames = ['predev', 'prebuild', 'prelint', 'pretest']
|
|
302
|
+
const callers = lifecycleNames.filter((name) => scripts[name]?.includes('npm run sync:screens'))
|
|
303
|
+
if (callers.length > 0 && typeof scripts['sync:screens'] !== 'string') {
|
|
304
|
+
diagnostics.push(
|
|
305
|
+
diagnostic('KSF040', 'ERROR', `${callers.join(', ')}에서 없는 sync:screens script를 호출합니다.`)
|
|
306
|
+
)
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const syncCommand = scripts['sync:screens']
|
|
311
|
+
if (syncCommand === 'key-screen-sync') {
|
|
312
|
+
diagnostics.push(diagnostic('KSF040', 'PASS', 'sync:screens가 package CLI를 사용합니다.'))
|
|
313
|
+
} else if (typeof syncCommand === 'string') {
|
|
314
|
+
diagnostics.push(
|
|
315
|
+
diagnostic(
|
|
316
|
+
'KSF040',
|
|
317
|
+
syncCommand.includes('scripts/sync-screens.mjs') ? 'WARN' : 'SKIP',
|
|
318
|
+
syncCommand.includes('scripts/sync-screens.mjs')
|
|
319
|
+
? 'sync:screens가 복제형 script를 사용합니다.'
|
|
320
|
+
: '사용자 정의 sync:screens 명령은 자동 판정하지 않습니다.',
|
|
321
|
+
{ command: syncCommand }
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
} else {
|
|
325
|
+
diagnostics.push(diagnostic('KSF040', 'SKIP', 'sync:screens script가 없습니다.'))
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function summaryFor(diagnostics) {
|
|
330
|
+
return Object.fromEntries(
|
|
331
|
+
['PASS', 'WARN', 'ERROR', 'SKIP'].map((status) => [
|
|
332
|
+
status.toLowerCase(),
|
|
333
|
+
diagnostics.filter((item) => item.status === status).length
|
|
334
|
+
])
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function diagnoseProject({
|
|
339
|
+
projectRoot: projectRootInput = process.cwd(),
|
|
340
|
+
targetPackageRoot: targetPackageRootInput = defaultTargetPackageRoot
|
|
341
|
+
} = {}) {
|
|
342
|
+
const projectRoot = resolve(projectRootInput)
|
|
343
|
+
if (!existsSync(projectRoot) || !statSync(projectRoot).isDirectory()) {
|
|
344
|
+
throw new Error(`프로젝트 디렉터리가 없습니다: ${projectRoot}`)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const target = packageInfo(resolve(targetPackageRootInput), '검사 대상 framework manifest')
|
|
348
|
+
const diagnostics = []
|
|
349
|
+
let projectManifest
|
|
350
|
+
try {
|
|
351
|
+
projectManifest = readJson(join(projectRoot, 'package.json'), '프로젝트 manifest')
|
|
352
|
+
diagnostics.push(diagnostic('KSF001', 'PASS', '프로젝트 package.json을 읽었습니다.'))
|
|
353
|
+
} catch (error) {
|
|
354
|
+
diagnostics.push(diagnostic('KSF001', 'ERROR', error.message))
|
|
355
|
+
return {
|
|
356
|
+
schemaVersion: 1,
|
|
357
|
+
projectRoot,
|
|
358
|
+
mode: 'unknown',
|
|
359
|
+
target: { path: target.path, version: target.version },
|
|
360
|
+
installed: undefined,
|
|
361
|
+
diagnostics,
|
|
362
|
+
summary: summaryFor(diagnostics)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const declared = projectManifest.dependencies?.['key-screen-framework']
|
|
367
|
+
if (typeof declared === 'string') {
|
|
368
|
+
diagnostics.push(
|
|
369
|
+
diagnostic('KSF002', 'PASS', `runtime dependency가 선언되어 있습니다: ${declared}`, { declared })
|
|
370
|
+
)
|
|
371
|
+
} else if (typeof projectManifest.devDependencies?.['key-screen-framework'] === 'string') {
|
|
372
|
+
diagnostics.push(
|
|
373
|
+
diagnostic('KSF002', 'ERROR', 'key-screen-framework는 devDependencies가 아니라 dependencies에 있어야 합니다.')
|
|
374
|
+
)
|
|
375
|
+
} else {
|
|
376
|
+
diagnostics.push(diagnostic('KSF002', 'ERROR', 'key-screen-framework runtime dependency가 없습니다.'))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const installed = resolveInstalledPackage(projectRoot)
|
|
380
|
+
if (installed) {
|
|
381
|
+
diagnostics.push(
|
|
382
|
+
diagnostic('KSF003', 'PASS', `프로젝트에서 framework ${installed.version}을 resolve했습니다.`, {
|
|
383
|
+
path: installed.path,
|
|
384
|
+
version: installed.version
|
|
385
|
+
})
|
|
386
|
+
)
|
|
387
|
+
} else {
|
|
388
|
+
diagnostics.push(diagnostic('KSF003', 'ERROR', '프로젝트에서 설치된 key-screen-framework를 resolve할 수 없습니다.'))
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const mode = installed && installed.path === target.path ? 'installed' : 'preview'
|
|
392
|
+
const range = comparableRange(declared)
|
|
393
|
+
if (!range) {
|
|
394
|
+
diagnostics.push(
|
|
395
|
+
diagnostic('KSF004', 'SKIP', 'file/git/workspace/dist-tag dependency spec은 SemVer 비교를 건너뜁니다.', {
|
|
396
|
+
declared
|
|
397
|
+
})
|
|
398
|
+
)
|
|
399
|
+
} else if (!installed) {
|
|
400
|
+
diagnostics.push(diagnostic('KSF004', 'SKIP', '설치 버전이 없어 선언 범위와 비교하지 못했습니다.'))
|
|
401
|
+
} else if (semver.satisfies(installed.version, range)) {
|
|
402
|
+
diagnostics.push(diagnostic('KSF004', 'PASS', `설치 버전 ${installed.version}이 선언 범위 ${declared}에 맞습니다.`))
|
|
403
|
+
} else {
|
|
404
|
+
diagnostics.push(diagnostic('KSF004', 'ERROR', `설치 버전 ${installed.version}이 선언 범위 ${declared}에 맞지 않습니다.`))
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!range || semver.satisfies(target.version, range)) {
|
|
408
|
+
diagnostics.push(
|
|
409
|
+
diagnostic('KSF005', range ? 'PASS' : 'SKIP', range
|
|
410
|
+
? `검사 대상 버전 ${target.version}이 선언 범위에 맞습니다.`
|
|
411
|
+
: '검사 대상 버전과 비-SemVer dependency spec 비교를 건너뜁니다.')
|
|
412
|
+
)
|
|
413
|
+
} else {
|
|
414
|
+
diagnostics.push(
|
|
415
|
+
diagnostic(
|
|
416
|
+
'KSF005',
|
|
417
|
+
mode === 'installed' ? 'ERROR' : 'WARN',
|
|
418
|
+
`검사 대상 버전 ${target.version}이 선언 범위 ${declared}에 맞지 않습니다.`
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const nodeRange = comparableRange(target.manifest.engines?.node)
|
|
424
|
+
if (!nodeRange) {
|
|
425
|
+
diagnostics.push(diagnostic('KSF010', 'SKIP', '검사 대상 패키지에 비교 가능한 Node engine이 없습니다.'))
|
|
426
|
+
} else if (semver.satisfies(process.versions.node, nodeRange)) {
|
|
427
|
+
diagnostics.push(diagnostic('KSF010', 'PASS', `Node ${process.versions.node}이 대상 engine ${target.manifest.engines.node}에 맞습니다.`))
|
|
428
|
+
} else {
|
|
429
|
+
diagnostics.push(diagnostic('KSF010', 'ERROR', `Node ${process.versions.node}이 대상 engine ${target.manifest.engines.node}에 맞지 않습니다.`))
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
for (const [peerName, peerRangeValue] of Object.entries(target.manifest.peerDependencies ?? {})) {
|
|
433
|
+
const id = `KSF011.${peerName}`
|
|
434
|
+
const peerManifest = resolveDependencyPackage(projectRoot, peerName)
|
|
435
|
+
const optional = target.manifest.peerDependenciesMeta?.[peerName]?.optional === true
|
|
436
|
+
if (!peerManifest) {
|
|
437
|
+
diagnostics.push(
|
|
438
|
+
diagnostic(id, optional ? 'SKIP' : 'ERROR', optional
|
|
439
|
+
? `선택 peer ${peerName}이 설치되지 않았습니다.`
|
|
440
|
+
: `필수 peer ${peerName}@${peerRangeValue}을 프로젝트에서 resolve할 수 없습니다.`)
|
|
441
|
+
)
|
|
442
|
+
continue
|
|
443
|
+
}
|
|
444
|
+
const peerRange = comparableRange(peerRangeValue)
|
|
445
|
+
if (!peerRange || !semver.valid(peerManifest.version)) {
|
|
446
|
+
diagnostics.push(diagnostic(id, 'SKIP', `${peerName} peer 버전을 SemVer로 비교할 수 없습니다.`, {
|
|
447
|
+
version: peerManifest.version,
|
|
448
|
+
required: peerRangeValue
|
|
449
|
+
}))
|
|
450
|
+
} else if (semver.satisfies(peerManifest.version, peerRange)) {
|
|
451
|
+
diagnostics.push(diagnostic(id, 'PASS', `${peerName}@${peerManifest.version}이 대상 범위 ${peerRangeValue}에 맞습니다.`))
|
|
452
|
+
} else {
|
|
453
|
+
diagnostics.push(diagnostic(id, 'ERROR', `${peerName}@${peerManifest.version}이 대상 범위 ${peerRangeValue}에 맞지 않습니다.`))
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
checkExportFiles(target, diagnostics)
|
|
458
|
+
const { imports, warnings } = scanImports(projectRoot)
|
|
459
|
+
diagnostics.push(
|
|
460
|
+
warnings.length === 0
|
|
461
|
+
? diagnostic('KSF019', 'PASS', `프로젝트 source ${projectSourceFiles(projectRoot).length}개를 분석했습니다.`)
|
|
462
|
+
: diagnostic('KSF019', 'WARN', `source ${warnings.length}개를 분석하지 못했습니다.`, { items: warnings })
|
|
463
|
+
)
|
|
464
|
+
checkUsedExports(target, imports, diagnostics)
|
|
465
|
+
checkLegacyAliases(projectRoot, imports, diagnostics)
|
|
466
|
+
checkScripts(projectManifest, diagnostics)
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
schemaVersion: 1,
|
|
470
|
+
projectRoot,
|
|
471
|
+
mode,
|
|
472
|
+
target: { path: target.path, version: target.version },
|
|
473
|
+
installed: installed ? { path: installed.path, version: installed.version } : undefined,
|
|
474
|
+
diagnostics,
|
|
475
|
+
summary: summaryFor(diagnostics)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function parseCliArgs(argv) {
|
|
480
|
+
const options = {}
|
|
481
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
482
|
+
const token = argv[index]
|
|
483
|
+
if (!token.startsWith('--')) throw new Error(`Unexpected argument: ${token}`)
|
|
484
|
+
const [name, inlineValue] = token.slice(2).split(/=(.*)/s, 2)
|
|
485
|
+
if (!['project-root', 'json', 'help'].includes(name)) throw new Error(`Unknown option: --${name}`)
|
|
486
|
+
if (Object.hasOwn(options, name)) throw new Error(`Option may only be provided once: --${name}`)
|
|
487
|
+
if (name === 'json' || name === 'help') {
|
|
488
|
+
if (inlineValue !== undefined) throw new Error(`Option --${name} does not accept a value.`)
|
|
489
|
+
options[name] = true
|
|
490
|
+
continue
|
|
491
|
+
}
|
|
492
|
+
const value = inlineValue ?? argv[index + 1]
|
|
493
|
+
if (!value || value.startsWith('--')) throw new Error(`Option --${name} requires a value.`)
|
|
494
|
+
options[name] = value
|
|
495
|
+
if (inlineValue === undefined) index += 1
|
|
496
|
+
}
|
|
497
|
+
return options
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function printHuman(report, stdout) {
|
|
501
|
+
stdout.write(`프로젝트: ${report.projectRoot}\n`)
|
|
502
|
+
stdout.write(`모드: ${report.mode}\n`)
|
|
503
|
+
stdout.write(`검사 대상: key-screen-framework@${report.target.version}\n`)
|
|
504
|
+
stdout.write(`설치 버전: ${report.installed?.version ?? 'resolve 실패'}\n`)
|
|
505
|
+
for (const item of report.diagnostics) stdout.write(`[${item.status}] ${item.id} ${item.message}\n`)
|
|
506
|
+
stdout.write(
|
|
507
|
+
`요약: PASS ${report.summary.pass}, WARN ${report.summary.warn}, ERROR ${report.summary.error}, SKIP ${report.summary.skip}\n`
|
|
508
|
+
)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function printHelp(stdout) {
|
|
512
|
+
stdout.write('Usage: key-screen-doctor [options]\n\n')
|
|
513
|
+
stdout.write(' --project-root <path> diagnostic target (default: cwd)\n')
|
|
514
|
+
stdout.write(' --json print a machine-readable report\n')
|
|
515
|
+
stdout.write(' --help show this help\n')
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export function runDoctorCli(
|
|
519
|
+
argv,
|
|
520
|
+
{
|
|
521
|
+
stdout = process.stdout,
|
|
522
|
+
stderr = process.stderr,
|
|
523
|
+
targetPackageRoot = defaultTargetPackageRoot,
|
|
524
|
+
cwd = process.cwd()
|
|
525
|
+
} = {}
|
|
526
|
+
) {
|
|
527
|
+
let options
|
|
528
|
+
try {
|
|
529
|
+
options = parseCliArgs(argv)
|
|
530
|
+
if (options.help) {
|
|
531
|
+
printHelp(stdout)
|
|
532
|
+
return 0
|
|
533
|
+
}
|
|
534
|
+
const report = diagnoseProject({
|
|
535
|
+
projectRoot: options['project-root'] ? resolve(cwd, options['project-root']) : cwd,
|
|
536
|
+
targetPackageRoot
|
|
537
|
+
})
|
|
538
|
+
if (options.json) stdout.write(`${JSON.stringify(report, null, 2)}\n`)
|
|
539
|
+
else printHuman(report, stdout)
|
|
540
|
+
return report.summary.error > 0 ? 1 : 0
|
|
541
|
+
} catch (error) {
|
|
542
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
543
|
+
if (options?.json || argv.includes('--json')) {
|
|
544
|
+
stdout.write(`${JSON.stringify({ schemaVersion: 1, fatal: { id: 'KSF000', message } }, null, 2)}\n`)
|
|
545
|
+
} else {
|
|
546
|
+
stderr.write(`${message}\n`)
|
|
547
|
+
}
|
|
548
|
+
return 2
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (isDirectExecution(import.meta.url, process.argv[1])) {
|
|
553
|
+
process.exitCode = runDoctorCli(process.argv.slice(2))
|
|
554
|
+
}
|