|
2 | 2 |
|
3 | 3 | var _ = require("lodash"); |
4 | 4 | var Immutable = require("immutable"); |
5 | | -var qs = require("qs"); |
6 | 5 |
|
7 | 6 | var utils = require("./utils"); |
| 7 | +var pluginUtils = require("./plugins"); |
8 | 8 | var connectUtils = require("./connect-utils"); |
9 | 9 |
|
10 | 10 | module.exports = { |
@@ -113,90 +113,27 @@ module.exports = { |
113 | 113 |
|
114 | 114 | var plugins = bs.options |
115 | 115 | .get("plugins") |
116 | | - .map(function (item) { |
117 | | - if (typeof item === "string") { |
118 | | - return getFromString(item); |
119 | | - } |
120 | | - if (Immutable.Map.isMap(item)) { |
121 | | - |
122 | | - if (item.has("module")) { |
123 | | - |
124 | | - var nameOrObj = item.get("module"); |
125 | | - var opts = item.get("opts"); |
126 | | - if (opts) { |
127 | | - opts = opts.toJS(); |
128 | | - } else { opts = {} } |
129 | | - |
130 | | - if (typeof nameOrObj === "string") { |
131 | | - var plugin = getFromString(nameOrObj); |
132 | | - plugin.opts = opts; |
133 | | - return plugin; |
134 | | - } |
| 116 | + .map(pluginUtils.resolvePlugin) |
| 117 | + .map(pluginUtils.requirePlugin); |
135 | 118 |
|
136 | | - if (Immutable.Map.isMap(nameOrObj)) { |
137 | | - return { |
138 | | - module: nameOrObj.toJS(), |
139 | | - opts: opts |
140 | | - } |
141 | | - } |
142 | | - } |
| 119 | + plugins |
| 120 | + .forEach(function (plugin) { |
| 121 | + if (plugin.errors && plugin.errors.length) { |
| 122 | + return logPluginError(plugin); |
143 | 123 | } |
144 | | - return { |
145 | | - name: item, |
146 | | - opts: {} |
147 | | - } |
148 | | - }) |
149 | | - .map(function (item) { |
150 | | - if (!item.module) { |
151 | | - item.module = require(item.name); |
152 | | - } |
153 | | - return item; |
| 124 | + bs.registerPlugin(plugin.module, plugin.options); |
154 | 125 | }); |
155 | 126 |
|
156 | | - console.log(plugins.toJS()); |
157 | | - |
158 | | - function getFromString(string) { |
159 | | - var split = string.split('?'); |
160 | | - if (split.length > 1) { |
161 | | - return { |
162 | | - name: split[0], |
163 | | - opts: qs.parse(split[1]) |
164 | | - } |
165 | | - } |
166 | | - return { |
167 | | - name: split[0], |
168 | | - opts: {} |
169 | | - }; |
| 127 | + function logPluginError (plugin) { |
| 128 | + bs.events.emit("config:error", { |
| 129 | + msg: [ |
| 130 | + "Plugin: {cyan:'%s'} not found.", plugin.name, |
| 131 | + "\nPlease check for typos :)" |
| 132 | + ] |
| 133 | + }); |
| 134 | + utils.fail(true); |
170 | 135 | } |
171 | 136 |
|
172 | | - //function createOneFromString(string) { |
173 | | - // |
174 | | - //} |
175 | | - //bs.options.get("plugins").forEach(function (item) { |
176 | | - // |
177 | | - // if (_.isString(item)) { |
178 | | - // loadPlugin(item); |
179 | | - // } |
180 | | - // |
181 | | - // if (Immutable.Map.isMap(item)) { |
182 | | - // if (item.has("module")) { |
183 | | - // loadPlugin(item.get("module"), item.get("options")); |
184 | | - // } else { |
185 | | - // loadPlugin(item); |
186 | | - // } |
187 | | - // } |
188 | | - //}); |
189 | | - // |
190 | | - //function loadPlugin (name, opts) { |
191 | | - // opts = opts ? opts.toJS() : {}; |
192 | | - // if (_.isString(name)) { |
193 | | - // opts.moduleName = name; |
194 | | - // bs.registerPlugin(require(name), opts); |
195 | | - // } else { |
196 | | - // bs.registerPlugin(name.toJS(), opts); |
197 | | - // } |
198 | | - //} |
199 | | - |
200 | 137 | done(); |
201 | 138 | }, |
202 | 139 | /** |
|
0 commit comments