forked from tympanix/Electorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (103 loc) · 3.54 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
'use strict';
const fs = require('fs');
const gulp = require('gulp');
const {server} = require('electron-connect')
const useref = require('gulp-useref');
const clean = require('gulp-clean');
const run = require('run-sequence');
const less = require('gulp-less');
const concat = require('gulp-concat');
const path = require('path');
const merge = require('merge-stream');
const PROD = process.env.NODE_ENV === 'production'
const OUT = "./app";
const CLEAN = [`!${OUT}/package.json`, `!${OUT}/node_modules`, `${OUT}/*`];
const semantic = './bower_components/semantic/src'
gulp.task('serve', function () {
let electron = server.create({
path: 'app'
});
// Start browser process
electron.start('--debug');
// Restart browser process
gulp.watch('src/app.js', () => run('build:app', electron.restart))
gulp.watch('src/lib/*.js', () => run('build:lib', electron.restart))
// Reload renderer process
gulp.watch(['src/*.html', 'src/scripts/**'], () => run('build:useref', electron.reload));
gulp.watch(['src/views/**/*'], () => run('build:views', electron.reload));
gulp.watch(['src/css/**/*'], () => run('build:less', electron.reload));
});
gulp.task('default', ['serve']);
gulp.task('clean', function() {
return gulp.src(CLEAN, {read: false})
.pipe(clean());
});
gulp.task('build:useref', function() {
return gulp.src('src/*.html')
.pipe(useref({
dev: function(content) {
return PROD ? '' : content
}
}))
.pipe(gulp.dest(OUT))
});
gulp.task('build:app', function() {
return gulp.src('src/app.js')
.pipe(gulp.dest(OUT));
});
gulp.task('build:views', function() {
return gulp.src('src/views/**/*', {base: 'src'})
.pipe(gulp.dest(OUT))
})
gulp.task('build:lib', function() {
return gulp.src('src/lib/**/*', {base: 'src'})
.pipe(gulp.dest(OUT))
})
gulp.task('build:others', function() {
return gulp.src(['src/css/fonts/**/*', 'src/img/**/*', 'build/**/*'], {base: 'src'})
.pipe(gulp.dest(OUT))
})
gulp.task('build:assets' , function () {
return gulp.src('./bower_components/semantic/dist/themes/default/assets/**')
.pipe(gulp.dest(OUT + '/css/themes/default/assets'))
});
gulp.task('semantic:src', function() {
return gulp.src([
path.join(semantic, '**'),
'!'+path.join(semantic, 'themes/**'),
'!'+path.join(semantic, 'themes/')
]).pipe(gulp.dest('src/css/semantic'))
})
gulp.task('semantic:default', function() {
let themes = ['default']
return gulp.src(themes.map(t => path.join(semantic, 'themes', t, '/**')),
{base: path.join(semantic, 'themes')})
.pipe(gulp.dest('src/css/themes'))
})
gulp.task('build:semantic', ['semantic:src', 'semantic:default'])
gulp.task('build:static', ['build:app', 'build:views', 'build:lib', 'build:others', 'build:assets'])
gulp.task('build:less', function() {
let dir = 'src/css/themes'
let themes = fs.readdirSync(dir)
.filter(function(file) {
let stat = fs.statSync(path.join(dir, file))
return stat.isDirectory() && file !== 'default'
})
let tasks = themes.map(function(theme) {
return gulp.src(['src/css/semantic/semantic.less', 'src/css/styles.less'])
.pipe(less({
paths: [semantic],
globalVars: {
"@renderTheme": theme
}
}))
.pipe(concat(theme + '.css'))
.pipe(gulp.dest(path.join(OUT, 'css', 'themes')))
})
return merge(tasks)
})
gulp.task('build:styles', ['build:semantic'], function() {
gulp.start('build:less')
})
gulp.task('build', ['build:useref', 'build:static', 'build:styles']);
gulp.task('install', ['build:semantic'])