|
| 1 | +import { List, Map } from "immutable"; |
| 2 | + |
1 | 3 | var path = require("path"); |
2 | 4 | var url = require("url"); |
3 | 5 | var _ = require("../lodash.custom"); |
@@ -274,12 +276,106 @@ opts.callbacks = { |
274 | 276 | * @returns {Map} |
275 | 277 | */ |
276 | 278 | opts.merge = function(values, argv) { |
277 | | - return immDefs.mergeDeep(values).withMutations(function(item) { |
278 | | - item.map(function(value, key) { |
279 | | - if (opts.callbacks[key]) { |
280 | | - item.set(key, opts.callbacks[key](value, argv)); |
| 279 | + const merged = immDefs.mergeDeep(values); |
| 280 | + const transforms = [ |
| 281 | + function addToFilesOption(incoming) { |
| 282 | + if (!incoming.get("watch")) { |
| 283 | + return incoming; |
281 | 284 | } |
282 | | - }); |
| 285 | + |
| 286 | + let serverPaths = []; |
| 287 | + |
| 288 | + const fromServeStatic = incoming |
| 289 | + .get("serveStatic", List([])) |
| 290 | + .toArray(); |
| 291 | + const ssPaths = fromServeStatic |
| 292 | + .reduce((acc, ss) => { |
| 293 | + if (typeof ss === "string") { |
| 294 | + return acc.concat(ss); |
| 295 | + } |
| 296 | + if (ss.dir && typeof ss.dir === "string") { |
| 297 | + return acc.concat(ss); |
| 298 | + } |
| 299 | + return acc; |
| 300 | + }, []) |
| 301 | + .map(p => path.resolve(p)); |
| 302 | + |
| 303 | + ssPaths.forEach(p => serverPaths.push(p)); |
| 304 | + |
| 305 | + const server = incoming.get("server"); |
| 306 | + if (server) { |
| 307 | + if (server === true) { |
| 308 | + serverPaths.push("."); |
| 309 | + } |
| 310 | + if (typeof server === "string") { |
| 311 | + serverPaths.push(server); |
| 312 | + } |
| 313 | + if ( |
| 314 | + List.isList(server) && |
| 315 | + server.every(x => typeof x === "string") |
| 316 | + ) { |
| 317 | + server.forEach(s => serverPaths.push(s)); |
| 318 | + } |
| 319 | + if (Map.isMap(server)) { |
| 320 | + const baseDirs = server.get("baseDir", List([])).toArray(); |
| 321 | + baseDirs.forEach(s => serverPaths.push(s)); |
| 322 | + } |
| 323 | + } |
| 324 | + |
| 325 | + const output = incoming.update("files", files => { |
| 326 | + return List([]) |
| 327 | + .concat(files, serverPaths) |
| 328 | + .filter(Boolean); |
| 329 | + }); |
| 330 | + return output; |
| 331 | + }, |
| 332 | + function addDefaultIgnorePatterns(incoming) { |
| 333 | + if (!incoming.get("watch")) { |
| 334 | + return incoming; |
| 335 | + } |
| 336 | + |
| 337 | + return incoming.update("watchOptions", watchOptions => { |
| 338 | + const userIgnored = List([]) |
| 339 | + .concat(watchOptions.get("ignored")) |
| 340 | + .filter(Boolean) |
| 341 | + .toSet(); |
| 342 | + |
| 343 | + const merged = userIgnored.merge([ |
| 344 | + /node_modules/, |
| 345 | + /bower_components/, |
| 346 | + /\.sass-cache/, |
| 347 | + /\.vscode/, |
| 348 | + /\.git/, |
| 349 | + /\.idea/, |
| 350 | + "!node_modules/**/*", |
| 351 | + "!**/node_modules/**" |
| 352 | + ]); |
| 353 | + |
| 354 | + return watchOptions.merge({ |
| 355 | + ignored: merged.toList(), |
| 356 | + cwd: incoming.get("cwd") |
| 357 | + }); |
| 358 | + }); |
| 359 | + }, |
| 360 | + function copyCLIIgnoreToWatchOptions(incoming) { |
| 361 | + if (!incoming.has("ignore")) { |
| 362 | + return incoming; |
| 363 | + } |
| 364 | + return incoming.updateIn(["watchOptions", "ignored"], ignored => { |
| 365 | + return ignored.merge(incoming.get("ignore")); |
| 366 | + }); |
| 367 | + } |
| 368 | + ]; |
| 369 | + |
| 370 | + const transformed = transforms.reduce((acc, item) => { |
| 371 | + return item.call(null, acc); |
| 372 | + }, merged); |
| 373 | + |
| 374 | + return transformed.map(function(value, key) { |
| 375 | + if (opts.callbacks[key]) { |
| 376 | + return opts.callbacks[key](value, argv); |
| 377 | + } |
| 378 | + return value; |
283 | 379 | }); |
284 | 380 | }; |
285 | 381 |
|
|
0 commit comments