ol-stac 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.github/workflows/deploy.yml +67 -0
- package/.github/workflows/publish.yml +32 -0
- package/.github/workflows/release.yml +21 -0
- package/.github/workflows/test.yml +85 -0
- package/CHANGELOG.md +14 -0
- package/DEVELOPING.md +104 -0
- package/LICENSE.md +201 -0
- package/README.md +43 -0
- package/config/jsdoc/api/conf.json +38 -0
- package/config/jsdoc/api/index.md +1 -0
- package/config/jsdoc/api/readme.md +65 -0
- package/config/jsdoc/api/template/README.md +3 -0
- package/config/jsdoc/api/template/publish.js +743 -0
- package/config/jsdoc/api/template/static/scripts/linenumber.js +11 -0
- package/config/jsdoc/api/template/static/scripts/main.js +305 -0
- package/config/jsdoc/api/template/static/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/config/jsdoc/api/template/static/scripts/prettify/lang-css.js +2 -0
- package/config/jsdoc/api/template/static/scripts/prettify/prettify.js +28 -0
- package/config/jsdoc/api/template/static/styles/carbon.css +65 -0
- package/config/jsdoc/api/template/static/styles/jaguar.css +512 -0
- package/config/jsdoc/api/template/static/styles/prettify-jsdoc.css +111 -0
- package/config/jsdoc/api/template/static/styles/prettify-tomorrow.css +132 -0
- package/config/jsdoc/api/template/static/theme +1 -0
- package/config/jsdoc/api/template/tmpl/container.tmpl +205 -0
- package/config/jsdoc/api/template/tmpl/details.tmpl +84 -0
- package/config/jsdoc/api/template/tmpl/example.tmpl +2 -0
- package/config/jsdoc/api/template/tmpl/examples.tmpl +16 -0
- package/config/jsdoc/api/template/tmpl/exceptions.tmpl +30 -0
- package/config/jsdoc/api/template/tmpl/layout.tmpl +92 -0
- package/config/jsdoc/api/template/tmpl/mainpage.tmpl +14 -0
- package/config/jsdoc/api/template/tmpl/members.tmpl +38 -0
- package/config/jsdoc/api/template/tmpl/method.tmpl +132 -0
- package/config/jsdoc/api/template/tmpl/navigation.tmpl +59 -0
- package/config/jsdoc/api/template/tmpl/observables.tmpl +39 -0
- package/config/jsdoc/api/template/tmpl/params.tmpl +109 -0
- package/config/jsdoc/api/template/tmpl/properties.tmpl +85 -0
- package/config/jsdoc/api/template/tmpl/returns.tmpl +72 -0
- package/config/jsdoc/api/template/tmpl/source.tmpl +8 -0
- package/config/jsdoc/api/template/tmpl/stability.tmpl +7 -0
- package/config/jsdoc/api/template/tmpl/tutorial.tmpl +19 -0
- package/config/jsdoc/api/template/tmpl/type.tmpl +7 -0
- package/config/jsdoc/info/conf.json +22 -0
- package/config/jsdoc/info/publish.js +175 -0
- package/config/jsdoc/package.json +4 -0
- package/config/jsdoc/plugins/api.cjs +181 -0
- package/config/jsdoc/plugins/default-export.cjs +35 -0
- package/config/jsdoc/plugins/define-plugin.cjs +33 -0
- package/config/jsdoc/plugins/events.cjs +39 -0
- package/config/jsdoc/plugins/inline-options.cjs +102 -0
- package/config/jsdoc/plugins/markdown.cjs +119 -0
- package/config/jsdoc/plugins/observable.cjs +69 -0
- package/config/jsdoc/plugins/virtual-plugin.cjs +16 -0
- package/config/rollup-full-build.js +24 -0
- package/config/tsconfig-build.json +25 -0
- package/examples/.eslintrc +29 -0
- package/examples/index.html +100 -0
- package/examples/index.js +109 -0
- package/examples/planetary-computer.html +14 -0
- package/examples/planetary-computer.js +53 -0
- package/examples/resources/Jugl.js +15 -0
- package/examples/resources/common.js +111 -0
- package/examples/stac-collection-webmaplinks.html +9 -0
- package/examples/stac-collection-webmaplinks.js +55 -0
- package/examples/stac-item-from-object.html +9 -0
- package/examples/stac-item-from-object.js +102 -0
- package/examples/stac-item-tileserver.html +9 -0
- package/examples/stac-item-tileserver.js +34 -0
- package/examples/stac-item.html +9 -0
- package/examples/stac-item.js +45 -0
- package/examples/stac-itemcollection.html +11 -0
- package/examples/stac-itemcollection.js +39 -0
- package/examples/templates/example.html +206 -0
- package/examples/templates/readme.md +3 -0
- package/examples/webpack/config.mjs +69 -0
- package/examples/webpack/example-builder.js +410 -0
- package/package.json +107 -0
- package/site/build.js +26 -0
- package/site/layouts/default.hbs +78 -0
- package/site/src/doc/faq.md +8 -0
- package/site/src/doc/index.md +22 -0
- package/site/src/doc/quickstart.md +121 -0
- package/site/src/doc/tutorials/index.md +8 -0
- package/site/src/download/index.hbs +62 -0
- package/site/src/favicon.ico +0 -0
- package/site/src/index.hbs +71 -0
- package/site/src/theme/index.css +26 -0
- package/site/src/theme/site.css +531 -0
- package/src/ol/events/ErrorEvent.js +25 -0
- package/src/ol/layer/STAC.js +780 -0
- package/src/ol/layer/stacUtil.js +169 -0
- package/src/ol/source/GeoTIFF2.js +47 -0
- package/tasks/.eslintrc +5 -0
- package/tasks/build-website.sh +90 -0
- package/tasks/create-release.js +107 -0
- package/tasks/generate-index.js +125 -0
- package/tasks/generate-info.js +189 -0
- package/tasks/get-latest-release.js +36 -0
- package/tasks/newest-tag.js +52 -0
- package/tasks/prepare-package.js +46 -0
- package/tasks/publish.sh +90 -0
- package/test/README.md +56 -0
- package/test/browser/.eslintrc +14 -0
- package/test/browser/karma.config.cjs +94 -0
- package/test/browser/spec/ol/layer/STAC.test.js +18 -0
- package/test/browser/test-extensions.js +419 -0
- package/tsconfig.json +62 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import VectorLayer from 'ol/layer/Vector.js';
|
|
2
|
+
import {Fill, Stroke, Style} from 'ol/style.js';
|
|
3
|
+
import {STAC} from 'stac-js';
|
|
4
|
+
import {WMTSCapabilities} from 'ol/format.js';
|
|
5
|
+
import {
|
|
6
|
+
fromEPSGCode,
|
|
7
|
+
isRegistered as isProj4Registered,
|
|
8
|
+
} from 'ol/proj/proj4.js';
|
|
9
|
+
|
|
10
|
+
export const defaultBoundsStyle = new Style({
|
|
11
|
+
fill: new Fill({
|
|
12
|
+
color: 'rgba(255,255,255,0.4)',
|
|
13
|
+
}),
|
|
14
|
+
stroke: new Stroke({
|
|
15
|
+
color: '#3399CC',
|
|
16
|
+
width: 3,
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const defaultCollectionStyle = new Style({
|
|
21
|
+
stroke: new Stroke({
|
|
22
|
+
color: '#ff9933',
|
|
23
|
+
width: 1,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the STAC objects associated with this event, if any. Excludes API Collections.
|
|
29
|
+
* @param {import('ol/MapBrowserEvent.js').default} event The asset to read the information from.
|
|
30
|
+
* @return {Promise<Array<STAC>>} A list of STAC objects
|
|
31
|
+
*/
|
|
32
|
+
export async function getStacObjectsForEvent(event) {
|
|
33
|
+
const objects = event.map
|
|
34
|
+
.getAllLayers()
|
|
35
|
+
.filter((layer) => {
|
|
36
|
+
if (
|
|
37
|
+
layer instanceof VectorLayer &&
|
|
38
|
+
layer.get('bounds') === true &&
|
|
39
|
+
layer.get('stac') instanceof STAC
|
|
40
|
+
) {
|
|
41
|
+
const features = layer
|
|
42
|
+
.getSource()
|
|
43
|
+
.getFeaturesAtCoordinate(event.coordinate);
|
|
44
|
+
return features.length > 0;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
})
|
|
48
|
+
.map((layer) => layer.get('stac'));
|
|
49
|
+
// Make sure we return no duplicates
|
|
50
|
+
return [...new Set(objects)];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the source info for the GeoTiff from the asset.
|
|
55
|
+
* @param {import('stac-js').Asset} asset The asset to read the information from.
|
|
56
|
+
* @param {Array<number>} bands The (one-based) bands to show.
|
|
57
|
+
* @return {import('ol/source/GeoTIFF.js').SourceInfo} The source info for the GeoTiff asset
|
|
58
|
+
*/
|
|
59
|
+
export function getGeoTiffSourceInfoFromAsset(asset, bands) {
|
|
60
|
+
const sourceInfo = {
|
|
61
|
+
url: asset.getAbsoluteUrl(),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let band = null;
|
|
65
|
+
// If there's just one band, we can also read the information from there.
|
|
66
|
+
if (asset.getBands().length === 1) {
|
|
67
|
+
band = 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// TODO: It would be useful if OL would allow min/max values per band
|
|
71
|
+
const {minimum, maximum} = asset.getMinMaxValues(band);
|
|
72
|
+
if (typeof minimum === 'number') {
|
|
73
|
+
sourceInfo.min = minimum;
|
|
74
|
+
}
|
|
75
|
+
if (typeof maximum === 'number') {
|
|
76
|
+
sourceInfo.max = maximum;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// TODO: It would be useful if OL would allow multiple no-data values
|
|
80
|
+
const nodata = asset.getNoDataValues(band);
|
|
81
|
+
if (nodata.length > 0) {
|
|
82
|
+
sourceInfo.nodata = nodata[0];
|
|
83
|
+
} else {
|
|
84
|
+
sourceInfo.nodata = NaN; // NaN is usually a reasonable default if nothing is provided
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (bands.length > 0) {
|
|
88
|
+
sourceInfo.bands = bands;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return sourceInfo;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets the projection from the asset or link.
|
|
96
|
+
* @param {import('stac-js').STACReference} reference The asset or link to read the information from.
|
|
97
|
+
* @param {import('ol/proj.js').ProjectionLike} defaultProjection A default projection to use.
|
|
98
|
+
* @return {Promise<import('ol/proj.js').ProjectionLike>} The projection, if any.
|
|
99
|
+
*/
|
|
100
|
+
export async function getProjection(reference, defaultProjection = undefined) {
|
|
101
|
+
let projection = defaultProjection;
|
|
102
|
+
if (isProj4Registered()) {
|
|
103
|
+
// TODO: It would be great to handle WKT2 and PROJJSON, but is not supported yet by proj4js.
|
|
104
|
+
const epsgCode = reference.getMetadata('proj:epsg');
|
|
105
|
+
if (epsgCode) {
|
|
106
|
+
try {
|
|
107
|
+
projection = await fromEPSGCode(epsgCode);
|
|
108
|
+
} catch (_) {
|
|
109
|
+
// pass
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return projection;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the style for the footprint.
|
|
118
|
+
* Removes the fill if anything is meant to be shown in the bounds.
|
|
119
|
+
*
|
|
120
|
+
* @param {Style} [originalStyle] The original style for the footprint.
|
|
121
|
+
* @param {import('./STAC.js').default} [layerGroup] The associated STAC layergroup to check.
|
|
122
|
+
* @return {Style} The adapted style for the footprint.
|
|
123
|
+
*/
|
|
124
|
+
export function getBoundsStyle(originalStyle, layerGroup) {
|
|
125
|
+
const style = originalStyle.clone();
|
|
126
|
+
if (!layerGroup.hasOnlyBounds()) {
|
|
127
|
+
style.setFill(null);
|
|
128
|
+
}
|
|
129
|
+
return style;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get a URL from a web-map-link that is specific enough, i.e.
|
|
134
|
+
* replaces any occurances of {s} if possible, otherwise returns null.
|
|
135
|
+
* @param {import('./STAC.js').Link} link The web map link.
|
|
136
|
+
* @return {string|null} Specific URL
|
|
137
|
+
*/
|
|
138
|
+
export function getSpecificWebMapUrl(link) {
|
|
139
|
+
let url = link.href;
|
|
140
|
+
if (url.includes('{s}')) {
|
|
141
|
+
if (
|
|
142
|
+
Array.isArray(link['href:servers']) &&
|
|
143
|
+
link['href:servers'].length > 0
|
|
144
|
+
) {
|
|
145
|
+
const i = (Math.random() * link['href:servers'].length) | 0;
|
|
146
|
+
url = url.replace('{s}', link['href:servers'][i]);
|
|
147
|
+
} else {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return url;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Gets the WMTS capabilities from the given web-map-links URL.
|
|
156
|
+
* @param {string} url Base URL for the WMTS
|
|
157
|
+
* @return {Promise<Object|null>} Resolves with the WMTS Capabilities object
|
|
158
|
+
*/
|
|
159
|
+
export async function getWmtsCapabilities(url) {
|
|
160
|
+
try {
|
|
161
|
+
const urlObj = new URL(url);
|
|
162
|
+
urlObj.searchParams.set('service', 'wmts');
|
|
163
|
+
urlObj.searchParams.set('request', 'GetCapabilities');
|
|
164
|
+
const response = await fetch(urlObj);
|
|
165
|
+
return new WMTSCapabilities().read(await response.text());
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// to avoid: error TS8022: JSDoc '@extends' is not attached to a class.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module ol/source/GeoTIFF2
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import GeoTIFF from 'ol/source/GeoTIFF.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import("ol/source/GeoTIFF.js").Options} GeoTIFFSourceOptions
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import("ol/source/GeoTIFF.js").SourceInfo} SourceInfo
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {import("ol/source/GeoTIFF.js").Options} Options
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} Options2
|
|
24
|
+
* @extends Options
|
|
25
|
+
* @property {import("ol/proj.js").ProjectionLike} [projection] Source projection. If not provided, the GeoTIFF metadata
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @classdesc
|
|
30
|
+
* A source for working with GeoTIFF data.
|
|
31
|
+
*
|
|
32
|
+
* Available for backward compatibility with ol <= 7.5.1
|
|
33
|
+
*
|
|
34
|
+
* @api
|
|
35
|
+
*/
|
|
36
|
+
export default class GeoTIFF2 extends GeoTIFF {
|
|
37
|
+
/**
|
|
38
|
+
* @param {Options2} options Data tile options.
|
|
39
|
+
*/
|
|
40
|
+
constructor(options) {
|
|
41
|
+
super(options);
|
|
42
|
+
|
|
43
|
+
if (options.projection) {
|
|
44
|
+
this.projection = options.projection;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Run this script to build the website.
|
|
5
|
+
#
|
|
6
|
+
set -o errexit
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Destination directory for the website.
|
|
10
|
+
#
|
|
11
|
+
build=build/site
|
|
12
|
+
|
|
13
|
+
usage() {
|
|
14
|
+
cat <<-EOF
|
|
15
|
+
|
|
16
|
+
Usage: ${1} [options]
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
-v <version>
|
|
20
|
+
Version identifier. If omitted, the current branch name will be used.
|
|
21
|
+
|
|
22
|
+
-l <version>
|
|
23
|
+
The latest release version. If provided, the root of the website will be
|
|
24
|
+
rebuilt using this version identifier. If the -l value matches the -v value,
|
|
25
|
+
the examples and API docs will be copied to en/latest. If the -l option
|
|
26
|
+
is omitted, only the examples and API docs will be rebuilt (not the root of the site).
|
|
27
|
+
EOF
|
|
28
|
+
exit 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
root=false
|
|
32
|
+
|
|
33
|
+
while getopts ":v:l:" o; do
|
|
34
|
+
case "${o}" in
|
|
35
|
+
v)
|
|
36
|
+
version=${OPTARG}
|
|
37
|
+
;;
|
|
38
|
+
l)
|
|
39
|
+
latest=${OPTARG}
|
|
40
|
+
;;
|
|
41
|
+
*)
|
|
42
|
+
usage
|
|
43
|
+
;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
shift $((OPTIND-1))
|
|
47
|
+
|
|
48
|
+
if [ -z "${version}" ]; then
|
|
49
|
+
version=$(git branch --show-current)
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
root=$(cd -P -- "$(dirname -- "${0}")" && pwd -P)/..
|
|
53
|
+
cd ${root}
|
|
54
|
+
|
|
55
|
+
rm -rf ${build}
|
|
56
|
+
|
|
57
|
+
if [ -n "${latest}" ] ; then
|
|
58
|
+
echo "Building the website root with ${latest}"
|
|
59
|
+
mkdir -p ${build}
|
|
60
|
+
OL_VERSION=${latest} node site/build.js
|
|
61
|
+
cp -r site/build/* ${build}/
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
mkdir -p ${build}/en/${version}/
|
|
65
|
+
|
|
66
|
+
echo "Building examples for ${version}"
|
|
67
|
+
npm run build-examples
|
|
68
|
+
mv build/examples ${build}/en/${version}/
|
|
69
|
+
|
|
70
|
+
echo "Building API docs for ${version}"
|
|
71
|
+
npm run apidoc
|
|
72
|
+
mv build/apidoc ${build}/en/${version}/
|
|
73
|
+
|
|
74
|
+
echo "Building the package ${version}"
|
|
75
|
+
npm run build-package
|
|
76
|
+
mv build/ol ${build}/en/${version}/
|
|
77
|
+
|
|
78
|
+
if [[ "${latest}" == "${version}" ]] ; then
|
|
79
|
+
echo "Copying to en/latest"
|
|
80
|
+
cp -r ${build}/en/${version} ${build}/en/latest
|
|
81
|
+
|
|
82
|
+
echo "Building release artifacts"
|
|
83
|
+
pushd ${build}
|
|
84
|
+
zip -r ${OLDPWD}/build/${version}-site.zip . -x "en/${version}/*"
|
|
85
|
+
popd
|
|
86
|
+
|
|
87
|
+
pushd ${build}/en/${version}/ol
|
|
88
|
+
zip -r ${OLDPWD}/build/${version}-package.zip .
|
|
89
|
+
popd
|
|
90
|
+
fi
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import esMain from 'es-main';
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import {Octokit} from '@octokit/rest';
|
|
4
|
+
import {basename} from 'node:path';
|
|
5
|
+
import {hideBin} from 'yargs/helpers';
|
|
6
|
+
import {readFile, stat} from 'node:fs/promises';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} Options
|
|
10
|
+
* @property {string} token The bearer token.
|
|
11
|
+
* @property {string} tag The tag.
|
|
12
|
+
* @property {boolean} draft Create a draft release.
|
|
13
|
+
* @property {boolean} notes Generate release notes.
|
|
14
|
+
* @property {string} site Path to zip archive with site contents.
|
|
15
|
+
* @property {string} package Path to zip archive with source and full build.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const owner = 'm-mohr';
|
|
19
|
+
const repo = 'ol-stac';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a release.
|
|
23
|
+
* @param {Options} options The release options.
|
|
24
|
+
*/
|
|
25
|
+
async function createRelease(options) {
|
|
26
|
+
const client = new Octokit({
|
|
27
|
+
auth: options.token,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const response = await client.rest.repos.createRelease({
|
|
31
|
+
owner,
|
|
32
|
+
repo,
|
|
33
|
+
tag_name: options.tag,
|
|
34
|
+
generate_release_notes: options.notes,
|
|
35
|
+
draft: options.draft,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await uploadAsset(
|
|
39
|
+
client,
|
|
40
|
+
response.data,
|
|
41
|
+
options.site,
|
|
42
|
+
'Examples and docs (zip)'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
await uploadAsset(
|
|
46
|
+
client,
|
|
47
|
+
response.data,
|
|
48
|
+
options.package,
|
|
49
|
+
'Package archive (zip)'
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function uploadAsset(client, release, assetPath, label) {
|
|
54
|
+
const name = basename(assetPath);
|
|
55
|
+
const stats = await stat(assetPath);
|
|
56
|
+
const data = await readFile(assetPath);
|
|
57
|
+
|
|
58
|
+
await client.rest.repos.uploadReleaseAsset({
|
|
59
|
+
url: release.upload_url,
|
|
60
|
+
name,
|
|
61
|
+
label,
|
|
62
|
+
headers: {
|
|
63
|
+
'content-type': 'application/zip',
|
|
64
|
+
'content-length': stats.size,
|
|
65
|
+
},
|
|
66
|
+
data,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (esMain(import.meta)) {
|
|
71
|
+
const options = yargs(hideBin(process.argv))
|
|
72
|
+
.option('token', {
|
|
73
|
+
describe: 'The token for auth',
|
|
74
|
+
type: 'string',
|
|
75
|
+
})
|
|
76
|
+
.demandOption('token')
|
|
77
|
+
.option('tag', {
|
|
78
|
+
describe: 'The release tag (e.g. v7.0.0)',
|
|
79
|
+
type: 'string',
|
|
80
|
+
})
|
|
81
|
+
.demandOption('tag')
|
|
82
|
+
.option('package', {
|
|
83
|
+
describe: 'Path to the archive with the source package',
|
|
84
|
+
type: 'string',
|
|
85
|
+
})
|
|
86
|
+
.demandOption('package')
|
|
87
|
+
.option('site', {
|
|
88
|
+
describe: 'Path to the archive with the site contents',
|
|
89
|
+
type: 'string',
|
|
90
|
+
})
|
|
91
|
+
.demandOption('site')
|
|
92
|
+
.option('draft', {
|
|
93
|
+
describe: 'Create a draft release',
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
default: true,
|
|
96
|
+
})
|
|
97
|
+
.option('notes', {
|
|
98
|
+
describe: 'Generate release notes',
|
|
99
|
+
type: 'boolean',
|
|
100
|
+
default: true,
|
|
101
|
+
})
|
|
102
|
+
.parse();
|
|
103
|
+
|
|
104
|
+
createRelease(options).catch((err) => {
|
|
105
|
+
process.stderr.write(`${err.stack}\n`, () => process.exit(1));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import esMain from 'es-main';
|
|
2
|
+
import fse from 'fs-extra';
|
|
3
|
+
import generateInfo from './generate-info.js';
|
|
4
|
+
import path, {dirname} from 'path';
|
|
5
|
+
import {fileURLToPath} from 'url';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Read the symbols from info file.
|
|
9
|
+
* @return {Promise<Array>} Resolves with an array of symbol objects.
|
|
10
|
+
*/
|
|
11
|
+
async function getSymbols() {
|
|
12
|
+
const info = await generateInfo();
|
|
13
|
+
return info.symbols.filter((symbol) => symbol.kind != 'member');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generate an import statement.
|
|
18
|
+
* @param {Object} symbol Symbol.
|
|
19
|
+
* @param {string} member Member.
|
|
20
|
+
* @return {string} An import statement.
|
|
21
|
+
*/
|
|
22
|
+
function getImport(symbol, member) {
|
|
23
|
+
const defaultExport = symbol.name.split('~');
|
|
24
|
+
if (symbol.isDefaultExport) {
|
|
25
|
+
const from = defaultExport[0].replace(/^module\:/, './');
|
|
26
|
+
const importName = from.replace(/[.\/]+/g, '$');
|
|
27
|
+
return `import ${importName} from '${from}.js';`;
|
|
28
|
+
}
|
|
29
|
+
const namedExport = symbol.name.split('.');
|
|
30
|
+
if (
|
|
31
|
+
member &&
|
|
32
|
+
namedExport.length > 1 &&
|
|
33
|
+
(defaultExport.length <= 1 || defaultExport[0].includes('.'))
|
|
34
|
+
) {
|
|
35
|
+
const from = namedExport[0].replace(/^module\:/, './');
|
|
36
|
+
const importName = from.replace(/[.\/]+/g, '_');
|
|
37
|
+
return `import {${member} as ${importName}$${member}} from '${from}.js';`;
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generate code to export a named symbol.
|
|
44
|
+
* @param {Object} symbol Symbol.
|
|
45
|
+
* @param {Object<string, string>} namespaces Already defined namespaces.
|
|
46
|
+
* @param {Object} imports Imports.
|
|
47
|
+
* @return {string} Export code.
|
|
48
|
+
*/
|
|
49
|
+
function formatSymbolExport(symbol, namespaces, imports) {
|
|
50
|
+
const name = symbol.name;
|
|
51
|
+
const parts = name.split('~');
|
|
52
|
+
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
|
|
53
|
+
const last = nsParts.length - 1;
|
|
54
|
+
const imp = getImport(symbol, nsParts[last]);
|
|
55
|
+
if (imp) {
|
|
56
|
+
const isNamed = parts[0].includes('.');
|
|
57
|
+
const importName = isNamed
|
|
58
|
+
? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last]
|
|
59
|
+
: '$' + nsParts.join('$');
|
|
60
|
+
let line = nsParts[0];
|
|
61
|
+
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
|
|
62
|
+
line += `.${nsParts[i]}`;
|
|
63
|
+
namespaces[line] =
|
|
64
|
+
(line in namespaces ? namespaces[line] : true) && i < ii - 1;
|
|
65
|
+
}
|
|
66
|
+
line += ` = ${importName};`;
|
|
67
|
+
imports[imp] = true;
|
|
68
|
+
return line;
|
|
69
|
+
}
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Generate export code given a list symbol names.
|
|
75
|
+
* @param {Array<Object>} symbols List of symbols.
|
|
76
|
+
* @return {string} Export code.
|
|
77
|
+
*/
|
|
78
|
+
function generateExports(symbols) {
|
|
79
|
+
const namespaces = {};
|
|
80
|
+
const imports = {};
|
|
81
|
+
const blocks = [];
|
|
82
|
+
symbols.forEach(function (symbol) {
|
|
83
|
+
const name = symbol.name;
|
|
84
|
+
if (!name.includes('#')) {
|
|
85
|
+
const imp = getImport(symbol);
|
|
86
|
+
if (imp) {
|
|
87
|
+
imports[imp] = true;
|
|
88
|
+
}
|
|
89
|
+
const line = formatSymbolExport(symbol, namespaces, imports);
|
|
90
|
+
if (line) {
|
|
91
|
+
blocks.push(line);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const defs = [...new Set(blocks)];
|
|
96
|
+
const lines = Object.keys(imports).concat(defs.sort());
|
|
97
|
+
lines.push('', 'export default ol;');
|
|
98
|
+
return lines.join('\n');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generate the exports code.
|
|
103
|
+
* @return {Promise<string>} Resolves with the exports code.
|
|
104
|
+
*/
|
|
105
|
+
export default async function main() {
|
|
106
|
+
const symbols = await getSymbols();
|
|
107
|
+
return generateExports(symbols);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* If running this module directly, read the config file, call the main
|
|
112
|
+
* function, and write the output file.
|
|
113
|
+
*/
|
|
114
|
+
if (esMain(import.meta)) {
|
|
115
|
+
const baseDir = dirname(fileURLToPath(import.meta.url));
|
|
116
|
+
|
|
117
|
+
main()
|
|
118
|
+
.then(async (code) => {
|
|
119
|
+
const filepath = path.join(baseDir, '..', 'build', 'index.js');
|
|
120
|
+
await fse.outputFile(filepath, code);
|
|
121
|
+
})
|
|
122
|
+
.catch((err) => {
|
|
123
|
+
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
|
124
|
+
});
|
|
125
|
+
}
|