|
| 1 | +import { Map, List, fromJS } from "immutable"; |
| 2 | +import { addToFilesOption } from "./transforms/addToFilesOption"; |
| 3 | +import { addDefaultIgnorePatterns } from "./transforms/addDefaultIgnorePatterns"; |
| 4 | +import { copyCLIIgnoreToWatchOptions } from "./transforms/copyCLIIgnoreToWatchOptions"; |
| 5 | +import { handleExtensionsOption } from "./transforms/handleExtensionsOption"; |
| 6 | +import { handleFilesOption } from "./transforms/handleFilesOption"; |
| 7 | +import { handleGhostModeOption } from "./transforms/handleGhostModeOption"; |
| 8 | +import { handlePortsOption } from "./transforms/handlePortsOption"; |
| 9 | +import { handleProxyOption } from "./transforms/handleProxyOption"; |
| 10 | +import { handleServerOption } from "./transforms/handleServerOption"; |
| 11 | +import { appendServerIndexOption } from "./transforms/appendServerIndexOption"; |
| 12 | +import { appendServerDirectoryOption } from "./transforms/appendServerDirectoryOption"; |
| 13 | + |
| 14 | +const _ = require("../lodash.custom"); |
| 15 | +const defaultConfig = require("../default-config"); |
| 16 | +const immDefs = fromJS(defaultConfig); |
| 17 | + |
| 18 | +/** |
| 19 | + * @param {Object} input |
| 20 | + * @returns {Map} |
| 21 | + */ |
| 22 | +export function merge(input) { |
| 23 | + const merged = immDefs.mergeDeep(input); |
| 24 | + const transforms = [ |
| 25 | + addToFilesOption, |
| 26 | + addDefaultIgnorePatterns, |
| 27 | + copyCLIIgnoreToWatchOptions, |
| 28 | + handleServerOption, |
| 29 | + appendServerIndexOption, |
| 30 | + appendServerDirectoryOption, |
| 31 | + handleProxyOption, |
| 32 | + handlePortsOption, |
| 33 | + handleGhostModeOption, |
| 34 | + handleFilesOption, |
| 35 | + handleExtensionsOption |
| 36 | + ]; |
| 37 | + |
| 38 | + const output = transforms.reduce((acc, item) => { |
| 39 | + return item.call(null, acc); |
| 40 | + }, merged); |
| 41 | + |
| 42 | + // console.log(output.toJSON()); |
| 43 | + |
| 44 | + return output; |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * @param string |
| 49 | + */ |
| 50 | +export function explodeFilesArg(string): string { |
| 51 | + return string.split(",").map(item => item.trim()); |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * @param value |
| 56 | + * @returns {{globs: Array, objs: Array}} |
| 57 | + */ |
| 58 | +export function makeFilesArg(value) { |
| 59 | + let globs = []; |
| 60 | + let objs = []; |
| 61 | + |
| 62 | + if (_.isString(value)) { |
| 63 | + globs = globs.concat(explodeFilesArg(value)); |
| 64 | + } |
| 65 | + |
| 66 | + if (List.isList(value) && value.size) { |
| 67 | + value.forEach(function(value) { |
| 68 | + if (_.isString(value)) { |
| 69 | + globs.push(value); |
| 70 | + } else { |
| 71 | + if (Map.isMap(value)) { |
| 72 | + objs.push(value); |
| 73 | + } |
| 74 | + } |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + return { |
| 79 | + globs: globs, |
| 80 | + objs: objs |
| 81 | + }; |
| 82 | +} |
0 commit comments