Project

General

Profile

Hydrilla source package format » History » Version 6

koszko, 02/25/2022 04:56 PM

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