logseq/gulpfile.js

124 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-12-17 07:38:03 +00:00
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')
2021-09-10 08:39:35 +00:00
const publicStaticPath = path.join(__dirname, 'public/static')
const sourcePath = path.join(__dirname, 'src/main/frontend')
const resourceFilePath = path.join(resourcesPath, '**')
2021-09-10 08:39:35 +00:00
const outputFilePath = path.join(outputPath, '**')
const css = {
watchCSS () {
return cp.spawn(`yarn css:watch`, {
shell: true,
stdio: 'inherit'
})
},
buildCSS (...params) {
return cp.spawn(`yarn css:build`, {
shell: true,
stdio: 'inherit'
})
2021-03-19 04:23:58 +00:00
}
}
const common = {
clean () {
return del(['./static/**/*', '!./static/yarn.lock', '!./static/node_modules'])
},
syncResourceFile () {
return gulp.src(resourceFilePath).pipe(gulp.dest(outputPath))
},
syncAssetFiles () {
return gulp.src([
"./node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**",
"!**/*/i18n-*.js"
])
.pipe(gulp.dest(path.join(outputPath, 'js', 'excalidraw-assets')))
},
keepSyncResourceFile () {
return gulp.watch(resourceFilePath, { ignoreInitial: true }, common.syncResourceFile)
2021-09-10 08:39:35 +00:00
},
syncAllStatic () {
2021-10-18 11:15:03 +00:00
return gulp.src([
outputFilePath,
'!' + path.join(outputPath, 'node_modules/**')
]).pipe(gulp.dest(publicStaticPath))
2021-09-10 08:39:35 +00:00
},
syncJS_CSSinRt () {
return gulp.src([
path.join(outputPath, 'js/**'),
path.join(outputPath, 'css/**')
], { base: outputPath }).pipe(gulp.dest(publicStaticPath))
},
keepSyncStaticInRt () {
2021-10-18 11:15:03 +00:00
return gulp.watch([
path.join(outputPath, 'js/**'),
path.join(outputPath, 'css/**')
], { ignoreInitial: true }, common.syncJS_CSSinRt)
}
}
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.syncAssetFiles, common.syncAllStatic,
gulp.parallel(common.keepSyncResourceFile, css.watchCSS, common.keepSyncStaticInRt))
exports.build = gulp.series(common.clean, common.syncResourceFile, common.syncAssetFiles, css.buildCSS)