-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-test-runner): add init generator
- Loading branch information
robby rabbitman
committed
Jun 29, 2024
1 parent
291520d
commit f77acfc
Showing
17 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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 @@ | ||
# web-test-runner |
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,11 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft-07/schema", | ||
"generators": { | ||
"init": { | ||
"factory": "./src/generators/init", | ||
"schema": "./src/generators/init.schema.json", | ||
"description": "Registers @robby-rabbitman/web-test-runner/plugin in the nx.json.", | ||
"hidden": true | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ges/web-test-runner-plugin/jest.config.ts → packages/web-test-runner/jest.config.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft-07/schema", | ||
"cli": "nx", | ||
"$id": "RobbyRabbitmanWebTestRunnerInit", | ||
"title": "Initializes the @robby-rabbitman/web-test-runner in a nx workspace.", | ||
"description": "Registers @robby-rabbitman/web-test-runner/plugin in the nx.json.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"targetName": { | ||
"description": "The name of the web-test-runner target", | ||
"type": "string", | ||
"default": "test" | ||
}, | ||
"skipFormat": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"skipAddPlugin": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
ExpandedPluginConfiguration, | ||
Generator, | ||
formatFiles, | ||
readNxJson, | ||
updateNxJson, | ||
} from '@nx/devkit'; | ||
|
||
export const webTestRunnerPluginPath = | ||
'@robby-rabbitman/web-test-runner/plugin'; | ||
|
||
export interface WebTestRunnerInitGeneratorSchema { | ||
testTarget?: string; | ||
skipAddPlugin?: boolean; | ||
skipFormat?: boolean; | ||
} | ||
|
||
export const initGenerator: Generator< | ||
WebTestRunnerInitGeneratorSchema | ||
> = async (tree, schema) => { | ||
if (!schema?.skipAddPlugin) { | ||
const nxJson = readNxJson(tree); | ||
nxJson.plugins ??= []; | ||
|
||
const hasPlugin = nxJson.plugins.some((pluginConfig) => | ||
typeof pluginConfig === 'string' | ||
? pluginConfig === webTestRunnerPluginPath | ||
: pluginConfig.plugin === webTestRunnerPluginPath | ||
); | ||
|
||
if (!hasPlugin) { | ||
nxJson.plugins.push(webTestRunnerPluginConfiguration(schema)); | ||
updateNxJson(tree, nxJson); | ||
} | ||
} | ||
|
||
if (!schema?.skipFormat) { | ||
await formatFiles(tree); | ||
} | ||
}; | ||
|
||
export default initGenerator; | ||
|
||
const webTestRunnerPluginConfiguration = ( | ||
schema?: WebTestRunnerInitGeneratorSchema | ||
) => | ||
({ | ||
plugin: webTestRunnerPluginPath, | ||
options: { | ||
targetName: schema?.testTarget ?? 'test', | ||
}, | ||
} as ExpandedPluginConfiguration); |
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,2 @@ | ||
export { initGenerator as generator } from './generators/init'; | ||
export { createNodesV2 } from './plugin'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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