-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
127 lines (115 loc) · 3.35 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
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minify = require('gulp-minify-css'),
argv = require('yargs').argv,
url = require('url'),
proxy = require('proxy-middleware'),
preprocess = require('gulp-preprocess'),
strip = require('gulp-strip-debug'),
shell = require('gulp-shell'),
svgstore = require('gulp-svgstore'),
cheerio = require('gulp-cheerio'),
svgmin = require('gulp-svgmin'),
path = require('path'),
fs = require('fs')
// Static server with proxy
gulp.task('default', ['build', 'sass:watch', 'preprocess:watch'], function () {
browserSync.init({
port: 8888,
files: ["*.html", "src/lib/**"],
server: {
baseDir: ["./dist", "./"]
},
open: false,
notify: false,
inject: true
})
})
gulp.task('sass', function () {
return gulp.src('./src/assets/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({ browsers: ['last 2 versions'] }))
.pipe(minify())
.pipe(gulp.dest('./dist/assets/css'))
.pipe(browserSync.stream())
});
gulp.task('sass:watch', ['sass'], function () {
gulp.watch('./src/assets/sass/**/*.scss', ['sass'])
})
gulp.task('preprocess', ['svg'], function() {
return gulp.src('./src/*.html')
.pipe(preprocess({context: { NODE_ENV: argv.production ? 'production' : 'development'}}))
.pipe(gulp.dest('./dist/'))
})
gulp.task('preprocess:watch', ['preprocess'], function() {
gulp.watch('./src/*.html', ['preprocess'])
})
gulp.task('js', function() {
if(argv.production) {
return gulp.src('')
.pipe(shell([
'jspm bundle-sfx ./src/lib/main ./dist/assets/js/main.js --minify --skip-source-maps'
]))
}
})
gulp.task('debug', ['js'], function() {
return gulp.src('./dist/assets/js/*.js')
.pipe(strip())
.pipe(gulp.dest('./dist/assets/js/'))
})
gulp.task('svg', function () {
return gulp.src('./src/assets/svg/*.svg')
.pipe(svgmin(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative))
return {
plugins: [{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
}))
.pipe(cheerio({
run: function ($) {
$('[fill]').removeAttr('fill');
},
parserOptions: { xmlMode: true }
}))
.pipe(svgstore({inlineSvg: true}))
.pipe(gulp.dest('./src/assets/svg'))
})
gulp.task('copy', function() {
var files = [
'./src/media/*',
'./src/assets/images/*',
'./src/favicon.ico',
'./src/apple-touch-icon.png'
]
if(!argv.production) {
files.push('src/lib/**/*')
}
return gulp.src(files, { base: './src' })
.pipe(gulp.dest('./dist/'))
})
gulp.task('build', ['sass', 'js', 'svg', 'copy', 'preprocess'])
// Imgur tasks
var request = require('request'),
imgurCredentials = require('./credentials-imgur.js')
gulp.task('imgur:create', function () {
return request({
url: "https://api.imgur.com/3/album/",
method: 'post',
headers: {
'Authorization': 'Client-ID ' + imgurCredentials.clientId
}
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body)
console.log("Album ID: " + data.data.id)
console.log("Album deletehash: " + data.data.deletehash)
}
})
})