-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
111 lines (90 loc) · 2.88 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
var fs = require('fs'),
path = require('path'),
gulp = require('gulp'),
// Load all gulp plugins automatically
// and attach them to the `plugins` object
plugins = require('gulp-load-plugins')(),
// Temporary solution until gulp 4
// https://github.com/gulpjs/gulp/issues/355
runSequence = require('run-sequence'),
pkg = require('./package.json');
gulp.task('archive:create_archive_dir', function () {
fs.mkdirSync(path.resolve('archive'), '0755');
});
gulp.task('archive:zip', function (done) {
var archiveName = path.resolve('archive', pkg.name + '_v' + pkg.version + '.zip'),
archiver = require('archiver')('zip'),
files = require('glob').sync('**/*.*', {
cwd : 'dist',
dot : true // include hidden files
}),
output = fs.createWriteStream(archiveName);
archiver.on('error', function (error) {
done();
throw error;
});
output.on('close', done);
files.forEach(function (file) {
var filePath = path.resolve('dist', file);
// `archiver.bulk` does not maintain the file
// permissions, so we need to add files individually
archiver.append(fs.createReadStream(filePath), {
name : file,
mode : fs.statSync(filePath)
});
});
archiver.pipe(output);
archiver.finalize();
});
gulp.task('clean', function (done) {
require('del')(['archive', 'dist', 'bower_components'], done);
});
gulp.task('copy', [
'copy:bem-components',
'copy:license',
'copy:misc'
]);
gulp.task('copy:bem-components', function () {
return gulp.src([
'bower_components/bem-components-dist/desktop/bem-components.css',
'bower_components/bem-components-dist/desktop/bem-components.ie.css',
'bower_components/bem-components-dist/desktop/bem-components.js+bh.js'
])
.pipe(gulp.dest('dist/vendor/bem-components'));
});
gulp.task('copy:license', function () {
return gulp.src('LICENSE.txt')
.pipe(gulp.dest('dist'));
});
gulp.task('copy:misc', function () {
return gulp.src(['src/**/*'], { dot : true })
.pipe(gulp.dest('dist'));
});
gulp.task('lint:js', function () {
return gulp.src([
'gulpfile.js',
'src/js/*.js',
'test/*.js'
]).pipe(plugins.jscs())
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'));
});
gulp.task('install:bower', function () {
return plugins.bower();
});
gulp.task('archive', function (done) {
runSequence(
'build',
'archive:create_archive_dir',
'archive:zip',
done);
});
gulp.task('build', function (done) {
runSequence(
['clean', 'lint:js'],
'install:bower',
'copy',
done);
});
gulp.task('default', ['build']);