forked from pattern-lab/styleguidekit-assets-default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
137 lines (118 loc) · 4.7 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
/* 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");
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-patternlab', function (cb) {
return plugins.del(['dist/styleguide/css/*'],cb);
});
gulp.task('clean:fonts', function (cb) {
return plugins.del(['dist/styleguide/fonts/*'],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-general', ['clean:css-patternlab'], function() {
return gulp.src(['src/css/prism-okaidia.css','src/css/typeahead.css'])
.pipe(plugins.concat('prism-typeahead.css'))
.pipe(gulp.dest('dist/styleguide/css'))
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.minifyCss())
.pipe(gulp.dest('dist/styleguide/css'))
.pipe(copyPublic("styleguide/css"));
});
gulp.task('build:css-patternlab', ['build:css-general'], function() {
return plugins.rubySass('src/sass/styleguide.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(plugins.rename({suffix: '.min'}))
.pipe(plugins.minifyCss())
.pipe(gulp.dest('dist/styleguide/css'))
.pipe(copyPublic("styleguide/css"));
});
gulp.task('build:fonts', ['clean:fonts'], function() {
return gulp.src('src/fonts/*')
.pipe(gulp.dest('dist/styleguide/fonts'))
.pipe(copyPublic("styleguide/fonts"));
});
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/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-patternlab', 'build:html', 'build:js-pattern'], function () {
if (args.watch !== undefined) {
gulp.watch(['src/bower_components/**/*'], ['build:bower']);
gulp.watch(['src/css/prism-okaidia.css'],['build:css-general']);
gulp.watch(['src/sass/styleguide.scss'], ['build:css-patternlab']);
gulp.watch(['src/html/*'], ['build:html']);
gulp.watch(['src/js/*'], ['build:js-pattern']);
}
});