@@ -11,7 +11,8 @@ assertNonEmptyString(interfaceJson.label, 'interface.json label')
1111assertVersion ( interfaceJson . version , 'interface.json version' , true )
1212assertArrayOfRecords ( interfaceJson . controller , 'interface.json controller' )
1313assertArrayOfRecords ( interfaceJson . resource , 'interface.json resource' )
14- assertArrayOfStrings ( interfaceJson . import , 'interface.json import' )
14+ // import 可省略(MFAAvalonia 风格下用于引入额外 pipeline,本项目无外部依赖时省略)。
15+ assertArrayOfStrings ( interfaceJson . import ?? [ ] , 'interface.json import' )
1516
1617const CONTROLLER_TYPES = [
1718 'Adb' ,
@@ -47,7 +48,7 @@ if (interfaceJson.resource[0]?.path?.[0] !== './resource/base') {
4748
4849// 所有 import / resource 路径必须实际存在。
4950for ( const p of [
50- ...interfaceJson . import ,
51+ ...( interfaceJson . import ?? [ ] ) ,
5152 ...interfaceJson . resource . flatMap ( ( r ) => r . path )
5253] ) {
5354 if ( ! existsSync ( p ) ) throw new Error ( `referenced path does not exist: ${ p } ` )
@@ -73,9 +74,55 @@ for (const path of walkJsonFiles([
7374console . log ( '[OK] project schema shape is valid' )
7475
7576// --- helpers ---
77+
78+ // MaaFW 项目约定 JSON 可带 // 行注释与 /* */ 块注释(JSONC)。
79+ // JSON.parse 不认注释,故解析前剥离(跳过字符串字面量内的注释符号)。
80+ function stripJsonc ( text ) {
81+ let out = ''
82+ let i = 0
83+ const n = text . length
84+ while ( i < n ) {
85+ const ch = text [ i ]
86+ const next = text [ i + 1 ]
87+ // 字符串字面量:原样复制到闭合引号(处理 \" 转义)
88+ if ( ch === '"' ) {
89+ out += ch
90+ i += 1
91+ while ( i < n ) {
92+ const c = text [ i ]
93+ out += c
94+ i += 1
95+ if ( c === '\\' && i < n ) {
96+ out += text [ i ]
97+ i += 1
98+ } else if ( c === '"' ) {
99+ break
100+ }
101+ }
102+ continue
103+ }
104+ // 行注释
105+ if ( ch === '/' && next === '/' ) {
106+ while ( i < n && text [ i ] !== '\n' ) i += 1
107+ continue
108+ }
109+ // 块注释
110+ if ( ch === '/' && next === '*' ) {
111+ i += 2
112+ while ( i < n && ! ( text [ i ] === '*' && text [ i + 1 ] === '/' ) ) i += 1
113+ i += 2
114+ out += ' '
115+ continue
116+ }
117+ out += ch
118+ i += 1
119+ }
120+ return out
121+ }
122+
76123function readJson ( path ) {
77124 if ( ! existsSync ( path ) ) throw new Error ( `${ path } is missing` )
78- return JSON . parse ( readFileSync ( path , 'utf8' ) )
125+ return JSON . parse ( stripJsonc ( readFileSync ( path , 'utf8' ) ) )
79126}
80127
81128function assertEqual ( actual , expected , message ) {
0 commit comments