You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
67 lines
2.1 KiB
6 years ago
|
const httpServer = require('http-server')
|
||
|
const remixd = require('remixd')
|
||
|
const path = require('path')
|
||
|
const merge = require('merge')
|
||
|
const colors = require('colors')
|
||
6 years ago
|
|
||
|
const DEFAULT_OPTIONS = {
|
||
6 years ago
|
protocol: 'http',
|
||
|
host: 'localhost',
|
||
|
port: '8088'
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
|
module.exports = (embark) => {
|
||
6 years ago
|
// plugin options
|
||
6 years ago
|
const readOnly = embark.pluginConfig.readOnly || false
|
||
5 years ago
|
const { protocol, host, port } = merge.recursive(DEFAULT_OPTIONS, embark.pluginConfig.remixIde)
|
||
6 years ago
|
|
||
|
// globals
|
||
6 years ago
|
const remixIdeUrl = `${protocol}://${host}` + `${port ? `:${port}` : ''}`
|
||
|
const sharedFolder = path.join(__dirname, '../../')
|
||
|
const sharedFolderService = remixd.services.sharedFolder
|
||
|
let server
|
||
7 years ago
|
|
||
6 years ago
|
// setup HTTP server
|
||
|
if (['localhost', '127.0.0.1', '0.0.0.0'].includes(host)) {
|
||
|
server = httpServer.createServer({
|
||
|
root: path.join(__dirname, '../../node_modules/remix-ide')
|
||
6 years ago
|
})
|
||
6 years ago
|
server.listen(port, '127.0.0.1', function () {
|
||
6 years ago
|
embark.logger.info('Remix IDE (via embark-remix plugin) available at ' + colors.underline(remixIdeUrl))
|
||
|
})
|
||
6 years ago
|
} else {
|
||
6 years ago
|
embark.logger.info('embark-remix is set to connect to a Remix IDE at ' + colors.underline(remixIdeUrl))
|
||
6 years ago
|
}
|
||
|
|
||
|
// setup Embark service check
|
||
7 years ago
|
embark.registerServiceCheck('Remix IDE', (cb) => {
|
||
6 years ago
|
return cb({ name: `Remix IDE ${host}:${port}`, status: 'on' })
|
||
|
})
|
||
7 years ago
|
|
||
6 years ago
|
// setup remixd shared folder service
|
||
|
const sharedFolderRouter = new remixd.Router(65520, sharedFolderService, { remixIdeUrl }, (webSocket) => {
|
||
6 years ago
|
sharedFolderService.setWebSocket(webSocket)
|
||
|
sharedFolderService.setupNotifications(sharedFolder)
|
||
|
sharedFolderService.sharedFolder(sharedFolder, readOnly)
|
||
6 years ago
|
})
|
||
6 years ago
|
const killRemixD = sharedFolderRouter.start()
|
||
6 years ago
|
const kill = () => {
|
||
6 years ago
|
if (server) server.close()
|
||
6 years ago
|
embark.logger.info(colors.red('embark-remix stopped'))
|
||
|
process.exit()
|
||
6 years ago
|
}
|
||
|
|
||
|
if (process.platform === 'win32') {
|
||
|
require('readline').createInterface({
|
||
|
input: process.stdin,
|
||
|
output: process.stdout
|
||
|
}).on('SIGINT', function () {
|
||
6 years ago
|
process.emit('SIGINT')
|
||
|
})
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
6 years ago
|
process.on('SIGINT', kill) // catch ctrl-c
|
||
|
process.on('SIGTERM', kill) // catch kill
|
||
|
process.on('exit', killRemixD)
|
||
7 years ago
|
}
|