Skip to content

Commit

Permalink
infer Angular framework
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter committed Oct 11, 2024
1 parent b6544e6 commit 372db36
Show file tree
Hide file tree
Showing 3 changed files with 21 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 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 372db36

Please sign in to comment.