Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-plugin): add generator for plugin-lint
- Loading branch information
1 parent
3d44680
commit 0ad1d23
Showing
8 changed files
with
122 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export interface NxPluginLintExecutorOptions { | ||
validateSchemas: string; | ||
validateImplementationLocations: string; | ||
validateSchemas: boolean; | ||
validateImplementationLocations: boolean; | ||
packageJson: 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
8 changes: 8 additions & 0 deletions
8
packages/nx-plugin/src/generators/plugin-lint/__snapshots__/generator.spec.ts.snap
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,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`plugin-lint generator should add plugin-lint target by default 1`] = ` | ||
Object { | ||
"executor": "@nrwl/nx-plugin:plugin-lint", | ||
"options": Object {}, | ||
} | ||
`; |
40 changes: 40 additions & 0 deletions
40
packages/nx-plugin/src/generators/plugin-lint/generator.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,40 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { Tree, readProjectConfiguration } from '@nrwl/devkit'; | ||
|
||
import generator from './generator'; | ||
import pluginGenerator from '../plugin/plugin'; | ||
import { Linter } from '@nrwl/linter'; | ||
|
||
describe('plugin-lint generator', () => { | ||
let appTree: Tree; | ||
let libName: string; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace(2); | ||
pluginGenerator(appTree, { | ||
name: 'plugin', | ||
importPath: '@acme/plugin', | ||
compiler: 'tsc', | ||
linter: Linter.EsLint, | ||
skipFormat: false, | ||
skipTsConfig: false, | ||
unitTestRunner: 'jest', | ||
}); | ||
}); | ||
|
||
it('should add plugin-lint target by default', async () => { | ||
await generator(appTree, { projectName: 'plugin' }); | ||
const config = readProjectConfiguration(appTree, 'plugin').targets?.[ | ||
'plugin-lint' | ||
]; | ||
expect(config).toMatchSnapshot(); | ||
}); | ||
|
||
it('should not overwrite existing target', async () => { | ||
await generator(appTree, { projectName: 'plugin', targetName: 'build' }); | ||
const config = readProjectConfiguration(appTree, 'plugin').targets?.[ | ||
'build' | ||
]; | ||
expect(config.executor).not.toEqual('@nrwl/nx-plugin:plugin-lint'); | ||
}) | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/nx-plugin/src/generators/plugin-lint/generator.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,40 @@ | ||
import { | ||
formatFiles, | ||
logger, | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { PluginLintGeneratorSchema } from './schema'; | ||
|
||
function normalizeOptions( | ||
options: PluginLintGeneratorSchema | ||
): Required<PluginLintGeneratorSchema> { | ||
return { | ||
...options, | ||
targetName: options.targetName ?? 'plugin-lint', | ||
}; | ||
} | ||
|
||
export default async function pluiginLintGenerator( | ||
tree: Tree, | ||
options: PluginLintGeneratorSchema | ||
) { | ||
const normalizedOptions = normalizeOptions(options); | ||
|
||
const project = readProjectConfiguration(tree, normalizedOptions.projectName); | ||
project.targets ??= {}; | ||
const existing = project.targets[normalizedOptions.targetName]; | ||
if (existing) { | ||
logger.error( | ||
`${normalizedOptions.projectName} > ${normalizedOptions.targetName} already exists.` | ||
); | ||
} else { | ||
project.targets[normalizedOptions.targetName] = { | ||
executor: '@nrwl/nx-plugin:plugin-lint', | ||
options: {}, | ||
}; | ||
updateProjectConfiguration(tree, normalizedOptions.projectName, project); | ||
} | ||
await formatFiles(tree); | ||
} |
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,4 @@ | ||
export interface PluginLintGeneratorSchema { | ||
projectName: string; | ||
targetName?: 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,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"$id": "PluginLint", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"projectName": { | ||
"type": "string", | ||
"description": "Which project should be the target be added to?" | ||
}, | ||
"targetName": { | ||
"type": "string", | ||
"description": "What should the target be called?", | ||
"default": "plugin-lint" | ||
} | ||
}, | ||
"required": ["projectName", "targetName"] | ||
} |