Skip to content
Open
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
18 changes: 12 additions & 6 deletions app/api/workflows/[workflowId]/download/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { db } from "@/lib/db";
import { workflows } from "@/lib/db/schema";
import { generateWorkflowModule } from "@/lib/workflow-codegen";
import type { WorkflowEdge, WorkflowNode } from "@/lib/workflow-store";
import { getAllEnvVars, getDependenciesForActions } from "@/plugins";
import { getDependenciesForActions, getEnvVarsForActions } from "@/plugins";

// Path to the Next.js boilerplate directory
const BOILERPLATE_PATH = join(process.cwd(), "lib", "next-boilerplate");
Expand Down Expand Up @@ -154,18 +154,24 @@ function getIntegrationDependencies(
}

/**
* Generate .env.example content based on registered integrations
* Generate .env.example content based on workflow nodes
*/
function generateEnvExample(): string {
function generateEnvExample(nodes: WorkflowNode[]): string {
const lines = ["# Add your environment variables here"];

// Add system integration env vars
lines.push("");
lines.push("# For database integrations");
lines.push("DATABASE_URL=your_database_url");

// Add plugin env vars from registry
const envVars = getAllEnvVars();
// Extract action IDs from workflow nodes
const actionIds = nodes
.filter((node) => node.data.type === "action")
.map((node) => node.data.config?.actionType as string)
.filter(Boolean);

// Get only env vars for used integrations
const envVars = getEnvVarsForActions(actionIds);
const groupedByPrefix: Record<
string,
Array<{ name: string; description: string }>
Expand Down Expand Up @@ -328,7 +334,7 @@ For more information, visit the [Workflow documentation](https://workflow.is).
`;

// Add .env.example file (dynamically generated from plugin registry)
allFiles[".env.example"] = generateEnvExample();
allFiles[".env.example"] = generateEnvExample(workflow.nodes as WorkflowNode[]);

return NextResponse.json({
success: true,
Expand Down
1 change: 1 addition & 0 deletions plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {
getAllDependencies,
getAllEnvVars,
getAllIntegrations,
getEnvVarsForActions,
getCredentialMapping,
getDependenciesForActions,
getIntegration,
Expand Down
28 changes: 28 additions & 0 deletions plugins/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,34 @@ export function getDependenciesForActions(
return deps;
}

/**
* Get environment variables for specific action IDs
*/
export function getEnvVarsForActions(
actionIds: string[]
): Array<{ name: string; description: string }> {
const envVars: Array<{ name: string; description: string }> = [];
const integrations = new Set<IntegrationType>();

// Find which integrations are used
for (const actionId of actionIds) {
const action = findActionById(actionId);
if (action) {
integrations.add(action.integration);
}
}

// Get env vars for those integrations only
for (const integrationType of integrations) {
const plugin = integrationRegistry.get(integrationType);
if (plugin) {
envVars.push(...getPluginEnvVars(plugin));
}
}

return envVars;
}

/**
* Get environment variables for a single plugin (from formFields)
*/
Expand Down