Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
runner: {
mode: 'harness',
files: [$GENKIT_HARNESS_FILES],
},
};
26 changes: 26 additions & 0 deletions genkit-tools/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ const sampleTemplatePaths: Record<Platform, string> = {
nextjs: '../../config/nextjs.genkit.ts.template',
};

const nextjsToolsConfigTemplatePath =
'../../config/nextjs.genkit-tools.config.js.template';

/** Supported runtimes for the init command. */
const supportedRuntimes: Runtime[] = ['node'];

Expand Down Expand Up @@ -250,6 +253,7 @@ export const init = new Command('init')
) {
generateSampleFile(platform, modelOptions[model].plugin, plugins);
}
generateToolsConfig(platform);
} catch (error) {
logger.error(error);
process.exit(1);
Expand Down Expand Up @@ -325,6 +329,28 @@ async function updatePackageJson() {
fs.writeFileSync(packageJsonPath, JSON.stringify(newPackageJson, null, 2));
}

/**
* Generates an appropriate tools config for the given platform.
* @param platform platform
*/
function generateToolsConfig(platform: Platform) {
if (platform === 'nextjs') {
const templatePath = path.join(__dirname, nextjsToolsConfigTemplatePath);
let template = fs.readFileSync(templatePath, 'utf8');
if (fs.existsSync('src/app')) {
template = template.replace('$GENKIT_HARNESS_FILES', `'./src/app/*.ts'`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked about this in chat whether we want/need to limit this more to include only genkit related files... but it seems to work like this, so perhaps not necessary.

} else if (fs.existsSync('app')) {
template = template.replace('$GENKIT_HARNESS_FILES', `'./app/*.js'`);
} else {
throw new Error(
'Unable to resolve source folder (app or src/app) of you next.js app.'
);
}
const configPath = path.join(process.cwd(), 'genkit-tools.conf.js');
fs.writeFileSync(configPath, template, 'utf8');
}
}

/**
* Generates a sample index.ts file.
* @param platform Deployment platform.
Expand Down
10 changes: 6 additions & 4 deletions genkit-tools/common/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ export class Runner {
}
if (this.autoReload) {
const config = await findToolsConfig();
this.buildCommand = config?.builder?.cmd;
if (!this.buildCommand && detectRuntime(process.cwd()) === 'node') {
this.buildCommand = 'npm run build';
if (config?.runner?.mode !== 'harness') {
this.buildCommand = config?.builder?.cmd;
if (!this.buildCommand && detectRuntime(process.cwd()) === 'node') {
this.buildCommand = 'npm run build';
}
this.build();
}
this.build();
this.watchForChanges();
}
return this.startApp();
Expand Down