mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-11-27 04:09:55 +01:00
7ef9ce9a4e
* Bump webpack-dev-server from 4.15.1 to 5.0.2 Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 4.15.1 to 5.0.2. - [Release notes](https://github.com/webpack/webpack-dev-server/releases) - [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md) - [Commits](https://github.com/webpack/webpack-dev-server/compare/v4.15.1...v5.0.2) --- updated-dependencies: - dependency-name: webpack-dev-server dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * ! Fix running `yarn dev` --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: PikachuEXE <git@pikachuexe.net>
168 lines
3.7 KiB
JavaScript
168 lines
3.7 KiB
JavaScript
process.env.NODE_ENV = 'development'
|
|
|
|
const electron = require('electron')
|
|
const webpack = require('webpack')
|
|
const WebpackDevServer = require('webpack-dev-server')
|
|
const kill = require('tree-kill')
|
|
|
|
const path = require('path')
|
|
const { spawn } = require('child_process')
|
|
|
|
let electronProcess = null
|
|
let manualRestart = null
|
|
|
|
const remoteDebugging = process.argv.indexOf('--remote-debug') !== -1
|
|
const web = process.argv.indexOf('--web') !== -1
|
|
|
|
let mainConfig
|
|
let rendererConfig
|
|
let webConfig
|
|
|
|
if (!web) {
|
|
mainConfig = require('./webpack.main.config')
|
|
rendererConfig = require('./webpack.renderer.config')
|
|
} else {
|
|
webConfig = require('./webpack.web.config')
|
|
}
|
|
|
|
if (remoteDebugging) {
|
|
// disable dvtools open in electron
|
|
process.env.RENDERER_REMOTE_DEBUGGING = true
|
|
}
|
|
|
|
// Define exit code for relaunch and set it in the environment
|
|
const relaunchExitCode = 69
|
|
process.env.FREETUBE_RELAUNCH_EXIT_CODE = relaunchExitCode
|
|
|
|
const port = 9080
|
|
|
|
async function killElectron(pid) {
|
|
return new Promise((resolve, reject) => {
|
|
if (pid) {
|
|
kill(pid, err => {
|
|
if (err) reject(err)
|
|
|
|
resolve()
|
|
})
|
|
} else {
|
|
resolve()
|
|
}
|
|
})
|
|
}
|
|
|
|
async function restartElectron() {
|
|
console.log('\nStarting electron...')
|
|
|
|
const { pid } = electronProcess || {}
|
|
await killElectron(pid)
|
|
|
|
electronProcess = spawn(electron, [
|
|
path.join(__dirname, '../dist/main.js'),
|
|
// '--enable-logging', // Enable to show logs from all electron processes
|
|
remoteDebugging ? '--inspect=9222' : '',
|
|
remoteDebugging ? '--remote-debugging-port=9223' : ''
|
|
],
|
|
// { stdio: 'inherit' } // required for logs to actually appear in the stdout
|
|
)
|
|
|
|
electronProcess.on('exit', (code, _) => {
|
|
if (code === relaunchExitCode) {
|
|
electronProcess = null
|
|
restartElectron()
|
|
return
|
|
}
|
|
|
|
if (!manualRestart) process.exit(0)
|
|
})
|
|
}
|
|
|
|
function startMain() {
|
|
const compiler = webpack(mainConfig)
|
|
const { name } = compiler
|
|
|
|
compiler.hooks.afterEmit.tap('afterEmit', async () => {
|
|
console.log(`\nCompiled ${name} script!`)
|
|
|
|
manualRestart = true
|
|
await restartElectron()
|
|
setTimeout(() => {
|
|
manualRestart = false
|
|
}, 2500)
|
|
|
|
console.log(`\nWatching file changes for ${name} script...`)
|
|
})
|
|
|
|
compiler.watch({
|
|
aggregateTimeout: 500,
|
|
},
|
|
err => {
|
|
if (err) console.error(err)
|
|
})
|
|
}
|
|
|
|
function startRenderer(callback) {
|
|
const compiler = webpack(rendererConfig)
|
|
const { name } = compiler
|
|
|
|
compiler.hooks.afterEmit.tap('afterEmit', () => {
|
|
console.log(`\nCompiled ${name} script!`)
|
|
console.log(`\nWatching file changes for ${name} script...`)
|
|
})
|
|
|
|
const server = new WebpackDevServer({
|
|
static: {
|
|
directory: path.join(process.cwd(), 'static'),
|
|
watch: {
|
|
ignored: [
|
|
/(dashFiles|storyboards)\/*/,
|
|
'/**/.DS_Store',
|
|
]
|
|
}
|
|
},
|
|
port
|
|
}, compiler)
|
|
|
|
server.startCallback(err => {
|
|
if (err) console.error(err)
|
|
|
|
callback()
|
|
})
|
|
}
|
|
|
|
function startWeb (callback) {
|
|
const compiler = webpack(webConfig)
|
|
const { name } = compiler
|
|
|
|
compiler.hooks.afterEmit.tap('afterEmit', () => {
|
|
console.log(`\nCompiled ${name} script!`)
|
|
console.log(`\nWatching file changes for ${name} script...`)
|
|
})
|
|
|
|
const server = new WebpackDevServer({
|
|
static: {
|
|
directory: path.join(process.cwd(), 'dist/web/static'),
|
|
watch: {
|
|
ignored: [
|
|
/(dashFiles|storyboards)\/*/,
|
|
'/**/.DS_Store',
|
|
]
|
|
}
|
|
},
|
|
port
|
|
}, compiler)
|
|
|
|
server.startCallback(err => {
|
|
if (err) console.error(err)
|
|
|
|
callback({ port: server.options.port })
|
|
})
|
|
}
|
|
if (!web) {
|
|
startRenderer(startMain)
|
|
} else {
|
|
startWeb(async ({ port }) => {
|
|
const open = (await import('open')).default
|
|
open(`http://localhost:${port}`)
|
|
})
|
|
}
|