Skip to content

Commit

Permalink
Provide modules with reference without docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Mar 24, 2022
1 parent 6f74fc5 commit 1d7d5a4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test/integration/**/test-results.xml
test/integration/dist/**/*.js
test/integration/dist/**/*.json
.eslintcache
src/style-spec/dist/index.cjs
src/style-spec/dist/
_batfish_site
_batfish_tmp
_site
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"build-test-suite": "rollup -c test/integration/rollup.config.test.js",
"build-flow-types": "mkdir -p dist && cp build/mapbox-gl.js.flow dist/mapbox-gl.js.flow && cp build/mapbox-gl.js.flow dist/mapbox-gl-dev.js.flow",
"build-css": "postcss -o dist/mapbox-gl.css src/css/mapbox-gl.css",
"build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/* dist/style-spec",
"build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/index.* dist/style-spec",
"watch-css": "postcss --watch -o dist/mapbox-gl.css src/css/mapbox-gl.css",
"build-token": "node build/generate-access-token-script.js",
"build-benchmarks": "BENCHMARK_VERSION=${BENCHMARK_VERSION:-\"$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --short=7 HEAD)\"} rollup -c bench/versions/rollup_config_benchmarks.js",
Expand Down
4 changes: 4 additions & 0 deletions src/style-spec/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Mapbox GL style specification & utilities

This package is a temporary, source code identical fork of [@mapbox/mapbox-gl-style-spec](https://npmjs.com/package/@mapbox/mapbox-gl-style-spec), maintained by OpenLayers contributors. It provides separate exports for all of its modules, and a style spec without docs and examples to reduce build sizes. When [#11628](https://github.com/mapbox/mapbox-gl-js/pull/11628) is merged, this package will be obsolete.

This directory contains code and reference files that define the Mapbox GL style specification and provides some utilities for working with Mapbox styles.

## npm package
Expand All @@ -9,6 +11,8 @@ package so that they can be installed without the bulk of GL JS.

npm install @mapbox/mapbox-gl-style-spec

In addition to ESM and CJS bundles, the package also provides separate modules. The difference between the bundles and the modules is that the modules use a minified version of the `latest` style refererence, which does not contain any `doc` and `example` fields. See the `exports` section of `package.json` for available modules.

## CLI Tools

If you install this package globally, you will have access to several CLI tools.
Expand Down
2 changes: 2 additions & 0 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,5 @@ function getDefaultValue(spec: StylePropertySpecification): Value {
return spec.default;
}
}

export {isExpressionFilter} from '../feature_filter/index.js';
2 changes: 2 additions & 0 deletions src/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,5 @@ function interpolationFactor(input, base, lowerValue, upperValue) {
return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
}
}

export {default as convertFunction} from './convert.js';
44 changes: 41 additions & 3 deletions src/style-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mapbox/mapbox-gl-style-spec",
"name": "@openlayers/mapbox-gl-style-spec",
"description": "a specification for mapbox gl styles",
"version": "13.24.0-alpha.6",
"version": "13.24.0-alpha.8",
"author": "Mapbox",
"keywords": [
"mapbox",
Expand All @@ -17,15 +17,53 @@
"require": "./dist/index.cjs",
"import": "./dist/index.es.js"
},
"./v8": "./src/reference/v8.json",
"./v8.min": "./dist/reference/v8.json",
"./latest": "./dist/reference/latest.js",
"./format": "./dist/format.js",
"./migrate": "./dist/migrate.js",
"./composite": "./dist/composite.js",
"./derefLayers": "./dist/deref.js",
"./diff": "./dist/diff.js",
"./ValidationError": "./dist/error/validation_error.js",
"./ParsingError": "./dist/error/parsing_error.js",
"./expression": "./dist/expression/index.js",
"./featureFilter": "./dist/feature_filter/index.js",
"./convertFilter": "./dist/feature_filter/convert.js",
"./Color": "./dist/util/color.js",
"./function": "./dist/function/index.js",
"./validate": "./dist/validate_style.js",
"./validateMapboxApiSupported": "./dist/validate_mapbox_api_supported.js",
"./visit": "./dist/visit.js",
"./": {
"import": "./"
}
},
"typesVersions": {
"*": {
"latest": ["dist/reference/latest.js"],
"format": ["dist/format.js"],
"migrate": ["dist/migrate.js"],
"composite": ["dist/composite.js"],
"derefLayers": ["dist/deref.js"],
"diff": ["dist/diff.js"],
"ValidationError": ["dist/error/validation_error.js"],
"ParsingError": ["dist/error/parsing_error.js"],
"expression": ["dist/expression/index.js"],
"featureFilter": ["dist/feature_filter/index.js"],
"convertFilter": ["dist/feature_filter/convert.js"],
"Color": ["dist/util/color.js"],
"function": ["dist/function/index.js"],
"validate": ["dist/validate_style.js"],
"validateMapboxApiSupported": ["dist/validate_mapbox_api_supported.js"],
"visit": ["dist/visit.js"]
}
},
"scripts": {
"pretest": "npm run build",
"test": "node ./test.js",
"copy-flow-typed": "cp -R ../../flow-typed .",
"build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm",
"build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm && node prepare_modules.js",
"prepublishOnly": "npm run copy-flow-typed && npm run build",
"postpublish": "rm -r flow-typed dist/index.cjs"
},
Expand Down
34 changes: 34 additions & 0 deletions src/style-spec/prepare_modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node
import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'fs';
import glob from 'glob';
import unassert from 'rollup-plugin-unassert';
import flow from '@mapbox/flow-remove-types';
import {dirname, join} from 'path';

const removeAssert = unassert({include: [/\.js$/]});

async function main() {
const files = glob.sync('**/*.js', {
ignore: ['+(bin|build|node_modules|dist)/**/*', 'rollup.config.js', 'test.js', 'prepare_modules.js']
});
for (let i = 0, ii = files.length; i < ii; i++) {
const path = files[i];
console.log(path);
let file = readFileSync(path, 'utf8');
file = flow(file, path).toString();
const {code} = await removeAssert.transform(file, path);
const dir = join('dist', dirname(path));
if (!existsSync(dir)) {
mkdirSync(dir);
}
writeFileSync(join('dist', path), code, 'utf8');
}

if (!existsSync(join('dist', 'reference'))) {
mkdirSync('dist/reference');
}
const fullSpecJson = readFileSync('./reference/v8.json', 'utf8');
const minifiedSpec = JSON.parse(fullSpecJson, (key, value) => ['doc', 'example'].includes(key) ? undefined : value);
writeFileSync('./dist/reference/v8.json', JSON.stringify(minifiedSpec), 'utf8');
}
main();

0 comments on commit 1d7d5a4

Please sign in to comment.