2022-08-10 10:09:02 -05:00
export const hooks = {
2022-03-06 12:48:51 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Hook into webpack configuration .
2022-08-10 10:09:02 -05:00
* @ param { string } target The build target ; e . g . ` server ` .
2023-11-30 21:41:42 -06:00
* @ param { Object } config The webpack configuration .
* @ param { Object } env The webpack environment .
* @ param { Object } argv The webpack commandline arguments .
* @ see { @ link https : //webpack.js.org/configuration/configuration-types/#exporting-a-function}
2022-08-10 10:09:02 -05:00
* /
2023-11-30 21:41:42 -06:00
'@flecks/core.build' : ( target , config , env , argv ) => {
2022-08-10 10:09:02 -05:00
if ( 'something' === target ) {
2023-11-30 21:41:42 -06:00
if ( 'production' === argv . mode ) {
config . plugins . push ( new SomePlugin ( ) ) ;
}
2022-08-10 10:09:02 -05:00
}
} ,
2022-03-06 12:48:51 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Alter build configurations after they have been hooked .
* @ param { Object } configs The webpack configurations keyed by target .
* @ param { Object } env The webpack environment .
* @ param { Object } argv The webpack commandline arguments .
* @ see { @ link https : //webpack.js.org/configuration/configuration-types/#exporting-a-function}
* /
2022-08-10 10:09:02 -05:00
'@flecks/core.build.alter' : ( configs ) => {
2023-11-30 21:41:42 -06:00
// Maybe we want to do something if a target exists..?
if ( configs . someTarget ) {
2022-08-10 10:09:02 -05:00
// Do something...
2023-11-30 21:41:42 -06:00
// And then maybe we want to remove it from the build configuration..? That's ok!
delete configs . someTarget ;
2022-08-10 10:09:02 -05:00
}
} ,
2022-03-09 07:25:58 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Register build configuration .
* /
2022-08-10 10:09:02 -05:00
'@flecks/core.build.config' : ( ) => [
2022-03-06 12:48:51 -06:00
/ * *
2022-08-10 10:09:02 -05:00
* If you document your config files like this , documentation will be automatically
* generated .
* /
'.myrc.js' ,
2022-03-06 12:48:51 -06:00
/ * *
2022-08-10 10:09:02 -05:00
* Make sure you return them as an array expression , like this .
* /
2023-12-02 22:31:14 -06:00
[ 'something.config.js' , { specifier : ( specific ) => ` something. ${ specific } .config.js ` } ] ,
2022-08-10 10:09:02 -05:00
] ,
2022-03-06 12:48:51 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Define CLI commands .
2023-12-31 16:21:43 -06:00
* @ param { [ Command ] ( https : //github.com/tj/commander.js/tree/master#declaring-program-variable)} program The [Commander.js](https://github.com/tj/commander.js) program.
2023-11-30 21:41:42 -06:00
* /
2023-12-31 16:21:43 -06:00
'@flecks/core.commands' : ( program , flecks ) => {
const { Argument } = flecks . fleck ( '@flecks/core/server' ) ;
return {
// So this could be invoked like:
// npx flecks something -t --blow-up blah
something : {
action : ( ... args ) => {
// Run the command...
} ,
args : [
new Argument ( '<somearg>' , 'some argument' ) ,
] ,
description : 'This command does tests and also blows up' ,
options : [
'-t, --test' , 'Do a test' ,
'-b, --blow-up' , 'Blow up instead of running the command' ,
] ,
2022-08-10 10:09:02 -05:00
} ,
2023-12-31 16:21:43 -06:00
} ;
} ,
2022-03-08 16:03:06 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Define configuration .
* /
2022-08-10 10:09:02 -05:00
'@flecks/core.config' : ( ) => ( {
whatever : 'configuration' ,
your : 1337 ,
fleck : 'needs' ,
2022-03-06 12:48:51 -06:00
/ * *
2022-08-10 10:09:02 -05:00
* Also , comments like this will be used to automatically generate documentation .
* /
though : 'you should keep the values serializable' ,
} ) ,
2022-03-06 12:48:51 -06:00
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -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 ) => {
2022-08-10 10:09:02 -05:00
if ( 'my-fleck' === path ) {
updatedFleck . doSomething ( ) ;
}
} ,
2022-03-06 12:48:51 -06:00
2023-12-08 05:32:28 -06:00
/ * *
* Invoked when a gathered set is HMR ' d .
* @ param { constructor } gathered The gathered set .
* @ param { string } hook The gather hook ; e . g . ` @flecks/db/server.models ` .
* /
'@flecks/core.hmr.gathered' : ( gathered , hook ) => {
// Do something with the gathered set...
} ,
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Invoked when a gathered class is HMR ' d .
* @ param { constructor } Class The class .
* @ param { string } hook The gather hook ; e . g . ` @flecks/db/server.models ` .
* /
2023-12-08 05:32:28 -06:00
'@flecks/core.hmr.gathered.class' : ( Class , hook ) => {
2022-08-10 10:09:02 -05:00
// Do something with Class...
} ,
2022-03-06 12:48:51 -06:00
2024-01-09 14:23:12 -06:00
/ * *
* Invoked when flecks is building a fleck dependency graph .
* @ param { Digraph } graph The dependency graph .
* @ param { string } hook The hook ; e . g . ` @flecks/db/server ` .
* /
'@flecks/core.priority' : ( graph , hook ) => {
// Make `@flecks/user/server`'s `@flecks/server.up` implementation depend on
// `@flecks/db/server`'s:
if ( '@flecks/server.up' === hook ) {
graph . addDependency ( '@flecks/user/server' , '@flecks/db/server' ) ;
// Remove a dependency.
graph . removeDependency ( '@flecks/user/server' , '@flecks/db/server' ) ;
}
} ,
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Invoked when the application is starting . Use for order - independent initialization tasks .
* /
2024-01-05 22:49:02 -06:00
'@flecks/core.starting' : ( ) => {
console . log ( 'starting!' ) ;
2022-03-06 12:48:51 -06:00
} ,
2022-08-10 10:09:02 -05:00
/ * *
2023-11-30 21:41:42 -06:00
* Define build targets .
* /
2022-08-10 10:09:02 -05:00
'@flecks/core.targets' : ( ) => [ 'sometarget' ] ,
} ;