Skip to content

Commit baeb6d1

Browse files
committed
build: add manifest.json schema
1 parent d9ef2aa commit baeb6d1

File tree

19 files changed

+1295
-0
lines changed

19 files changed

+1295
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# JSON Schema
22+
23+
> [JSON schema][json-schema] for `manifest.json`.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var schema = require( '@stdlib/_tools/manifest-json/schema' );
41+
```
42+
43+
#### schema()
44+
45+
Returns a [JSON schema][json-schema] for `manifest.json`.
46+
47+
```javascript
48+
var json = schema();
49+
// returns <Object>
50+
```
51+
52+
</section>
53+
54+
<!-- /.usage -->
55+
56+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
57+
58+
<section class="notes">
59+
60+
</section>
61+
62+
<!-- /.notes -->
63+
64+
<!-- Package usage examples. -->
65+
66+
<section class="examples">
67+
68+
## Examples
69+
70+
<!-- eslint no-undef: "error" -->
71+
72+
```javascript
73+
var join = require( 'path' ).join;
74+
var Ajv = require( 'ajv' );
75+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
76+
var schema = require( '@stdlib/_tools/manifest-json/schema' );
77+
78+
var manifest = readJSON( join( __dirname, 'fixtures', 'manifest.json' ) );
79+
var ajv = new Ajv();
80+
81+
var bool = ajv.validate( schema(), manifest );
82+
var errs = ajv.errors;
83+
```
84+
85+
</section>
86+
87+
<!-- /.examples -->
88+
89+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
90+
91+
<section class="references">
92+
93+
</section>
94+
95+
<!-- /.references -->
96+
97+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
98+
99+
<section class="related">
100+
101+
</section>
102+
103+
<!-- /.related -->
104+
105+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
106+
107+
<section class="links">
108+
109+
[json-schema]: http://json-schema.org/
110+
111+
</section>
112+
113+
<!-- /.links -->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"fields": [
3+
{
4+
"field": "src",
5+
"resolve": true,
6+
"relative": true
7+
},
8+
{
9+
"field": "include",
10+
"resolve": true,
11+
"relative": true
12+
},
13+
{
14+
"field": "libraries",
15+
"resolve": false,
16+
"relative": false
17+
},
18+
{
19+
"field": "libpath",
20+
"resolve": true,
21+
"relative": false
22+
}
23+
],
24+
"confs": [
25+
{
26+
"task": "build",
27+
"src": [
28+
"./src/main.c"
29+
],
30+
"include": [
31+
"./include"
32+
],
33+
"libraries": [],
34+
"libpath": [],
35+
"dependencies": []
36+
},
37+
{
38+
"task": "benchmark",
39+
"src": [
40+
"./src/main.c"
41+
],
42+
"include": [
43+
"./include"
44+
],
45+
"libraries": [],
46+
"libpath": [],
47+
"dependencies": []
48+
},
49+
{
50+
"task": "examples",
51+
"src": [
52+
"./src/main.c"
53+
],
54+
"include": [
55+
"./include"
56+
],
57+
"libraries": [],
58+
"libpath": [],
59+
"dependencies": []
60+
}
61+
]
62+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/**
3+
* @license Apache-2.0
4+
*
5+
* Copyright (c) 2024 The Stdlib Authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
'use strict';
21+
22+
var join = require( 'path' ).join;
23+
var Ajv = require( 'ajv' );
24+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
25+
var schema = require( './../lib' );
26+
27+
var manifest = readJSON( join( __dirname, 'fixtures', 'manifest.json' ) );
28+
var ajv = new Ajv();
29+
30+
var bool = ajv.validate( schema(), manifest );
31+
console.log( bool );
32+
33+
var errs = ajv.errors;
34+
console.log( errs );
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* JSON schema for manifest.json.
23+
*
24+
* @module @stdlib/_tools/manifest-json/schema
25+
*
26+
* @example
27+
* var schema = require( '@stdlib/_tools/manifest-json/schema' );
28+
*
29+
* var json = schema();
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var copy = require( '@stdlib/utils/copy' );
24+
var SCHEMA = require( './schema.json' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Returns a JSON schema for manifest.json.
31+
*
32+
* @returns {Object} JSON schema
33+
*
34+
* @example
35+
* var json = schema();
36+
*/
37+
function schema() {
38+
return copy( SCHEMA );
39+
}
40+
41+
42+
// EXPORTS //
43+
44+
module.exports = schema;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"type": "object",
4+
"properties": {
5+
"options": {
6+
"type": "object",
7+
"description": "Key-value pairs where each key corresponds to a field in 'confs' and may be used to conditionally select a configuration. Each value corresponds to the key's default value.",
8+
"additionalProperties": true
9+
},
10+
"fields": {
11+
"type": "array",
12+
"items": {
13+
"type": "object",
14+
"properties": {
15+
"field": {
16+
"type": "string",
17+
"description": "Key name corresponding to a field in 'confs'.",
18+
"minLength": 1
19+
},
20+
"resolve": {
21+
"type": "boolean",
22+
"description": "Indicates whether to resolve field values as file paths. If 'true', all field values are resolved relative to the manifest file."
23+
},
24+
"relative": {
25+
"type": "boolean",
26+
"description": "Indicates whether to resolve field values as relative file paths. This field is only considered when a manifest is a root manifest. If 'true', all field values, including those originating from dependencies, are resolved as relative file paths relative to the root manifest."
27+
}
28+
},
29+
"required": ["field", "resolve", "relative"],
30+
"additionalProperties": false
31+
},
32+
"uniqueItems": true
33+
},
34+
"confs": {
35+
"type": "array",
36+
"items": {
37+
"type": "object",
38+
"properties": {
39+
"src": {
40+
"type": "array",
41+
"items": {
42+
"type": "string",
43+
"minLength": 1
44+
},
45+
"description": "Array of source files.",
46+
"uniqueItems": true,
47+
"minItems": 1
48+
},
49+
"include": {
50+
"type": "array",
51+
"items": {
52+
"type": "string",
53+
"minLength": 1
54+
},
55+
"description": "Array of include directories.",
56+
"uniqueItems": true
57+
},
58+
"libraries": {
59+
"type": "array",
60+
"items": {
61+
"type": "string",
62+
"minLength": 1
63+
},
64+
"description": "Array of linked library dependencies.",
65+
"uniqueItems": true
66+
},
67+
"libpath": {
68+
"type": "array",
69+
"items": {
70+
"type": "string",
71+
"minLength": 1
72+
},
73+
"description": "Array of linked library paths.",
74+
"uniqueItems": true
75+
},
76+
"dependencies": {
77+
"type": "array",
78+
"items": {
79+
"type": "string",
80+
"minLength": 1
81+
},
82+
"description": "Array of package dependencies containing source files.",
83+
"uniqueItems": true
84+
}
85+
},
86+
"required": ["src", "include", "libraries", "libpath", "dependencies"],
87+
"additionalProperties": true
88+
},
89+
"uniqueItems": true
90+
}
91+
},
92+
"required": ["options", "fields", "confs"],
93+
"additionalProperties": false
94+
}

0 commit comments

Comments
 (0)