forked from jbdemonte/gmap3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulp-options.js
195 lines (182 loc) · 5.22 KB
/
gulp-options.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
var features = ["autofit", "bicyclinglayer", "circle", "clear", "cluster", "defaults", "destroy", "directionsrenderer",
"exec", "get", "getaddress", "getdistance", "getelevation", "getgeoloc", "getlatlng", "getmaxzoom", "getroute",
"groundoverlay", "imagemaptype", "infowindow", "kmllayer", "marker", "overlay", "panel", "polygon", "polyline", "rectangle",
"streetviewpanorama", "styledmaptype", "trafficlayer", "trigger"],
dependencies = {
cluster: ["overlay", "marker"],
polyline: ["poly"],
polygon: ["poly"]
},
examples = {
autocomplete: ["getaddress", "clear", "marker"],
"cluster calculator": ["clear", "marker", "cluster"],
clusters: ["clear", "marker", "cluster", "get", "overlay"],
"context-menu": ["clear", "marker", "getroute", "get", "directionsrenderer"],
ebrosur: ["marker", "cluster", "get"]
},
demos = {
address: ["marker", "getaddress", "infowindow"],
autofit: ["circle", "autofit"],
circle: ["circle"],
clear: ["circle", "marker", "cluster", "circle", "rectangle", "polyline", "polygon"],
"cluster - add real marker": ["marker", "cluster", "get"],
"cluster - filter": ["marker", "cluster", "get"],
"cluster - remove a marker": ["marker", "cluster", "clear"],
cluster: ["marker", "cluster"],
control: [],
"control-advanced": ["exec", "marker", "circle", "rectangle"],
debug: ["defaults"],
distance: ["getdistance"],
elevation: ["getelevation", "marker", "infowindow"],
"elevation-path": ["getelevation", "marker", "getelevation"],
"Fusion Tables": ["bikeLayer", "trafficlayer"],
geoloc: ["getgeoloc", "marker"],
groundoverlay: ["groundoverlay"],
ids: ["marker", "get"],
imagemaptype: ["imagemaptype", "get"],
infowindow: ["infowindow"],
"kml - tag": ["kmllayer", "get"],
kml: ["kmllayer", "get"],
latlng: ["getlatlng", "marker"],
"map-options": [],
marker: ["marker"],
markers: ["marker"],
markerWithLabel: ["marker"],
maxzoom: ["getmaxzoom"],
overlay: ["marker", "overlay", "get"],
panel: ["panel"],
polygon: ["polygon", "infowindow"],
polyline: ["polyline"],
rectangle: ["rectangle"],
rightclick: ["marker"],
selector: ["marker"],
streetviewpanorama: ["marker", "infowindow"],
tags: ["get", "marker", "clear"],
trigger: ["trigger"]
};
var argv = require("yargs").argv,
fs = require("fs"),
path = require("path"),
revert = !!argv.only;
/**
* Return CLI value or default value
* @param name {string}
* @returns {boolean}
*/
function testOption(name, def) {
return name in argv ? Boolean(argv[name]) : def;
}
/**
* Return options list depending on CLI arguments
* @return {object} optionName => boolean
*/
function getOptions() {
var result = [];
features.forEach(function (name) {
if (!result[name]) { // may already be done by dependencies
result[name] = testOption(name, !revert);
if (result[name]) {
getDependecies(name).forEach(function (dependency) {
result[dependency] = true;
});
}
}
});
return result;
}
/**
* List recursively a path and return all files
* @param dir {string}
* @returns {Array}
*/
function walk(dir) {
var stat,
results = [],
list = fs.readdirSync(dir);
list.forEach(function (file) {
file = dir + "/" + file;
stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(walk(file));
} else {
results.push(file);
}
});
return results;
}
/**
* return file dependencies based on global dependencies
* @param current {string}
* @returns {Array}
*/
function getDependecies(current) {
var result = [];
if (dependencies[current]) {
dependencies[current].forEach(function (name) {
result.push(name);
if (dependencies[name]) { // dependency has dependencies
result = result.concat(result, getDependecies(name));
}
});
}
return result;
}
exports.options = getOptions;
/**
* return partials
* @return {object} partialName => partialFilePath
*/
exports.partials = function () {
var basename,
result = {},
files = walk("src/tools");
files.forEach(function (p) {
if (p !== "." && p !== "..") {
basename = path.basename(p).replace(/\..*/, "");
result[basename] = p;
}
});
return result;
};
/**
* return demo files depending on CLI arguments
* @return {Array}
*/
exports.assets = function () {
var filename, required,
result = [],
options = getOptions();
/**
* Return True if all options required are satisfied
* @param required {Array}
* @returns {boolean}
*/
function valid(required) {
var result = true;
required.forEach(function (option) {
result = result && options[option];
return result;
});
return result;
}
// add demo
for (filename in demos) {
if (valid(demos[filename])) {
result.push("assets/demo/" + filename + ".html");
}
}
// specifics demo assets
if (options.cluster) {
result.push("assets/demo/images/*");
}
if (options.marker) {
result.push("assets/demo/external/*");
}
// add examples
for (filename in examples) {
if (valid(examples[filename])) {
result.push("assets/examples/" + filename + "/**/*");
}
}
return result;
};