Skip to content

Commit

Permalink
add unminified build, use token from env var, update babel (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored Nov 20, 2018
1 parent 75a15d2 commit acad49b
Show file tree
Hide file tree
Showing 7 changed files with 1,698 additions and 712 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"presets": ["es2015"],
"presets": ["@babel/preset-env"],
"env": {
"test": {
"sourceMaps": "inline",
"plugins": [
"__coverage__"
"istanbul"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
dist/mapbox-gl-draw.js
coverage/
.nyc_output/
debug/access_token_generated.js
11 changes: 11 additions & 0 deletions build/generate-access-token-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
'use strict';
const fs = require('fs');
const path = require('path');
const script = fs.readFileSync(path.join(__dirname, '../debug/access_token.js'), 'utf-8')
.replace('process.env.MapboxAccessToken',
JSON.stringify(process.env.MapboxAccessToken))
.replace('process.env.MAPBOX_ACCESS_TOKEN',
JSON.stringify(process.env.MAPBOX_ACCESS_TOKEN));

fs.writeFileSync(path.join(__dirname, '../debug/access_token_generated.js'), script);
20 changes: 20 additions & 0 deletions debug/access_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

mapboxgl.accessToken = getAccessToken();

function getAccessToken() {
var accessToken = (
process.env.MapboxAccessToken ||
process.env.MAPBOX_ACCESS_TOKEN ||
getURLParameter('access_token') ||
localStorage.getItem('accessToken')
);
localStorage.setItem('accessToken', accessToken);
return accessToken;
}

function getURLParameter(name) {
var regexp = new RegExp('[?&]' + name + '=([^&#]*)', 'i');
var output = regexp.exec(window.location.href);
return output && output[1];
}
1 change: 1 addition & 0 deletions debug/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<script src='/mapbox-gl.js'></script>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.css' type='text/css' />
<script src='/debug/access_token_generated.js'></script>
<script src='/mapbox-gl-draw.js'></script>
<script src='/app.js'></script>
<script type='text/javascript'>
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"docs-modes-life-cycle": "documentation readme --readme-file ./docs/MODES.md -s \"Life Cycle Functions\" src/modes/mode_interface.js --shallow",
"test": "NODE_ENV=test npm run lint && npm run tape",
"lint": "eslint --no-eslintrc -c .eslintrc index.js src test",
"tape": "tape -r ./test/mock-browser.js -r babel-register test/*.test.js",
"tape": "tape -r ./test/mock-browser.js -r @babel/register test/*.test.js",
"coverage": "NODE_ENV=test nyc --reporter html npm run tape && opener coverage/index.html",
"build": "NODE_ENV=production browserify index.js --standalone MapboxDraw > dist/mapbox-gl-draw.js",
"prepublish": "NODE_ENV=production browserify index.js --standalone MapboxDraw | uglifyjs -c -m > dist/mapbox-gl-draw.js",
"start": "node server.js"
"build-token": "node build/generate-access-token-script.js",
"build": "NODE_ENV=production browserify index.js --standalone MapboxDraw > dist/mapbox-gl-draw-unminified.js",
"build-min": "NODE_ENV=production browserify index.js --standalone MapboxDraw | uglifyjs -c -m > dist/mapbox-gl-draw.js",
"prepublish": "npm run build && npm run build-min",
"start": "npm run build-token && node server.js"
},
"repository": {
"type": "git",
Expand All @@ -43,13 +45,13 @@
"instrument": false
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"@mapbox/mapbox-gl-draw-static-mode": "^1.0.1",
"@turf/centroid": "^6.0.0",
"babel-core": "^6.9.1",
"babel-eslint": "^8.0.3",
"babel-plugin-__coverage__": "^11.0.0",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.5.2",
"babel-plugin-istanbul": "^5.1.0",
"babelify": "^10.0.0",
"browserify": "^16.1.1",
"browserify-middleware": "^8.1.0",
Expand Down
Loading

0 comments on commit acad49b

Please sign in to comment.