-
-
Notifications
You must be signed in to change notification settings - Fork 33
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-check
executor to check code format
You can also use the alias `check-format` to run the executor
- Loading branch information
Showing
9 changed files
with
119 additions
and
2 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
47 changes: 47 additions & 0 deletions
47
packages/nx-spring-boot/src/executors/format-check/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 { formatCheckExecutor } from './executor'; | ||
import { FormatCheckExecutorOptions } 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-check'); | ||
const options: FormatCheckExecutorOptions = { | ||
root: 'apps/bootapp' | ||
}; | ||
|
||
describe('Format Check 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:check '} | ||
${true} | ${'gradle'} | ${'build.gradle'} | ${'gradle spotlessCheck '} | ||
${false} | ${'maven'} | ${'pom.xml'} | ${MAVEN_WRAPPER_EXECUTABLE + ' spotless:check '} | ||
${false} | ${'gradle'} | ${'build.gradle'} | ${GRADLE_WRAPPER_EXECUTABLE + ' spotlessCheck '} | ||
`('should execute a $buildSystem format check and ignoring wrapper : $ignoreWrapper', async ({ ignoreWrapper, formatFile, execute }) => { | ||
mocked(fsUtility.fileExists).mockImplementation((filePath: string) => filePath.indexOf(formatFile) !== -1); | ||
|
||
await formatCheckExecutor({ ...options, ignoreWrapper }, mockContext); | ||
|
||
expectExecutorCommandRanWith(execute, mockContext, options); | ||
}); | ||
|
||
}); |
17 changes: 17 additions & 0 deletions
17
packages/nx-spring-boot/src/executors/format-check/executor.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,17 @@ | ||
import { ExecutorContext } from '@nrwl/devkit' | ||
import * as path from 'path' | ||
import { runBootPluginCommand } from '../../utils/boot-utils'; | ||
import { FormatCheckExecutorOptions } from './schema' | ||
|
||
export async function formatCheckExecutor(options: FormatCheckExecutorOptions, context: ExecutorContext){ | ||
const root = path.resolve(context.root, options.root); | ||
const result = runBootPluginCommand('format-check', options.args, { cwd : root, ignoreWrapper: options.ignoreWrapper}); | ||
|
||
if (!result.success) { | ||
throw new Error(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default formatCheckExecutor; |
6 changes: 6 additions & 0 deletions
6
packages/nx-spring-boot/src/executors/format-check/schema.d.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,6 @@ | ||
|
||
export interface FormatCheckExecutorOptions { | ||
root: string; | ||
ignoreWrapper?: boolean; | ||
args?: string[]; | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/nx-spring-boot/src/executors/format-check/schema.json
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": "Check 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