latus/packages/http/src/index.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-30 06:28:29 -06:00
import {spawn} from 'child_process';
import {createHttpServer} from './server';
2020-12-01 15:36:14 -06:00
let httpServer;
2020-11-30 06:28:29 -06:00
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
2020-12-01 18:37:19 -06:00
'@latus/core/config': () => ({
host: '0.0.0.0',
port: 32340,
}),
2020-12-01 02:44:31 -06:00
'@latus/core/build': (configs) => {
2020-11-30 06:28:29 -06:00
// eslint-disable-next-line no-console
if ('production' === process.env.NODE_ENV) {
// eslint-disable-next-line global-require, no-param-reassign
configs.client = require('./build/.neutrinorc');
}
else {
const binary = `$(npm --prefix ${process.cwd()} bin)/webpack-dev-server`;
const config = `${__dirname}/src/build/webpack.config.js`;
const options = {
shell: true,
stdio: 'inherit',
};
process.stdout.write(`${binary} --mode development --config ${config}\n`);
spawn(`${binary} --mode development --config ${config}`, options);
}
},
2020-12-01 15:36:14 -06:00
'@latus/core/up': async (plugins) => {
httpServer = await createHttpServer(plugins);
},
'@latus/repl/context': () => ({
httpServer,
}),
2020-11-30 06:28:29 -06:00
},
};