UNPKG

3.21 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4exports.__esModule = true;
5exports.babelrcReducer = void 0;
6var _merge2 = _interopRequireDefault(require("lodash/merge"));
7var _findIndex2 = _interopRequireDefault(require("lodash/findIndex"));
8const babelrcReducer = (state = {
9 stages: {
10 develop: {
11 plugins: [],
12 presets: [],
13 options: {
14 cacheDirectory: true,
15 sourceType: `unambiguous`
16 }
17 },
18 "develop-html": {
19 plugins: [],
20 presets: [],
21 options: {
22 cacheDirectory: true,
23 sourceType: `unambiguous`
24 }
25 },
26 "build-html": {
27 plugins: [],
28 presets: [],
29 options: {
30 cacheDirectory: true,
31 sourceType: `unambiguous`
32 }
33 },
34 "build-javascript": {
35 plugins: [],
36 presets: [],
37 options: {
38 cacheDirectory: true,
39 sourceType: `unambiguous`
40 }
41 }
42 }
43}, action) => {
44 switch (action.type) {
45 case `SET_BABEL_PLUGIN`:
46 {
47 Object.keys(state.stages).forEach(stage => {
48 if (action.payload.stage && action.payload.stage !== stage) {
49 return;
50 }
51 const index = (0, _findIndex2.default)(state.stages[stage].plugins, plugin => plugin.name === action.payload.name);
52 // If the plugin already exists, merge the options.
53 // Otherwise, add it to the end.
54 if (index !== -1) {
55 const plugin = state.stages[stage].plugins[index];
56 state.stages[stage].plugins[index] = {
57 name: plugin.name,
58 options: (0, _merge2.default)(plugin.options, action.payload.options)
59 };
60 } else {
61 state.stages[stage].plugins = [...state.stages[stage].plugins, action.payload];
62 }
63 });
64 return state;
65 }
66 case `SET_BABEL_PRESET`:
67 {
68 Object.keys(state.stages).forEach(stage => {
69 if (action.payload.stage && action.payload.stage !== stage) {
70 return;
71 }
72 const index = (0, _findIndex2.default)(state.stages[stage].presets, plugin => plugin.name === action.payload.name);
73 // If the plugin already exists, merge the options.
74 // Otherwise, add it to the end.
75 if (index !== -1) {
76 const plugin = state.stages[stage].presets[index];
77 state.stages[stage].presets[index] = {
78 name: plugin.name,
79 options: (0, _merge2.default)(plugin.options, action.payload.options)
80 };
81 } else {
82 state.stages[stage].presets = [...state.stages[stage].presets, action.payload];
83 }
84 });
85 return state;
86 }
87 case `SET_BABEL_OPTIONS`:
88 {
89 Object.keys(state.stages).forEach(stage => {
90 if (action.payload.stage && action.payload.stage !== stage) {
91 return;
92 }
93 state.stages[stage].options = {
94 ...state.stages[stage].options,
95 ...action.payload.options
96 };
97 });
98 return state;
99 }
100 }
101 return state;
102};
103exports.babelrcReducer = babelrcReducer;
104//# sourceMappingURL=babelrc.js.map
\No newline at end of file