forked from kaishin/unredacted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.coffee
143 lines (123 loc) · 4.12 KB
/
gulpfile.coffee
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
138
139
140
141
142
143
argv = require("yargs").argv
browserSync = require "browser-sync"
cache = require "gulp-cached"
coffee = require "gulp-coffee"
dateFormat = require "dateformat"
del = require "del"
gulp = require "gulp"
gutil = require "gulp-util"
include = require "gulp-include"
mediaQueries = require "gulp-combine-media-queries"
minifyCSS = require "gulp-minify-css"
minifyJS = require "gulp-uglify"
prefix = require "gulp-autoprefixer"
rename = require "gulp-rename"
replace = require "gulp-replace"
runSequence = require "run-sequence"
sass = require "gulp-ruby-sass"
scssLint = require "gulp-scss-lint"
shell = require "gulp-shell"
slugify = require "underscore.string/slugify"
now = new Date()
title = argv.t ? "Untitled"
dashedTitle = slugify(title)
messages =
jekyllBuild: "Rebuilding Jekyll..."
sourceFolder = "."
destinationFolder = "./_site"
paths =
sass: "#{sourceFolder}/_scss/"
coffee: "#{sourceFolder}/_coffee/"
styles: "#{sourceFolder}/css/"
destinationStyles: "#{destinationFolder}/css/"
scripts: "#{sourceFolder}/scripts/"
destinationScripts: "#{destinationFolder}/scripts/"
jekyllFiles: [
"#{sourceFolder}/**/*.html",
"#{sourceFolder}/**/*.md",
"#{sourceFolder}/**/*.yml",
"#{sourceFolder}/**/*.xml",
"!#{sourceFolder}/node_modules/**/*",
"!#{destinationFolder}/**/*"
]
gulp.task "default", ["develop"]
gulp.task "develop", ->
runSequence ["watch", "browser-sync"]
gulp.task "build", ->
runSequence ["sass", "coffee", "vendorJS"], "lintSass", "jekyll-build"
gulp.task "clean",
del.bind(null, ["_site"])
gulp.task "watch", ["sass", "coffee", "jekyll-serve"], ->
gulp.watch "#{paths.sass}/**/*.scss", ["sass"]
gulp.watch "#{paths.coffee}/**/*.coffee", ["coffee"]
gulp.watch "#{paths.coffee}/vendor.js", ["vendorJS"]
gulp.watch paths.jekyllFiles, ["jekyll-rebuild"]
gulp.task "jekyll-serve",
shell.task "bundle exec jekyll build --config _config.yml,_config.serve.yml", quiet: true
browserSync.notify messages.jekyllBuild
gulp.task "jekyll-build",
shell.task "bundle exec jekyll build"
gulp.task "jekyll-rebuild", ["jekyll-serve"], ->
browserSync.reload()
gulp.task "doctor",
shell.task "jekyll doctor"
gulp.task "sass", ->
gulp.src("#{paths.sass}/*.scss")
.pipe sass
precision: 2
bundleExec: true
.on "error", (error) -> gutil.log(error.message)
.pipe prefix ["last 2 versions", "> 2%", "ie 11", "Firefox ESR"], cascade: false
.pipe mediaQueries()
.pipe cache paths.styles
.pipe minifyCSS()
.pipe gulp.dest(paths.destinationStyles)
.pipe gulp.dest(paths.styles)
.pipe browserSync.reload(stream: true)
gulp.task "minifyCSS", ->
gulp.src("#{paths.destinationStyles}/*.css")
.pipe cache paths.styles
.pipe minifyCSS()
.pipe gulp.dest(paths.destinationStyles)
.pipe gulp.dest(paths.styles)
gulp.task "lintSass", ->
gulp.src("#{paths.sass}/*.scss")
.pipe cache paths.sass
.pipe scssLint
"config": ".scss-lint.yml",
"bundleExec": true
.pipe scssLint.failReporter()
.on "error", (error) -> gutil.log(error.message)
gulp.task "coffee", ->
gulp.src("#{paths.coffee}/*.coffee")
.pipe cache paths.coffee
.pipe coffee bare: true
.on "error", (error) -> gutil.log(error.message)
.pipe cache paths.scripts
.pipe minifyJS()
.pipe gulp.dest(paths.destinationScripts)
.pipe gulp.dest(paths.scripts)
.pipe browserSync.reload(stream: true)
gulp.task "vendorJS", ->
gulp.src("#{paths.coffee}/vendor.js")
.pipe include()
.on "error", (error) -> gutil.log(error.message)
.pipe cache paths.scripts
.pipe minifyJS()
.pipe gulp.dest(paths.destinationScripts)
.pipe gulp.dest(paths.scripts)
.pipe browserSync.reload(stream: true)
gulp.task "browser-sync", ->
browserSync.init null,
server:
baseDir: "_site"
host: "localhost"
port: 4000
open: true
browser: "Google Chrome"
gulp.task "post", ->
gulp.src("./_posts/_template.md")
.pipe rename "#{dateFormat(now, 'yyyy-mm-dd')}-#{dashedTitle}.md"
.pipe replace(/DATE_PLACEHOLDER/g, "#{dateFormat(now, 'yyyy-mm-dd hh:MM:ss o')}")
.pipe replace(/TITLE_PLACEHOLDER/g, title)
.pipe gulp.dest("./_posts")