Skip to content

Commit

Permalink
feat(nx-quarkus): make build executor results cacheable
Browse files Browse the repository at this point in the history
This allows leveraring Nx's computation cache and distributed caching
  • Loading branch information
tinesoft authored Jul 9, 2022
1 parent 4528715 commit 6fb6a36
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
16 changes: 12 additions & 4 deletions packages/nx-quarkus/src/generators/project/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,28 @@ describe('project generator', () => {

expect(logger.info).toHaveBeenNthCalledWith(2, `📦 Extracting Quarkus project zip to '${workspaceRoot}/${rootDir}/${options.name}'...`);
});

it('should update workspace.json', async () => {
it.each`
projectType
${'application'}
${'library'}
`(`should update workspace.json for '$projectType'`, async ({ projectType }) => {
const zipFiles = [{ filePath: `${options.artifactId}/pom.xml`, fileContent: POM_XML}, `${options.artifactId}/mvnw`, `${options.artifactId}/README.md`, ];
const quarkusZip = mockZipEntries(zipFiles);
// mock the zip content returned by the real call to Quarkus Initializer
jest.spyOn(mockedResponse.body, 'pipe').mockReturnValue(syncToAsyncIterable(quarkusZip));

await projectGenerator(tree, options);
await projectGenerator(tree, {...options, projectType});

const project = readProjectConfiguration(tree, options.name);
expect(project.root).toBe(`apps/${options.name}`);
const projectDir = projectType === 'application' ? 'apps' : 'libs';
expect(project.root).toBe(`${projectDir}/${options.name}`);

const commands:BuilderCommandAliasType[] = ['dev', 'remoteDev', 'test', 'clean', 'build', 'format', 'format-check', 'package', 'addExtension', 'listExtensions'];
commands.forEach(cmd => {
expect(project.targets[cmd].executor).toBe(`${NX_QUARKUS_PKG}:${cmd}`);
if(cmd === 'build') {
expect(project.targets[cmd].outputs).toEqual([`${project.root}/target`]);
}
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/nx-quarkus/src/generators/project/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export async function projectGenerator(tree: Tree, options: ProjectGeneratorOpti
executor: `${NX_QUARKUS_PKG}:${command}`,
options: {
root: normalizedOptions.projectRoot
}
},
...( command == 'build' ? {outputs: [`${normalizedOptions.projectRoot}/${normalizedOptions.buildSystem === 'MAVEN' ? 'target' : 'build'}`]}: {})
};
}
addProjectConfiguration(tree, normalizedOptions.projectName, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import {
Tree,
names,
getWorkspaceLayout,
} from '@nrwl/devkit';
import { getProjectRootDir } from '@nxrocks/common';
import { ProjectGeneratorOptions, NormalizedSchema } from '../schema';



export function normalizeOptions(tree:Tree,
options: ProjectGeneratorOptions
): NormalizedSchema {
const { appsDir, libsDir } = getWorkspaceLayout(tree);
const projectRootDir = options.projectType === 'application' ? appsDir : libsDir;
const projectRootDir = getProjectRootDir(tree, options.projectType);
const name = names(options.name).fileName;
const projectDirectory = options.directory
? `${names(options.directory).fileName}/${name}`
: name;
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
const projectName = projectDirectory.replace(/\//g, '-');
const projectRoot = `${projectRootDir}/${projectDirectory}`;
const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-quarkus/src/generators/project/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ProjectGeneratorOptions {

quarkusInitializerUrl?: string;

buildSystem?: 'MAVEN' | 'GRADLE' | 'GRADLE_KOTLIN_DSL';
buildSystem: 'MAVEN' | 'GRADLE' | 'GRADLE_KOTLIN_DSL';
groupId?: string;
artifactId?: string;
skipCodeSamples?: boolean;
Expand Down

0 comments on commit 6fb6a36

Please sign in to comment.