Hydrilla source package format » History » Version 8
koszko, 03/02/2022 05:31 PM
spell "JavaScript" with capital "J" and "S"
1 | 1 | koszko | # Hydrilla source package format |
---|---|---|---|
2 | |||
3 | 6 | koszko | This page explains the upcoming format for source packages used to build Hydrilla site content. It refers to the upcoming Hydrilla 1.0 release. |
4 | 1 | koszko | |
5 | You might also want to read about the data format of [[Hydrilla on-disk data format| built Hydrilla resources]]. |
||
6 | |||
7 | ## How Hydrilla packages are built |
||
8 | Hydrilla package builder expects a source package directory and a destination directory to be specified on the command line. If source package directory is missing, current directory is used as default. |
||
9 | |||
10 | ## Desination directory |
||
11 | The destination directory can be considered the same as [[Hydrilla on-disk data format#How-Hydrilla-loads-content|Hydrilla's content directory]] - built artifacts will be written in conformance with Hydrilla data format. |
||
12 | |||
13 | ## Source package directory |
||
14 | 4 | koszko | Source package directory is expected to contain an `index.json` file (although Hydrilla builder can be told to use another file and behave as if it was `index.json`). Hydrilla builder loads it (smartly ignoring "//" comments in it) and collects the definitions of site resources and pattern->payload mappings in it. |
15 | 1 | koszko | |
16 | ## Format of an index.json |
||
17 | 8 | koszko | |
18 | 3 | koszko | ### Example |
19 | 1 | koszko | To understand the format, look into this example file with explanatory comments in it: |
20 | |||
21 | ``` javascript |
||
22 | // SPDX-License-Identifier: CC0-1.0 |
||
23 | |||
24 | 4 | koszko | // Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org> |
25 | 1 | koszko | // Available under the terms of Creative Commons Zero v1.0 Universal. |
26 | |||
27 | // This is an example index.json file describing Hydrilla site content. As you |
||
28 | // can see, for storing site content information Hydrilla utilizes JSON with an |
||
29 | // additional extension in the form of '//' comments support. |
||
30 | |||
31 | // An index.json file conveys definitions of site resources and pattern->payload |
||
32 | // mappings. The definitions may reference files under index.json's containing |
||
33 | // directory, using relative paths. This is how scripts, license texts, etc. are |
||
34 | // included. |
||
35 | // File reference always takes the form of an object with "file" property |
||
36 | // specifying path to the file. In certain contexts additional properties may be |
||
37 | // allowed or required. Unix paths (using '/' as separator) are assumed. It is |
||
38 | // not allowed for an index.json file to reference files outside its directory. |
||
39 | |||
40 | // Certain objects are allowed to contain a "comment" field. Although '//' |
||
41 | // comments can be used in index.json files, they will not be included in |
||
42 | // generated JSON definitions. If a comment should be included in the |
||
43 | // definitions served by Hydrilla API, it should be put in a "comment" field of |
||
44 | // the proper object. |
||
45 | |||
46 | // Unknown object properties will be ignored. This is for compatibility with |
||
47 | // possible future revisions of the format. |
||
48 | { |
||
49 | // Once our index.json schema changes, this field's value will change. Our |
||
50 | // software will be able to handle both current and older formats thanks to |
||
51 | // this information present in every index.json file. Schemas that differ by |
||
52 | // the first (major) number are always incompatible (e.g. a Hydrilla builder |
||
53 | 3 | koszko | // instance released at the time of 1.2 being the most recent schema version |
54 | 5 | koszko | // will not understand version 2.1). |
55 | 3 | koszko | // Schemas that are backwards-compatible will have the same major number |
56 | // and might differ by the second (minor) version number. The third (patch) |
||
57 | // and subsequent numbers are being ignored right now. |
||
58 | 5 | koszko | "$schema": "https://hydrilla.koszko.org/schemas/package_source-1.schema.json", |
59 | 1 | koszko | |
60 | // Used when referring to this source package. Should be consize, unique |
||
61 | // (among other source package names) and can only use a restricted set of |
||
62 | // characters. It has to match: [-0-9a-z.]+ |
||
63 | "source_name": "hello", |
||
64 | |||
65 | 4 | koszko | // This property lists files that contain copyright information regarding |
66 | // this source package as well as texts of licenses used. Although no |
||
67 | // specific format of these files is mandated, it is recommended to make |
||
68 | // each source package REUSE-compliant, generate an spdx report for it as |
||
69 | // `report.spdx` and list this report together with all license files here. |
||
70 | 1 | koszko | "copyright": [ |
71 | 3 | koszko | {"file": "report.spdx"}, |
72 | {"file": "LICENSES/CC0-1.0.txt"} |
||
73 | 1 | koszko | ], |
74 | |||
75 | // Where this software/work initially comes from. |
||
76 | 4 | koszko | "upstream_url": "https://git.koszko.org/hydrilla-source-package-example", |
77 | 1 | koszko | |
78 | // Additional "comment" field can be used if needed. |
||
79 | // "comment": "" |
||
80 | |||
81 | // List of actual site resources and pattern->payload mappings. Each of them |
||
82 | // is represented by an object. Meta-sites and replacement site interfaces |
||
83 | // will also belong here once they get implemented. |
||
84 | "definitions": [ |
||
85 | 3 | koszko | { |
86 | // Value of "type" can currently be one of: "resource" and |
||
87 | // "mapping". The one we have here, "resource", defines a list |
||
88 | // of injectable scripts that can be used as a payload or as a |
||
89 | // dependency of another "resource". In the future CSS style sheets |
||
90 | // and WASM modules will also be composite parts of a "resource" as |
||
91 | // scripts are now. |
||
92 | "type": "resource", |
||
93 | 1 | koszko | |
94 | 3 | koszko | // Used when referring to this resource in "dependencies" list of |
95 | // another resource or in "payload" field of a mapping. Should |
||
96 | // be consize and can only use a restricted set of characters. It |
||
97 | 1 | koszko | // has to match: [-0-9a-z]+ |
98 | "identifier": "helloapple", |
||
99 | |||
100 | // "long_name" should be used to specify a user-friendly alternative |
||
101 | // to an identifier. It should generally not collide with a long |
||
102 | // name of some resource with a different uuid and also shouldn't |
||
103 | // change in-between versions of the same resource, although |
||
104 | // exceptions to both rules might be considered. Long name is |
||
105 | // allowed to contain arbitrary unicode characters (within reason!). |
||
106 | 3 | koszko | "long_name": "Hello Apple", |
107 | |||
108 | 5 | koszko | // Item definitions contain version information. Version is |
109 | // represented as an array of integers, with major version number |
||
110 | // being the first array item. In case of resources, version is |
||
111 | // accompanied by a revision field which contains a positive |
||
112 | // integer. If versions specified by arrays of different length need |
||
113 | // to be compared, the shorter array gets padded with zeroes on the |
||
114 | // right. This means that for example version 1.3 could be given as |
||
115 | // both [1, 3] and [1, 3, 0, 0] (aka 1.3.0.0) and either would mean |
||
116 | // the same. |
||
117 | 3 | koszko | // Different versions (e.g. 1.0 and 1.3) of the same resource can be |
118 | // defined in separate index.json files. This makes it easy to |
||
119 | // accidently cause an identifier clash. To help detect it, we |
||
120 | // require that each resource has a uuid associated with it. Attempt |
||
121 | // to define multiple resources with the same identifier and |
||
122 | // different uuids will result in an error being reported. Defining |
||
123 | // multiple resources with different identifiers and the same uuid |
||
124 | // is disallowed for now (it may be later permitted if we consider |
||
125 | // it good for some use-case). |
||
126 | "uuid": "a6754dcb-58d8-4b7a-a245-24fd7ad4cd68", |
||
127 | 1 | koszko | |
128 | // Version should match the upstream version of the resource (e.g. a |
||
129 | 8 | koszko | // version of JavaScript library). Revision number starts as 1 for |
130 | 3 | koszko | // each new resource version and gets incremented by 1 each time a |
131 | // modification to the packaging of this version is done. Hydrilla |
||
132 | // will allow multiple definitions of the same resource to load, as |
||
133 | // long as their versions differ. Thanks to the "version" and |
||
134 | // "revision" fields, clients will know they have to update certain |
||
135 | // resource after it has been updated. If multiple definitions of |
||
136 | // the same version of given resource are provided, an error is |
||
137 | // generated (even if those definitions differ by revision number). |
||
138 | "version": [2021, 11, 10], |
||
139 | "revision": 1, |
||
140 | 1 | koszko | |
141 | // A short, meaningful description of what the resource is and/or |
||
142 | 3 | koszko | // what it does. |
143 | "description": "greets an apple", |
||
144 | 1 | koszko | |
145 | 3 | koszko | // If needed, a "comment" field can be added to provide some |
146 | // additional information. |
||
147 | // "comment": "this resource something something", |
||
148 | 1 | koszko | |
149 | 3 | koszko | // Resource's "dependencies" array shall contain names of other |
150 | // resources that (in case of scripts at least) should get evaluated |
||
151 | // on a page before this resource's own scripts. |
||
152 | 1 | koszko | "dependencies": [{"identifier": "hello-message"}], |
153 | |||
154 | 8 | koszko | // Array of JavaScript files that belong to this resource. |
155 | 3 | koszko | "scripts": [ |
156 | {"file": "hello.js"}, |
||
157 | {"file": "bye.js"} |
||
158 | ] |
||
159 | }, { |
||
160 | "type": "resource", |
||
161 | "identifier": "hello-message", |
||
162 | "long_name": "Hello Message", |
||
163 | "uuid": "1ec36229-298c-4b35-8105-c4f2e1b9811e", |
||
164 | "version": [2021, 11, 10], |
||
165 | "revision": 2, |
||
166 | "description": "define messages for saying hello and bye", |
||
167 | // If "dependencies" is empty, it can also be omitted. |
||
168 | // "dependencies": [], |
||
169 | "scripts": [{"file": "message.js"}] |
||
170 | }, { |
||
171 | "type": "mapping", |
||
172 | 1 | koszko | |
173 | 3 | koszko | // Has similar function to resource's identifier. Should be consize |
174 | // and can only use a restricted set of characters. It has to match: |
||
175 | // [-0-9a-z]+ |
||
176 | // It can be the same as some resource identifier (those are |
||
177 | // different entities and are treated separately). |
||
178 | "identifier": "helloapple", |
||
179 | 1 | koszko | |
180 | 3 | koszko | // "long name" and "uuid" have the same meaning as in the case of |
181 | // resources. Uuids of a resource and a mapping can technically be |
||
182 | // the same, but it is recommended to avoid even this kind of |
||
183 | // repetition. |
||
184 | "long_name": "Hello Apple", |
||
185 | "uuid": "54d23bba-472e-42f5-9194-eaa24c0e3ee7", |
||
186 | 1 | koszko | |
187 | 3 | koszko | // "version" differs from its counterpart in resource in that it has |
188 | // no accompanying revision number. |
||
189 | "version": [2021, 11, 10], |
||
190 | 1 | koszko | |
191 | 3 | koszko | // A short, meaningful description of what the mapping does. |
192 | "description": "causes apple to get greeted on Hydrillabugs issue tracker", |
||
193 | 1 | koszko | |
194 | 3 | koszko | // A comment, if necessary. |
195 | // "comment": "blah blah because bleh" |
||
196 | 1 | koszko | |
197 | 3 | koszko | // The "payloads" object specifies which payloads are to be applied |
198 | // to which URLs. |
||
199 | "payloads": { |
||
200 | // Each key should be a valid Haketilo URL pattern. |
||
201 | 1 | koszko | "https://hydrillabugs.koszko.org/***": { |
202 | // Should be the name of an existing resource. The resource |
||
203 | // may, but doesn't have to, be defined in the same |
||
204 | 3 | koszko | // index.json file. |
205 | "identifier": "helloapple" |
||
206 | }, |
||
207 | // More associations may follow. |
||
208 | "https://hachettebugs.koszko.org/***": { |
||
209 | "identifier": "helloapple" |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | ], |
||
214 | 4 | koszko | // We can also list additional files to include in the produced source |
215 | // archive. Hydrilla builder will then include those together with all |
||
216 | // script and copyright files used. |
||
217 | "additional_files": [ |
||
218 | {"file": "README.txt"}, |
||
219 | {"file": "README.txt.license"}, |
||
220 | {"file": ".reuse/dep5"} |
||
221 | ], |
||
222 | // We can optionally tell Hydrilla builder to run the REUSE tool to generate |
||
223 | // report.spdx file. Using this option requires REUSE to be installed and |
||
224 | // and importable in the Python virtualenv used by Hydrilla builder. |
||
225 | "reuse_generate_spdx_report": true |
||
226 | 3 | koszko | } |
227 | ``` |
||
228 | 4 | koszko | |
229 | ### [JSON schema](https://json-schema.org/) |
||
230 | 7 | koszko | Valid index.json file should conform to the schema available [here](https://hydrilla.koszko.org/schemas/package_source-1.0.1.schema.json). |