Skip to content

Commit b95bc34

Browse files
authored
feat(sage-monorepo): nx plugin now infers projects that use the Angular framework (#2894)
1 parent e2ecb1f commit b95bc34

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

libs/sage-monorepo/nx-plugin/src/plugins/build-image-target.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { TargetConfiguration } from '@nx/devkit';
2-
import { Builder } from './project-metadata';
2+
import { Builder, Framework } from './project-metadata';
33

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

2627
let context = projectRoot;
2728
// TODO: The context must be set to '.' for Angular app. Be more specific.
29+
// Actually, this is also valid for `agora-api` built with Webpack.
2830
if (projectBuilder === 'webpack') {
2931
context = '.';
3032
}

libs/sage-monorepo/nx-plugin/src/plugins/build-project-configuration.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ export async function buildProjectConfiguration(
1010

1111
const pluginConfig = options.pluginConfig;
1212

13-
if (options.projectMetadata.containerType === 'Docker') {
13+
if (options.projectMetadata.containerType === 'docker') {
1414
targets[pluginConfig.buildImageTargetName] = await buildImageTarget(
1515
options.projectRoot,
1616
options.projectName,
1717
options.projectMetadata.builder,
18+
options.projectMetadata.framework,
1819
);
1920
}
2021

libs/sage-monorepo/nx-plugin/src/plugins/project-metadata.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export type Builder = 'esbuild' | 'webpack' | 'gradle' | 'maven' | 'poetry';
77
// export type TypeChecker = 'mypy' | 'pyright';
88
// export type TestingTool = 'pytest' | null;
99
// export type Formatter = 'Black' | 'Prettier';
10-
export type ContainerType = 'Docker' | 'Singularity';
10+
export type ContainerType = 'docker' | 'singularity';
1111
// export type Language = 'python' | 'typescript' | 'javascript';
12-
// export type Framework = 'Flask' | 'React' | 'Angular' | 'Vue' | null;
12+
export type Framework = 'angular';
1313

1414
export type ProjectMetadata = {
1515
projectType: ProjectType;
@@ -24,7 +24,7 @@ export type ProjectMetadata = {
2424
// formatter: Formatter;
2525
containerType: ContainerType | null;
2626
// language: Language;
27-
// framework: Framework;
27+
framework: Framework | null;
2828
};
2929

3030
export function inferProjectMetadata(
@@ -37,6 +37,7 @@ export function inferProjectMetadata(
3737
projectType: inferProjectType(projectRoot),
3838
builder: inferBuilder(siblingFiles, localProjectConfiguration),
3939
containerType: inferContainerType(siblingFiles),
40+
framework: inferFramework(localProjectConfiguration),
4041
};
4142
}
4243

@@ -68,7 +69,18 @@ function inferBuilder(
6869
}
6970

7071
function inferContainerType(siblingFiles: string[]): ContainerType | null {
71-
if (siblingFiles.includes('Dockerfile')) return 'Docker';
72+
if (siblingFiles.includes('Dockerfile')) return 'docker';
73+
74+
return null;
75+
}
76+
77+
function inferFramework(localProjectConfiguration: ProjectConfiguration): Framework | null {
78+
const buildExecutor = localProjectConfiguration?.targets?.['build']?.executor ?? '';
79+
const angularBuildExecutors = ['@angular-devkit/build-angular:browser'];
80+
81+
if (angularBuildExecutors.includes(buildExecutor)) {
82+
return 'angular';
83+
}
7284

7385
return null;
7486
}

0 commit comments

Comments
 (0)