Skip to content

Commit

Permalink
feat(sage-monorepo): nx plugin now infers projects that use the Angul…
Browse files Browse the repository at this point in the history
…ar framework (#2894)
  • Loading branch information
tschaffter authored Oct 11, 2024
1 parent e2ecb1f commit b95bc34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { TargetConfiguration } from '@nx/devkit';
import { Builder } from './project-metadata';
import { Builder, Framework } from './project-metadata';

export async function buildImageTarget(
projectRoot: string,
projectName: string,
projectBuilder: Builder | undefined | null, // TODO: builder could be app or image, be more specific
projectFramework: Framework | null,
): Promise<TargetConfiguration> {
const dependsOn = [];
if (projectBuilder === 'gradle') {
dependsOn.push({
target: 'build-image-base',
});
} else if (projectBuilder === 'webpack') {
} else if (projectBuilder === 'webpack' && projectFramework === 'angular') {
dependsOn.push({
// TODO: the task `server` is more about Angular that the build itself. To revisit. Also,
// shall we let the user decide between CSR and SSR?
Expand All @@ -25,6 +26,7 @@ export async function buildImageTarget(

let context = projectRoot;
// TODO: The context must be set to '.' for Angular app. Be more specific.
// Actually, this is also valid for `agora-api` built with Webpack.
if (projectBuilder === 'webpack') {
context = '.';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ export async function buildProjectConfiguration(

const pluginConfig = options.pluginConfig;

if (options.projectMetadata.containerType === 'Docker') {
if (options.projectMetadata.containerType === 'docker') {
targets[pluginConfig.buildImageTargetName] = await buildImageTarget(
options.projectRoot,
options.projectName,
options.projectMetadata.builder,
options.projectMetadata.framework,
);
}

Expand Down
20 changes: 16 additions & 4 deletions libs/sage-monorepo/nx-plugin/src/plugins/project-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export type Builder = 'esbuild' | 'webpack' | 'gradle' | 'maven' | 'poetry';
// export type TypeChecker = 'mypy' | 'pyright';
// export type TestingTool = 'pytest' | null;
// export type Formatter = 'Black' | 'Prettier';
export type ContainerType = 'Docker' | 'Singularity';
export type ContainerType = 'docker' | 'singularity';
// export type Language = 'python' | 'typescript' | 'javascript';
// export type Framework = 'Flask' | 'React' | 'Angular' | 'Vue' | null;
export type Framework = 'angular';

export type ProjectMetadata = {
projectType: ProjectType;
Expand All @@ -24,7 +24,7 @@ export type ProjectMetadata = {
// formatter: Formatter;
containerType: ContainerType | null;
// language: Language;
// framework: Framework;
framework: Framework | null;
};

export function inferProjectMetadata(
Expand All @@ -37,6 +37,7 @@ export function inferProjectMetadata(
projectType: inferProjectType(projectRoot),
builder: inferBuilder(siblingFiles, localProjectConfiguration),
containerType: inferContainerType(siblingFiles),
framework: inferFramework(localProjectConfiguration),
};
}

Expand Down Expand Up @@ -68,7 +69,18 @@ function inferBuilder(
}

function inferContainerType(siblingFiles: string[]): ContainerType | null {
if (siblingFiles.includes('Dockerfile')) return 'Docker';
if (siblingFiles.includes('Dockerfile')) return 'docker';

return null;
}

function inferFramework(localProjectConfiguration: ProjectConfiguration): Framework | null {
const buildExecutor = localProjectConfiguration?.targets?.['build']?.executor ?? '';
const angularBuildExecutors = ['@angular-devkit/build-angular:browser'];

if (angularBuildExecutors.includes(buildExecutor)) {
return 'angular';
}

return null;
}

0 comments on commit b95bc34

Please sign in to comment.