-
Notifications
You must be signed in to change notification settings - Fork 67
/
gulpfile.js
114 lines (98 loc) · 3.91 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
/* load command line arguments */
var args = require('yargs').argv;
/* load gulp */
var gulp = require('gulp');
/* load the plugins */
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins({ scope: ['devDependencies'] });
plugins.del = require("del");
plugins.mainBowerFiles = require("main-bower-files");
/* copy the dist folder into the designated public folder */
function copyPublic(suffix) {
if (args['copy-dist'] !== undefined) {
return gulp.dest(args['copy-dist'] + "/" + suffix);
} else {
return plugins.util.noop();
}
}
/* clean tasks */
gulp.task('clean:bower', function (cb) {
return plugins.del(['dist/styleguide/bower_components/*'],cb);
});
gulp.task('clean:css', function (cb) {
return plugins.del(['dist/styleguide/css/*'],cb);
});
gulp.task('clean:html', function (cb) {
return plugins.del(['dist/*.html'],cb);
});
gulp.task('clean:images', function (cb) {
return plugins.del(['dist/styleguide/images/*'],cb);
});
gulp.task('clean:js', function (cb) {
return plugins.del(['dist/styleguide/js/*'],cb);
});
/* core tasks */
gulp.task('build:bower', ['clean:bower'], function(){
return gulp.src(plugins.mainBowerFiles())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.uglify())
.pipe(gulp.dest("dist/styleguide/bower_components"))
.pipe(copyPublic("styleguide/bower_components"));
});
gulp.task('build:css', function() {
return plugins.rubySass('src/sass/pattern-lab.scss', { style: 'expanded', "sourcemap=none": true })
.pipe(plugins.autoprefixer({browsers: ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'android 4']}, {map: false }))
.pipe(gulp.dest('dist/styleguide/css'))
.pipe(copyPublic("styleguide/css"));
});
gulp.task('build:html', ['clean:html'], function() {
return gulp.src('src/html/index.html')
.pipe(plugins.fileInclude({ prefix: '@@', basepath: '@file' }))
.pipe(gulp.dest('dist'))
.pipe(copyPublic(""));
});
gulp.task('build:images', ['clean:images'], function() {
return gulp.src('src/images/*')
.pipe(plugins.imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [plugins.pngcrush()]
}))
.pipe(gulp.dest('dist/styleguide/images'))
.pipe(copyPublic("styleguide/images"));
});
gulp.task('build:js-viewer', ['clean:js'], function() {
return gulp.src(['src/js/*.js','!src/js/modal-styleguide.js'])
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter('default'))
.pipe(plugins.resolveDependencies( { pattern: /\* @requires [\s-]*(.*?\.js)/g } ))
.on('error', function(err) { console.log(err.message); })
.pipe(plugins.concat('patternlab-viewer.js'))
.pipe(gulp.dest('dist/styleguide/js'))
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.uglify())
.pipe(gulp.dest('dist/styleguide/js'))
.pipe(copyPublic("styleguide/js"));
});
gulp.task('build:js-pattern', ['build:js-viewer'], function() {
// 'src/js/annotations-pattern.js','src/js/code-pattern.js','src/js/info-panel.js'
return gulp.src(['src/js/postmessage.js', 'src/js/panels-shared.js', 'src/js/clipboard.min.js', 'src/js/modal-styleguide.js'])
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter('default'))
.pipe(plugins.resolveDependencies( { pattern: /\* @requires [\s-]*(.*?\.js)/g } ))
.on('error', function(err) { console.log(err.message); })
.pipe(plugins.concat('patternlab-pattern.js'))
.pipe(gulp.dest('dist/styleguide/js'))
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.uglify())
.pipe(gulp.dest('dist/styleguide/js'))
.pipe(copyPublic("styleguide/js"));
});
gulp.task('default', ['build:bower', 'build:css', 'build:html', 'build:js-pattern'], function () {
if (args.watch !== undefined) {
gulp.watch(['src/bower_components/**/*'], ['build:bower']);
gulp.watch(['src/sass/pattern-lab.scss', 'src/sass/scss/**/*'], ['build:css']);
gulp.watch(['src/html/*'], ['build:html']);
gulp.watch(['src/js/*'], ['build:js-pattern']);
}
});