This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
129 lines (118 loc) · 3.89 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
"use strict";
var fs = require('fs'),
path = require('path'),
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
livereload = require('gulp-livereload'),
json = JSON.parse(fs.readFileSync('./package.json')),
browserSync = require('browser-sync'),
reload = browserSync.stream,
args = require('yargs').argv;
var config = (function () {
var appName = json.name;
var path = {
bower: './bower_components/',
assets: './' + appName + '/assets',
static: './' + appName + '/static'
};
return {
path: path,
scss: {
input: path.assets + '/scss/style.scss',
include: [
path.bower + '/bootstrap/scss/',
path.bower + '/font-awesome/scss',
path.assets + '/scss/',
],
output: path.static + "/css",
watch: [
path.assets + '/scss/**.scss'
]
},
icons: {
input: [
path.bower + '/font-awesome/fonts/**.*'
],
output: path.static + "/fonts"
},
script: {
input: [
path.bower + '/jquery/dist/jquery.js',
path.bower + '/bootstrap-sass/assets/javascripts/bootstrap/tab.js',
path.bower + '/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
path.bower + '/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js',
path.bower + '/bootstrap-sass/assets/javascripts/bootstrap/tooltip.js',
path.assets + '/js/*.js'
],
output: path.static + '/js/script.js',
watch: [
path.assets + '/js/*.js'
]
}
};
}());
gulp.task('bower', function () {
return $.bower(config.path.bower);
});
gulp.task('icons', function () {
return gulp.src(config.icons.input)
.pipe(gulp.dest(config.icons.output));
});
gulp.task('config', function () {
console.log(config);
});
gulp.task('serve', function (){
browserSync({
proxy: args.host || 'localhost:8000'
});
});
gulp.task('js', function () {
var filename = path.basename(config.script.output);
var dirname = path.dirname(config.script.output);
console.log({filename:filename, dirname:dirname})
return gulp.src(config.script.input)
.pipe(require('gulp-debug')())
.pipe($.concat(filename))
.pipe(require('gulp-debug')())
.pipe(gulp.dest(dirname))
.pipe(livereload())
.pipe($.uglify())
.pipe($.rename({ extname: '.min.js' }))
.pipe(require('gulp-debug')())
.pipe(gulp.dest(dirname))
.pipe(require('gulp-debug')())
.pipe(livereload());
});
gulp.task('scss', function () {
return gulp.src(config.scss.input)
.pipe(require('gulp-debug')())
.pipe($.sass({
style: "expanded",
includePaths: config.scss.include
}))
.pipe(require('gulp-debug')())
.pipe($.autoprefixer())
.pipe(require('gulp-debug')())
.pipe(gulp.dest(config.scss.output))
.pipe(require('gulp-debug')())
.pipe(livereload())
.pipe(require('gulp-debug')())
.pipe($.rename({ extname: '.min.css' }))
.pipe(require('gulp-debug')())
.pipe($.minifyCss())
.pipe(require('gulp-debug')())
.pipe(gulp.dest(config.scss.output))
.pipe(require('gulp-debug')())
.pipe(livereload());
});
// Rerun the task when a file changes
gulp.task('watch', ['serve'], function () {
livereload.listen();
config.scss.watch.forEach(function (path) {
gulp.watch(path, ['scss']);
});
config.script.watch.forEach(function (path) {
gulp.watch(path, ['js']);
});
});
gulp.task('default', ['bower', 'icons', 'js', 'scss', 'watch']);