Skip to content

Commit bdd4aa5

Browse files
authored
Merge pull request #897 from opencomponents/callbacks
[DX-515] Async waterfall was calling the wrong callback
2 parents 9c354dd + 5189606 commit bdd4aa5

File tree

1 file changed

+43
-46
lines changed

1 file changed

+43
-46
lines changed

src/cli/facade/dev.js

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const watch = require('../domain/watch');
1616
const wrapCliCallback = require('../wrap-cli-callback');
1717

1818
module.exports = function(dependencies) {
19-
const local = dependencies.local,
20-
logger = dependencies.logger;
19+
const { local, logger } = dependencies;
20+
const cliMessages = strings.messages.cli;
21+
const cliErrors = strings.errors.cli;
2122

2223
return function(opts, callback) {
2324
const componentsDir = opts.dirPath,
2425
port = opts.port || 3000,
2526
baseUrl = opts.baseUrl || `http://localhost:${port}/`,
26-
errors = strings.errors.cli,
2727
fallbackRegistryUrl = opts.fallbackRegistryUrl,
2828
hotReloading = _.isUndefined(opts.hotReloading)
2929
? true
@@ -38,11 +38,9 @@ module.exports = function(dependencies) {
3838
if (err) {
3939
logger.err(format(strings.errors.generic, err));
4040
} else {
41-
logger.warn(
42-
format(strings.messages.cli.CHANGES_DETECTED, changedFile)
43-
);
41+
logger.warn(format(cliMessages.CHANGES_DETECTED, changedFile));
4442
if (!hotReloading) {
45-
logger.warn(strings.messages.cli.HOT_RELOADING_DISABLED);
43+
logger.warn(cliMessages.HOT_RELOADING_DISABLED);
4644
} else if (!componentDir) {
4745
cb(components, refreshLiveReload);
4846
} else {
@@ -59,7 +57,7 @@ module.exports = function(dependencies) {
5957

6058
if (!packaging) {
6159
packaging = true;
62-
logger.warn(strings.messages.cli.PACKAGING_COMPONENTS, true);
60+
logger.warn(cliMessages.PACKAGING_COMPONENTS, true);
6361

6462
async.eachSeries(
6563
componentsDirs,
@@ -68,13 +66,11 @@ module.exports = function(dependencies) {
6866
componentPath: dir,
6967
minify: false,
7068
verbose: opts.verbose,
71-
production: opts['production']
69+
production: opts.production
7270
};
7371

7472
local.package(packageOptions, err => {
75-
if (!err) {
76-
i++;
77-
}
73+
if (!err) i++;
7874
cb(err);
7975
});
8076
},
@@ -86,12 +82,12 @@ module.exports = function(dependencies) {
8682
: error;
8783
logger.err(
8884
format(
89-
strings.errors.cli.PACKAGING_FAIL,
85+
cliErrors.PACKAGING_FAIL,
9086
componentsDirs[i],
9187
errorDescription
9288
)
9389
);
94-
logger.warn(strings.messages.cli.RETRYING_10_SECONDS);
90+
logger.warn(cliMessages.RETRYING_10_SECONDS);
9591
setTimeout(() => {
9692
packaging = false;
9793
packageComponents(componentsDirs);
@@ -114,7 +110,7 @@ module.exports = function(dependencies) {
114110
if (data.errorCode === 'PLUGIN_MISSING_FROM_REGISTRY') {
115111
logger.err(
116112
format(
117-
strings.errors.cli.PLUGIN_MISSING_FROM_REGISTRY,
113+
cliErrors.PLUGIN_MISSING_FROM_REGISTRY,
118114
data.errorDetails,
119115
colors.blue(strings.commands.cli.MOCK_PLUGIN)
120116
)
@@ -123,47 +119,50 @@ module.exports = function(dependencies) {
123119
});
124120
};
125121

126-
logger.warn(strings.messages.cli.SCANNING_COMPONENTS, true);
122+
logger.warn(cliMessages.SCANNING_COMPONENTS, true);
127123
local.getComponentsByDir(componentsDir, (err, components) => {
128124
if (_.isEmpty(components)) {
129-
err = format(errors.DEV_FAIL, errors.COMPONENTS_NOT_FOUND);
125+
err = format(cliErrors.DEV_FAIL, cliErrors.COMPONENTS_NOT_FOUND);
130126
callback(err);
131127
return logger.err(err);
132128
}
133129

134130
logger.ok('OK');
135-
_.forEach(components, component => {
136-
logger.log(colors.green('├── ') + component);
137-
});
131+
_.forEach(components, component =>
132+
logger.log(colors.green('├── ') + component)
133+
);
138134

139135
handleDependencies({ components, logger }, (err, dependencies) => {
140136
if (err) {
141137
logger.err(err);
142138
return callback(err);
143139
}
144140
packageComponents(components, () => {
145-
async.waterfall([
146-
callback => {
147-
if (hotReloading) {
148-
getPort(port + 1, (error, otherPort) => {
149-
if (error) {
150-
return callback(error);
151-
}
152-
const liveReloadServer = livereload.createServer({
153-
port: otherPort
154-
});
155-
const refresher = () => liveReloadServer.refresh('/');
156-
157-
callback(null, {
158-
refresher,
159-
port: otherPort
141+
async.waterfall(
142+
[
143+
next => {
144+
if (hotReloading) {
145+
getPort(port + 1, (error, otherPort) => {
146+
if (error) {
147+
return next(error);
148+
}
149+
const liveReloadServer = livereload.createServer({
150+
port: otherPort
151+
});
152+
const refresher = () => liveReloadServer.refresh('/');
153+
next(null, { refresher, port: otherPort });
160154
});
161-
});
162-
} else {
163-
callback(null, { refresher: _.noop, port: null });
155+
} else {
156+
next(null, { refresher: _.noop, port: null });
157+
}
158+
}
159+
],
160+
(err, liveReload) => {
161+
if (err) {
162+
logger.err(err);
163+
return callback(err);
164164
}
165-
},
166-
(liveReload, callback) => {
165+
167166
const registry = new oc.Registry({
168167
baseUrl,
169168
prefix: opts.prefix || '',
@@ -182,21 +181,19 @@ module.exports = function(dependencies) {
182181

183182
registerPlugins(registry);
184183

185-
logger.warn(
186-
format(strings.messages.cli.REGISTRY_STARTING, baseUrl)
187-
);
184+
logger.warn(format(cliMessages.REGISTRY_STARTING, baseUrl));
188185
if (liveReload.port) {
189186
logger.warn(
190187
format(
191-
strings.messages.cli.REGISTRY_LIVERELOAD_STARTING,
188+
cliMessages.REGISTRY_LIVERELOAD_STARTING,
192189
liveReload.port
193190
)
194191
);
195192
}
196193
registry.start(err => {
197194
if (err) {
198195
if (err.code === 'EADDRINUSE') {
199-
err = format(strings.errors.cli.PORT_IS_BUSY, port);
196+
err = format(cliErrors.PORT_IS_BUSY, port);
200197
}
201198

202199
logger.err(err);
@@ -212,7 +209,7 @@ module.exports = function(dependencies) {
212209
callback(null, registry);
213210
});
214211
}
215-
]);
212+
);
216213
});
217214
});
218215
});

0 commit comments

Comments
 (0)