-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
130 lines (114 loc) · 4.02 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const gulp = require("gulp");
const ts = require("gulp-typescript");
const sourcemaps = require('gulp-sourcemaps');
const nodemon = require('gulp-nodemon');
const watch = require('gulp-watch');
const minify = require('gulp-minify');
const replace = require('gulp-replace');
const fs = require('fs')
const paths = {
pages: ['src/nodes/*.html'],
src: 'src',
dist: 'dist'
};
function copyResources() {
const tsProjectresources = ts.createProject("tsconfig-resources.json");
return tsProjectresources.src()
.pipe(sourcemaps.init())
.pipe(tsProjectresources())
.js
.pipe(gulp.dest('resources'));
}
function copyHtml() {
const prepareIcalEvents = fs.readFileSync('./resources/prepareIcalEvents.js', 'utf8');
const config = fs.readFileSync('./resources/config.js', 'utf8');
const timezones = fs.readFileSync('./resources/timezones.js', 'utf8');
const template = fs.readFileSync('./src/resources/template.html', 'utf8');
return gulp.src('src/nodes/*.html', { base: 'src/nodes' })
.pipe(replace('<!-- template.html -->', template))
.pipe(replace('{ { prepareIcalEvents } }', prepareIcalEvents))
.pipe(replace('{ { icalEventsConfig } }', config))
.pipe(replace('{ { icalEventsTimezones } }', timezones))
.pipe(gulp.dest(paths.dist));
}
gulp.task("copy-html", copyHtml);
gulp.task("copy-resources", copyResources);
gulp.task('develop', function (done) {
const stream = nodemon({
legacyWatch: true,
exec: 'node --inspect=9229 --preserve-symlinks --experimental-modules --trace-warnings ' + (process.env.NODE_RED_JS ? process.env.NODE_RED_JS : '/usr/lib/node_modules/node-red/red.js'),
ext: '*.js',
watch: [paths.dist],
ignore: ["*.map"],
done: done,
verbose: true,
delay: 2000,
env: { "NO_UPDATE_NOTIFIER": "1" }
});
copyResources();
copyHtml();
const tsProject = ts.createProject("tsconfig.json");
const tsProjectresources = ts.createProject("tsconfig-resources.json");
tsProjectresources.src()
.pipe(sourcemaps.init())
.pipe(tsProjectresources())
.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('resources'));
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist));
watch(paths.pages).on('change', () => {
copyHtml();
stream.emit('restart', 10)
});
watch('src/resources/*.html').on('change', () => {
copyHtml();
stream.emit('restart', 10)
});
watch('src/**/*.ts').on('change', () => {
gulp.series(() => {
tsProjectresources.src()
.pipe(sourcemaps.init())
.pipe(tsProjectresources())
.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('resources'));
}, () => {
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist));
})
stream.emit('restart', 10)
});
stream
.on('restart', function () {
console.log('restarted!')
})
.on('crash', function () {
console.error('Application has crashed!\n')
stream.emit('restart', 10) // restart the server in 10 seconds
})
})
gulp.task("default",
gulp.series('copy-resources', 'copy-html',
() => {
const tsProject = ts.createProject("tsconfig.json");
return tsProject.src()
.pipe(tsProject())
.js
.pipe(minify({
ext: {
min: '.js' // Set the file extension for minified files to just .js
},
noSource: true // Don’t output a copy of the source file
}))
.pipe(gulp.dest(paths.dist));
})
);