forked from hp-net/homebridge-nibe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
87 lines (74 loc) · 2.45 KB
/
gulpfile.ts
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
78
79
80
81
82
83
84
85
86
87
import { dest, parallel, series, src } from 'gulp';
import * as ts from 'gulp-typescript';
import gulpif from 'gulp-if';
import htmlmin from 'gulp-htmlmin';
import imagemin from 'gulp-imagemin';
import del from 'del';
import gulpESLintNew from 'gulp-eslint-new';
import nodemon from 'gulp-nodemon';
import jest from 'gulp-jest';
const tsProject = ts.createProject('tsconfig.json', { rootDir: 'src/' });
const destDir = 'dist/';
const isHtml = (file) => file.extname === '.html';
const isImage = (file) => file.extname === '.png';
exports.uiBuild = () => src('homebridge-ui/**')
.pipe(gulpif(isHtml, htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
})))
.pipe(gulpif(isImage, imagemin()))
.pipe(dest(`${destDir}homebridge-ui/`));
exports.yamlBuild = () => src('+(config|lang)/*.yaml')
.pipe(dest(`${destDir}`));
exports.typescriptBuild = () => src('src/**/*.ts')
.pipe(tsProject())
.pipe(dest(`${destDir}`));
exports.eslint = () => src(['src/**/*.ts', 'gulpfile.ts'])
.pipe(gulpESLintNew())
.pipe(gulpESLintNew.format())
.pipe(gulpESLintNew.failAfterError());
exports.eslintFix = () => src(['src/**/*.ts', 'gulpfile.ts'])
.pipe(gulpESLintNew({ fix: true }))
.pipe(gulpESLintNew.fix());
exports.clean = () => del([`${destDir}`]);
exports.build = parallel(exports.yamlBuild, exports.typescriptBuild, exports.uiBuild);
exports.watch = (done) => nodemon({
exec: 'homebridge -I -D',
signal: 'SIGTERM',
ext: 'ts html yaml',
ignore: [`${destDir}**`],
env: { 'NODE_OPTIONS': '--trace-warnings' },
done: done,
tasks: function (changedFiles) {
const tasks = Array<string>();
if (!changedFiles) {
return tasks;
}
changedFiles.forEach(function (file) {
const fileExt = file.split('.').pop();
if (fileExt === 'ts' && !~tasks.indexOf('typescriptBuild')) {
tasks.push('typescriptBuild');
}
if (fileExt === 'html' && !~tasks.indexOf('uiBuild')) {
tasks.push('uiBuild');
}
if (fileExt === 'yaml' && !~tasks.indexOf('yamlBuild')) {
tasks.push('yamlBuild');
}
});
return tasks;
},
});
exports.jest = () => {
process.env.NODE_ENV = 'test';
return src('tests/**/*.test.ts')
.pipe(jest({
preset: 'ts-jest',
testEnvironment: 'node',
transform: { '^.+\\.ts?$': 'ts-jest' },
transformIgnorePatterns: ['<rootDir>/node_modules/'],
}));
};
exports.test = series(exports.eslint, exports.jest);
exports.default = exports.build;