This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
164 lines (147 loc) · 3.71 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
var gulp = require('gulp');
var path = require('path');
var webserver = require('gulp-webserver');
var eslint = require('gulp-eslint');
var rename = require('gulp-rename');
var rimraf = require('rimraf');
var runSequence = require('run-sequence');
var ghPages = require('gulp-gh-pages');
var bootlint = require('gulp-bootlint');
var gutil = require("gulp-util");
var gwebpack = require("gulp-webpack");
var watch = require("gulp-watch");
var webpack = require("webpack");
var config = {
src: {
all: './',
siteFiles: [
'index.html',
'datasource.html',
'build/*',
'bower_components/**/*',
'data/**/*',
'lib/**/*',
'src/css/*',
'src/img/**'
],
build: 'build',
dist: 'dist',
deploy: 'dist/**/*',
jsDir: 'src/js',
js: 'src/js/**/*.js'
}
};
/*
* jshint to check for syntax errors
*/
gulp.task('lint', function () {
return gulp.src(config.src.js)
.pipe(eslint({useEslintrc: true}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('bootlint', function () {
return gulp.src('./index.html')
.pipe(bootlint());
});
/**
* Packs the UI into a single file
*/
gulp.task("webpack", function () {
return gulp.src(config.src.js)
.pipe(gwebpack({
devtool: "source-map",
output: {
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /(node_modules|bower_components)/,
loader: 'babel'
}]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
}))
.pipe(gulp.dest(config.src.build));
});
/*
* Clean out the dist directory so we don't have any excess junk
*/
gulp.task('clean', function (cb) {
rimraf(config.src.dist, cb);
});
/*
* Copy static content into a single point for deployment, without the extra cruft.
*/
gulp.task('site', function () {
return gulp.src(config.src.siteFiles, {'base': '.'}).pipe(gulp.dest(config.src.dist));
});
/*
* Runs all the required tasks to create distributable site package in output folder.
*/
gulp.task('build', function (cb) {
return runSequence(
'lint',
'webpack',
'site',
cb);
});
//helper for the web server task
function serve(reload) {
return webserver({
path: '/usda-challenge',
livereload: reload,
defaultFile: 'index.html',
open: false
});
}
/**
* Starts the server for the "serve" task
*/
gulp.task('serve-server', function () {
gulp.src(config.src.all)
.pipe(serve(true));
});
/**
* Watches the js for file changes and calls build
*/
gulp.task('watch', function () {
watch(config.src.js, function () {
runSequence('lint', 'webpack');
});
});
/*
* Live-reload server to make the app available (localhost:8000) and auto-refresh when files change.
*/
gulp.task('serve', function (cb) {
runSequence('lint', 'webpack', 'watch', 'serve-server');
});
/*
* Web server to host the app, but from output folder, replicating live deploy with built resources.
*/
gulp.task('serve-dist', function () {
gulp.src(config.src.dist)
.pipe(serve(false));
});
/*
* Push the built site content to public gh-pages.
*/
gulp.task('ghpages', function () {
return gulp.src(config.src.deploy)
.pipe(ghPages());
});
/**
* Full deploy cycle.
*/
gulp.task('deploy', function (cb) {
runSequence(
'clean',
'build',
'ghpages',
cb);
});
gulp.task('test', ['lint', 'bootlint']);
gulp.task('default', ['test', 'serve']);