logseq/gulpfile.js

188 lines
5.3 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 ip = require('ip')
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 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')))
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))
},
// NOTE: All assets from node_modules are copied to the output directory
syncAssetFiles (...params) {
return gulp.series(
() => gulp.src([
'./node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**',
'!**/*/i18n-*.js'
])
.pipe(gulp.dest(path.join(outputPath, 'js', 'excalidraw-assets'))),
() => gulp.src('node_modules/katex/dist/katex.min.js')
.pipe(gulp.dest(path.join(outputPath, 'js'))),
2023-06-29 07:54:28 +00:00
() => gulp.src('node_modules/html2canvas/dist/html2canvas.min.js')
.pipe(gulp.dest(path.join(outputPath, 'js'))),
() => gulp.src('node_modules/@tabler/icons/iconfont/tabler-icons.min.css')
.pipe(gulp.dest(path.join(outputPath, 'css'))),
2023-06-29 07:54:28 +00:00
() => gulp.src('node_modules/inter-ui/Inter (web)/*.*')
.pipe(gulp.dest(path.join(outputPath, 'fonts', 'inter'))),
() => gulp.src([
'node_modules/@tabler/icons/iconfont/fonts/**',
'node_modules/katex/dist/fonts/*.woff2'
])
.pipe(gulp.dest(path.join(outputPath, 'css', 'fonts'))),
)(...params)
},
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)
},
2022-09-01 13:17:43 +00:00
async runCapWithLocalDevServerEntry (cb) {
const mode = process.env.PLATFORM || 'ios'
const IP = ip.address()
const LOGSEQ_APP_SERVER_URL = `http://${IP}:3001`
2022-09-01 04:20:57 +00:00
if (typeof global.fetch === 'function') {
try {
await fetch(LOGSEQ_APP_SERVER_URL)
} catch (e) {
return cb(new Error(`/* ❌ Please check if the service is ON. (${LOGSEQ_APP_SERVER_URL}) ❌ */`))
}
}
console.log(`------ Cap ${mode.toUpperCase()} -----`)
console.log(`Dev serve at: ${LOGSEQ_APP_SERVER_URL}`)
console.log(`--------------------------------------`)
cp.execSync(`npx cap sync ${mode}`, {
stdio: 'inherit',
env: Object.assign(process.env, {
LOGSEQ_APP_SERVER_URL
})
})
Feat: sync progress for electron (#6662) * fix: state shouldn't be returned in ipc * feat: download && upload processing * enhance(ui): interaction of show password checkbox * feat: time left * feat: download progress * Set download batch size to 100 * improve(ui): progress pane of file sync indicator * improve(ui): progress pie of each file state * improve(ui): progress pie of each file state * improve(ui): progress pie of each downloading file * fix: add last changed time * enhance: time left * fix: total needs to be larger than finished * fix: wait for update-graphs-txid! * enhance: show in-progress files first * chore: ui polish * improve(ui): persist stauts of sync files list toggle switch * fix(ui): visibility of sync now button on mobile * chore: remove ios static out after sync * fix: debounce clicking on sync icon * fix: repos not refreshed after unlink or delete * enhance: automatically save page-metadata.edn to avoid sync when restart * improve(ui): sync now shortcut for file sync progress pane * enhance: data transfer icons * fix: stop sync if switched to another graph * fix: can't switch * enhance: sort files first before uploading or downloading * fix: clear current graph uuid when sync stops * fix: separate progress by graphs * fix: check files only in the current progress * fix: prevent multiple sync managers for the same graph * fix: remove redundant files watchers * enhance(sync): re-exec remote->local-full-sync when exception re-exec remote->local-full-sync when <update-local-files return exceptions * enhance(sync): re-exec remote->local-full-sync when exception re-exec remote->local-full-sync when <update-local-files return exceptions * fix(sync): set-progress-callback, update rsapi * fix(sync): uploading progress bar Co-authored-by: Tienson Qin <tiensonqin@gmail.com> Co-authored-by: charlie <xyhp915@qq.com> Co-authored-by: rcmerci <rcmerci@gmail.com>
2022-09-22 18:00:24 +00:00
cp.execSync(`rm -rf ios/App/App/public/static/out`, {
stdio: 'inherit'
})
cp.execSync(`npx cap run ${mode} --external`, {
stdio: 'inherit',
env: Object.assign(process.env, {
LOGSEQ_APP_SERVER_URL
})
})
cb()
}
}
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'
})
}
2022-09-01 13:17:43 +00:00
exports.cap = common.runCapWithLocalDevServerEntry
exports.clean = common.clean
exports.watch = gulp.series(common.syncResourceFile, common.syncAssetFiles, common.syncAllStatic,
gulp.parallel(common.keepSyncResourceFile, css.watchCSS))
exports.build = gulp.series(common.clean, common.syncResourceFile, common.syncAssetFiles, css.buildCSS)