-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-spring-boot): add
format
executor
You can now use `nx run your-app:run` to format the code.
- Loading branch information
Showing
11 changed files
with
242 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/nx-spring-boot/src/executors/format/executor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { logger } from '@nrwl/devkit'; | ||
import { mocked } from 'ts-jest/utils'; | ||
|
||
import { formatExecutor } from './executor'; | ||
import { FormatExecutorOptions } from './schema'; | ||
import { GRADLE_WRAPPER_EXECUTABLE, MAVEN_WRAPPER_EXECUTABLE, NX_SPRING_BOOT_PKG } from '@nxrocks/common'; | ||
import { expectExecutorCommandRanWith, mockExecutorContext } from '@nxrocks/common/testing'; | ||
|
||
//first, we mock | ||
jest.mock('child_process'); | ||
jest.mock('@nrwl/workspace/src/utils/fileutils'); | ||
|
||
//then, we import | ||
import * as fsUtility from '@nrwl/workspace/src/utils/fileutils'; | ||
import * as cp from 'child_process'; | ||
|
||
const mockContext = mockExecutorContext(NX_SPRING_BOOT_PKG, 'format'); | ||
const options: FormatExecutorOptions = { | ||
root: 'apps/bootapp' | ||
}; | ||
|
||
describe('Format Executor', () => { | ||
|
||
beforeEach(async () => { | ||
jest.spyOn(logger, 'info'); | ||
jest.spyOn(cp, 'execSync'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it.each` | ||
ignoreWrapper | buildSystem | formatFile | execute | ||
${true} | ${'maven'} | ${'pom.xml'} | ${'mvn spotless:apply '} | ||
${true} | ${'gradle'} | ${'build.gradle'} | ${'gradle spotlessApply '} | ||
${false} | ${'maven'} | ${'pom.xml'} | ${MAVEN_WRAPPER_EXECUTABLE + ' spotless:apply '} | ||
${false} | ${'gradle'} | ${'build.gradle'} | ${GRADLE_WRAPPER_EXECUTABLE + ' spotlessApply '} | ||
`('should execute a $buildSystem format and ignoring wrapper : $ignoreWrapper', async ({ ignoreWrapper, formatFile, execute }) => { | ||
mocked(fsUtility.fileExists).mockImplementation((filePath: string) => filePath.indexOf(formatFile) !== -1); | ||
|
||
await formatExecutor({ ...options, ignoreWrapper }, mockContext); | ||
|
||
expectExecutorCommandRanWith(execute, mockContext, options); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ExecutorContext } from '@nrwl/devkit' | ||
import * as path from 'path' | ||
import { FormatExecutorOptions } from './schema' | ||
import { runBootPluginCommand } from '../../utils/boot-utils' | ||
|
||
export async function formatExecutor(options: FormatExecutorOptions, context: ExecutorContext){ | ||
const root = path.resolve(context.root, options.root); | ||
const result = runBootPluginCommand('format', options.args, { cwd : root, ignoreWrapper: options.ignoreWrapper}); | ||
|
||
if (!result.success) { | ||
throw new Error(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default formatExecutor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface FormatExecutorOptions { | ||
root: string; | ||
ignoreWrapper?: boolean; | ||
args?: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"title": "Format executor", | ||
"description": "", | ||
"cli": "nx", | ||
"type": "object", | ||
"properties": { | ||
"root": { | ||
"description": "The project root", | ||
"type": "string" | ||
}, | ||
"ignoreWrapper": { | ||
"description": "Whether or not to use the embedded wrapper (`mvnw`or `gradlew`) to perfom build operations", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"args": { | ||
"description": "The argument to be passed to the underlying Spring Boot command", | ||
"type": "array", | ||
"default": [] | ||
} | ||
}, | ||
"required": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.