-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
77 lines (61 loc) · 2.24 KB
/
gulpfile.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var fs = require('fs');
// Gulp Plugins
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var exec = require('gulp-exec');
var rename = require('gulp-rename');
var shell = require('gulp-shell');
var util = require('gulp-util');
var uglify = require('gulp-uglify');
var scripts = [];
var isProduction = (process.env.NODE_ENV === 'production');
var homeDir = require('os').homedir();
var config = {
example: './bridge/accessories/homebridge-rf-outlet/config-example.json',
src: './bridge/config.json',
dest: isProduction ? '/var/lib/homebridge' : homeDir + '/.homebridge/',
filePath: this.dest + 'config.json'
}
var accessories = {
filename: ['homebridge-rf-outlet.js'],
src: ['./bridge/accessories/homebridge-rf-outlet/index.js'],
dest: homeDir + '/.homebridge/accessories/'
}
var bridgeConfig = require(config.src).bridge;
gulp.task('clean', ['stop-homebridge'], function() {
return gulp.src([config.filePath, accessories.dest])
.pipe(clean({ force: true }));
});
gulp.task('copy-config', ['clean'], function() {
util.log('copying config to ' + config.dest);
return gulp.src(config.src)
.pipe(gulp.dest(config.dest));
});
gulp.task('copy-accessories', ['clean'], function() {
util.log('copying accessories to ' + accessories.dest);
return gulp.src(accessories.src)
.pipe(rename(accessories.filename))
.pipe(gulp.dest(accessories.dest));
})
gulp.task('debug-homebridge', ['copy-config', 'copy-accessories'], function() {
gulp.src('')
.pipe(isProduction ? shell('homebridge') :
shell('DEBUG=* homebridge -D -P ./bridge/accessories/'));
});
gulp.task('start-homebridge', ['stop-homebridge'], function() {
gulp.src('')
.pipe(isProduction ? shell('homebridge') :
shell('homebridge'));
});
gulp.task('stop-homebridge', function() {
gulp.src('')
.pipe(shell('#!/bin/bash; if [[ $(lsof -P -ti :' + bridgeConfig.port + ') ]]; then kill $(lsof -P -ti :' + bridgeConfig.port + '); fi'));
});
gulp.task('watch', function() {
gulp.watch(config.src, [''])
gulp.watch(scripts, ['']);
});
gulp.task('build', ['stop-homebridge', 'copy-config', 'copy-accessories']);
gulp.task('debug', ['debug-homebridge', 'watch']);
gulp.task('default', ['start-homebridge', 'watch']);