diff --git a/app/.neutrinorc.js b/app/.neutrinorc.js index 4100347..4df75eb 100644 --- a/app/.neutrinorc.js +++ b/app/.neutrinorc.js @@ -30,7 +30,7 @@ module.exports = { }), mocha(), node({ - hot: false, + hot: true, }), (neutrino) => { [ @@ -65,7 +65,7 @@ module.exports = { }]); neutrino.config .entry('index') - .prepend('@latus/core/start'); + .add('@latus/core/start'); if ('production' !== neutrino.config.get('mode')) { neutrino.config .entry('index') @@ -74,6 +74,7 @@ module.exports = { .plugin('start-server') .tap((args) => { const options = args[0]; + options.signal = true; const inspectArg = process.argv.find((arg) => -1 !== arg.indexOf('--inspect')); if (inspectArg) { options.nodeArgs.push(inspectArg); diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 1e91030..ca39934 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -1,3 +1,5 @@ +import {LatusPlugin} from './latus-plugin'; + export { unique as arrayUnique, flatten as arrayFlatten, @@ -9,15 +11,68 @@ export {default as EventEmitter} from './event-emitter'; export {deflate, inflate} from './flate'; export {compose, fastApply} from './function'; export {decorateWithLatus, gatherWithLatus, default as gather} from './gather'; -export {LatusPlugin} from './latus-plugin'; export {default as Middleware} from './middleware'; export {default as Latus} from './latus'; export * from './string'; +export {LatusPlugin}; + export const Class = class {}; export default { hooks: { + '@latus/core/build': (configs, latus) => { + // eslint-disable-next-line no-undef + configs.app.use.unshift((neutrino) => { + const defaults = Object.keys(latus.originalConfig) + .map((plugin) => { + const config = {}; + [plugin, `${plugin}/server`].forEach((path) => { + try { + // eslint-disable-next-line no-eval + eval('require.resolve')(path); + config[path] = {}; + } + // eslint-disable-next-line no-empty + catch (error) {} + }); + return config; + }) + .filter((config) => !!config) + .reduce((r, o) => ({...r, ...o}), {}); + const config = Object.fromEntries( + Object.keys(defaults) + .map((path) => [ + path, + latus.get(path), + ]), + ); + neutrino.config + .plugin('latus') + .use(LatusPlugin( + neutrino, + () => config, + (plugin, modulesObject) => { + plugin.writeModule('/%/latus/server/virtual', [ + 'global.$$latus = {', + ` config: ${JSON.stringify(config)},`, + ` modules: ${modulesObject},`, + '};', + 'if (module.hot) {', + ' Object.keys(global.$$latus.modules).forEach((key) => {', + ' module.hot.accept(key, () => {', + " console.log('kesy!');", + ' });', + ' });', + '}', + ].join('\n')); + }, + )); + neutrino.config + .entry('index') + .add('/%/latus/server/virtual'); + }); + }, '@latus/core/config': () => ({ id: 'latus', }), diff --git a/packages/core/src/latus-plugin.js b/packages/core/src/latus-plugin.js index ec3f39f..f95fefd 100644 --- a/packages/core/src/latus-plugin.js +++ b/packages/core/src/latus-plugin.js @@ -22,7 +22,8 @@ exports.LatusPlugin = (neutrino, getConfig, write) => class LatusPlugin { }); compiler.hooks.beforeCompile.tapPromise('LatusPlugin', async () => { const paths = Object.keys(await getConfig()) - .map((path) => Latus.runtimePath(path)); + .map((path) => Latus.runtimePath(path)) + .filter((path) => !!path); const pathMap = paths.map((path) => `'${path}': require('${path}')`).join(', '); write(plugin, `{${pathMap}}`, paths); }); diff --git a/packages/core/src/start.js b/packages/core/src/start.js index d5f0eca..15e5f7e 100644 --- a/packages/core/src/start.js +++ b/packages/core/src/start.js @@ -1,14 +1,14 @@ +/* eslint-disable no-console */ import Latus from './latus'; -process.stdout.write('Latus starting...\n'); +console.log('Latus starting...'); (async () => { - const latus = Latus.create(); + const latus = new Latus(global.$$latus); try { await Promise.all(latus.invokeFlat('@latus/core/starting')); await Promise.all(latus.invokeFlat('@latus/core/started')); await latus.invokeSequential('@latus/core/server/up'); - // eslint-disable-next-line no-console console.log('Latus up!'); } catch (error) {