-
-
Notifications
You must be signed in to change notification settings - Fork 292
/
gulpfile.js
434 lines (419 loc) · 12.8 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
const fs = require('fs');
var gulp = require("gulp");
var path = require("path");
var maker = require("./node_modules/echarts-mapmaker/src/maker");
const glob = require("glob");
const pug = require("pug");
const template = require("swig");
var rename = require('gulp-rename');
var minify = require("gulp-minify");
LOCATION = "./starbucks/json";
NATURAL_EARTH = [
{
"country": "italy",
"label": "Italy",
"zhong_wen": "意大利"
},
{
"country": "colombia",
"label": "Colombia",
"zhong_wen": "哥伦比亚"
},
{
"country": "tanzania",
"label": "Tanzania",
"zhong_wen": "坦桑尼亚"
},
{
"country": "switzerland",
"label": "Switzerland",
"zhong_wen": "瑞士"
},
{
"country": "nauru",
"label": "Nauru",
"zhong_wen": "瑙鲁"
},
{
"country": "fiji",
"label": "Fiji",
"zhong_wen": "斐济"
}
];
NAMES = {
"Afghanistan": "阿富汗",
"Albania": "阿尔巴尼亚",
"Algeria": "阿尔及利亚",
"Andorra": "安道尔",
"Angola": "安哥拉",
"Anguilla": "安圭拉",
"Antigua and Barbuda": "安提瓜和巴布达",
"Argentina": "阿根廷",
"Armenia": "亚美尼亚",
"Australia": "澳大利亚",
"Austria": "奥地利",
"Azerbaijan": "阿塞拜疆",
"Bahrain": "巴林",
"Bangladesh": "孟加拉国",
"Barbados": "巴巴多斯",
"Belarus": "白俄罗斯",
"Belgium": "比利时",
"Belize": "伯利兹",
"Benin": "贝宁",
"Bermuda": "百慕达群岛",
"Bhutan": "不丹",
"Bolivia": "玻利维亚",
"Bosnia and Herzegovina": "波斯尼亚-黑塞哥维那",
"Botswana": "博茨瓦纳",
"Brazil": "巴西",
"British Indian Ocean Territory": "英属印度洋领地",
"British Virgin Islands": "英属维尔京群岛",
"Brunei": "文莱",
"Bulgaria": "保加利亚",
"Burkina Faso": "布基纳法索",
"Burundi": "蒲隆地",
"Cambodia": "柬埔寨",
"Cameroon": "喀麦隆",
"Canada": "加拿大",
"Cape Verde": "佛得角",
"Cayman Islands": "开曼群岛",
"Central African Republic": "中非共和国",
"Chad": "乍得",
"Chile": "智利",
"Comoros": "科摩罗",
"Congo-Brazzaville": "刚果-布拉柴维尔",
"Congo-Kinshasa": "刚果金",
"Cook Islands": "库克群岛",
"Coral Sea Islands Territory": "珊瑚海群岛领地",
"Costa Rica": "哥斯达黎加",
"Croatia": "克罗地亚",
"Cuba": "古巴",
"Cyprus": "塞浦路斯",
"Czechia": "捷克",
"Denmark": "丹麦",
"Djibouti": "吉布提",
"Dominica": "多米尼克",
"Dominican Republic": "多米尼加共和国",
"East Timor": "东帝汶",
"Ecuador": "厄瓜多尔",
"Egypt": "埃及",
"El Salvador": "萨尔瓦多",
"Equatorial Guinea": "赤道几内亚",
"Eritrea": "厄立特里亚",
"Estonia": "爱沙尼亚",
"Ethiopia": "埃塞俄比亚",
"Falkland Islands": "福克兰群岛",
"Faroe Islands": "法罗群岛",
"Federated States of Micronesia": "密克罗尼西亚联邦",
"Finland": "芬兰",
"France": "法国",
"Gabon": "加蓬",
"Georgia": "格鲁吉亚",
"Germany": "德国",
"Ghana": "加纳",
"Gibraltar": "直布罗陀",
"Greece": "希腊",
"Greenland": "格陵兰",
"Guatemala": "危地马拉",
"Guernsey": "根西",
"Guinea-Bissau": "几内亚比索",
"Guinea": "几内亚",
"Guyana": "圭亚那",
"Haiti": "海地",
"Honduras": "洪都拉斯",
"Hungary": "匈牙利",
"Iceland": "冰岛",
"India": "印度",
"Indonesia": "印度尼西亚, 印尼",
"Iraq": "伊拉克",
"Ireland": "爱尔兰",
"Islamic Republic of Iran": "伊朗",
"Isle of Man": "马恩岛",
"Israel": "以色列",
"Jamaica": "牙买加",
"Japan": "日本",
"Jersey": "泽西",
"Jordan": "约旦",
"Kazakhstan": "哈萨克斯坦",
"Kenya": "肯尼亚",
"Kiribati": "基里巴斯",
"Kuwait": "科威特",
"Kyrgyzstan": "吉尔吉斯斯坦",
"Laos": "老挝",
"Latvia": "拉脱维亚",
"Lebanon": "黎巴嫩",
"Lesotho": "莱索托",
"Liberia": "利比里亚",
"Libya": "利比亚",
"Liechtenstein": "列支敦士登",
"Lithuania": "立陶宛",
"Luxemburg": "卢森堡",
"Macedonia": "马其顿",
"Madagascar": "马达加斯加",
"Malawi": "马拉维",
"Malaysia": "马来西亚",
"Maldives": "马尔代夫",
"Mali": "马里",
"Malta": "马耳他",
"Marshall Islands": "马绍尔群岛",
"Mauritania": "毛里塔尼亚",
"Mauritius": "毛里求斯",
"Mexico": "墨西哥",
"Moldova": "摩尔多瓦",
"Monaco": "摩纳哥",
"Mongolia": "蒙古",
"Montenegro": "黑山",
"Montserrat": "蒙特塞拉特",
"Morocco": "摩洛哥",
"Mozambique": "莫桑比克",
"Myanmar": "缅甸",
"Namibia": "纳米比亚",
"Nepal": "尼泊尔",
"New Zealand": "新西兰",
"Nicaragua": "尼加拉瓜",
"Niger": "尼日尔",
"Nigeria": "尼日利亚",
"Niue": "纽埃",
"North Korea": "朝鲜",
"Norway": "挪威",
"Oman": "阿曼",
"Pakistan": "巴基斯坦",
"Palau": "帕劳",
"Palestine": "巴勒斯坦",
"Panama": "巴拿马",
"Papua New Guinea": "巴布亚新几内亚",
"Paraguay": "巴拉圭",
"Peru": "秘鲁",
"Philippines": "菲律宾",
"Pitcairn Islands": "皮特凱恩群島",
"Poland": "波兰",
"Portugal": "葡萄牙",
"Qatar": "卡塔尔",
"Republic of Kosovo": "科索沃",
"Romania": "罗马尼亚",
"Russia": "俄罗斯",
"Rwanda": "卢旺达",
"Sahrawi Arab Democratic Republic": "撒拉威阿拉伯民主共和国",
"Saint Helena Ascension and Tristan da Cunha": "圣赫勒拿-阿森松和特里斯坦-达库尼亚",
"Saint Kitts and Nevis": "圣基茨和尼维斯",
"Saint Lucia": "圣卢西亚",
"Saint Vincent and the Grenadines": "圣文森特和格林纳丁斯",
"Samoa": "萨摩亚",
"San Marino": "圣马力诺",
"Saudi Arabia": "沙特阿拉伯",
"Senegal": "塞内加尔",
"Serbia": "塞尔维亚",
"Seychelles": "塞舌尔",
"Sierra Leone": "塞拉利昂",
"Singapore": "新加坡",
"Slovakia": "斯洛伐克",
"Slovenia": "斯洛文尼亚",
"Solomon Islands": "所罗门群岛",
"Somalia": "索马里",
"South Africa": "南非",
"South Georgia and the South Sandwich Islands": "南乔治亚和南桑威奇群岛",
"South Korea": "韩国",
"South Sudan": "南苏丹",
"Spain": "西班牙",
"Sri Lanka": "斯里兰卡",
"Sudan": "苏丹",
"Suriname": "苏里南",
"Swaziland": "史瓦济兰",
"Sweden": "瑞典",
"Syria": "叙利亚",
"Tajikistan": "塔吉克斯坦",
"Thailand": "泰国",
"The Bahamas": "巴哈马",
"The Gambia": "冈比亚",
"The Netherlands": "荷兰",
"Togo": "多哥",
"Tokelau": "托克劳",
"Tonga": "汤加",
"Trinidad and Tobago": "特立尼达和多巴哥",
"Tunisia": "突尼斯",
"Turkey": "土耳其",
"Turkmenistan": "土库曼",
"Turks and Caicos Islands": "特克斯和凯科斯群岛",
"Tuvalu": "吐瓦鲁",
"Uganda": "乌干达",
"Ukraine": "乌克兰",
"United Arab Emirates": "阿拉伯联合酋长国",
"United Kingdom": "英国",
"Uruguay": "乌拉圭",
"USA": "美国",
"Uzbekistan": "乌兹别克斯坦",
"Vanuatu": "瓦努阿图",
"Vatican City": "梵蒂冈",
"Venezuela": "委内瑞拉",
"Vietnam": "越南",
"Yemen": "也门",
"Zambia": "赞比亚",
"Zimbabwe": "津巴布韦"
}
gulp.task("default", ["readme", "world", "config", "template","naturalEarth"], function() {
glob(LOCATION + '/*.json', function(err, files){
if(err) throw err;
files.forEach( (filePath) => {
var fileName = path.basename(filePath);
var countryFile = fileName.substring(0, fileName.length-5)
var countryName = countryFile.replace(/_/g, ' ');
if(countryName in NAMES){
var countryChineseName = NAMES[countryName];
if(!countryChineseName){
console.log("Ignored " + countryName);
}else{
maker.makeJs(filePath, path.join('echarts-countries-js', countryFile + ".js"), countryChineseName);
}
}
});
});
});
gulp.task('readme', function(){
var tmpl = template.compileFile(path.join('templates', 'README.mdt'));
var countries = JSON.parse(JSON.stringify(NAMES));
NATURAL_EARTH.forEach( (item) => {
countries[item['label']] = item['zhong_wen']
});
var options = {num_cities: Object.keys(countries).length, countries: countries};
fs.writeFile("README.md", tmpl(options), function(err){
if(err) throw err;
});
});
gulp.task('config', function(){
var pinyin_map = {}
var file_map = {};
Object.keys(NAMES).forEach(function(key){
var myKey = NAMES[key];
var myValue = key.replace(/ /g, '_');
pinyin_map[myKey] = myValue;
});
Object.keys(pinyin_map).forEach(function(key){
var myKey = pinyin_map[key];
file_map[myKey] = myKey;
});
file_map['china'] = 'china';
file_map['world'] = 'world';
file_map['eckert3-world'] = 'eckert3-world';
file_map['china-cities'] = 'china-cities';
NATURAL_EARTH.forEach( (item) => {
pinyin_map[item['zhong_wen']] = item['label']
});
var config = {
PINYIN_MAP: pinyin_map,
FILE_MAP: file_map,
JUPYTER_URL: '/nbextensions/echarts-countries-js',
JUPYTER_ENTRY: 'echarts-countries-js/index',
GITHUB_URL: 'https://echarts-maps.github.io/echarts-countries-js',
JS_FOLDER: 'echarts-countries-js'
}
fs.writeFile("registry.json", JSON.stringify(config, null, 4), function(err){
if (err) throw err;
});
});
gulp.task('template', function(){
// for each file
glob(LOCATION + '/*.json', function(err, files){
if(err) throw err;
var countryFiles = [];
var countryNames = [];
files.forEach( (filePath) => {
// find its name
var fileName = path.basename(filePath);
var countryFile = fileName.substring(0, fileName.length-5)
var countryName = countryFile.replace(/_/g, ' ');
var countryChineseName = NAMES[countryName];
if(countryName in NAMES){
countryFiles.push('echarts-countries-js/' + countryFile + '.js');
countryNames.push(NAMES[countryName]);
}else{
console.log("Ignored " + countryName);
}
});
countryFiles.push('echarts-countries-js/china.js');
countryFiles.push('echarts-countries-js/world.js');
countryNames.push('china');
countryNames.push('world');
NATURAL_EARTH.forEach( (item) => {
countryFiles.push('echarts-countries-js/' + item['label'] + '.js');
countryNames.push(item['zhong_wen']);
});
countryFiles.push('echarts-countries-js/eckert3-world.js');
countryNames.push('eckert3-world');
countryFiles.push('echarts-countries-js/china-cities.js');
countryNames.push('china-cities');
var index = pug.compileFile(path.join("templates", "index.pug"));
var options = {num_countries: countryFiles.length,
countryFiles: countryFiles,
countries: countryNames};
fs.writeFile('preview.html', index(options), function(err){
if(err) throw err;
});
});
});
gulp.task('naturalEarth', function(){
NATURAL_EARTH.forEach( (item) => {
maker.makeJs('geojson/shape-with-internal-borders/'+item['country']+ '.geojson', item['label'] + '.js', item['zhong_wen']);
gulp.src(item['label'] + '.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
})
/*
gulp.task('switzerland', function() {
maker.makeJs('geojson/shape-with-internal-borders/switzerland.geojson', 'Switzerland.js', '瑞士');
gulp.src('Switzerland.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
gulp.task('tanzania', function() {
maker.makeJs('geojson/shape-with-internal-borders/tanzania.geojson', 'Tanzania.js', '坦桑尼亚');
gulp.src('Tanzania.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
gulp.task('colombia', function() {
maker.makeJs('geojson/shape-with-internal-borders/colombia.geojson', 'Colombia.js', '哥伦比亚');
gulp.src('Colombia.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
*/
gulp.task('world', function(){
gulp.src(['./node_modules/echarts/map/js/world.js', './node_modules/echarts/map/js/china.js'])
.pipe(rename({dirname: ''}))
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
gulp.task('custom-world', function(){
maker.makeJs('geojson/shape-with-internal-borders/eckert3-world.geojson', 'eckert3-world.js', 'eckert3-world');
gulp.src('eckert3-world.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});
gulp.task('china-cities', function() {
maker.makeJs('./node_modules/echarts/map/json/china-cities.json', 'china-cities.js', 'china-cities');
gulp.src('china-cities.js', {base: '.'})
.pipe(minify({
noSource: true,
ext: { min: ".js"}
}))
.pipe(gulp.dest('echarts-countries-js'));
});