flow: niiice

This commit is contained in:
cha0s 2020-12-01 02:44:31 -06:00
parent aac31dc3c1
commit b1a42934df
12 changed files with 6409 additions and 25 deletions

View File

@ -22,7 +22,10 @@ export default class Plugins {
}
invoke(hook, ...args) {
return Object.keys(this.hooks[hook]).reduce((r, plugin) => ({
if (!this.hooks[hook]) {
return [];
}
return this.hooks[hook].map(({plugin}) => plugin).reduce((r, plugin) => ({
...r,
[plugin]: this.invokePlugin(hook, plugin, ...args),
}), {});

View File

@ -5,7 +5,7 @@ const {Plugins} = require('@latus/core');
return;
}
const plugins = new Plugins(window.$$latus);
await Promise.all(plugins.invokeFlat('@latus/http/up'));
await Promise.all(plugins.invokeFlat('@latus/http/up', plugins));
// eslint-disable-next-line no-console
console.log('Latus up!\n');
})();

View File

@ -4,7 +4,7 @@ import {createHttpServer} from './server';
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
build: (configs) => {
'@latus/core/build': (configs) => {
// eslint-disable-next-line no-console
if ('production' === process.env.NODE_ENV) {
// eslint-disable-next-line global-require, no-param-reassign

View File

@ -2,6 +2,7 @@ import {join} from 'path';
import {WebpackPlugin} from '@latus/core';
import {createFsFromVolume, Volume} from 'memfs';
import neutrino from 'neutrino';
import webpack, {HotModuleReplacementPlugin} from 'webpack';
import devMiddleware from 'webpack-dev-middleware';
import hotMiddleware from 'webpack-hot-middleware';
@ -12,25 +13,40 @@ const {
NODE_ENV,
} = process.env;
const requestConfig = (plugins, req) => (
plugins.invokeReduce('@latus/http/plugins', {}, (r, s) => ({...r, ...s}), req)
);
const common = (latusConfig) => ({
target: 'web',
output: {
filename: 'latus.js',
path: '/',
},
plugins: [
new WebpackPlugin(latusConfig),
],
entry: {
latus: [
`${__dirname}/client/latus`,
const common = (plugins, req) => {
const instance = neutrino({
root: process.cwd(),
use: [
/* eslint-disable no-param-reassign */
(neutrino) => {
neutrino.config
.entry('latus')
.add(`${__dirname}/client/latus`);
neutrino.config
.plugin('WebpackPlugin')
.use(WebpackPlugin, [
plugins.invokeReduce(
'@latus/http/plugins',
{},
(r, s) => ({...r, ...s}),
plugins,
req,
),
]);
},
(neutrino) => {
plugins.invokeFlat('@latus/http/build').forEach((middleware) => neutrino.use(middleware));
},
(neutrino) => {
neutrino.config.output
.filename('latus.js')
.path('/');
},
/* eslint-enable no-param-reassign */
],
},
});
});
return instance.webpack();
};
const varyBy = (req) => (req.user || 0) && req.user.id;
@ -48,7 +64,7 @@ const vary = (fn) => {
const dev = (plugins) => vary(
(req) => {
const config = {
...common(requestConfig(plugins, req)),
...common(plugins, req),
mode: 'development',
};
config.entry.latus.push('webpack-hot-middleware/client');
@ -69,7 +85,7 @@ const dev = (plugins) => vary(
const production = (plugins) => vary(
(req) => {
const config = {
...common(requestConfig(plugins, req)),
...common(plugins, req),
mode: 'production',
};
const compiler = webpack(config);
@ -84,7 +100,7 @@ const production = (plugins) => vary(
}
compiler.run((error, stats) => {
if (error) {
res.error(error);
next(error);
return;
}
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
@ -93,6 +109,8 @@ const production = (plugins) => vary(
all: false,
errors: true,
}).replace(new RegExp(process.cwd(), 'g'), '<cwd>');
// eslint-disable-next-line no-console
console.error(renderedStats);
res.send([
'window.addEventListener("load", () => {',
"window.document.body.innerHTML = '<pre>' + ",
@ -102,7 +120,7 @@ const production = (plugins) => vary(
].join(''));
}
else {
fs.createReadStream('/latus.js').pipe(res);
fs.createReadStream(Object.keys(volume.toJSON())[0]).pipe(res);
}
});
};

View File

@ -0,0 +1 @@
module.exports = require('../../config/.eslintrc');

1
packages/react/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/entry.js*

View File

@ -0,0 +1,11 @@
const copy = require('@neutrinojs/copy');
const config = require('../../config/.neutrinorc');
config.options = {
mains: {
index: 'index',
entry: 'entry',
},
};
module.exports = config;

View File

@ -0,0 +1,38 @@
{
"name": "@latus/react",
"version": "1.0.0",
"main": "index.js",
"author": "cha0s",
"license": "MIT",
"scripts": {
"build": "NODE_PATH=./node_modules webpack --mode production",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js",
"watch": "NODE_PATH=./node_modules webpack --watch --mode development"
},
"files": [
"index.js",
"index.js.map",
"entry.js",
"entry.js.map"
],
"dependencies": {
"@neutrinojs/react": "^9.4.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-hot-loader": "^4.13.0"
},
"devDependencies": {
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/copy": "9.4.0",
"@neutrinojs/library": "^9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
}
}

View File

@ -0,0 +1,18 @@
import React from 'react';
import {render} from 'react-dom';
import {hot} from 'react-hot-loader';
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
'@latus/http/up': (plugins) => {
const modules = plugins.invoke('@latus/react/components');
const heated = React.createElement(
hot(module)(React.Fragment),
{},
Object.entries(modules).map(([key, module]) => React.createElement(module, {key})),
);
return render(heated, window.document.getElementById('root'));
},
},
};

View File

@ -0,0 +1,27 @@
const react = require('@neutrinojs/react');
const middleware = (neutrino) => {
neutrino.use(react({
clean: false,
}));
neutrino.use((neutrino) => {
neutrino.config.optimization
.runtimeChunk(false)
.splitChunks(false);
neutrino.config.plugins
.delete('html-index');
neutrino.config.entryPoints
.delete('index');
});
};
// eslint-disable-next-line import/prefer-default-export
export const $$latus = {
hooks: {
'@latus/http/build': () => middleware,
'@latus/http/plugins': ({config: {'@latus/react': {entry = './src/react'}}}) => ({
'@latus/react/entry': {},
[entry]: {},
}),
},
};

View File

@ -0,0 +1,6 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
module.exports = neutrino(require(`${__dirname}/.neutrinorc`)).webpack();

6261
packages/react/yarn.lock Normal file

File diff suppressed because it is too large Load Diff