forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
113 lines (95 loc) · 2.92 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
const fs = require('fs')
const utils = require('util')
const cp = require('child_process')
const exec = utils.promisify(cp.exec)
const path = require('path')
const gulp = require('gulp')
const cleanCSS = require('gulp-clean-css')
const del = require('del')
const outputPath = path.join(__dirname, 'static')
const resourcesPath = path.join(__dirname, 'resources')
const publicStaticPath = path.join(__dirname, 'public/static')
const sourcePath = path.join(__dirname, 'src/main/frontend')
const resourceFilePath = path.join(resourcesPath, '**')
const outputFilePath = path.join(outputPath, '**')
const css = {
watchCSS () {
return cp.spawn(`yarn css:watch`, {
shell: true,
stdio: 'inherit'
})
},
buildCSS (...params) {
return gulp.series(
() => exec(`yarn css:build`, {}),
css._optimizeCSSForRelease
)(...params)
},
_optimizeCSSForRelease () {
return gulp.src(path.join(outputPath, 'css', 'style.css'))
.pipe(cleanCSS())
.pipe(gulp.dest(path.join(outputPath, 'css')))
}
}
const common = {
clean () {
return del(['./static/**/*', '!./static/yarn.lock', '!./static/node_modules'])
},
syncResourceFile () {
return gulp.src(resourceFilePath).pipe(gulp.dest(outputPath))
},
keepSyncResourceFile () {
return gulp.watch(resourceFilePath, { ignoreInitial: true }, common.syncResourceFile)
},
syncStatic () {
return gulp.src([
outputFilePath,
'!' + path.join(outputPath, 'node_modules/**')
]).pipe(gulp.dest(publicStaticPath))
},
keepSyncStatic () {
return gulp.watch([
path.join(outputPath, 'js/**'),
path.join(outputPath, 'css/**')
], { ignoreInitial: true }, common.syncStatic)
}
}
exports.electron = () => {
if (!fs.existsSync(path.join(outputPath, 'node_modules'))) {
cp.execSync('yarn', {
cwd: outputPath,
stdio: 'inherit'
})
}
cp.execSync('yarn electron:dev', {
cwd: outputPath,
stdio: 'inherit'
})
}
exports.electronMaker = async () => {
cp.execSync('yarn cljs:release-electron', {
stdio: 'inherit'
})
const pkgPath = path.join(outputPath, 'package.json')
const pkg = require(pkgPath)
const version = fs.readFileSync(path.join(__dirname, 'src/main/frontend/version.cljs'))
.toString().match(/[0-9.]{3,}/)[0]
if (!version) {
throw new Error('release version error in src/**/*/version.cljs')
}
pkg.version = version
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
if (!fs.existsSync(path.join(outputPath, 'node_modules'))) {
cp.execSync('yarn', {
cwd: outputPath,
stdio: 'inherit'
})
}
cp.execSync('yarn electron:make', {
cwd: outputPath,
stdio: 'inherit'
})
}
exports.clean = common.clean
exports.watch = gulp.series(common.syncResourceFile, common.syncStatic, gulp.parallel(common.keepSyncResourceFile, css.watchCSS, common.keepSyncStatic))
exports.build = gulp.series(common.clean, common.syncResourceFile, css.buildCSS)