@@ -150,6 +150,9 @@ const sampleTemplatePaths: Record<Platform, string> = {
150
150
nextjs : '../../config/nextjs.genkit.ts.template' ,
151
151
} ;
152
152
153
+ const nextjsToolsConfigTemplatePath =
154
+ '../../config/nextjs.genkit-tools.config.js.template' ;
155
+
153
156
/** Supported runtimes for the init command. */
154
157
const supportedRuntimes : Runtime [ ] = [ 'node' ] ;
155
158
@@ -250,6 +253,7 @@ export const init = new Command('init')
250
253
) {
251
254
generateSampleFile ( platform , modelOptions [ model ] . plugin , plugins ) ;
252
255
}
256
+ generateToolsConfig ( platform ) ;
253
257
} catch ( error ) {
254
258
logger . error ( error ) ;
255
259
process . exit ( 1 ) ;
@@ -325,6 +329,28 @@ async function updatePackageJson() {
325
329
fs . writeFileSync ( packageJsonPath , JSON . stringify ( newPackageJson , null , 2 ) ) ;
326
330
}
327
331
332
+ /**
333
+ * Generates an appropriate tools config for the given platform.
334
+ * @param platform platform
335
+ */
336
+ function generateToolsConfig ( platform : Platform ) {
337
+ if ( platform === 'nextjs' ) {
338
+ const templatePath = path . join ( __dirname , nextjsToolsConfigTemplatePath ) ;
339
+ let template = fs . readFileSync ( templatePath , 'utf8' ) ;
340
+ if ( fs . existsSync ( 'src/app' ) ) {
341
+ template = template . replace ( '$GENKIT_HARNESS_FILES' , `'./src/app/*.ts'` ) ;
342
+ } else if ( fs . existsSync ( 'app' ) ) {
343
+ template = template . replace ( '$GENKIT_HARNESS_FILES' , `'./app/*.js'` ) ;
344
+ } else {
345
+ throw new Error (
346
+ 'Unable to resolve source folder (app or src/app) of you next.js app.'
347
+ ) ;
348
+ }
349
+ const configPath = path . join ( process . cwd ( ) , 'genkit-tools.conf.js' ) ;
350
+ fs . writeFileSync ( configPath , template , 'utf8' ) ;
351
+ }
352
+ }
353
+
328
354
/**
329
355
* Generates a sample index.ts file.
330
356
* @param platform Deployment platform.
0 commit comments