Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .oxfmtrc.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"tabWidth": 4,
"singleQuote": true,
"bracketSpacing": false,
"trailingComma": "none"
}
1 change: 0 additions & 1 deletion bin/gl-style-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ function help() {
console.log('usage:');
console.log(' gl-style-migrate style-v7.json > style-v8.json');
}

2 changes: 1 addition & 1 deletion bin/gl-style-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import rw from 'rw';
import {validateStyle as validate} from '../src/validate_style';

const argv = minimist(process.argv.slice(2), {
boolean: 'json',
boolean: 'json'
});

if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
Expand Down
3 changes: 2 additions & 1 deletion build/bump-version-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const changelogPath = 'CHANGELOG.md';
let changelog = readFileSync(changelogPath, 'utf8');
changelog = changelog.replace('## main', `## ${process.argv[2]}`);
changelog = changelog.replaceAll('- _...Add new stuff here..._\n', '');
changelog = `## main
changelog =
`## main

### ✨ Features and improvements
- _...Add new stuff here..._
Expand Down
146 changes: 76 additions & 70 deletions build/generate-docs.ts

Large diffs are not rendered by default.

66 changes: 38 additions & 28 deletions build/generate-style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ function jsDocComment(property) {
if (!lines.length) {
return undefined;
}
return [
'/**',
...lines.map(line => ` * ${line}`),
' */',
].join('\n');
return ['/**', ...lines.map((line) => ` * ${line}`), ' */'].join('\n');
}

function jsDocBlock(tag, value) {
Expand All @@ -40,9 +36,11 @@ ${formatJSON(value)}

function unionType(values) {
if (Array.isArray(values)) {
return values.map(v => JSON.stringify(v)).join(' | ');
return values.map((v) => JSON.stringify(v)).join(' | ');
} else {
return Object.keys(values).map(v => JSON.stringify(v)).join(' | ');
return Object.keys(values)
.map((v) => JSON.stringify(v))
.join(' | ');
}
}

Expand All @@ -60,7 +58,11 @@ function propertyType(property) {
case 'enum':
return unionType(property.values);
case 'array': {
const elementType = propertyType(typeof property.value === 'string' ? {type: property.value, values: property.values} : property.value);
const elementType = propertyType(
typeof property.value === 'string'
? {type: property.value, values: property.values}
: property.value
);
if (property.length) {
return `[${Array(property.length).fill(elementType).join(', ')}]`;
} else {
Expand Down Expand Up @@ -104,32 +106,37 @@ function objectDeclaration(key, properties) {
function objectType(properties, indent) {
return `{
${Object.keys(properties)
.filter(k => k !== '*')
.flatMap(k => {
.filter((k) => k !== '*')
.flatMap((k) => {
const declarations = [propertyDeclaration(k, properties[k])];
if (properties[k].transition) {
declarations.push(transitionPropertyDeclaration(k));
}
return declarations;
})
.map(declaration => {
.map((declaration) => {
return declaration
.split('\n')
.map(line => ` ${indent}${line}`)
.map((line) => ` ${indent}${line}`)
.join('\n');
})
.join(',\n')}
${indent}}`;
}

function sourceTypeName(key) {
return key.replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`)
return key
.replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`)
.replace(/_dem/, 'DEM')
.replace(/Geojson/, 'GeoJSON');
}

function layerTypeName(key) {
return key.split('-').map(k => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`)).concat('LayerSpecification').join('');
return key
.split('-')
.map((k) => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`))
.concat('LayerSpecification')
.join('');
Comment on lines +135 to +139
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before: harder to read due to line length

}

function layerType(key) {
Expand Down Expand Up @@ -165,9 +172,9 @@ function layerType(key) {

const layerTypes = Object.keys(spec.layer.type.values);

writeFileSync('src/types.g.ts',
writeFileSync(
'src/types.g.ts',
Comment on lines +175 to +176
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before: weird indentation

`// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
/* eslint-disable */

export type ColorSpecification = string;

Expand Down Expand Up @@ -394,21 +401,24 @@ ${objectDeclaration('ProjectionSpecification', spec.projection)}

${objectDeclaration('TerrainSpecification', spec.terrain)}

${spec.source.map(key => {
let str = objectDeclaration(sourceTypeName(key), spec[key]);
if (sourceTypeName(key) === 'GeoJSONSourceSpecification') {
// This is done in order to overcome the type system's inability to express this type:
str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string');
}
return str;
}).join('\n\n')}
${spec.source
.map((key) => {
let str = objectDeclaration(sourceTypeName(key), spec[key]);
if (sourceTypeName(key) === 'GeoJSONSourceSpecification') {
// This is done in order to overcome the type system's inability to express this type:
str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string');
}
return str;
})
.join('\n\n')}

export type SourceSpecification =
${spec.source.map(key => ` | ${sourceTypeName(key)}`).join('\n')}
${spec.source.map((key) => ` | ${sourceTypeName(key)}`).join('\n')}

${layerTypes.map(key => layerType(key)).join('\n\n')}
${layerTypes.map((key) => layerType(key)).join('\n\n')}

export type LayerSpecification =
${layerTypes.map(key => ` | ${layerTypeName(key)}`).join('\n')};
${layerTypes.map((key) => ` | ${layerTypeName(key)}`).join('\n')};

`);
`
);
12 changes: 5 additions & 7 deletions build/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ const regex = /^## (\d+\.\d+\.\d+.*?)\n(.+?)(?=\n^## \d+\.\d+\.\d+.*?\n)/gms;

let releaseNotes = [];
let match;
while (match = regex.exec(changelog)) {

while ((match = regex.exec(changelog))) {
releaseNotes.push({
'version': match[1],
'changelog': match[2].trim(),
version: match[1],
changelog: match[2].trim()
});
}

const latest = releaseNotes[0];
const previous = releaseNotes[1];


// Print the release notes template.

const templatedReleaseNotes = `https://github.com/maplibre/maplibre-gl-style-spec
Expand All @@ -41,5 +40,4 @@ ${latest.changelog}

${semver.prerelease(latest.version) ? 'Pre-release version' : ''}`;


process.stdout.write(templatedReleaseNotes.trimEnd());
process.stdout.write(templatedReleaseNotes.trimEnd());
2 changes: 1 addition & 1 deletion build/rollup_plugin_minify_style_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Plugin} from 'rollup';

function replacer(key: string, value: any) {
return (key === 'doc' || key === 'example' || key === 'sdk-support') ? undefined : value;
return key === 'doc' || key === 'example' || key === 'sdk-support' ? undefined : value;
}

export default function minifyStyleSpec(): Plugin {
Expand Down
2 changes: 1 addition & 1 deletion build/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import jsonStringify from 'json-stringify-pretty-compact';

/**
* Formats a JSON value into a reasonably compact and readable JSON string.
*
*
* @param obj - object to be formatted
* @returns formatted JSON
*/
Expand Down
Loading