-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (133 loc) · 4.07 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
const fs = require('fs')
const spawn = require('child_process').spawn
const {resolve} = require('path')
const endOfLine = require('os').EOL
const gulp = require('gulp')
const download = require('gulp-download')
const unzip = require('gulp-unzip')
const sequence = require('run-sequence')
const clean = require('gulp-clean')
const {merge} = require('event-stream')
const TEMP_DIR = resolve('./temp')
const DIST_DIR = resolve('./')
const SRC_DIR = resolve('./src')
gulp.task('pre-clean', () => {
const args = [TEMP_DIR, resolve('./fonts'), resolve('./themes'), resolve('./semantic.min.css')]
return gulp.src(args, {read: false})
.pipe(clean())
})
gulp.task('download-sem', () => {
return download('https://github.com/Semantic-Org/Semantic-UI/archive/master.zip')
.pipe(gulp.dest(resolve(TEMP_DIR)))
})
gulp.task('unzip-sem', () => {
return gulp.src(resolve('./temp/master.zip'))
.pipe(unzip())
.pipe(gulp.dest(TEMP_DIR))
})
gulp.task('npm-is-garbage-use-yarn', () => {
return gulp.src(resolve(`${TEMP_DIR}/Semantic-UI-master/package-lock.json`), {read: false})
.pipe(clean())
})
gulp.task('install-sem', done => {
const projectDir = resolve(`${TEMP_DIR}/Semantic-UI-master`)
const args = ['--prefix', projectDir, 'install', projectDir, '--ignore-scripts', '--unsafe-perm=true']
spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', args, {
cwd: process.cwd(),
stdio: 'inherit'
}).on('exit', (code, signal) => {
if (code === 0) {
return done()
}
return done(code, signal)
}).on('error', done)
})
gulp.task('install-sem-gulp', done => {
const projectDir = resolve(`${TEMP_DIR}/Semantic-UI-master`)
const args = ['--gulpfile', `${projectDir}/gulpfile.js`, '--cwd', projectDir, 'install']
const gulpProcess = spawn(/^win/.test(process.platform) ? 'gulp.cmd' : 'gulp', args, {
cwd: process.cwd()
}).on('exit', (code, signal) => {
if (code === 0) {
return done()
}
return done(code, signal)
}).on('error', done)
gulpProcess.stdout.on('data', () => gulpProcess.stdin.write(endOfLine))
})
gulp.task('set-google-fonts-false', done => {
const importFile = resolve(`${TEMP_DIR}/Semantic-UI-master/src/site/globals/site.variables`)
fs.access(importFile, fs.constants.W_OK, err => {
if (err) {
return done(`${err} is not writable`)
}
fs.appendFile(importFile, `${endOfLine}@importGoogleFonts: false;${endOfLine}`, error => {
if (error) {
return done(err)
}
return done()
})
})
})
gulp.task('set-fonts-extension', done => {
const importFile = resolve(`${TEMP_DIR}/Semantic-UI-master/src/site/globals/site.overrides`)
const cssFile = resolve('./src/fontsExtension.css')
fs.access(importFile, fs.constants.W_OK, err => {
if (err) {
return done(`${err} is not writable`)
}
fs.readFile(cssFile, 'utf-8', (error, data) => {
if (error) {
return done(`${error} is not readable`)
}
fs.appendFile(importFile, `${endOfLine}${data}${endOfLine}`, erro => {
if (erro) {
return done(erro)
}
return done()
})
})
})
})
gulp.task('build-sem', done => {
const projectDir = resolve(`${TEMP_DIR}/Semantic-UI-master`)
const args = ['--gulpfile', `${projectDir}/gulpfile.js`, '--cwd', projectDir, 'build']
spawn(/^win/.test(process.platform) ? 'gulp.cmd' : 'gulp', args, {
cwd: process.cwd()
}).on('exit', (code, signal) => {
if (code === 0) {
return done()
}
return done(code, signal)
}).on('error', done)
})
gulp.task('build-dist', done => {
const projectDir = resolve(`${TEMP_DIR}/Semantic-UI-master`)
return merge(
gulp.src(`${projectDir}/dist/themes/**/*`)
.pipe(gulp.dest(`${DIST_DIR}/themes`)),
gulp.src(`${projectDir}/dist/semantic.min.css`)
.pipe(gulp.dest(`${DIST_DIR}/`)),
gulp.src(`${SRC_DIR}/fonts/**/*`)
.pipe(gulp.dest(`${DIST_DIR}/fonts`))
)
})
gulp.task('clean', () => {
return gulp.src(TEMP_DIR, {read: false})
.pipe(clean())
})
gulp.task('default', done => {
return sequence(
'pre-clean',
'download-sem',
'unzip-sem',
'npm-is-garbage-use-yarn',
'install-sem',
'install-sem-gulp',
'set-google-fonts-false',
'set-fonts-extension',
'build-sem',
'build-dist',
'clean',
done)
})