refactor: hooks
This commit is contained in:
parent
ba33810599
commit
43f9c7c3dd
|
@ -1,29 +1,21 @@
|
|||
import {Hooks} from '@flecks/core';
|
||||
|
||||
// const {
|
||||
// NODE_ENV,
|
||||
// } = process.env;
|
||||
|
||||
export default {
|
||||
[Hooks]: {
|
||||
'@flecks/server.up': async (flecks) => {
|
||||
// if ('production' === NODE_ENV) {
|
||||
// return;
|
||||
// }
|
||||
const {Project, User} = flecks.get('$flecks/db.models');
|
||||
if (!await User.findOne({where: {email: 'persea@cha0s.io'}})) {
|
||||
const user = await User.create({
|
||||
email: 'persea@cha0s.io',
|
||||
isAdmin: true,
|
||||
});
|
||||
await user.addHashedPassword('foobar');
|
||||
await user.addProject(
|
||||
await Project.create({
|
||||
uuid: 'c41ddaac-89c2-46a4-b3e5-1d634a1a7c36',
|
||||
}),
|
||||
);
|
||||
await user.save();
|
||||
}
|
||||
},
|
||||
export const hooks = {
|
||||
'@flecks/server.up': async (flecks) => {
|
||||
// if ('production' === NODE_ENV) {
|
||||
// return;
|
||||
// }
|
||||
const {Project, User} = flecks.get('$flecks/db.models');
|
||||
if (!await User.findOne({where: {email: 'persea@cha0s.io'}})) {
|
||||
const user = await User.create({
|
||||
email: 'persea@cha0s.io',
|
||||
isAdmin: true,
|
||||
});
|
||||
await user.addHashedPassword('foobar');
|
||||
await user.addProject(
|
||||
await Project.create({
|
||||
uuid: 'c41ddaac-89c2-46a4-b3e5-1d634a1a7c36',
|
||||
}),
|
||||
);
|
||||
await user.save();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import {join} from 'path';
|
||||
|
||||
import {Hooks} from '@flecks/core';
|
||||
import isElectron from 'is-electron';
|
||||
|
||||
const {
|
||||
|
@ -8,29 +7,27 @@ const {
|
|||
NODE_ENV,
|
||||
} = process.env;
|
||||
|
||||
export default {
|
||||
[Hooks]: {
|
||||
'@flecks/core.starting': (flecks) => {
|
||||
const {browserWindowOptions} = flecks.get('@flecks/electron/server');
|
||||
browserWindowOptions.icon = join(FLECKS_CORE_ROOT, 'icon.png');
|
||||
},
|
||||
'@flecks/electron/server.window': async (win) => {
|
||||
// win.removeMenu();
|
||||
if ('production' !== NODE_ENV) {
|
||||
win.openDevTools();
|
||||
}
|
||||
win.maximize();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
});
|
||||
},
|
||||
'@flecks/web/server.request.route': (flecks) => async (req, res, next) => {
|
||||
if (isElectron() && 0 === req.user.id) {
|
||||
const {User} = flecks.get('$flecks/db.models');
|
||||
req.logIn(await User.findByPk(1), next);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
},
|
||||
export const hooks = {
|
||||
'@flecks/core.starting': (flecks) => {
|
||||
const {browserWindowOptions} = flecks.get('@flecks/electron/server');
|
||||
browserWindowOptions.icon = join(FLECKS_CORE_ROOT, 'icon.png');
|
||||
},
|
||||
'@flecks/electron/server.window': async (win) => {
|
||||
// win.removeMenu();
|
||||
if ('production' !== NODE_ENV) {
|
||||
win.openDevTools();
|
||||
}
|
||||
win.maximize();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
});
|
||||
},
|
||||
'@flecks/web/server.request.route': (flecks) => async (req, res, next) => {
|
||||
if (isElectron() && 0 === req.user.id) {
|
||||
const {User} = flecks.get('$flecks/db.models');
|
||||
req.logIn(await User.findByPk(1), next);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
replaceResource,
|
||||
undo,
|
||||
} from '@avocado/resource/persea';
|
||||
import {Hooks} from '@flecks/core';
|
||||
|
||||
import Persea from './components/persea';
|
||||
import organization from './sidebar/organization';
|
||||
|
@ -17,37 +16,35 @@ import {
|
|||
|
||||
export * from './state';
|
||||
|
||||
export default {
|
||||
[Hooks]: {
|
||||
'@flecks/react.roots': () => Persea,
|
||||
'@flecks/redux.effects': (flecks) => {
|
||||
const withSocket = (fn) => (...args) => fn(...args.concat(flecks.get('$flecks/socket.socket')));
|
||||
return Object.fromEntries(
|
||||
[
|
||||
patchJsonResource,
|
||||
redo,
|
||||
replaceResource,
|
||||
undo,
|
||||
]
|
||||
.map((action) => [
|
||||
action,
|
||||
withSocket((store, action, socket) => {
|
||||
if (action.meta?.isRemote) {
|
||||
return;
|
||||
}
|
||||
socket.send(['Action', action]);
|
||||
}),
|
||||
]),
|
||||
);
|
||||
},
|
||||
'@flecks/redux.slices': () => ({
|
||||
project,
|
||||
projects,
|
||||
resource,
|
||||
}),
|
||||
'@persea/core.sidebar': () => ({
|
||||
projects: projectsSidebar,
|
||||
organization,
|
||||
}),
|
||||
export const hooks = {
|
||||
'@flecks/react.roots': () => Persea,
|
||||
'@flecks/redux.effects': (flecks) => {
|
||||
const withSocket = (fn) => (...args) => fn(...args.concat(flecks.get('$flecks/socket.socket')));
|
||||
return Object.fromEntries(
|
||||
[
|
||||
patchJsonResource,
|
||||
redo,
|
||||
replaceResource,
|
||||
undo,
|
||||
]
|
||||
.map((action) => [
|
||||
action,
|
||||
withSocket((store, action, socket) => {
|
||||
if (action.meta?.isRemote) {
|
||||
return;
|
||||
}
|
||||
socket.send(['Action', action]);
|
||||
}),
|
||||
]),
|
||||
);
|
||||
},
|
||||
'@flecks/redux.slices': () => ({
|
||||
project,
|
||||
projects,
|
||||
resource,
|
||||
}),
|
||||
'@persea/core.sidebar': () => ({
|
||||
projects: projectsSidebar,
|
||||
organization,
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -1,39 +1,37 @@
|
|||
import {join} from 'path';
|
||||
|
||||
import {Flecks, Hooks} from '@flecks/core';
|
||||
import {Flecks} from '@flecks/core';
|
||||
import express from 'express';
|
||||
|
||||
import startFlush from './start-flush';
|
||||
|
||||
const resources = express.static(join(process.cwd(), 'projects'));
|
||||
|
||||
export default {
|
||||
[Hooks]: {
|
||||
'@flecks/core.starting': (flecks) => {
|
||||
flecks.set('$persea/core.patches', []);
|
||||
flecks.set('$persea/core.replacements', []);
|
||||
startFlush(flecks);
|
||||
},
|
||||
'@flecks/core.webpack': (target, config) => {
|
||||
if ('web' === target) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
config.devServer.writeToDisk = true;
|
||||
}
|
||||
},
|
||||
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
||||
'@flecks/db/server.models.decorate': (
|
||||
Flecks.decorate(require.context('./models/decorators', false, /\.js$/))
|
||||
),
|
||||
'@flecks/web/server.request.socket': () => (req, res, next) => {
|
||||
if (req.url.startsWith('/projects')) {
|
||||
req.url = req.url.slice(9);
|
||||
resources(req, res, next);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
},
|
||||
'@flecks/socket.packets.decorate': (
|
||||
Flecks.decorate(require.context('./packets/decorators', false, /\.js$/))
|
||||
),
|
||||
export const hooks = {
|
||||
'@flecks/core.starting': (flecks) => {
|
||||
flecks.set('$persea/core.patches', []);
|
||||
flecks.set('$persea/core.replacements', []);
|
||||
startFlush(flecks);
|
||||
},
|
||||
'@flecks/core.webpack': (target, config) => {
|
||||
if ('web' === target) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
config.devServer.writeToDisk = true;
|
||||
}
|
||||
},
|
||||
'@flecks/db/server.models': Flecks.provide(require.context('./models', false, /\.js$/)),
|
||||
'@flecks/db/server.models.decorate': (
|
||||
Flecks.decorate(require.context('./models/decorators', false, /\.js$/))
|
||||
),
|
||||
'@flecks/web/server.request.socket': () => (req, res, next) => {
|
||||
if (req.url.startsWith('/projects')) {
|
||||
req.url = req.url.slice(9);
|
||||
resources(req, res, next);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
},
|
||||
'@flecks/socket.packets.decorate': (
|
||||
Flecks.decorate(require.context('./packets/decorators', false, /\.js$/))
|
||||
),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user