Skip to content

Commit

Permalink
Generate UMD build. Fixes #27.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevage committed Apr 11, 2021
1 parent 9f59d17 commit 385e334
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
42 changes: 42 additions & 0 deletions rollup.config.js
@@ -0,0 +1,42 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
export default [
{
input: 'src/index.js',
output: [
{
file: 'dist/index.js',
format: 'umd', // UMD version for browser, and for Node (for Jest testing)
name: 'U',
},
{
file: 'commonjs/index.js',
format: 'cjs', // CommonJS version for node? Not even sure this is required.
},
{
file: 'dist/index.esm.js',
format: 'esm', // ES2015 modules version so consumers can tree-shake
},
],
plugins: [
commonjs(),
nodeResolve(),
babel({ babelHelpers: 'bundled' }),
],
},
{
input: 'src/index.test.js',
output: [
{
file: 'commonjs/index.test.js',
format: 'cjs',
},
],
plugins: [
commonjs(),
nodeResolve(),
babel({ babelHelpers: 'bundled' }),
],
},
];
17 changes: 3 additions & 14 deletions src/index.js
@@ -1,6 +1,6 @@
const kebabCase = require('kebab-case');
const allProps = require('./keys.json');
const jamSession = require('@mapbox/expression-jamsession');
import kebabCase from 'kebab-case';
// const allProps = require('./keys.json');
import * as allProps from './keys';

function isPaintProp(prop) {
return allProps.paints.indexOf(prop) >= 0;
Expand All @@ -20,15 +20,6 @@ function whichProp(prop) {
return 'other';
}

// this is the deprecated U`foo == blah` jam-session syntax.
// function utils(...args) {
// if (args[0] && Array.isArray(args[0]) && args[0].raw) {
// // We're being used as a tagged template
// return jamSession.formulaToExpression(args[0].raw[0]);
// } else
// throw 'Mapbox-gl-utils unexpectedly called as a function. Use .init(map)';
// }

function parseSource(source) {
if (
String(source).match(/\.(geo)?json/) ||
Expand Down Expand Up @@ -737,6 +728,4 @@ function initClass(U) {
const U = Utils.prototype;
initClass(U);

// Hmm. Using ES2015 export seems to play nicer with Webpack. But then testing within Node doesn't work. Sigh.
// module.exports = Utils;
export default Utils;
1 change: 1 addition & 0 deletions src/keys.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions updateKeys.js
Expand Up @@ -5,10 +5,11 @@ Should be run when new properties are added to that spec.

const styleSpec = require('@mapbox/mapbox-gl-style-spec/reference/v8.json');
const fs = require('fs');
const styleSpecVersion = require('./node_modules/@mapbox/mapbox-gl-style-spec/package.json').version;
const styleSpecVersion = require('./node_modules/@mapbox/mapbox-gl-style-spec/package.json')
.version;
const out = {
paints: [],
layouts: []
layouts: [],
};
Object.keys(styleSpec)
.filter(x => /^paint_/.test(x))
Expand All @@ -17,10 +18,15 @@ Object.keys(styleSpec)
Object.keys(styleSpec)
.filter(x => /^layout_/.test(x))
.forEach(key => out.layouts.push(...Object.keys(styleSpec[key])));

out.paints = Array.from(new Set(out.paints));
out.layouts = Array.from(new Set(out.layouts));
const outFile = 'dist/keys.json';
fs.writeFileSync(outFile, JSON.stringify(out));

console.log(`Wrote updated ${outFile} based on Mapbox-GL style spec ${styleSpecVersion}.`);
const outFileJS = 'src/keys.js';
fs.writeFileSync(outFileJS, 'module.exports = ' + JSON.stringify(out));

console.log(
`Wrote updated ${outFile} based on Mapbox-GL style spec ${styleSpecVersion}.`
);

0 comments on commit 385e334

Please sign in to comment.