2020-12-17 07:38:03 +00:00
|
|
|
const fs = require('fs')
|
2021-03-18 11:46:39 +00:00
|
|
|
const utils = require('util')
|
2021-01-21 04:11:02 +00:00
|
|
|
const cp = require('child_process')
|
2021-03-18 11:46:39 +00:00
|
|
|
const exec = utils.promisify(cp.exec)
|
2020-10-30 07:58:42 +00:00
|
|
|
const path = require('path')
|
2020-10-29 11:14:27 +00:00
|
|
|
const gulp = require('gulp')
|
|
|
|
const cleanCSS = require('gulp-clean-css')
|
2020-10-30 07:58:42 +00:00
|
|
|
const del = require('del')
|
|
|
|
|
|
|
|
const outputPath = path.join(__dirname, 'static')
|
|
|
|
const resourcesPath = path.join(__dirname, 'resources')
|
2020-12-15 08:08:13 +00:00
|
|
|
const sourcePath = path.join(__dirname, 'src/main/frontend')
|
2020-10-30 07:58:42 +00:00
|
|
|
const resourceFilePath = path.join(resourcesPath, '**')
|
2020-10-29 11:14:27 +00:00
|
|
|
|
2020-10-30 07:58:42 +00:00
|
|
|
const css = {
|
2021-03-18 11:46:39 +00:00
|
|
|
watchCSS () {
|
2021-03-20 09:37:08 +00:00
|
|
|
return cp.spawn(`yarn css:watch`, {
|
|
|
|
shell: true,
|
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
2020-10-30 07:58:42 +00:00
|
|
|
},
|
2020-10-29 11:14:27 +00:00
|
|
|
|
2020-12-15 08:08:13 +00:00
|
|
|
buildCSS (...params) {
|
2020-12-21 01:26:51 +00:00
|
|
|
return gulp.series(
|
2021-03-18 11:46:39 +00:00
|
|
|
() => exec(`yarn css:build`, {}),
|
2021-03-19 12:54:46 +00:00
|
|
|
css._optimizeCSSForRelease
|
2021-03-19 04:23:58 +00:00
|
|
|
)(...params)
|
2020-10-30 07:58:42 +00:00
|
|
|
},
|
|
|
|
|
2020-12-15 08:08:13 +00:00
|
|
|
_optimizeCSSForRelease () {
|
2020-10-30 07:58:42 +00:00
|
|
|
return gulp.src(path.join(outputPath, 'css', 'style.css'))
|
|
|
|
.pipe(cleanCSS())
|
2020-11-02 08:33:07 +00:00
|
|
|
.pipe(gulp.dest(path.join(outputPath, 'css')))
|
2021-03-19 04:23:58 +00:00
|
|
|
}
|
2020-10-29 11:14:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 07:58:42 +00:00
|
|
|
const common = {
|
2020-12-15 08:08:13 +00:00
|
|
|
clean () {
|
2021-01-21 04:11:02 +00:00
|
|
|
return del(['./static/**/*', '!./static/yarn.lock', '!./static/node_modules'])
|
2020-10-30 07:58:42 +00:00
|
|
|
},
|
|
|
|
|
2020-12-15 08:08:13 +00:00
|
|
|
syncResourceFile () {
|
2020-10-30 07:58:42 +00:00
|
|
|
return gulp.src(resourceFilePath).pipe(gulp.dest(outputPath))
|
|
|
|
},
|
|
|
|
|
2020-12-15 08:08:13 +00:00
|
|
|
keepSyncResourceFile () {
|
2021-03-19 04:23:58 +00:00
|
|
|
return gulp.watch(resourceFilePath, { ignoreInitial: true }, common.syncResourceFile)
|
2020-10-30 07:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 11:14:27 +00:00
|
|
|
|
2021-01-21 04:11:02 +00:00
|
|
|
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'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-28 15:00:36 +00:00
|
|
|
exports.electronMaker = async () => {
|
2021-03-16 15:01:46 +00:00
|
|
|
cp.execSync('yarn cljs:release', {
|
2021-01-28 07:57:42 +00:00
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
|
|
|
|
2021-01-28 15:00:36 +00:00
|
|
|
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))
|
|
|
|
|
2021-01-28 07:57:42 +00:00
|
|
|
if (!fs.existsSync(path.join(outputPath, 'node_modules'))) {
|
|
|
|
cp.execSync('yarn', {
|
|
|
|
cwd: outputPath,
|
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
cp.execSync('yarn electron:make', {
|
|
|
|
cwd: outputPath,
|
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-30 07:58:42 +00:00
|
|
|
exports.clean = common.clean
|
2021-03-19 04:23:58 +00:00
|
|
|
exports.watch = gulp.series(common.syncResourceFile, gulp.parallel(common.keepSyncResourceFile, css.watchCSS))
|
2020-12-17 07:38:03 +00:00
|
|
|
exports.build = gulp.series(common.clean, common.syncResourceFile, css.buildCSS)
|