flecks/packages/core/build/dox/hooks.js

120 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-03-06 12:48:51 -06:00
import {Hooks} from '@flecks/core';
export default {
[Hooks]: {
/**
* Hook into neutrino configuration.
* @param {string} target The build target; e.g. `server`.
* @param {Object} config The neutrino configuration.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.build': (target, config) => {
2022-03-06 12:48:51 -06:00
if ('something' === target) {
config[target].use.push(someNeutrinoMiddleware);
}
},
/**
* Alter build configurations after they have been hooked.
* @param {Object} configs The neutrino configurations.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.build.alter': (configs) => {
2022-03-06 12:48:51 -06:00
// 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;
}
},
2022-03-09 07:25:58 -06:00
/**
* Register build configuration.
*/
'@flecks/core.build.config': () => [
2022-03-09 08:53:19 -06:00
/**
* If you document your config files like this, documentation will be automatically
* generated.
*/
2022-03-09 07:25:58 -06:00
'.myrc.js',
2022-03-09 08:53:19 -06:00
/**
* Make sure you return them as an array expression, like this.
*/
2022-03-09 07:25:58 -06:00
['mygeneralrc.js', {specifier: (specific) => `${specific}.mygeneralrc.js`}],
],
2022-03-06 12:48:51 -06:00
/**
* Define CLI commands.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.commands': (program) => ({
2022-03-06 12:48:51 -06:00
// 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',
],
},
}),
/**
* Define configuration.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.config': () => ({
2022-03-06 12:48:51 -06:00
whatever: 'configuration',
your: 1337,
fleck: 'needs',
though: 'you should keep the values serializable',
}),
2022-03-08 16:03:06 -06:00
/**
* Invoked when a fleck is HMR'd
* @param {string} path The path of the fleck
* @param {Module} updatedFleck The updated fleck module.
*/
'@flecks/core.hmr': (path, updatedFleck) => {
if ('my-fleck' === path) {
updatedFleck.doSomething();
}
},
2022-03-06 12:48:51 -06:00
/**
* Invoked when a gathered class is HMR'd.
* @param {constructor} Class The class.
2022-03-08 16:03:06 -06:00
* @param {string} hook The gather hook; e.g. `@flecks/db/server.models`.
2022-03-06 12:48:51 -06:00
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.hmr.gathered': (Class, hook) => {
2022-03-06 12:48:51 -06:00
// Do something with Class...
},
/**
* Invoked when the application is starting. Use for order-independent initialization tasks.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.starting': (flecks) => {
2022-03-06 12:48:51 -06:00
flecks.set('$my-fleck/value', initializeMyValue());
},
/**
* Define neutrino build targets.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.targets': () => ['sometarget'],
2022-03-06 12:48:51 -06:00
/**
* Hook into webpack configuration.
* @param {string} target The build target; e.g. `server`.
* @param {Object} config The neutrino configuration.
*/
2022-03-08 16:03:06 -06:00
'@flecks/core.webpack': (target, config) => {
2022-03-06 12:48:51 -06:00
if ('something' === target) {
config.stats = 'verbose';
}
},
},
};