diff --git a/.npmignore b/.npmignore index 5da68f50..0e9220e4 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,8 @@ .circleci/ .git/ -example/ +examples/ test/ .editorconfig .eslintrc webpack.*.js +tsconfig.*.json diff --git a/README.md b/README.md index 732cb5eb..96bd3710 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ for rendering. ### stylefunction ```js -import stylefunction from 'ol-mapbox-style/stylefunction'; +import stylefunction from 'ol-mapbox-style/dist/stylefunction'; ``` Creates a style function from the `glStyle` object for all layers that use diff --git a/example/.eslintrc b/examples/.eslintrc similarity index 100% rename from example/.eslintrc rename to examples/.eslintrc diff --git a/example/_template.html b/examples/_template.html similarity index 100% rename from example/_template.html rename to examples/_template.html diff --git a/example/data/geojson-inline.json b/examples/data/geojson-inline.json similarity index 100% rename from example/data/geojson-inline.json rename to examples/data/geojson-inline.json diff --git a/example/data/geojson.json b/examples/data/geojson.json similarity index 100% rename from example/data/geojson.json rename to examples/data/geojson.json diff --git a/example/data/sprites.json b/examples/data/sprites.json similarity index 100% rename from example/data/sprites.json rename to examples/data/sprites.json diff --git a/example/data/sprites.png b/examples/data/sprites.png similarity index 100% rename from example/data/sprites.png rename to examples/data/sprites.png diff --git a/example/data/sprites@2x.json b/examples/data/sprites@2x.json similarity index 100% rename from example/data/sprites@2x.json rename to examples/data/sprites@2x.json diff --git a/example/data/sprites@2x.png b/examples/data/sprites@2x.png similarity index 100% rename from example/data/sprites@2x.png rename to examples/data/sprites@2x.png diff --git a/example/data/states.geojson b/examples/data/states.geojson similarity index 100% rename from example/data/states.geojson rename to examples/data/states.geojson diff --git a/example/data/states.json b/examples/data/states.json similarity index 100% rename from example/data/states.json rename to examples/data/states.json diff --git a/example/data/tilejson.json b/examples/data/tilejson.json similarity index 100% rename from example/data/tilejson.json rename to examples/data/tilejson.json diff --git a/example/data/wms.json b/examples/data/wms.json similarity index 100% rename from example/data/wms.json rename to examples/data/wms.json diff --git a/example/geojson-inline.js b/examples/geojson-inline.js similarity index 100% rename from example/geojson-inline.js rename to examples/geojson-inline.js diff --git a/example/geojson.js b/examples/geojson.js similarity index 100% rename from example/geojson.js rename to examples/geojson.js diff --git a/example/index.html b/examples/index.html similarity index 100% rename from example/index.html rename to examples/index.html diff --git a/example/mapbox.js b/examples/mapbox.js similarity index 100% rename from example/mapbox.js rename to examples/mapbox.js diff --git a/example/openmaptiles.js b/examples/openmaptiles.js similarity index 100% rename from example/openmaptiles.js rename to examples/openmaptiles.js diff --git a/example/stylefunction.js b/examples/stylefunction.js similarity index 100% rename from example/stylefunction.js rename to examples/stylefunction.js diff --git a/example/tilejson-vectortile.js b/examples/tilejson-vectortile.js similarity index 100% rename from example/tilejson-vectortile.js rename to examples/tilejson-vectortile.js diff --git a/example/tilejson.js b/examples/tilejson.js similarity index 100% rename from example/tilejson.js rename to examples/tilejson.js diff --git a/example/wms.js b/examples/wms.js similarity index 100% rename from example/wms.js rename to examples/wms.js diff --git a/package.json b/package.json index a26be43e..f7df2afc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ol-mapbox-style", "version": "5.0.2", "description": "Create OpenLayers maps from Mapbox Style objects", - "main": "index.js", + "main": "dist/index.js", "repository": { "type": "git", "url": "git://github.com/openlayers/ol-mapbox-style.git" @@ -17,10 +17,10 @@ ], "license": "BSD-2-Clause", "scripts": { - "start": "webpack-dev-server --config ./webpack.config.js", + "start": "webpack-dev-server --config ./webpack.config.examples.js", "prepare": "npm run doc && npm run build", - "build": "webpack-cli --mode=production --config ./webpack.config.olms.js && webpack-cli --mode=production", - "doc": "documentation readme -s API index.js stylefunction.js --document-exported true", + "build": "tsc --project tsconfig-build.json && webpack-cli --mode=production --config ./webpack.config.olms.js && webpack-cli --mode=production --config ./webpack.config.examples.js", + "doc": "documentation readme -s API src/index.js src/stylefunction.js --document-exported true", "karma": "karma start test/karma.conf.js", "lint": "eslint test example *.js", "typecheck": "tsc --project tsconfig-typecheck.json", @@ -28,7 +28,7 @@ "test": "npm run karma -- --single-run --log-level error" }, "dependencies": { - "@mapbox/mapbox-gl-style-spec": "^13.9.0", + "@mapbox/mapbox-gl-style-spec": "^13.10.1", "mapbox-to-css-font": "^2.4.0", "webfont-matcher": "^1.1.0" }, @@ -36,18 +36,18 @@ "ol": "^6.1.0" }, "devDependencies": { - "@types/node": "^12.7.12", + "@types/node": "^12.12.19", "babel-loader": "^8.0.6", "buble": "^0.19.8", "buble-loader": "^0.5.1", "copy-webpack-plugin": "^4.6.0", - "css-loader": "^1.0.1", + "css-loader": "^3.4.0", "deep-freeze": "0.0.1", - "documentation": "^11.0.1", + "documentation": "^12.1.4", "eslint": "^5.16.0", "eslint-config-openlayers": "^11.0.0", "html-webpack-plugin": "^3.2.0", - "karma": "^4.3.0", + "karma": "^4.4.1", "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.2", "karma-mocha": "^1.3.0", @@ -56,14 +56,14 @@ "mapbox-gl-styles": "^2.0.2", "mini-css-extract-plugin": "^0.4.5", "mocha": "^5.2.0", - "ol": "^6.0.1", + "ol": "^6.1.1", "puppeteer": "^1.20.0", "should": "^13.2.3", "sinon": "^7.5.0", "style-loader": "^0.23.1", - "typescript": "^3.6.3", - "webpack": "^4.41.0", - "webpack-cli": "^3.3.9", - "webpack-dev-server": "^3.8.2" + "typescript": "3.5.3", + "webpack": "^4.41.3", + "webpack-cli": "^3.3.10", + "webpack-dev-server": "^3.9.0" } } diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js diff --git a/olms.js b/src/olms.js similarity index 100% rename from olms.js rename to src/olms.js diff --git a/stylefunction.js b/src/stylefunction.js similarity index 99% rename from stylefunction.js rename to src/stylefunction.js index 00a77ec8..347c1f99 100644 --- a/stylefunction.js +++ b/src/stylefunction.js @@ -11,8 +11,8 @@ import Icon from 'ol/style/Icon'; import Text from 'ol/style/Text'; import Circle from 'ol/style/Circle'; import RenderFeature from 'ol/render/Feature'; -import derefLayers from '@mapbox/mapbox-gl-style-spec/deref'; import { + derefLayers, expression, Color, function as fn, latest as spec, @@ -168,7 +168,7 @@ function fromTemplate(text, properties) { /** * ```js - * import stylefunction from 'ol-mapbox-style/stylefunction'; + * import stylefunction from 'ol-mapbox-style/dist/stylefunction'; * ``` * Creates a style function from the `glStyle` object for all layers that use * the specified `source`, which needs to be a `"type": "vector"` or diff --git a/util.js b/src/util.js similarity index 100% rename from util.js rename to src/util.js diff --git a/tsconfig-build.json b/tsconfig-build.json new file mode 100644 index 00000000..bd2f9b57 --- /dev/null +++ b/tsconfig-build.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "target": "ES5", + "module": "es2015", + "sourceMap": true, + "allowJs": true, + "importHelpers": false, + }, + "include": [ + "./src/**/*.js" + ], + "exclude": [] +} \ No newline at end of file diff --git a/tsconfig-typecheck.json b/tsconfig-typecheck.json index 39fe431d..17e41852 100644 --- a/tsconfig-typecheck.json +++ b/tsconfig-typecheck.json @@ -14,6 +14,6 @@ ] }, "include": [ - "*.js" + "src/*.js" ] } \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.examples.js similarity index 87% rename from webpack.config.js rename to webpack.config.examples.js index c4fe410b..9c8c3d4f 100644 --- a/webpack.config.js +++ b/webpack.config.examples.js @@ -4,7 +4,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -/** Get the list of examples from the example directory. +/** Get the list of examples from the examples directory. * * @param {String} dirName - Name of the directory to read. * @param {Function} callback - Function to execute for each example. @@ -77,7 +77,7 @@ module.exports = (env, argv) => { context: __dirname, target: 'web', mode: prod ? 'production' : 'development', - entry: getEntries(path.resolve(__dirname, './example')), + entry: getEntries(path.resolve(path.join(__dirname, 'examples'))), optimization: { runtimeChunk: { name: 'common' @@ -90,11 +90,11 @@ module.exports = (env, argv) => { }, output: { filename: '[name].js', - path: path.join(__dirname, 'dist') + path: path.join(__dirname, 'dist', 'examples') }, resolve: { alias: { - 'ol-mapbox-style': path.join(__dirname, '.') + 'ol-mapbox-style': path.join(__dirname, 'src') } }, devtool: 'source-map', @@ -112,7 +112,7 @@ module.exports = (env, argv) => { test: /\.js$/, include: [ __dirname, - /node_modules\/(?!(ol|@mapbox\/mapbox-gl-style-spec)\/)/ + /node_modules\/(?!(@mapbox\/mapbox-gl-style-spec)\/)/ ], use: { loader: 'buble-loader' @@ -129,16 +129,17 @@ module.exports = (env, argv) => { }), // ensure the data is copied over. // currently the index.html is manually created. + // @ts-ignore new CopyWebpackPlugin([ { - from: path.resolve(__dirname, './example/data'), + from: path.resolve(__dirname, './examples/data'), to: 'data' }, { - from: path.resolve(__dirname, './example/index.html'), + from: path.resolve(__dirname, './examples/index.html'), to: 'index.html' } ]) - ].concat(getHtmlTemplates('./example')) + ].concat(getHtmlTemplates('./examples')) }; }; diff --git a/webpack.config.olms.js b/webpack.config.olms.js index 9967281b..7527b64d 100644 --- a/webpack.config.olms.js +++ b/webpack.config.olms.js @@ -1,7 +1,7 @@ const path = require('path'); module.exports = { - entry: './olms.js', + entry: './src/olms.js', devtool: 'source-map', node: {fs: 'empty'}, mode: 'production', @@ -10,8 +10,7 @@ module.exports = { { test: /\.js$/, include: [ - __dirname, - /node_modules\/(?!(ol|@mapbox\/mapbox-gl-style-spec)\/)/ + __dirname ], use: { loader: 'buble-loader'