-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
150 lines (133 loc) · 4.66 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
144
145
146
147
148
149
150
/**
* squatchin
*/
var gulp = require('gulp');
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var cp = require('child_process');
var debug = require('gulp-debug');
var del = require('del');
var execSync = require('sync-exec');
var fs = require('fs');
var imagemin = require('gulp-imagemin');
var mbf = require('main-bower-files');
var minifyCSS = require('gulp-minify-css');
var moment = require('moment');
var os = require('os');
var path = require('path');
var pkg = require('./package.json');
var prefix = require('gulp-autoprefixer');
var proxy = require('proxy-middleware');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var uncss = require('gulp-uncss');
var url = require('url');
var open = require('gulp-open');
var wiredep = require('wiredep').stream;
gulp.task('default', ['develop']);
gulp.task('build', ['sass', 'js', 'vendor']);
gulp.task('dist', function() {
runSequence('build', 'makedist');
});
gulp.task('develop', function() {
runSequence('build', ['watch', 'browser-sync']);
});
gulp.task('makedist', function() {
del(['dist'], function() {
fs.mkdirSync('dist');
gulp.src('app/**/*')
.pipe(gulp.dest('dist'));
var ver = 'dist/version.txt';
var now = moment();
// get current git revision from git.
// Requires 'git' command line!!
var rev = 'Not Available';
var branch = 'Not Available';
try {
rev = execSync('git rev-parse HEAD').stdout.trim();
branch = execSync('git rev-parse --abbrev-ref HEAD').stdout.trim();
}
catch (err) {
console.log('Error running "git rev-parse HEAD"');
console.log(' ' + err.message);
}
fs.appendFileSync(ver, '\nsquatchin');
fs.appendFileSync(ver, '\n===================');
fs.appendFileSync(ver, '\nName: squatchin');
fs.appendFileSync(ver, '\nDescription: Talk slides and code')
fs.appendFileSync(ver, '\nURL: http://github.com/bowmanmc/squatchin');
fs.appendFileSync(ver, '\nVersion: ' + pkg.version);
fs.appendFileSync(ver, '\nGit Branch: ' + branch);
fs.appendFileSync(ver, '\nGit Revision: ' + rev);
fs.appendFileSync(ver, '\nBuild Time: ' + now.format('YYYY-MM-DD HH:mm:ss'));
fs.appendFileSync(ver, '\nBuild Host: ' + os.hostname() + ' [' + os.platform() + ']');
fs.appendFileSync(ver, '\n');
fs.appendFileSync(ver, '\n');
});
});
gulp.task('watch', function () {
gulp.watch('app/styles/**/*.scss', ['sass']);
gulp.watch('app/modules/**/*.js', ['js']);
gulp.watch('bower.json', ['vendor']);
});
gulp.task('browser-sync', function() {
browserSync({
port: 9000,
files: [
'app/**/*.html',
'app/**/*.js',
'app/**/*.css',
'app/fonts/*',
'app/images/*'
],
watchOptions: {
ignoreInitial: true
},
server: {
baseDir: 'app'
}
});
});
// Build sass into a single site.min.css
gulp.task('sass', function () {
var bootstrap = 'app/bower_components/bootstrap-sass/assets/stylesheets';
var fontawesome = 'app/bower_components/fontawesome/scss';
return gulp.src('app/styles/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
onError: browserSync.notify,
errLogToConsole: true,
includePaths: [ bootstrap, fontawesome ]
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
//.pipe(minifyCSS())
.pipe(rename('site.min.css'))
.pipe(sourcemaps.write())
//.pipe(debug())
.pipe(gulp.dest('app/styles'));
});
// thanks @esvendsen !!!
gulp.task('vendor', ['vendor-js']);
gulp.task('vendor-js', function() {
var jsRegex = (/.*\.js$/i);
return gulp.src(mbf({ filter: jsRegex }))
//.pipe(debug())
.pipe(sourcemaps.init())
.pipe(concat('vendor.js'))
//.pipe(gulp.dest('app/scripts'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('app/scripts'));
});
gulp.task('js', function() {
return gulp.src('app/modules/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
//.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('app/scripts'));
});