@@ -152,7 +152,35 @@ typedef Infos = {
152152 var contributors : Array <String >;
153153 @:optional var tags : Array <String >;
154154 @:optional var dependencies : Dependencies ;
155- @:optional var main : String ;
155+ @:optional var main : String ;
156+ @:optional var documentation : LibraryDocumentation ;
157+ }
158+
159+ /** Documentation data held in the `documentation` field of the `haxelib.json` file. **/
160+ typedef LibraryDocumentation = {
161+ @:optional var defines : String ;
162+ @:optional var metadata : String ;
163+ }
164+
165+ /** Metadata documentation data as should be declared in the json linked in the
166+ * `documentation.metadata` field of the `haxelib.json` file. **/
167+ typedef MetadataDocumentation = {
168+ var metadata : String ;
169+ var doc : String ;
170+ @:optional var platforms : Array <String >;
171+ @:optional var params : Array <String >;
172+ @:optional var targets : Array <String >;
173+ @:optional var links : Array <String >;
174+ }
175+
176+ /** Define documentation data as should be declared in the json linked in the
177+ * `documentation.defines` field of the `haxelib.json` file. **/
178+ typedef DefineDocumentation = {
179+ var define : String ;
180+ var doc : String ;
181+ @:optional var platforms : Array <String >;
182+ @:optional var params : Array <String >;
183+ @:optional var links : Array <String >;
156184}
157185
158186/** An abstract enum representing the different Licenses a project can have. **/
@@ -263,6 +291,48 @@ class Data {
263291 }
264292 }
265293
294+ /** Throws an exception if files referenced in `documentation` field of an `infos` do not exist or are invalid **/
295+ public static function checkDocumentation ( zip : List <Entry >, infos : Infos ) {
296+ if (infos .documentation == null ) return ;
297+
298+ var hasDefines = infos .documentation .defines == null ;
299+ var hasMetadata = infos .documentation .metadata == null ;
300+ if (! hasDefines && ! hasMetadata ) return ;
301+
302+ var basePath = Data .locateBasePath (zip );
303+ var definesPath = hasDefines ? null : basePath + infos .documentation .defines ;
304+ var metadataPath = hasMetadata ? null : basePath + infos .documentation .metadata ;
305+ var definesFound = false ;
306+ var metadataFound = false ;
307+
308+ for (f in zip ) {
309+ if (hasDefines && StringTools .startsWith (f .fileName , definesPath )) {
310+ definesFound = true ;
311+ try {
312+ var jsondata = Reader .unzip (f ).toString ();
313+ var defines : Array <DefineDocumentation > = Json .parse (jsondata );
314+ Validator .validate (defines );
315+ } catch (_ : Dynamic ) {
316+ throw ' Defines documentation json file does not match expected format' ;
317+ }
318+ } else if (hasMetadata && StringTools .startsWith (f .fileName , metadataPath )) {
319+ metadataFound = true ;
320+ try {
321+ var jsondata = Reader .unzip (f ).toString ();
322+ var metas : Array <MetadataDocumentation > = Json .parse (jsondata );
323+ Validator .validate (metas );
324+ } catch (_ : Dynamic ) {
325+ throw ' Metadata documentation json file does not match expected format' ;
326+ }
327+ }
328+
329+ if ((! hasDefines || definesFound ) && (! hasMetadata || metadataFound )) break ;
330+ }
331+
332+ if (hasDefines && ! definesFound ) throw ' Json file ` ${infos .documentation .defines }` not found' ;
333+ if (hasMetadata && ! metadataFound ) throw ' Json file ` ${infos .documentation .metadata }` not found' ;
334+ }
335+
266336 static function cleanDependencies (dependencies : Null <Dependencies >): Void {
267337 if (dependencies == null )
268338 return ;
0 commit comments