1- import { execSync } from "node:child_process" ;
21import path from "node:path" ;
32import type { Plugin } from "vite" ;
3+ import { generateFromEntryPoint } from "./index" ;
44
55/**
66 * Options for the AppKit types plugin.
@@ -14,22 +14,31 @@ interface AppKitTypesPluginOptions {
1414
1515/**
1616 * Vite plugin to generate types for AppKit queries.
17- * Calls `npx appkit-generate-types` under the hood.
17+ * Calls generateFromEntryPoint under the hood.
1818 * @param options - Options to override default values.
1919 * @returns Vite plugin to generate types for AppKit queries.
2020 */
2121export function appKitTypesPlugin ( options ?: AppKitTypesPluginOptions ) : Plugin {
2222 let root : string ;
23- let appRoot : string ;
2423 let outFile : string ;
2524 let watchFolders : string [ ] ;
2625
27- function generate ( ) {
26+ async function generate ( ) {
2827 try {
29- const args = [ appRoot , outFile ] . join ( " " ) ;
30- execSync ( `npx appkit-generate-types ${ args } ` , {
31- cwd : appRoot ,
32- stdio : "inherit" ,
28+ const warehouseId = process . env . DATABRICKS_WAREHOUSE_ID || "" ;
29+
30+ if ( ! warehouseId ) {
31+ console . warn (
32+ "[AppKit] Warehouse ID not found. Skipping type generation." ,
33+ ) ;
34+ return ;
35+ }
36+
37+ await generateFromEntryPoint ( {
38+ outFile,
39+ queryFolder : watchFolders [ 0 ] ,
40+ warehouseId,
41+ noCache : false ,
3342 } ) ;
3443 } catch ( error ) {
3544 // throw in production to fail the build
@@ -42,16 +51,15 @@ export function appKitTypesPlugin(options?: AppKitTypesPluginOptions): Plugin {
4251
4352 return {
4453 name : "appkit-types" ,
54+
4555 configResolved ( config ) {
4656 root = config . root ;
47- appRoot = path . resolve ( root , ".." ) ;
48-
4957 outFile = path . resolve ( root , options ?. outFile ?? "src/appKitTypes.d.ts" ) ;
50-
5158 watchFolders = ( options ?. watchFolders ?? [ "../config/queries" ] ) . map (
5259 ( folder ) => path . resolve ( root , folder ) ,
5360 ) ;
5461 } ,
62+
5563 buildStart ( ) {
5664 generate ( ) ;
5765 } ,
0 commit comments