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')
|
2022-09-01 04:16:45 +00:00
|
|
|
const ip = require('ip')
|
2020-10-30 07:58:42 +00:00
|
|
|
|
|
|
|
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')
|
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, '**')
|
2021-09-10 08:39:35 +00:00
|
|
|
const outputFilePath = path.join(outputPath, '**')
|
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) {
|
2022-02-18 15:02:24 +00:00
|
|
|
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
|
|
|
}
|
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))
|
|
|
|
},
|
|
|
|
|
2022-03-10 16:13:37 +00:00
|
|
|
// NOTE: All assets from node_modules are copied to the output directory
|
|
|
|
syncAssetFiles (...params) {
|
|
|
|
return gulp.series(
|
|
|
|
() => gulp.src([
|
2022-09-01 04:16:45 +00:00
|
|
|
'./node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**',
|
|
|
|
'!**/*/i18n-*.js'
|
2023-07-03 09:39:32 +00:00
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'js', 'excalidraw-assets'))),
|
|
|
|
() => gulp.src([
|
|
|
|
'node_modules/katex/dist/katex.min.js',
|
2023-07-21 12:27:43 +00:00
|
|
|
'node_modules/katex/dist/contrib/mhchem.min.js',
|
2023-07-03 09:39:32 +00:00
|
|
|
'node_modules/html2canvas/dist/html2canvas.min.js',
|
|
|
|
'node_modules/interactjs/dist/interact.min.js',
|
2023-07-21 11:19:51 +00:00
|
|
|
'node_modules/photoswipe/dist/umd/*.js',
|
2023-07-21 11:40:30 +00:00
|
|
|
'node_modules/reveal.js/dist/reveal.js',
|
2023-07-26 08:35:35 +00:00
|
|
|
'node_modules/shepherd.js/dist/js/shepherd.min.js',
|
2023-07-26 09:01:00 +00:00
|
|
|
'node_modules/marked/marked.min.js',
|
2023-07-26 11:09:44 +00:00
|
|
|
'node_modules/@highlightjs/cdn-assets/highlight.min.js',
|
2023-07-27 08:26:34 +00:00
|
|
|
'node_modules/@isomorphic-git/lightning-fs/dist/lightning-fs.min.js',
|
2023-11-16 07:26:51 +00:00
|
|
|
'packages/amplify/dist/amplify.js',
|
2024-01-26 10:29:53 +00:00
|
|
|
'packages/ui/dist/ui.js',
|
2023-12-10 12:13:45 +00:00
|
|
|
'node_modules/@logseq/sqlite-wasm/sqlite-wasm/jswasm/sqlite3.wasm',
|
2023-07-03 09:39:32 +00:00
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'js'))),
|
2023-07-26 16:58:47 +00:00
|
|
|
() => gulp.src([
|
|
|
|
'node_modules/pdfjs-dist/build/pdf.js',
|
|
|
|
'node_modules/pdfjs-dist/build/pdf.worker.js',
|
|
|
|
'node_modules/pdfjs-dist/web/pdf_viewer.js'
|
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'js', 'pdfjs'))),
|
|
|
|
() => gulp.src([
|
|
|
|
'node_modules/pdfjs-dist/cmaps/*.*',
|
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'js', 'pdfjs', 'cmaps'))),
|
2023-07-03 09:39:32 +00:00
|
|
|
() => gulp.src([
|
|
|
|
'node_modules/@tabler/icons/iconfont/tabler-icons.min.css',
|
2023-07-21 11:19:51 +00:00
|
|
|
'node_modules/inter-ui/inter.css',
|
|
|
|
'node_modules/reveal.js/dist/theme/fonts/source-sans-pro/**',
|
2023-07-03 09:39:32 +00:00
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'css'))),
|
2023-06-29 07:54:28 +00:00
|
|
|
() => gulp.src('node_modules/inter-ui/Inter (web)/*.*')
|
2023-06-29 08:22:00 +00:00
|
|
|
.pipe(gulp.dest(path.join(outputPath, 'css', 'Inter (web)'))),
|
2023-06-21 10:07:15 +00:00
|
|
|
() => gulp.src([
|
|
|
|
'node_modules/@tabler/icons/iconfont/fonts/**',
|
|
|
|
'node_modules/katex/dist/fonts/*.woff2'
|
2023-07-03 09:41:18 +00:00
|
|
|
]).pipe(gulp.dest(path.join(outputPath, 'css', 'fonts'))),
|
2022-03-10 16:13:37 +00:00
|
|
|
)(...params)
|
2022-02-18 01:56:39 +00:00
|
|
|
},
|
|
|
|
|
2020-12-15 08:08:13 +00:00
|
|
|
keepSyncResourceFile () {
|
2022-01-18 08:50:02 +00:00
|
|
|
return gulp.watch(resourceFilePath, { ignoreInitial: true }, common.syncResourceFile)
|
2021-09-10 08:39:35 +00:00
|
|
|
},
|
|
|
|
|
2021-12-27 09:09: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
|
|
|
},
|
|
|
|
|
2021-12-27 09:09: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/**')
|
2022-01-18 08:50:02 +00:00
|
|
|
], { ignoreInitial: true }, common.syncJS_CSSinRt)
|
2022-09-01 04:16:45 +00:00
|
|
|
},
|
|
|
|
|
2022-09-01 13:17:43 +00:00
|
|
|
async runCapWithLocalDevServerEntry (cb) {
|
2022-09-01 04:16:45 +00:00
|
|
|
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') {
|
2022-09-01 04:16:45 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-09-22 18:00:24 +00:00
|
|
|
cp.execSync(`rm -rf ios/App/App/public/static/out`, {
|
|
|
|
stdio: 'inherit'
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-09-01 04:16:45 +00:00
|
|
|
cp.execSync(`npx cap run ${mode} --external`, {
|
|
|
|
stdio: 'inherit',
|
|
|
|
env: Object.assign(process.env, {
|
|
|
|
LOGSEQ_APP_SERVER_URL
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cb()
|
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-11-18 07:41:35 +00:00
|
|
|
cp.execSync('yarn cljs:release-electron', {
|
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'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:17:43 +00:00
|
|
|
exports.cap = common.runCapWithLocalDevServerEntry
|
2020-10-30 07:58:42 +00:00
|
|
|
exports.clean = common.clean
|
2022-02-18 01:56:39 +00:00
|
|
|
exports.watch = gulp.series(common.syncResourceFile, common.syncAssetFiles, common.syncAllStatic,
|
2022-02-27 03:58:20 +00:00
|
|
|
gulp.parallel(common.keepSyncResourceFile, css.watchCSS))
|
2022-02-18 01:56:39 +00:00
|
|
|
exports.build = gulp.series(common.clean, common.syncResourceFile, common.syncAssetFiles, css.buildCSS)
|