Skip to content

Commit 4e4b034

Browse files
authored
Add support for customMetas and customDefines fields (#573)
* Add support for customMetas and customDefines fields * Move new documentation fields to 'documentation' object Also guard against previous haxe versions * Add metadata/define source * Update json schema * Check documentation fields * Rebuild run.n * Let maintainers add more documentation resources if they want * Revert "Let maintainers add more documentation resources if they want" This reverts commit cb7976c. * Typo * Rename Compiler metadata/defines functions * Rebuild run.n
1 parent 55e5092 commit 4e4b034

File tree

16 files changed

+231
-1
lines changed

16 files changed

+231
-1
lines changed

run.n

4.64 KB
Binary file not shown.

schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
},
4848
"additionalProperties": false
4949
},
50+
"documentation": {
51+
"type": "object",
52+
"description": "Project's documentation resources",
53+
"properties": {
54+
"defines": {
55+
"type": "string",
56+
"description": "Relative path to json file describing this project's custom defines"
57+
},
58+
"metadata": {
59+
"type": "string",
60+
"description": "Relative path to json file describing this project's custom metadata"
61+
}
62+
},
63+
"additionalProperties": false
64+
},
5065
"releasenote": {
5166
"description": "Short description of changes made in this version",
5267
"type": "string"

src/haxelib/Data.hx

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

src/haxelib/api/Connection.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ class Connection {
402402

403403
final infos = Data.readDataFromZip(zip, CheckData);
404404
Data.checkClassPath(zip, infos);
405+
Data.checkDocumentation(zip, infos);
405406

406407
// ask user which contributor they are
407408
final user = login(infos.contributors);

src/haxelib/api/GlobalScope.hx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,25 @@ class GlobalScope extends Scope {
185185
);
186186
addLine('-D ${info.name}=${info.version}');
187187

188+
if (info.documentation != null) {
189+
var doc = info.documentation;
190+
191+
// we'll have to change this to "4.3.0" after the release
192+
if (resolveCompiler().version >= SemVer.ofString("4.3.0-rc.1")) {
193+
// custom defines if defined
194+
if (doc.defines != null && doc.defines != "") {
195+
var path = Path.join([resolved.path, doc.defines]);
196+
addLine('--macro registerDefinesDescriptionFile(\'$path\', \'${info.name}\')');
197+
}
198+
199+
// custom metadatas if defined
200+
if (doc.metadata != null && doc.metadata != "") {
201+
var path = Path.join([resolved.path, doc.metadata]);
202+
addLine('--macro registerMetadataDescriptionFile(\'$path\', \'${info.name}\')');
203+
}
204+
}
205+
}
206+
188207
// add dependencies to stack
189208
final dependencies = info.dependencies.extractDataArray();
190209

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"name": "Malformed define"
4+
}
5+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "BadDefineJson",
3+
"url" : "http://example.org",
4+
"license": "GPL",
5+
"tags": ["bar", "test"],
6+
"description": "This project is an example of an haxelib project",
7+
"version": "1.0.0",
8+
"releasenote": "Initial release, everything is working correctly",
9+
"documentation": {
10+
"defines": "doc/defines.json"
11+
},
12+
"contributors": ["Bar"]
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is not a json file
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "BadMetaJson",
3+
"url" : "http://example.org",
4+
"license": "GPL",
5+
"tags": ["bar", "test"],
6+
"description": "This project is an example of an haxelib project",
7+
"version": "1.0.0",
8+
"releasenote": "Initial release, everything is working correctly",
9+
"documentation": {
10+
"metadata": "doc/meta.json"
11+
},
12+
"contributors": ["Bar"]
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"name": "Malformed meta"
4+
}
5+
]

0 commit comments

Comments
 (0)