Skip to content

Commit

Permalink
add project configuration builder options
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter committed Oct 6, 2024
1 parent b92e333 commit e8517a4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { TargetConfiguration } from '@nx/devkit';
import { buildImageTarget } from './build-image-target';
import { SageMonorepoProjectConfiguration } from './sage-monorepo-project-configuration';
import { SageMonorepoPluginConfiguration } from './sage-monorepo-plugin-configuration';
import { ProjectConfigurationBuilderOptions } from './project-configuration-builder-options';

export async function buildProjectConfiguration(
projectRoot: string,
config: SageMonorepoPluginConfiguration,
options: ProjectConfigurationBuilderOptions,
): Promise<SageMonorepoProjectConfiguration> {
const targets: Record<string, TargetConfiguration> = {};

targets[config.buildImageTargetName] = await buildImageTarget(projectRoot);
const pluginConfig = options.pluginConfig;

targets[pluginConfig.buildImageTargetName] = await buildImageTarget(options.projectRoot);

const metadata = {};
const tags: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PluginOptions } from './plugin-options';

export type PluginConfiguration = {
buildImageTargetName: string;
};

export function createPluginConfiguration({
buildImageTargetName = 'build-image',
}: PluginOptions): PluginConfiguration {
return {
buildImageTargetName,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type PluginOptions = {
buildImageTargetName?: string;
};
17 changes: 12 additions & 5 deletions libs/sage-monorepo/nx-sage-monorepo/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { dirname, join } from 'path';
import { existsSync, readdirSync } from 'fs';
import { getLockFileName } from '@nx/js';
import { SageMonorepoProjectConfiguration } from './sage-monorepo-project-configuration';
import { createPluginConfiguration } from './sage-monorepo-plugin-configuration';
import { SageMonorepoPluginOptions } from './sage-monorepo-plugin-options';
import { createPluginConfiguration } from './plugin-configuration';
import { PluginOptions } from './plugin-options';
import { buildProjectConfiguration } from './build-project-configuration';
import { inferProjectType } from './project-type';
import { inferProjectBuilder } from './project-builder';
import { ProjectConfigurationBuilderOptions } from './project-configuration-builder-options';

function readProjectCOnfigurationsCache(
cachePath: string,
Expand All @@ -36,7 +37,7 @@ function writeProjectConfigurationsToCache(

const projectFilePattern = '{apps,libs}/**/project.json';

export const createNodesV2: CreateNodesV2<SageMonorepoPluginOptions> = [
export const createNodesV2: CreateNodesV2<PluginOptions> = [
projectFilePattern,
async (configFilePaths, options, context) => {
options ??= {};
Expand All @@ -62,7 +63,7 @@ export const createNodesV2: CreateNodesV2<SageMonorepoPluginOptions> = [

async function createNodesInternal(
configFilePath: string,
options: SageMonorepoPluginOptions | undefined,
options: PluginOptions | undefined,
context: CreateNodesContext,
projectConfigurationsCache: Record<string, SageMonorepoProjectConfiguration>,
) {
Expand Down Expand Up @@ -97,7 +98,13 @@ async function createNodesInternal(
getLockFileName(detectPackageManager(context.workspaceRoot)),
])) + configFilePath;

projectConfigurationsCache[hash] ??= await buildProjectConfiguration(projectRoot, pluginConfig);
const projectConfigurationBuilderOptions: ProjectConfigurationBuilderOptions = {
projectRoot,
pluginConfig,
};
projectConfigurationsCache[hash] ??= await buildProjectConfiguration(
projectConfigurationBuilderOptions,
);

const { targets, metadata, tags } = projectConfigurationsCache[hash];
const project: ProjectConfiguration = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PluginConfiguration } from './plugin-configuration';

export type ProjectConfigurationBuilderOptions = {
projectRoot: string;
pluginConfig: PluginConfiguration;
};

This file was deleted.

This file was deleted.

0 comments on commit e8517a4

Please sign in to comment.