This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
162 lines (147 loc) · 3.68 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
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
const babel = require("gulp-babel");
const sourcemaps = require("gulp-sourcemaps");
const jasmineBrowser = require('gulp-jasmine-browser');
const order = require("gulp-order");
const browserSync = require("browser-sync").create();
//copies the html to the disribution folder
function copyHtml()
{
return gulp
.src("index.html")
.pipe(gulp.dest("./dist"));
};
//copies the views to the distribution folder
function copyViews()
{
return gulp
.src("views/*")
.pipe(gulp.dest("./dist/views"));
}
//copies the images folder to the distribution folder
function copyImgs()
{
return gulp
.src("img/*")
.pipe(gulp.dest("dist/img"));
}
//sets gulp to add prefixes with Autoprefixer after Dreamweaver outputs the Sass filee to CSS
//once the prefixer finishes its job, outputs the file to the distribution folder
function styles()
{
return gulp
.src("css/*.css")
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest("./dist/css"));
}
//copies the fonts to the distribution folder
function copyFonts()
{
return gulp
.src("css/*.ttf")
.pipe(gulp.dest("./dist/css"));
}
function copyServiceWorker()
{
return gulp
.src("sw.js")
.pipe(gulp.dest("./dist"));
}
//deals with concating the scripts while in development mode
function scripts()
{
return gulp
.src("js/**/*.js")
.pipe(sourcemaps.init())
.pipe(babel({presets: ['@babel/preset-env']}))
.pipe(order([
"js/app.js",
"js/services/librarian.js",
"js/libraryCtrl.js",
"js/storyCtrl.js", "js/settingsCtrl.js"]))
.pipe(concat("all.js"))
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/js"));
}
//deals with concating the scripts while in production mode
function scriptsDist()
{
return gulp
.src("js/**/*/js")
.pipe(sourcemaps.init())
.pipe(babel({presets: ['@babel/preset-env']}))
.pipe(order([
"js/app.js",
"js/services/librarian.js",
"js/libraryCtrl.js",
"js/storyCtrl.js", "js/settingsCtrl.js"]))
.pipe(concat("all.js"))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/js"));
}
//automatic testing in the Jasmine headless browser
function jasmineBrowserTest()
{
return gulp
.src(["dist/js/all.js", "tests/specs.js"])
.pipe(jasmineBrowser.specRunner({ console: true }))
.pipe(jasmineBrowser.headless({ driver: "chrome" }));
}
//testing in whatever browser you want to use; just enter "localhost:3001" in the address line
function browserTests()
{
return gulp
.src(["dist/js/all.js", "tests/specs.js"])
.pipe(jasmineBrowser.specRunner())
.pipe(jasmineBrowser.server({ port: 3001 }));
}
//prepare for distribution
function dist()
{
return gulp
.parallel(
copyHtml,
copyViews,
copyImgs,
copyFonts,
styles,
scriptsDist
);
}
//boot up the server
gulp.task("serve", function() {
browserSync.init({
server: {
baseDir: "./"
}
});
});
//watch files for changes
function watchFiles()
{
gulp.watch('/index.html', copyHtml);
gulp.watch('views/*', copyViews);
gulp.watch('img/*', copyImgs);
gulp.watch('css/*.css', styles);
gulp.watch('css/*.ttf', copyFonts);
gulp.watch('js/**/*.js', scripts);
gulp.watch('/sw.js', copyServiceWorker);
}
//exports for gulp to recognise them as tasks
exports.copyHtml = copyHtml;
exports.copyViews = copyViews;
exports.copyImgs = copyImgs;
exports.styles = styles;
exports.copyFonts = copyFonts;
exports.copyServiceWorker = copyServiceWorker;
exports.scripts = scripts;
exports.scriptsDist = scriptsDist;
exports.jasmineBrowserTest = jasmineBrowserTest;
exports.browserTests = browserTests;
exports.dist = dist;
exports.watchFiles = watchFiles;