mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 21:28:11 +02:00
Attempt to remove d3, lodash from bundle, but leave available for tests
This commit is contained in:
@@ -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);
|
||||
|
||||
+10
-8
@@ -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 = {};
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+1
-2
@@ -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 };
|
||||
|
||||
@@ -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",
|
||||
|
||||
+3
-4
@@ -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';
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<title>Mocha Tests</title>
|
||||
<link rel='stylesheet' href='../node_modules/mocha/mocha.css'>
|
||||
<link rel='stylesheet' href='../dist/iD.css'>
|
||||
<script src='../node_modules/d3/build/d3.js'></script>
|
||||
</head>
|
||||
<body style="overflow:scroll">
|
||||
<div id='mocha'></div>
|
||||
|
||||
@@ -4,7 +4,7 @@ iD.debug = true;
|
||||
|
||||
// disable things that use the network
|
||||
iD.data.imagery = [];
|
||||
_.forEach(iD.services, function(v,k) { delete iD.services[k]; });
|
||||
for (var k in iD.services) { delete iD.services[k]; }
|
||||
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
@@ -20,5 +20,3 @@ mocha.setup({
|
||||
});
|
||||
|
||||
expect = chai.expect;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var d3 = iD.d3;
|
||||
Reference in New Issue
Block a user