Skip to content

Commit

Permalink
fix(nx-spring-boot): correct generation issue on Nx workspaces >=v11.2.0
Browse files Browse the repository at this point in the history
Closes #37
  • Loading branch information
tinesoft committed Feb 7, 2021
1 parent 116e140 commit d3c3816
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 43 deletions.
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/build-image/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: BuildImageBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +36,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildImage = await architect.scheduleBuilder(
Expand All @@ -55,7 +56,7 @@ describe('Command Runner Builder', () => {
});

it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildImage = await architect.scheduleBuilder(
Expand Down
14 changes: 8 additions & 6 deletions packages/nx-spring-boot/src/builders/build-info/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Architect } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { schema } from '@angular-devkit/core';
import { join } from 'path';

import { BuildInfoBuilderSchema } from './schema';

jest.mock('child_process'); // we need to mock 'execSync' (see __mocks__/child_process.js)
Expand All @@ -13,14 +14,15 @@ const options: BuildInfoBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +37,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildInfo = await architect.scheduleBuilder(
Expand All @@ -56,7 +58,7 @@ describe('Command Runner Builder', () => {


it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildInfo = await architect.scheduleBuilder(
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/build-jar/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: BuildJarBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -36,7 +37,7 @@ describe('Command Runner Builder', () => {


it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildJar = await architect.scheduleBuilder(
Expand All @@ -56,7 +57,7 @@ describe('Command Runner Builder', () => {
});

it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildJar = await architect.scheduleBuilder(
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/build-war/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: BuildWarBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +36,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildWar = await architect.scheduleBuilder(
Expand All @@ -56,7 +57,7 @@ describe('Command Runner Builder', () => {


it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const buildWar = await architect.scheduleBuilder(
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/clean/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: CleanBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +36,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build ', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const clean = await architect.scheduleBuilder(
Expand All @@ -55,7 +56,7 @@ describe('Command Runner Builder', () => {
});

it('can run gradle build ', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const clean = await architect.scheduleBuilder(
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/run/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: RunBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +36,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const run = await architect.scheduleBuilder(
Expand All @@ -55,7 +56,7 @@ describe('Command Runner Builder', () => {
});

it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const run = await architect.scheduleBuilder(
Expand Down
13 changes: 7 additions & 6 deletions packages/nx-spring-boot/src/builders/test/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const options: TestBuilderSchema = {
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
let fileExists: jest.Mock<any>;
let statSync: jest.Mock;

beforeEach(async () => {
jest.resetModules();

fileExists = jest.fn();
jest.doMock('@nrwl/workspace/src/utils/fileutils', () => ({
fileExists,
statSync = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual('fs'),
statSync
}));

const registry = new schema.CoreSchemaRegistry();
Expand All @@ -35,7 +36,7 @@ describe('Command Runner Builder', () => {
});

it('can run maven build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('pom.xml') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('pom.xml') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const test = await architect.scheduleBuilder(
Expand All @@ -55,7 +56,7 @@ describe('Command Runner Builder', () => {
});

it('can run gradle build', async () => {
fileExists.mockImplementation((path: string) => path.indexOf('build.gradle') !== -1)
statSync.mockImplementation((path: string) => ({ isFile: () => path.indexOf('build.gradle') !== -1 }))

// A "run" can have multiple outputs, and contains progress information.
const test = await architect.scheduleBuilder(
Expand Down
9 changes: 8 additions & 1 deletion packages/nx-spring-boot/src/utils/boot-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ import { BuildCommandAliasType, BuildCore } from '../core/build-core.class';
import { GradleBuild } from '../core/gradle-build.class';
import { MavenBuild } from '../core/maven-build.class';
import { NormalizedSchema } from '../schematics/application/schema';
import { fileExists } from '@nrwl/workspace/src/utils/fileutils';
import * as fs from 'fs';

export function fileExists(filePath: string): boolean {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}

export function determineBuildSystem(cwd: string): BuildCore {
if (fileExists(`${cwd}/pom.xml`))
Expand Down

0 comments on commit d3c3816

Please sign in to comment.