-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
177 lines (147 loc) · 4.14 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
165
166
167
168
169
170
171
172
173
174
175
176
177
const { src, dest, parallel, series } = require('gulp');
const gulp = require('gulp');
const bs = require('browser-sync').create(); // create a browser sync instance.
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const cleanCSS = require('gulp-clean-css');
const babel = require('gulp-babel');
const clean = require('gulp-clean');
const nunjucks = require('gulp-nunjucks');
var argv = require('yargs').argv;
const nunjucks_lib = require('nunjucks');
function browserSyncHome() {
bs.init({
server: {
baseDir: "./build"
}
});
}
function bsReload() {
bs.reload();
}
function css() {
return src('scss/*.scss')
.pipe(sass())
.pipe(cleanCSS())
.pipe(dest('build'))
.pipe(bs.stream())
}
function js() {
return src('js/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(concat('jsmain.js'))
.pipe(dest('build'))
.pipe(bs.stream())
}
function html(){
return src('index.html')
.pipe(nunjucks.compile())
.pipe(dest('build'))
.pipe(bs.stream())
}
function readme(){
return src('README.md')
.pipe(dest('build'))
.pipe(bs.stream())
}
function data() {
return src('data/*')
.pipe(dest('build/data'))
.pipe(bs.stream())
}
function cleanify() {
return src('build', {read: false})
.pipe(clean());
}
function res() {
return src('res/*')
.pipe(dest('build/res'))
}
function imgs() {
return src('res/imgs/*')
.pipe(dest('build/res/imgs'))
}
function watchHome() {
gulp.watch("./scss/*", css);
gulp.watch("./js/*", js);
gulp.watch("./*.html", html);
gulp.watch("./data/*", data);
gulp.watch("./res/*", res);
gulp.watch("./res/imgs/*", imgs);
}
const watch = gulp.parallel(watchHome, browserSyncHome);
const build = gulp.series(gulp.parallel(css, html, js, data, res, imgs, readme));
const storyLocation = argv.story;
const storyURL = 'https://numbersofindia.github.io/'+storyLocation;
console.log("storyLocation", storyLocation);
console.log("storyURL", storyURL);
function browserSyncStory() {
bs.init({
server: {
baseDir: "./build"
}
});
}
function bsReload() {
bs.reload();
}
function cssStory() {
return src(storyLocation+'scss/*.scss')
.pipe(sass())
.pipe(cleanCSS())
.pipe(dest('build/'+storyLocation))
.pipe(bs.stream())
}
function jsStory() {
return src(storyLocation+'js/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(concat('jsmain.js'))
.pipe(dest('build/'+storyLocation))
.pipe(bs.stream())
}
function htmlStory(){
// console.log('dirnme',__dirname);
// nunjucks.configure('./html-templates');
return src(storyLocation+'index.html')
.pipe(nunjucks.compile({url:storyURL},{
env: new nunjucks_lib.Environment(new nunjucks_lib.FileSystemLoader('./html-templates'))
}))
.pipe(dest('build/'+storyLocation))
.pipe(bs.stream())
}
function dataStory() {
return src(storyLocation+'data/*')
.pipe(dest('build/'+storyLocation+'data'))
.pipe(bs.stream())
}
function cleanifyStory() {
return src('build/'+storyLocation, {read: false})
.pipe(clean());
}
function resStory() {
return src(storyLocation+'res/*')
.pipe(dest('build/'+storyLocation+'res'))
}
function watchStory() {
gulp.watch(storyLocation+"scss/*", cssStory);
gulp.watch(storyLocation+"js/*", jsStory);
gulp.watch(storyLocation+"*.html", htmlStory);
gulp.watch(storyLocation+"data/*", dataStory);
gulp.watch(storyLocation+"res/*", resStory);
}
const watchstory = gulp.parallel(watchStory, browserSyncStory);
const buildstory = gulp.parallel(cssStory, htmlStory, jsStory, dataStory, resStory);
const cleanifystory = gulp.parallel(cleanifyStory);
exports.watch = watch;
exports.bsReload = bsReload;
exports.watchstory = watchstory;
exports.buildstory = buildstory;
exports.cleanifystory = cleanifystory;
exports.default = build;