2020-03-28 18:52:12 +03:00
|
|
|
const express = require('express')
|
|
|
|
const cors = require('cors')
|
|
|
|
const app = express()
|
|
|
|
app.use(cors())
|
|
|
|
app.use(express.json())
|
|
|
|
const port = 7000
|
|
|
|
let appPid
|
|
|
|
|
|
|
|
app.post('/reply', (req, res) => {
|
|
|
|
if (req.body && req.body.msg !== 'TEST') {
|
|
|
|
throw new Error(`unexpected reply ${JSON.stringify(req.body)}`)
|
|
|
|
}
|
|
|
|
console.log('App event replied')
|
|
|
|
exit(0)
|
|
|
|
})
|
|
|
|
|
2020-08-19 05:36:46 +03:00
|
|
|
const server = app.listen(port, () =>
|
|
|
|
console.log(`Test listening on port ${port}!`)
|
|
|
|
)
|
2020-03-28 18:52:12 +03:00
|
|
|
|
2020-08-19 05:36:46 +03:00
|
|
|
const exit = (code) => {
|
2020-03-28 18:52:12 +03:00
|
|
|
server.close()
|
|
|
|
process.kill(appPid)
|
|
|
|
process.exit(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = require('path')
|
|
|
|
const dist = path.resolve(__dirname, 'dist')
|
|
|
|
|
2021-04-12 07:59:25 +03:00
|
|
|
const build = require('../tooling/cli.js/dist/api/build')
|
2020-03-28 18:52:12 +03:00
|
|
|
build({
|
|
|
|
build: {
|
|
|
|
devPath: dist
|
|
|
|
},
|
|
|
|
ctx: {
|
|
|
|
debug: true
|
|
|
|
}
|
|
|
|
}).then(() => {
|
2021-04-12 07:59:25 +03:00
|
|
|
const spawn = require('../tooling/cli.js/dist/helpers/spawn').spawn
|
2020-03-28 18:52:12 +03:00
|
|
|
const artifactPath = path.resolve(__dirname, 'src-tauri/target/debug/app')
|
|
|
|
appPid = spawn(
|
2020-08-19 05:36:46 +03:00
|
|
|
process.platform === 'win32'
|
|
|
|
? `${artifactPath}.exe`
|
|
|
|
: artifactPath.replace('debug/app', 'debug/./app'),
|
2020-03-28 18:52:12 +03:00
|
|
|
[],
|
|
|
|
null
|
|
|
|
)
|
|
|
|
|
|
|
|
// if it didn't reply, throw an error
|
|
|
|
setTimeout(() => {
|
|
|
|
throw new Error("App didn't reply")
|
|
|
|
}, 2000)
|
|
|
|
})
|