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
16 changes: 13 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion src/application/project/sdk/phpSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export enum PhpEnvVar {
APP_ID = 'CROCT_APP_ID',
}

/**
* An optional Croct integration installed when a companion library is already present.
*/
type Integration = {
detect: string,
install: string,
};

/**
* Base SDK for PHP projects.
*
Expand All @@ -54,6 +62,13 @@ export enum PhpEnvVar {
export abstract class PhpSdk implements Sdk {
private static readonly PHPSTAN_EXTENSION = 'vendor/croct/plug-php/extension.neon';

private static readonly INTEGRATIONS: readonly Integration[] = [
{
detect: 'storyblok/php-content-api-client',
install: 'croct/plug-storyblok',
},
];

protected readonly projectDirectory: WorkingDirectory;

protected readonly packageManager: PackageManager;
Expand Down Expand Up @@ -95,6 +110,8 @@ export abstract class PhpSdk implements Sdk {

const plan = await this.getInstallationPlan(installation);

const dependencies = [...plan.dependencies, ...await this.getIntegrationDependencies()];

const configuration: ProjectConfiguration = {
...plan.configuration,
paths: {
Expand Down Expand Up @@ -126,7 +143,7 @@ export abstract class PhpSdk implements Sdk {
});

try {
await this.packageManager.addDependencies(plan.dependencies, {logger: logger});
await this.packageManager.addDependencies(dependencies, {logger: logger});

notifier.confirm('Dependencies installed');
} catch (error) {
Expand Down Expand Up @@ -294,6 +311,22 @@ export abstract class PhpSdk implements Sdk {
});
}

/**
* Resolves the optional integration dependencies enabled by libraries already in the project.
*
* Merged into the installation plan automatically; subclasses without transparent
* auto-decoration override this to opt out.
*/
protected async getIntegrationDependencies(): Promise<string[]> {
const detected = await Promise.all(
PhpSdk.INTEGRATIONS.map(integration => this.packageManager.hasDependency(integration.detect)),
);

return PhpSdk.INTEGRATIONS
.filter((_, index) => detected[index])
.map(integration => integration.install);
}

protected abstract getInstallationPlan(installation: Installation): Promise<InstallationPlan>;

protected abstract generateSlotExampleFiles(slot: Slot, installation: Installation): Promise<ExampleFile[]>;
Expand Down
8 changes: 8 additions & 0 deletions src/application/project/sdk/plugPhpSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export class PlugPhpSdk extends PhpSdk {
});
}

protected getIntegrationDependencies(): Promise<string[]> {
/*
* Framework-agnostic PHP has no transparent auto-decoration, so optional integrations are
* left for the developer to wire manually.
*/
return Promise.resolve([]);
}

protected async generateSlotExampleFiles(slot: Slot, installation: Installation): Promise<ExampleFile[]> {
const paths = await this.getPaths(installation.configuration);

Expand Down
Loading