This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
forked from crowi/crowi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
180 lines (154 loc) · 4.72 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var cssmin = require('gulp-cssmin');
var mocha = require('gulp-spawn-mocha');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var source = require('vinyl-source-stream');
var webpack = require('webpack-stream');
var del = require('del');
var stylish = require('jshint-stylish');
var pkg = require('./package.json');
var dirs = {
cssSrc: './resource/css',
cssDist: './public/css',
jsSrc: './resource/js',
jsDist: './public/js',
};
var tests = {
watch: ['test/**/*.test.js'],
}
var css = {
src: dirs.cssSrc + '/' + pkg.name + '.scss',
main: dirs.cssDist + '/crowi-main.css',
dist: dirs.cssDist + '/crowi.css',
revealSrc: dirs.cssSrc + '/' + pkg.name + '-reveal.scss',
revealDist: dirs.cssDist + '/crowi-reveal.css',
watch: ['resource/css/*.scss'],
};
var js = {
bundledSrc: [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
'node_modules/inline-attachment/src/inline-attachment.js',
'node_modules/jquery.cookie/jquery.cookie.js',
'resource/thirdparty-js/jquery.selection.js',
],
src: dirs.jsSrc + '/app.js',
bundled: dirs.jsDist + '/bundled.js',
dist: dirs.jsDist + '/crowi.js',
admin: dirs.jsDist + '/admin.js',
form: dirs.jsDist + '/form.js',
presentation: dirs.jsDist + '/presentation.js',
app: dirs.jsDist + '/app.js',
clientWatch: ['resource/js/**/*.js'],
watch: ['test/**/*.test.js', 'app.js', 'lib/**/*.js'],
lint: ['app.js', 'lib/**/*.js'],
tests: tests.watch,
};
var cssIncludePaths = [
'node_modules/bootstrap-sass/assets/stylesheets',
'node_modules/font-awesome/scss',
'node_modules/reveal.js/css'
];
gulp.task('js:del', function() {
var fileList = [
js.dist,
js.bundled,
js.admin,
js.form,
js.presentation,
js.app,
];
fileList = fileList.concat(fileList.map(function(fn){ return fn.replace(/\.js/, '.min.js');}));
return del(fileList);
});
gulp.task('js:concat', ['js:del'], function() {
return gulp.src(js.bundledSrc)
.pipe(concat('bundled.js')) // jQuery
.pipe(gulp.dest(dirs.jsDist));
});
// move task for css and js to webpack over time.
gulp.task('webpack', ['js:concat'], function() {
return gulp.src(js.src)
.pipe(webpack(require('./webpack.config.js')))
.pipe(gulp.dest(dirs.jsDist));
});
gulp.task('js:min', ['webpack'], function() {
var fileList = [
js.dist,
js.bundled,
js.admin,
js.form,
js.presentation,
js.app,
];
fileList.forEach(function(jsfile) {
gulp.src(jsfile)
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dirs.jsDist));
});
});
gulp.task('jshint', function() {
return gulp.src(js.lint)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('test', function() {
return gulp.src(js.tests)
.pipe(mocha({
r: 'test/bootstrap.js',
globals: ['chai'],
R: 'dot',
}));
});
gulp.task('css:sass', function() {
gulp.src(css.revealSrc) // reveal
.pipe(sass({
outputStyle: 'nesed',
sourceComments: 'map',
includePaths: cssIncludePaths
}).on('error', sass.logError))
.pipe(gulp.dest(dirs.cssDist));
return gulp.src(css.src)
.pipe(sass({
outputStyle: 'nesed',
sourceComments: 'map',
includePaths: cssIncludePaths
}).on('error', sass.logError))
.pipe(rename({suffix: '-main'})) // create -main.css to prepare concating with highlight.js's css
.pipe(gulp.dest(dirs.cssDist));
});
gulp.task('css:concat', ['css:sass'], function() {
return gulp.src([css.main, 'node_modules/highlight.js/styles/tomorrow-night.css'])
.pipe(concat('crowi.css'))
.pipe(gulp.dest(dirs.cssDist))
});
gulp.task('css:min', ['css:concat'], function() {
gulp.src(css.revealDist)
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dirs.cssDist));
return gulp.src(css.dist)
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dirs.cssDist));
});
gulp.task('watch', function() {
var watchLogger = function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
};
var cssWatcher = gulp.watch(css.watch, ['css:concat']);
cssWatcher.on('change', watchLogger);
var jsWatcher = gulp.watch(js.clientWatch, ['webpack']);
jsWatcher.on('change', watchLogger);
var testWatcher = gulp.watch(js.watch, ['test']);
testWatcher.on('change', watchLogger);
});
gulp.task('css', ['css:sass', 'css:concat',]);
gulp.task('default', ['css:min', 'js:min',]);
gulp.task('dev', ['css:concat', 'webpack', 'jshint', 'test']);