diff --git a/build.js b/build.js index b4b6a1d74..b51849ec8 100644 --- a/build.js +++ b/build.js @@ -1,6 +1,12 @@ /* eslint-disable no-console */ -const _ = require('lodash'); +const _cloneDeep = require('lodash/cloneDeep'); +const _extend = require('lodash/extend'); +const _forEach = require('lodash/forEach'); +const _isEmpty = require('lodash/isEmpty'); +const _merge = require('lodash/merge'); +const _toPairs = require('lodash/toPairs'); + const fs = require('fs'); const glob = require('glob'); const jsonschema = require('jsonschema'); @@ -67,7 +73,7 @@ fs.writeFileSync('data/taginfo.json', JSON.stringify(taginfo, null, 4)); // Push changes from data/core.yaml into en.json var core = YAML.load(fs.readFileSync('data/core.yaml', 'utf8')); var imagery = YAML.load(fs.readFileSync('node_modules/editor-layer-index/i18n/en.yaml', 'utf8')); -var en = _.merge(core, { en: { presets: tstrings }}, imagery); +var en = _merge(core, { en: { presets: tstrings }}, imagery); fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4)); process.exit(); @@ -147,7 +153,7 @@ function suggestionsToPresets(presets) { delete existing[name]; } if (!existing[name]) { - tags = _.extend({name: name.replace(/"/g, '')}, suggestions[key][value][name].tags); + tags = _extend({name: name.replace(/"/g, '')}, suggestions[key][value][name].tags); addSuggestion(item, tags, name.replace(/"/g, ''), count); } } @@ -164,7 +170,7 @@ function suggestionsToPresets(presets) { } presets[category.replace(/"/g, '')] = { - tags: parent.tags ? _.merge(tags, parent.tags) : tags, + tags: parent.tags ? _merge(tags, parent.tags) : tags, name: name, icon: parent.icon, geometry: parent.geometry, @@ -201,20 +207,20 @@ function generatePresets() { presets[id] = preset; }); - presets = _.merge(presets, suggestionsToPresets(presets)); + presets = _merge(presets, suggestionsToPresets(presets)); return presets; } function generateTranslations(fields, presets) { - var translations = _.cloneDeep(tstrings); + var translations = _cloneDeep(tstrings); - _.forEach(translations.fields, function(field, id) { + _forEach(translations.fields, function(field, id) { var f = fields[id]; if (f.keys) { - field['label#'] = _.each(f.keys).map(function(key) { return key + '=*'; }).join(', '); - if (!_.isEmpty(field.options)) { - _.each(field.options, function(v,k) { + field['label#'] = _forEach(f.keys).map(function(key) { return key + '=*'; }).join(', '); + if (!_isEmpty(field.options)) { + _forEach(field.options, function(v,k) { if (id === 'access') { field.options[k]['title#'] = field.options[k]['description#'] = 'access=' + k; } else { @@ -224,8 +230,8 @@ function generateTranslations(fields, presets) { } } else if (f.key) { field['label#'] = f.key + '=*'; - if (!_.isEmpty(field.options)) { - _.each(field.options, function(v,k) { + if (!_isEmpty(field.options)) { + _forEach(field.options, function(v,k) { field.options[k + '#'] = f.key + '=' + k; }); } @@ -236,10 +242,10 @@ function generateTranslations(fields, presets) { } }); - _.forEach(translations.presets, function(preset, id) { + _forEach(translations.presets, function(preset, id) { var p = presets[id]; - if (!_.isEmpty(p.tags)) - preset['name#'] = _.toPairs(p.tags).map(function(pair) { return pair[0] + '=' + pair[1]; }).join(', '); + if (!_isEmpty(p.tags)) + preset['name#'] = _toPairs(p.tags).map(function(pair) { return pair[0] + '=' + pair[1]; }).join(', '); if (p.searchable !== false) { if (p.terms && p.terms.length) preset['terms#'] = 'terms: ' + p.terms.join(); @@ -269,7 +275,7 @@ function generateTaginfo(presets) { 'tags': [] }; - _.forEach(presets, function(preset) { + _forEach(presets, function(preset) { if (preset.suggestion) return; @@ -291,7 +297,7 @@ function generateTaginfo(presets) { } function validateCategoryPresets(categories, presets) { - _.forEach(categories, function(category) { + _forEach(categories, function(category) { if (category.members) { category.members.forEach(function(preset) { if (presets[preset] === undefined) { @@ -304,7 +310,7 @@ function validateCategoryPresets(categories, presets) { } function validatePresetFields(presets, fields) { - _.forEach(presets, function(preset) { + _forEach(presets, function(preset) { if (preset.fields) { preset.fields.forEach(function(field) { if (fields[field] === undefined) { @@ -317,7 +323,7 @@ function validatePresetFields(presets, fields) { } function validateDefaults (defaults, categories, presets) { - _.forEach(defaults.defaults, function (members, name) { + _forEach(defaults.defaults, function (members, name) { members.forEach(function (id) { if (!presets[id] && !categories[id]) { console.error('Unknown category or preset: ' + id + ' in default ' + name); diff --git a/data/update_locales.js b/data/update_locales.js index 786a657c1..89dbea5eb 100644 --- a/data/update_locales.js +++ b/data/update_locales.js @@ -1,10 +1,12 @@ /* Downloads the latest translations from Transifex */ -var request = require('request').defaults({ maxSockets: 1 }), - yaml = require('js-yaml'), - fs = require('fs'), - stringify = require('json-stable-stringify'), - _ = require('lodash'); +const _isEmpty = require('lodash/isEmpty'); +const _merge = require('lodash/merge'); + +var request = require('request').defaults({ maxSockets: 1 }); +var yaml = require('js-yaml'); +var fs = require('fs'); +var stringify = require('json-stable-stringify'); var resources = ['core', 'presets', 'imagery']; var outdir = './dist/locales/'; @@ -32,16 +34,16 @@ var sourceCore = yaml.load(fs.readFileSync('./data/core.yaml', 'utf8')), asyncMap(resources, getResource, function(err, locales) { if (err) return console.log(err); - var locale = _.merge(sourceCore, sourcePresets, sourceImagery), + var locale = _merge(sourceCore, sourcePresets, sourceImagery), dataLocales = {}; locales.forEach(function(l) { - locale = _.merge(locale, l); + locale = _merge(locale, l); }); asyncMap(Object.keys(locale), function(code, done) { - if (code === 'en' || _.isEmpty(locale[code])) { + if (code === 'en' || _isEmpty(locale[code])) { done(); } else { var obj = {}; diff --git a/index.html b/index.html index 42cce0eee..a874759e6 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,7 @@ id.features().disable('boundaries'); id.ui()(document.getElementById('id-container'), function() { - iD.d3.select('#about-list') + id.container().select('#about-list') .insert('li', '.user-list') .attr('class', 'source-switch') .call(iD.uiSourceSwitch(id) diff --git a/modules/index.js b/modules/index.js index ca73fb142..95a71a973 100644 --- a/modules/index.js +++ b/modules/index.js @@ -41,7 +41,6 @@ export { uiPresetEditor as uiPreset } from './ui/preset_editor'; export var debug = false; -import * as d3 from 'd3'; import * as lib from './lib/index'; -export { d3, lib }; +export { lib }; diff --git a/package.json b/package.json index 1af15ad5d..e7fa75d28 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "js-yaml": "^3.9.0", "jsonschema": "^1.1.0", "json-stable-stringify": "^1.0.1", + "lodash": "^4.17.0", "@mapbox/maki": "^4.0.0", "mapillary-js": "2.8.0", "minimist": "^1.2.0", diff --git a/svg/spriteify.js b/svg/spriteify.js index 9220fb323..73456b22e 100755 --- a/svg/spriteify.js +++ b/svg/spriteify.js @@ -1,15 +1,14 @@ #!/usr/bin/env node - 'use strict'; +var _merge = require('lodash/merge'); + var argv = require('minimist')(process.argv.slice(2)); if (argv.help || argv.h || !argv.svg) { return help(); } - var fs = require('fs'); var json = (argv.json ? JSON.parse(fs.readFileSync(argv.json)) : {}); -var _ = require('lodash'); var xml2js = require('xml2js'); xmlToJs(argv.svg, function (err, obj) { @@ -66,7 +65,7 @@ function transform(source) { var id = source['#attr'].id, replace = (id && json[id] !== undefined) ? json[id] : {}; - target['#attr'] = _.merge(source['#attr'], replace); + target['#attr'] = _merge(source['#attr'], replace); if (replace.viewBox !== undefined) { target['#name'] = 'symbol'; } diff --git a/test/index.html b/test/index.html index cf2737c66..4d6a2b13e 100644 --- a/test/index.html +++ b/test/index.html @@ -5,6 +5,7 @@