-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgulpfile.js
executable file
·158 lines (132 loc) · 4.32 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var gulp = require('gulp');
var babel = require('gulp-babel');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var bower = require('main-bower-files');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
const config = require('./package.json');
var modules = Object.keys(config['dependencies']);
for (var i = 0; i < modules.length; ++i) {
modules[i] = "./node_modules/" + modules[i] + "/**";
}
// for compass
var compass = require('gulp-compass');
var clientDir = '/client';
var serverDir = '/server';
var srcDir = './src';
var destDir = './build';
var serverSrcDir = srcDir + serverDir;
var serverDestDir = destDir + serverDir;
var clientSrcDir = srcDir + clientDir;
var clientDestDir = destDir + clientDir;
// for electron
var electron = require('electron-connect').server.create({'path': clientDestDir + "/"});
gulp.task('app-file-copy', function() {
gulp.src(['main.js', 'config/config.json', 'package.json'])
.pipe(gulp.dest(clientDestDir));
});
gulp.task('html-copy', function() {
gulp.src(clientSrcDir + '/html/**/*.html')
.pipe(gulp.dest(clientDestDir + '/html/'));
});
gulp.task('compass', function() {
gulp.src(clientSrcDir + '/sass/**/*.scss')
.pipe(plumber())
.pipe(compass({
config_file: './config/compass.rb',
comments: false,
css: clientDestDir + '/css/',
sass: clientSrcDir + '/sass/'
}));
});
gulp.task('babel', function() {
gulp.src(clientSrcDir + '/js/**/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(clientDestDir + '/js/'));
gulp.src(srcDir + '/lib/js/**/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./node_modules/'))
.pipe(gulp.dest(clientDestDir + '/node_modules/'));
gulp.src(serverSrcDir + '/js/**/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(serverDestDir + '/js/'));
});
gulp.task('copy-js-ext', function() {
gulp.src(bower())
.pipe(concat('ext-lib.js'))
.pipe(gulp.dest(clientDestDir + '/js/ext/'));
});
gulp.task('copy-images', function () {
gulp.src('./images/**/*.png')
.pipe(gulp.dest(clientDestDir + '/images/'));
});
gulp.task('copy-icon', function () {
gulp.src(['./icon/**/*.png', './icon/**/*.ico'])
.pipe(gulp.dest(clientDestDir + '/icon/'));
});
gulp.task('copy-node-modules', function () {
gulp.src(modules, {base: './node_modules'})
.pipe(gulp.dest(clientDestDir + '/node_modules/'));
});
gulp.task('watch', function() {
watch(['main.js', 'config/config.json', 'package.json'], function(event) {
gulp.start('app-file-copy');
});
watch(clientSrcDir + '/html/**/*.html', function(event) {
gulp.start('html-copy');
});
watch(clientSrcDir + '/sass/**/*.scss', function(event) {
gulp.start('compass');
});
watch(clientSrcDir + '/js/**/*.js', function(event) {
gulp.start('babel');
});
watch(serverSrcDir + '/js/**/*.js', function(event) {
gulp.start('babel');
});
watch(srcDir + '/lib/js/**/*.js', function(event) {
gulp.start('babel');
});
watch('./bower_components/**/*.js', function(event) {
gulp.start('copy-js-ext');
});
watch('./images/**/*.png', function(event) {
gulp.start('copy-images');
});
watch('./icon/**/*.png', function(event) {
gulp.start('copy-icon');
});
});
gulp.task('start', ['watch'], function() {
electron.start();
gulp.watch([
clientDestDir + '/main.js',
clientDestDir + '/config.json',
clientDestDir + '/package.json'
], electron.restart);
gulp.watch([
clientDestDir + '/**/*.*',
'!' + clientDestDir + '/node_modules/**/*.*'
], electron.reload);
});
gulp.task('default', [
'app-file-copy',
'html-copy',
'compass',
'babel',
'copy-js-ext',
'copy-images',
'copy-icon',
'copy-node-modules',
]
);