-
Notifications
You must be signed in to change notification settings - Fork 60
/
gulpfile.js
153 lines (123 loc) · 3.5 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
const {series, parallel, src, dest} = require('gulp')
const rename = require('gulp-rename')
const babel = require('gulp-babel')
const concat = require('gulp-concat')
const replace = require('gulp-replace')
const uglify = require('gulp-uglify')
const postcss = require('gulp-postcss')
const cleancss = require('gulp-clean-css')
/* Destination dir */
const destDir = './dist'
/* JS. Transpile with babel & minify */
const processJs = (baseName, isMin) => {
let r = src('src/js/' + baseName + '.js')
.pipe(babel({
presets: ['@babel/env']
}))
if (isMin) {
r = r.pipe(uglify()).pipe(rename(baseName + '.min.js'))
}
return r.pipe(dest(destDir + '/js'))
}
const processJsMain = () => {
return processJs('main')
}
const processJsMainMin = () => {
return processJs('main', true)
}
const processJsChartSample = () => {
return processJs('chart.sample')
}
const processJsChartSampleMin = () => {
return processJs('chart.sample', true)
}
/* CSS */
const processCss = () => {
return src('src/css/main.css')
.pipe(postcss())
.pipe(cleancss())
.pipe(dest(destDir + '/css'))
}
/* HTML */
const dateNowMillis = Date.now()
const concatHtml = file => {
let replaceHtmlClassWith = ''
const formScreenFiles = ['login']
if (formScreenFiles.indexOf(file) > -1) {
replaceHtmlClassWith = 'form-screen'
}
const sources = [
'src/html/parts/head.html',
'src/html/parts/app-open.html'
]
if (formScreenFiles.indexOf(file) < 0) {
sources.push(
'src/html/parts/navbar.html',
'src/html/parts/aside.html',
'src/html/parts/title-bar.html',
'src/html/parts/hero-bar.html'
)
}
sources.push(`src/html/${file}.html`)
if (formScreenFiles.indexOf(file) < 0) {
sources.push(
'src/html/parts/footer.html',
'src/html/parts/sample-modal.html'
)
}
sources.push(
'src/html/parts/app-close.html',
'src/html/parts/bottom-scripts.html'
)
if (file === 'index') {
sources.push('src/html/parts/bottom-scripts-home.html')
}
sources.push('src/html/parts/bottom.html')
const titleStrings = {
tables: 'Tables',
index: 'Dashboard',
forms: 'Forms',
profile: 'Profile',
login: 'Login'
}
const titleStringsLong = {
tables: 'Responsive Tables'
}
const titleStringReplacement = titleStrings[file] ? titleStrings[file] : ''
const titleStringLongReplacement = titleStringsLong[file] ? titleStringsLong[file] : titleStringReplacement
return src(sources)
.pipe(concat(`${file}.html`))
.pipe(replace('--date-now-millis', dateNowMillis.toString()))
.pipe(replace('--html-class', replaceHtmlClassWith))
.pipe(replace('--stylesheet-min-path', `css/main.css?v=${dateNowMillis.toString()}`))
.pipe(replace(`--set-active-${file}-html`, 'active'))
.pipe(replace(/ --set-active-[a-z-]+/gi, ''))
.pipe(replace('{{ titleString }}', titleStringReplacement))
.pipe(replace('{{ titleStringLong }}', titleStringLongReplacement))
.pipe(dest(destDir))
}
/* Img */
const copyImg = () => {
return src('src/img/*')
.pipe(dest(destDir + '/img'))
}
const copyTailwindFavicons = () => {
return src('src/tailwind-favicons/*')
.pipe(dest(destDir))
}
exports.default = series(
parallel(
() => concatHtml('index'),
() => concatHtml('tables'),
() => concatHtml('forms'),
() => concatHtml('profile'),
() => concatHtml('login'),
processJsMain,
processJsMainMin,
processJsChartSample,
processJsChartSampleMin,
copyImg,
copyTailwindFavicons,
),
processCss
)