forked from johnnymo87/styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
124 lines (113 loc) · 3.45 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
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
var babelify = require('babelify');
var sass = require('gulp-sass');
var autoprefix = require('gulp-autoprefixer');
var scsslint = require('gulp-scss-lint');
var minifyCSS = require('gulp-minify-css');
var connect = require('gulp-connect');
var history = require('connect-history-api-fallback');
var jsonSass = require('gulp-json-sass');
var header = require('gulp-header');
var stringifyObject = require('stringify-object');
var gutil = require('gulp-util');
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var fontName = 'icons';
function string_src(filename, string) {
var src = require('stream').Readable({ objectMode: true })
var prettyJSON = stringifyObject(string, {singleQuotes: false});
src._read = function () {
this.push(new gutil.File({ cwd: "", base: "", path: filename, contents: new Buffer(prettyJSON) }))
this.push(null)
}
return src
}
gulp.task('scripts', function(){
browserify({
entries: './src/js/index.js',
debug: true
})
.transform(babelify)
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./public'))
.pipe(connect.reload());
});
gulp.task('icons', function(){
gulp.src(['./src/lib/icons/*.svg'])
.pipe(iconfontCss({
fontName: fontName,
path: './src/lib/scss/_icons-template.scss',
targetPath: '../../src/scss/base/_icons.scss',
fontPath: '/fonts/'
}))
.pipe(iconfont({
fontName: fontName,
normalize: true,
fixedWidth: true,
centerHorizontally: true,
fontHeight: 1001
}))
.on('codepoints', function(codepoints, options) {
string_src('_icons.json', codepoints).pipe(gulp.dest("./src/lib/"));
})
.pipe(gulp.dest('././public/fonts/'));
});
gulp.task('import-styles', function(){
gulp.src('./bower_components/prism/themes/prism-twilight.css')
.pipe(gulp.dest('./public'));
});
gulp.task('styles', function(){
gulp.src('./src/scss/app.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('.'))
.pipe(minifyCSS({processImport: false}))
.pipe(autoprefix())
.pipe(gulp.dest('./public'))
.pipe(connect.reload());
});
gulp.task('scss-lint', function(){
gulp.src('./src/scss/**/*.scss')
.pipe(scsslint({
'config': __dirname + '/scss-lint.yml'
}))
.pipe(scsslint.failReporter('E'));
});
gulp.task('colors', function(){
var source = './src/lib/_colors.json';
var banner = "// generated from <%= source %> by gulp-json-sass\n\n";
gulp.src(source)
.pipe(jsonSass())
.pipe(header(banner, {source: source}))
.pipe(gulp.dest('./src/scss/base/'));
});
gulp.task('server', ['icons', 'colors', 'import-styles', 'styles', 'scripts'], function(){
connect.server({
root: ['public'],
livereload: true,
middleware: function() {
return [
history()
]
}
});
});
gulp.task('watch', function(){
gulp.watch('src/lib/icons/**', ['icons']);
gulp.watch('src/lib/scss/_icons-template.scss', ['icons']);
gulp.watch('src/lib/_colors.json', ['colors']);
gulp.watch('src/scss/**', ['scss-lint', 'styles']);
gulp.watch('src/js/**', ['scripts']);
});
gulp.task('package:css', ['icons', 'colors'], function(){
gulp.src('./lib/namely-ui.scss')
.pipe(sass())
.pipe(autoprefix())
.pipe(minifyCSS())
.pipe(gulp.dest('./dist'));
});
gulp.task('default', ['server', 'watch']);