[{"data":1,"prerenderedAt":1036},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks":3},{"id":4,"title":5,"body":6,"description":1018,"extension":1019,"frontmatter":1020,"heading":5,"meta":1027,"navigation":1029,"order":1024,"path":1030,"seo":1031,"sitemap":1032,"source":1033,"stem":1034,"__hash__":1035},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks.md","Lifecycle hooks",{"type":7,"value":8,"toc":1006},"minimark",[9,30,37,42,52,334,338,341,344,348,359,479,483,492,701,705,708,855,859,862,954,958],[10,11,12,13,17,18,25,26,29],"p",{},"Kubb runs on one shared, typed hook emitter, and every phase of a build fires a ",[14,15,16],"code",{},"kubb:*"," hook on it. Plugins listen through their ",[19,20,22],"a",{"href":21},".\u002Fplugins",[14,23,24],{},"hooks"," map. Outside code listens through ",[14,27,28],{},"kubb.hooks",".",[10,31,32,33,36],{},"Every hook name and its payload lives in the ",[14,34,35],{},"KubbHooks"," type. Handlers can be async, and Kubb awaits each one.",[38,39,41],"h2",{"id":40},"listening","Listening",[10,43,44,45,48,49,29],{},"Attach a listener with ",[14,46,47],{},"kubb.hooks.hook(name, handler)"," before you call ",[14,50,51],{},"build()",[53,54,58],"pre",{"language":55,"code":56,"class":57},"ts","import { createKubb } from 'kubb'\n\nconst kubb = createKubb({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fgen' },\n})\n\nkubb.hooks.hook('kubb:plugin:end', ({ plugin, duration }) => {\n  console.log(`${plugin.name} finished in ${duration}ms`)\n})\n\nkubb.hooks.hook('kubb:build:end', ({ files }) => {\n  console.log(`Generated ${files.length} files`)\n})\n\nawait kubb.build()","highlights",[14,59,61,88,89,88,91,88,109,88,126,88,150,88,155,88,157,88,200,88,245,88,249,88,251,88,281,88,313,88,317,88,319],{"class":60},"language-ts",[62,63,66,70,74,78,81,84],"span",{"class":64,"style":65},"line","display: inline",[62,67,69],{"style":68},"color:#d73a49;--hls-dark:#f97583","import ",[62,71,73],{"style":72},"color:#005cc5;--hls-dark:#79b8ff","{ ",[62,75,77],{"style":76},"color:#24292e;--hls-dark:#e1e4e8","createKubb ",[62,79,80],{"style":72},"} ",[62,82,83],{"style":68},"from ",[62,85,87],{"style":86},"color:#032f62;--hls-dark:#9ecbff","'kubb'","\n",[62,90],{"class":64,"style":65},[62,92,93,96,99,102,106],{"class":64,"style":65},[62,94,95],{"style":68},"const ",[62,97,98],{"style":76},"kubb ",[62,100,101],{"style":68},"= ",[62,103,105],{"style":104},"color:#6f42c1;--hls-dark:#b392f0","createKubb",[62,107,108],{"style":72},"({",[62,110,111,114,117,120,123],{"class":64,"style":65},[62,112,113],{"style":72},"  ",[62,115,116],{"style":72},"input",[62,118,119],{"style":68},": ",[62,121,122],{"style":86},"'.\u002FpetStore.yaml'",[62,124,125],{"style":68},",",[62,127,128,130,133,135,137,140,142,145,148],{"class":64,"style":65},[62,129,113],{"style":68},[62,131,132],{"style":72},"output",[62,134,119],{"style":68},[62,136,73],{"style":72},[62,138,139],{"style":72},"path",[62,141,119],{"style":68},[62,143,144],{"style":86},"'.\u002Fgen' ",[62,146,147],{"style":72},"}",[62,149,125],{"style":68},[62,151,152],{"class":64,"style":65},[62,153,154],{"style":72},"})",[62,156],{"class":64,"style":65},[62,158,159,162,164,166,168,171,174,177,180,183,186,188,191,194,197],{"class":64,"style":65},[62,160,161],{"style":76},"kubb",[62,163,29],{"style":68},[62,165,24],{"style":72},[62,167,29],{"style":68},[62,169,170],{"style":104},"hook",[62,172,173],{"style":72},"(",[62,175,176],{"style":86},"'kubb:plugin:end'",[62,178,179],{"style":68},", ",[62,181,182],{"style":72},"({ ",[62,184,185],{"style":76},"plugin",[62,187,179],{"style":68},[62,189,190],{"style":76},"duration ",[62,192,193],{"style":72},"}) ",[62,195,196],{"style":68},"=> ",[62,198,199],{"style":72},"{",[62,201,202,204,207,209,212,214,217,220,222,224,227,229,232,234,237,239,242],{"class":64,"style":65},[62,203,113],{"style":72},[62,205,206],{"style":76},"console",[62,208,29],{"style":68},[62,210,211],{"style":104},"log",[62,213,173],{"style":72},[62,215,216],{"style":86},"`",[62,218,219],{"style":76},"${",[62,221,185],{"style":76},[62,223,29],{"style":68},[62,225,226],{"style":72},"name",[62,228,147],{"style":76},[62,230,231],{"style":86}," finished in ",[62,233,219],{"style":76},[62,235,236],{"style":76},"duration",[62,238,147],{"style":76},[62,240,241],{"style":86},"ms`",[62,243,244],{"style":72},")",[62,246,247],{"class":64,"style":65},[62,248,154],{"style":72},[62,250],{"class":64,"style":65},[62,252,253,255,257,259,261,263,265,268,270,272,275,277,279],{"class":64,"style":65},[62,254,161],{"style":76},[62,256,29],{"style":68},[62,258,24],{"style":72},[62,260,29],{"style":68},[62,262,170],{"style":104},[62,264,173],{"style":72},[62,266,267],{"style":86},"'kubb:build:end'",[62,269,179],{"style":68},[62,271,182],{"style":72},[62,273,274],{"style":76},"files ",[62,276,193],{"style":72},[62,278,196],{"style":68},[62,280,199],{"style":72},[62,282,283,285,287,289,291,293,296,298,301,303,306,308,311],{"class":64,"style":65},[62,284,113],{"style":72},[62,286,206],{"style":76},[62,288,29],{"style":68},[62,290,211],{"style":104},[62,292,173],{"style":72},[62,294,295],{"style":86},"`Generated ",[62,297,219],{"style":76},[62,299,300],{"style":76},"files",[62,302,29],{"style":68},[62,304,305],{"style":72},"length",[62,307,147],{"style":76},[62,309,310],{"style":86}," files`",[62,312,244],{"style":72},[62,314,315],{"class":64,"style":65},[62,316,154],{"style":72},[62,318],{"class":64,"style":65},[62,320,321,324,326,328,331],{"class":64,"style":65},[62,322,323],{"style":68},"await ",[62,325,161],{"style":76},[62,327,29],{"style":68},[62,329,330],{"style":104},"build",[62,332,333],{"style":72},"()",[38,335,337],{"id":336},"firing-order","Firing order",[10,339,340],{},"A full generation run fires the hooks in this order.",[342,343],"lifecycle-timeline",{},[38,345,347],{"id":346},"generation-run","Generation run",[10,349,350,351,354,355,358],{},"These wrap a full run. A direct ",[14,352,353],{},".build()"," or ",[14,356,357],{},".safeBuild()"," does not fire them.",[360,361,362,378],"table",{},[363,364,365],"thead",{},[366,367,368,372,375],"tr",{},[369,370,371],"th",{},"Hook",[369,373,374],{},"Payload",[369,376,377],{},"When it fires",[379,380,381,397,412,425,437,452,467],"tbody",{},[366,382,383,389,394],{},[384,385,386],"td",{},[14,387,388],{},"kubb:lifecycle:start",[384,390,391],{},[14,392,393],{},"{ version }",[384,395,396],{},"The bundler plugin starts, before anything else",[366,398,399,404,409],{},[384,400,401],{},[14,402,403],{},"kubb:generation:start",[384,405,406],{},[14,407,408],{},"{ config }",[384,410,411],{},"A run begins, before setup",[366,413,414,419,422],{},[384,415,416],{},[14,417,418],{},"kubb:setup:start",[384,420,421],{},"none",[384,423,424],{},"Before the driver and storage are initialized",[366,426,427,432,434],{},[384,428,429],{},[14,430,431],{},"kubb:setup:end",[384,433,421],{},[384,435,436],{},"After setup, before the build pipeline",[366,438,439,444,449],{},[384,440,441],{},[14,442,443],{},"kubb:generation:end",[384,445,446],{},[14,447,448],{},"{ config, storage, status, diagnostics, filesCreated, hrStart }",[384,450,451],{},"The run finishes, after the output passes",[366,453,454,459,464],{},[384,455,456],{},[14,457,458],{},"kubb:generation:summary",[384,460,461],{},[14,462,463],{},"KubbGenerationSummaryContext",[384,465,466],{},"After the run, with the summary the reporters render",[366,468,469,474,476],{},[384,470,471],{},[14,472,473],{},"kubb:lifecycle:end",[384,475,421],{},[384,477,478],{},"The bundler plugin is done",[38,480,482],{"id":481},"build-pipeline","Build pipeline",[10,484,485,486,488,489,491],{},"These come from the pipeline, so ",[14,487,353],{}," and ",[14,490,357],{}," fire them too.",[360,493,494,504],{},[363,495,496],{},[366,497,498,500,502],{},[369,499,371],{},[369,501,374],{},[369,503,377],{},[379,505,506,521,536,551,566,580,595,610,625,640,672,686],{},[366,507,508,513,518],{},[384,509,510],{},[14,511,512],{},"kubb:plugin:setup",[384,514,515],{},[14,516,517],{},"KubbPluginSetupContext",[384,519,520],{},"Once per plugin during setup, to register generators, resolvers, macros, and options",[366,522,523,528,533],{},[384,524,525],{},[14,526,527],{},"kubb:build:start",[384,529,530],{},[14,531,532],{},"{ config, adapter, meta, getPlugin, files, upsertFile }",[384,534,535],{},"The AST is ready, before plugins run. Skipped when no adapter parsed input",[366,537,538,543,548],{},[384,539,540],{},[14,541,542],{},"kubb:plugin:start",[384,544,545],{},[14,546,547],{},"{ plugin }",[384,549,550],{},"Before a plugin's generators run",[366,552,553,558,563],{},[384,554,555],{},[14,556,557],{},"kubb:generate:schema",[384,559,560],{},[14,561,562],{},"(node, ctx)",[384,564,565],{},"For each schema node the adapter produced",[366,567,568,573,577],{},[384,569,570],{},[14,571,572],{},"kubb:generate:operation",[384,574,575],{},[14,576,562],{},[384,578,579],{},"For each operation node",[366,581,582,587,592],{},[384,583,584],{},[14,585,586],{},"kubb:generate:operations",[384,588,589],{},[14,590,591],{},"(nodes, ctx)",[384,593,594],{},"Once with every operation node",[366,596,597,602,607],{},[384,598,599],{},[14,600,601],{},"kubb:plugin:end",[384,603,604],{},[14,605,606],{},"{ plugin, duration, success, error, config, files, upsertFile }",[384,608,609],{},"After a plugin finishes, with its timing and a file snapshot",[366,611,612,617,622],{},[384,613,614],{},[14,615,616],{},"kubb:plugins:end",[384,618,619],{},[14,620,621],{},"{ config, files, upsertFile }",[384,623,624],{},"After every plugin has generated, before files hit disk. The spot to add aggregate files like a barrel",[366,626,627,632,637],{},[384,628,629],{},[14,630,631],{},"kubb:files:processing:start",[384,633,634],{},[14,635,636],{},"{ files }",[384,638,639],{},"Before the batch of generated files is written",[366,641,642,647,651],{},[384,643,644],{},[14,645,646],{},"kubb:files:processing:update",[384,648,649],{},[14,650,636],{},[384,652,653,654,656,657,660,661,664,665,488,668,671],{},"As files are written. Here ",[14,655,300],{}," holds progress records (",[14,658,659],{},"{ processed, total, percentage, source?, file, config }","), not the ",[14,662,663],{},"FileNode"," array the ",[14,666,667],{},":start",[14,669,670],{},":end"," variants carry",[366,673,674,679,683],{},[384,675,676],{},[14,677,678],{},"kubb:files:processing:end",[384,680,681],{},[14,682,636],{},[384,684,685],{},"After the batch is written",[366,687,688,693,698],{},[384,689,690],{},[14,691,692],{},"kubb:build:end",[384,694,695],{},[14,696,697],{},"{ files, config, outputDir }",[384,699,700],{},"After every file is written",[38,702,704],{"id":703},"output-passes","Output passes",[10,706,707],{},"These run after a successful build, only during a full generation run.",[360,709,710,720],{},[363,711,712],{},[366,713,714,716,718],{},[369,715,371],{},[369,717,374],{},[369,719,377],{},[379,721,722,734,746,758,770,786,804,822,840],{},[366,723,724,729,731],{},[384,725,726],{},[14,727,728],{},"kubb:format:start",[384,730,421],{},[384,732,733],{},"Before the formatter runs",[366,735,736,741,743],{},[384,737,738],{},[14,739,740],{},"kubb:format:end",[384,742,421],{},[384,744,745],{},"After formatting",[366,747,748,753,755],{},[384,749,750],{},[14,751,752],{},"kubb:lint:start",[384,754,421],{},[384,756,757],{},"Before the linter runs",[366,759,760,765,767],{},[384,761,762],{},[14,763,764],{},"kubb:lint:end",[384,766,421],{},[384,768,769],{},"After linting",[366,771,772,777,779],{},[384,773,774],{},[14,775,776],{},"kubb:hooks:start",[384,778,421],{},[384,780,781,782,785],{},"Before the ",[14,783,784],{},"postGenerate"," commands run",[366,787,788,793,798],{},[384,789,790],{},[14,791,792],{},"kubb:hook:start",[384,794,795],{},[14,796,797],{},"{ id, command, name, args }",[384,799,800,801,803],{},"Before one ",[14,802,784],{}," command runs",[366,805,806,811,816],{},[384,807,808],{},[14,809,810],{},"kubb:hook:line",[384,812,813],{},[14,814,815],{},"KubbHookLineContext",[384,817,818,819,821],{},"For each output line a ",[14,820,784],{}," command emits",[366,823,824,829,834],{},[384,825,826],{},[14,827,828],{},"kubb:hook:end",[384,830,831],{},[14,832,833],{},"KubbHookEndContext",[384,835,836,837,839],{},"After one ",[14,838,784],{}," command finishes",[366,841,842,847,849],{},[384,843,844],{},[14,845,846],{},"kubb:hooks:end",[384,848,421],{},[384,850,851,852,854],{},"After every ",[14,853,784],{}," command",[38,856,858],{"id":857},"messaging","Messaging",[10,860,861],{},"These carry log messages and diagnostics, and can fire at any point.",[360,863,864,874],{},[363,865,866],{},[366,867,868,870,872],{},[369,869,371],{},[369,871,374],{},[369,873,377],{},[379,875,876,891,905,919,934],{},[366,877,878,883,888],{},[384,879,880],{},[14,881,882],{},"kubb:info",[384,884,885],{},[14,886,887],{},"{ message, info }",[384,889,890],{},"An informational message",[366,892,893,898,902],{},[384,894,895],{},[14,896,897],{},"kubb:success",[384,899,900],{},[14,901,887],{},[384,903,904],{},"A step completed successfully",[366,906,907,912,916],{},[384,908,909],{},[14,910,911],{},"kubb:warn",[384,913,914],{},[14,915,887],{},[384,917,918],{},"A non-fatal problem",[366,920,921,926,931],{},[384,922,923],{},[14,924,925],{},"kubb:error",[384,927,928],{},[14,929,930],{},"{ error, meta }",[384,932,933],{},"An unstructured error, so its stack survives",[366,935,936,941,946],{},[384,937,938],{},[14,939,940],{},"kubb:diagnostic",[384,942,943],{},[14,944,945],{},"{ diagnostic }",[384,947,948,949,953],{},"A structured ",[19,950,952],{"href":951},"..\u002Fdiagnostics","diagnostic"," (warning, info, or an update notice)",[38,955,957],{"id":956},"related","Related",[959,960,961,973,990,997],"ul",{},[962,963,964,967,968,970,971],"li",{},[19,965,966],{"href":21},"Plugins"," for the plugin ",[14,969,24],{}," map and ",[14,972,517],{},[962,974,975,979,980,179,982,179,984,986,987],{},[19,976,978],{"href":977},".\u002Fengine","Engine"," for ",[14,981,105],{},[14,983,353],{},[14,985,357],{},", and ",[14,988,989],{},".generate()",[962,991,992,996],{},[19,993,995],{"href":994},"\u002Fdocs\u002F5.x\u002Fexplanation\u002Fextensions#plugins","Plugin concepts"," for the lifecycle as prose",[962,998,999,1002,1003,1005],{},[19,1000,1001],{"href":951},"Diagnostics"," for the shape of ",[14,1004,940],{}," payloads",{"title":1007,"searchDepth":1008,"depth":1008,"links":1009},"",5,[1010,1012,1013,1014,1015,1016,1017],{"id":40,"depth":1011,"text":41},2,{"id":336,"depth":1011,"text":337},{"id":346,"depth":1011,"text":347},{"id":481,"depth":1011,"text":482},{"id":703,"depth":1011,"text":704},{"id":857,"depth":1011,"text":858},{"id":956,"depth":1011,"text":957},"Every kubb:* hook a build fires, its payload, and when it fires. Listen with kubb.hooks.hook(name, handler) or from a plugin's hooks map.","md",{"layout":1021,"title":5,"description":1018,"outline":1022,"order":1024,"navigation":1025},"doc",[1011,1023],3,11,{"title":5,"icon":1026},"i-iconoir-refresh-double",{"layout":1021,"outline":1028},[1011,1023],{"title":5,"icon":1026},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks",{"title":5,"description":1018},{"loc":1030},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fhooks.md","docs\u002F5.x\u002Freference\u002Fkit\u002Fhooks","7ioTimtz4ixNqPsdCHkuhanxHD9a5lFFwcggocP0dCM",1792931644889]