refactor: hook doc
This commit is contained in:
parent
e0bd108990
commit
6e6cb3f0f4
|
@ -1,59 +1,104 @@
|
||||||
/**
|
import {Hooks} from '@flecks/core';
|
||||||
* Hook into neutrino configuration.
|
|
||||||
* @param {string} target - The build target; e.g. `server`.
|
|
||||||
* @param {Object} config - The neutrino configuration.
|
|
||||||
*/
|
|
||||||
hooks['@flecks/core/build'] = (target, config) => {};
|
|
||||||
|
|
||||||
/**
|
export default {
|
||||||
* Alter build configurations after they have been hooked.
|
[Hooks]: {
|
||||||
* @param {Object} configs - The neutrino configurations.
|
/**
|
||||||
*/
|
* Hook into neutrino configuration.
|
||||||
hooks['@flecks/core/build/alter'] = (configs) => {};
|
* @param {string} target The build target; e.g. `server`.
|
||||||
|
* @param {Object} config The neutrino configuration.
|
||||||
|
*/
|
||||||
|
'@flecks/core/build': (target, config) => {
|
||||||
|
if ('something' === target) {
|
||||||
|
config[target].use.push(someNeutrinoMiddleware);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define CLI commands.
|
* Alter build configurations after they have been hooked.
|
||||||
*/
|
* @param {Object} configs The neutrino configurations.
|
||||||
hooks['@flecks/core/commands'] = (program) => {};
|
*/
|
||||||
|
'@flecks/core/build/alter': (configs) => {
|
||||||
|
// Maybe we want to do something if a config exists..?
|
||||||
|
if (configs.something) {
|
||||||
|
// Do something...
|
||||||
|
// And then maybe we want to remove it from the build configuration..?
|
||||||
|
delete configs.something;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define configuration.
|
* Define CLI commands.
|
||||||
*/
|
*/
|
||||||
hooks['@flecks/core/config'] = () => {};
|
'@flecks/core/commands': (program) => ({
|
||||||
|
// So this could be invoked like:
|
||||||
|
// npx flecks something -t --blow-up blah
|
||||||
|
something: {
|
||||||
|
action: (...args) => {
|
||||||
|
// Run the command...
|
||||||
|
},
|
||||||
|
args: [
|
||||||
|
'<somearg>',
|
||||||
|
],
|
||||||
|
description: 'This sure is some command',
|
||||||
|
options: [
|
||||||
|
'-t, --test', 'Do a test',
|
||||||
|
'-b, --blow-up', 'Blow up instead of running the command',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alter configuration.
|
* Define configuration.
|
||||||
* @param {Object} config - The neutrino configuration.
|
*/
|
||||||
*/
|
'@flecks/core/config': () => ({
|
||||||
hooks['@flecks/core/config/alter'] = (config) => {};
|
whatever: 'configuration',
|
||||||
|
your: 1337,
|
||||||
|
fleck: 'needs',
|
||||||
|
though: 'you should keep the values serializable',
|
||||||
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when a gathered class is HMR'd.
|
* Invoked when a gathered class is HMR'd.
|
||||||
* @param {constructor} Class - The class.
|
* @param {constructor} Class The class.
|
||||||
* @param {string} hook - The gather hook; e.g. `@flecks/db/server/models`.
|
* @param {string} hook The gather hook; e.g. `@flecks/db/server/models`.
|
||||||
*/
|
*/
|
||||||
hooks['@flecks/core/gathered/hmr'] = (Class, hook) => {};
|
'@flecks/core/gathered/hmr': (Class, hook) => {
|
||||||
|
// Do something with Class...
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when a fleck is HMR'd
|
* Invoked when a fleck is HMR'd
|
||||||
* @param {constructor} Class - The class.
|
* @param {string} path The path of the fleck
|
||||||
* @param {string} hook - The gather hook; e.g. `@flecks/db/server/models`.
|
* @param {Module} updatedFleck The updated fleck module.
|
||||||
*/
|
*/
|
||||||
hooks['@flecks/core/hmr'] = (Class, hook) => {};
|
'@flecks/core/hmr': (path, updatedFleck) => {
|
||||||
|
if ('my-fleck' === path) {
|
||||||
|
updatedFleck.doSomething();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when the application is starting. Use for order-independent initialization tasks.
|
* Invoked when the application is starting. Use for order-independent initialization tasks.
|
||||||
*/
|
*/
|
||||||
hooks['@flecks/core/starting'] = () => {};
|
'@flecks/core/starting': (flecks) => {
|
||||||
|
flecks.set('$my-fleck/value', initializeMyValue());
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define neutrino build targets.
|
* Define neutrino build targets.
|
||||||
*/
|
*/
|
||||||
hooks['@flecks/core/targets'] = () => {};
|
'@flecks/core/targets': () => ['sometarget'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook into webpack configuration.
|
||||||
|
* @param {string} target The build target; e.g. `server`.
|
||||||
|
* @param {Object} config The neutrino configuration.
|
||||||
|
*/
|
||||||
|
'@flecks/core/webpack': (target, config) => {
|
||||||
|
if ('something' === target) {
|
||||||
|
config.stats = 'verbose';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook into webpack configuration.
|
|
||||||
* @param {string} target - The build target; e.g. `server`.
|
|
||||||
* @param {Object} config - The neutrino configuration.
|
|
||||||
*/
|
|
||||||
hooks['@flecks/core/webpack'] = (target, config) => {};
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user