forked from dunkelstern/ghost-theme-development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
143 lines (124 loc) · 3.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
138
139
140
141
142
143
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
plugins.minifyCSS = require('gulp-minify-css'); // does not autoload
plugins.gulpif = require('gulp-if'); // does not autoload
var lazypipe = require('lazypipe');
var onError = function (err) {
plugins.util.log(plugins.util.colors.red("Error"), err.message);
this.emit('end');
};
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
//
// compile scss files and emit normal version + source map and a
// minified version
//
gulp.task('sass', function () {
gulp.src('css/*.scss')
.pipe(plugins.plumber(onError))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass())
.pipe(plugins.colorguard())
.pipe(plugins.autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1'))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('content/themes/dev/assets/css'))
});
gulp.task('sass_minify', function () {
gulp.src('css/*.scss')
.pipe(plugins.sass())
.pipe(plugins.colorguard())
.pipe(plugins.autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1'))
.pipe(plugins.minifyCSS())
.pipe(gulp.dest('content/themes/dev/assets/css'))
});
//
// concat all javascript files to site.js
//
gulp.task('js', function () {
gulp.src('js/*.js')
.pipe(plugins.plumber(onError))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('site.js'))
.pipe(plugins.sourcemaps.write('.'))
.pipe(gulp.dest('content/themes/dev/assets/js'))
});
gulp.task('js_minify', function () {
gulp.src('js/*.js')
.pipe(plugins.concat('site.js'))
.pipe(gulp.dest('content/themes/dev/assets/js'))
});
//
// copy handlebars theme files over
//
gulp.task('templates_livereload', function() {
var embed_live_reload = lazypipe()
.pipe(plugins.rename, function (path) {
path.extname = ".html";
}
)
.pipe(plugins.embedlr)
.pipe(plugins.rename, function (path) {
path.extname = ".hbs";
}
);
gulp.src('templates/**/*.hbs')
.pipe(plugins.plumber(onError))
.pipe(plugins.gulpif(function (file) {
return endsWith(file.path, "default.hbs");
}, embed_live_reload()
))
.pipe(gulp.dest('content/themes/dev/'))
});
gulp.task('templates', function() {
gulp.src('templates/**/*.hbs')
.pipe(gulp.dest('content/themes/dev/'))
});
//
// copy stuff over
//
gulp.task('stuff', function() {
gulp.src('stuff/*')
.pipe(gulp.dest('content/themes/dev/'))
});
//
// copy font files over
//
gulp.task('fonts', function() {
gulp.src('fonts/*.{eot,svg,ttf,woff,otf}')
.pipe(gulp.dest('content/themes/dev/assets/fonts'))
});
//
// just run a live reload server and watch files for changes
//
gulp.task('livereload', ['sass', 'js', 'templates_livereload', 'fonts', 'stuff'], function() {
reloader = plugins.livereload("0.0.0.0:35729");
gulp.watch('css/**/*.scss', ['sass']);
gulp.watch('templates/**/*.hbs', ['templates_livereload']);
gulp.watch('fonts/*.{eot,svg,ttf,woff,otf}', ['fonts']);
gulp.watch('stuff/*', ['stuff']);
gulp.watch('js/*.js', ['js']);
gulp.watch('content/themes/dev/**/*.css').on('change', function(file) {
reloader.changed(file.path);
});
gulp.watch('content/themes/dev/**/*.hbs').on('change', function(file) {
reloader.changed(file.path);
});
var ghost = require('ghost');
process.env.NODE_ENV = 'development';
ghost({ config: __dirname + '/ghost-config.js' }).then(function (ghostServer) {
ghostServer.start();
});
});
gulp.task('dist', ['default'], function() {
gulp.src('content/themes/dev/**/*')
.pipe(plugins.gulpif(function (file) {
return !endsWith(file.path, ".map");
}, plugins.zip('dev-theme.zip')
))
.pipe(gulp.dest('.'));
});
//
// default task, compile everything
//
gulp.task('default', ['sass_minify', 'js_minify', 'templates', 'fonts', 'stuff']);