Repository navigation
Expand file tree
/
Copy pathrun.js
More file actions
50 lines (43 loc) · 1.51 KB
/
Copy pathrun.js
File metadata and controls
50 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const _ = require('lodash');
const BbPromise = require('bluebird');
const webpack = require('webpack');
module.exports = {
watch(command) {
const functionName = this.options.function;
if (functionName) {
this.serverless.cli.log(`Watch function ${functionName}...`);
} else {
this.serverless.cli.log('Watch service...');
}
const compiler = webpack(this.webpackConfig);
const watchOptions = {};
const usePolling = this.options['webpack-use-polling'];
if (usePolling) {
watchOptions.poll = _.isInteger(usePolling) ? usePolling : 3000;
this.serverless.cli.log(`Enabled polling (${watchOptions.poll} ms)`);
}
compiler.watch(watchOptions, (err /*, stats */) => {
if (err) {
throw err;
}
BbPromise.try(() => { // eslint-disable-line promise/catch-or-return, promise/no-promise-in-callback
if (this.originalServicePath) {
process.chdir(this.originalServicePath);
this.serverless.config.servicePath = this.originalServicePath;
}
if (!this.isWatching) {
this.isWatching = true;
return BbPromise.resolve();
}
this.serverless.cli.log('Sources changed.');
if (_.isFunction(command)) {
return command();
}
this.options.verbose && this.serverless.cli.log(`Invoke ${command}`);
return this.serverless.pluginManager.spawn(command);
})
.then(() => this.serverless.cli.log('Waiting for changes ...'));
});
},
};