docs(misc): refine schemas for @nrwl/workspace (#14522)

This commit is contained in:
Jason Jean 2023-01-20 15:16:45 -05:00 committed by GitHub
parent da0e3ba1c7
commit d6517506df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 78 additions and 22 deletions

View File

@ -123,6 +123,7 @@
"examplesFile": "`workspace.json`:\n\n```json\n//...\n\"frontend\": {\n \"targets\": {\n //...\n \"ls-project-root\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"command\": \"ls apps/frontend/src\"\n }\n }\n }\n}\n```\n\n```bash\nnx run frontend:ls-project-root\n```\n\n##### Chaining commands, interpolating args and setting the cwd\n\nLet's say each of our workspace projects has some custom bash scripts in a `scripts` folder.\nWe want a simple way to create empty bash script files for a given project, that have the execute permissions already set.\n\nGiven that Nx knows our workspace structure, we should be able to give it a project and the name of our script, and it should take care of the rest.\n\nThe `commands` option accepts as many commands as you want. By default, they all run in parallel.\nYou can run them sequentially by setting `parallel: false`:\n\n```json\n\"create-script\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"commands\": [\n \"mkdir -p scripts\",\n \"touch scripts/{args.name}.sh\",\n \"chmod +x scripts/{args.name}.sh\"\n ],\n \"cwd\": \"apps/frontend\",\n \"parallel\": false\n }\n}\n```\n\nBy setting the `cwd` option, each command will run in the `apps/frontend` folder.\n\nWe run the above with:\n\n```bash\nnx run frontend:create-script --args=\"--name=example\"\n```\n\nor simply with:\n\n```bash\nnx run frontend:create-script --name=example\n```\n\n##### Arguments forwarding\n\nWhen interpolation is not present in the command, all arguments are forwarded to the command by default.\n\nThis is useful when you need to pass raw argument strings to your command.\n\nFor example, when you run:\n\nnx run frontend:webpack --args=\"--config=example.config.js\"\n\n```json\n\"webpack\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"command\": \"webpack\"\n }\n}\n```\n\nThe above command will execute: `webpack --config=example.config.js`\n\nThis functionality can be disabled by using `commands` and expanding each `command` into an object\nthat sets the `forwardAllArgs` option to `false` as shown below:\n\n```json\n\"webpack\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"commands\": [\n {\n \"command\": \"webpack\",\n \"forwardAllArgs\": false\n }\n ]\n }\n}\n```\n\n##### Custom **done** conditions\n\nNormally, `run-commands` considers the commands done when all of them have finished running. If you don't need to wait until they're all done, you can set a special string that considers the commands finished the moment the string appears in `stdout` or `stderr`:\n\n```json\n\"finish-when-ready\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"commands\": [\n \"sleep 5 && echo 'FINISHED'\",\n \"echo 'READY'\"\n ],\n \"readyWhen\": \"READY\",\n \"parallel\": true\n }\n}\n```\n\n```bash\nnx run frontend:finish-when-ready\n```\n\nThe above commands will finish immediately, instead of waiting for 5 seconds.\n\n##### Nx Affected\n\nThe true power of `run-commands` comes from the fact that it runs through `nx`, which knows about your project graph. So you can run **custom commands** only for the projects that have been affected by a change.\n\nWe can create some configurations to generate docs, and if run using `nx affected`, it will only generate documentation for the projects that have been changed:\n\n```bash\nnx affected --target=generate-docs\n```\n\n```json\n//...\n\"frontend\": {\n \"targets\": {\n //...\n \"generate-docs\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"command\": \"npx compodoc -p apps/frontend/tsconfig.app.json\"\n }\n }\n }\n},\n\"api\": {\n \"targets\": {\n //...\n \"generate-docs\": {\n \"executor\": \"nx:run-commands\",\n \"options\": {\n \"command\": \"npx compodoc -p apps/api/tsconfig.app.json\"\n }\n }\n }\n}\n```\n"
},
"description": "Run any custom commands with Nx.",
"x-deprecated": "Use nx:run-commands instead. This will be removed in v16.",
"aliases": [],
"hidden": false,
"path": "/packages/workspace/src/executors/run-commands/schema.json",

View File

@ -26,6 +26,7 @@
"presets": []
},
"description": "Run an NPM script using Nx.",
"x-deprecated": "Use nx:run-script instead. This will be removed in v16.",
"aliases": [],
"hidden": false,
"path": "/packages/workspace/src/executors/run-script/schema.json",

View File

@ -27,7 +27,8 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
}
},
"presets": []

View File

@ -24,7 +24,8 @@
},
"directory": {
"type": "string",
"description": "A directory where the lib is placed."
"description": "A directory where the lib is placed.",
"x-priority": "important"
},
"linter": {
"description": "The tool to use for running lint checks.",
@ -45,7 +46,8 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
},
"skipTsConfig": {
"type": "boolean",
@ -60,7 +62,8 @@
},
"importPath": {
"type": "string",
"description": "The library name used to import it, like `@myorg/my-awesome-lib`."
"description": "The library name used to import it, like `@myorg/my-awesome-lib`.",
"x-priority": "important"
},
"babelJest": {
"type": "boolean",
@ -100,7 +103,8 @@
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"
"type": "boolean",
"x-priority": "internal"
}
},
"required": ["name"],

View File

@ -39,7 +39,8 @@
"type": "boolean",
"aliases": ["skip-format"],
"description": "Skip formatting files.",
"default": false
"default": false,
"x-priority": "internal"
}
},
"required": ["projectName", "destination"],

View File

@ -35,7 +35,8 @@
"type": "boolean",
"aliases": ["skip-format"],
"description": "Skip formatting files.",
"default": false
"default": false,
"x-priority": "internal"
},
"importPath": {
"type": "string",

View File

@ -24,7 +24,8 @@
"project": {
"description": "Project name.",
"type": "string",
"x-prompt": "What project does the target belong to?"
"x-prompt": "What project does the target belong to?",
"x-dropdown": "projects"
},
"command": {
"description": "Command to run.",

View File

@ -17,10 +17,11 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
}
},
"required": [],
"required": ["name"],
"presets": []
},
"aliases": ["workspace-schematic"],

View File

@ -104,6 +104,15 @@ export function Content({
>
{schemaViewModel.type}
</div>
{schemaViewModel.deprecated && (
<div
aria-hidden="true"
data-tooltip="Deprecated"
className="relative inline-flex rounded-md border border-red-100 bg-red-50 px-4 py-2 text-xs font-medium uppercase text-red-600 dark:border-red-900 dark:bg-red-900/30 dark:text-red-400"
>
Deprecated
</div>
)}
{schemaViewModel.hidden && (
<div
aria-hidden="true"
@ -144,6 +153,27 @@ export function Content({
</div>
</div>
{schemaViewModel.deprecated && (
<div className="my-6 block rounded-md bg-red-50 p-4 ring-1 ring-red-100 dark:bg-red-900/30 dark:ring-red-900">
<div className="flex">
<div className="flex-shrink-0">
<HandRaisedIcon
className="h-5 w-5 text-red-500"
aria-hidden="true"
/>
</div>
<div className="ml-3">
<div className="mt-0 block text-sm font-medium text-red-600 dark:text-red-400">
Deprecated
</div>
<p className="prose-sm mt-2 block text-red-700 dark:text-red-600">
{schemaViewModel.deprecated}
</p>
</div>
</div>
</div>
)}
{!schemaViewModel.subReference && schemaViewModel.hidden && (
<div className="my-6 block rounded-md bg-red-50 p-4 ring-1 ring-red-100 dark:bg-red-900/30 dark:ring-red-900">
<div className="flex">

View File

@ -19,6 +19,7 @@ function getReferenceFromQuery(query: string): string {
export interface SchemaViewModel {
currentSchema: NxSchema | null;
currentSchemaExamples: Example | Errors;
deprecated: string;
hidden: boolean;
lookup: Lookup;
packageName: string;
@ -63,6 +64,7 @@ export function getSchemaViewModel(
);
},
hidden: schema.hidden,
deprecated: schema['x-deprecated'],
type: schema.type,
};
}

View File

@ -76,6 +76,8 @@ export interface SchemaMetadata {
path: string;
schema: NxSchema | null;
type: 'executor' | 'generator';
'x-deprecated'?: string;
}
export interface NxSchema extends JsonSchema1 {

View File

@ -15,7 +15,8 @@
"run-commands": {
"implementation": "./src/executors/run-commands/run-commands.impl",
"schema": "./src/executors/run-commands/schema.json",
"description": "Run any custom commands with Nx."
"description": "Run any custom commands with Nx.",
"x-deprecated": "Use nx:run-commands instead. This will be removed in v16."
},
"counter": {
"implementation": "./src/executors/counter/counter.impl",
@ -27,7 +28,8 @@
"run-script": {
"implementation": "./src/executors/run-script/run-script.impl",
"schema": "./src/executors/run-script/schema.json",
"description": "Run an NPM script using Nx."
"description": "Run an NPM script using Nx.",
"x-deprecated": "Use nx:run-script instead. This will be removed in v16."
}
}
}

View File

@ -27,7 +27,8 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
}
}
}

View File

@ -24,7 +24,8 @@
},
"directory": {
"type": "string",
"description": "A directory where the lib is placed."
"description": "A directory where the lib is placed.",
"x-priority": "important"
},
"linter": {
"description": "The tool to use for running lint checks.",
@ -45,7 +46,8 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
},
"skipTsConfig": {
"type": "boolean",
@ -60,7 +62,8 @@
},
"importPath": {
"type": "string",
"description": "The library name used to import it, like `@myorg/my-awesome-lib`."
"description": "The library name used to import it, like `@myorg/my-awesome-lib`.",
"x-priority": "important"
},
"babelJest": {
"type": "boolean",
@ -100,7 +103,8 @@
},
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"
"type": "boolean",
"x-priority": "internal"
}
},
"required": ["name"]

View File

@ -39,7 +39,8 @@
"type": "boolean",
"aliases": ["skip-format"],
"description": "Skip formatting files.",
"default": false
"default": false,
"x-priority": "internal"
}
},
"required": ["projectName", "destination"]

View File

@ -35,7 +35,8 @@
"type": "boolean",
"aliases": ["skip-format"],
"description": "Skip formatting files.",
"default": false
"default": false,
"x-priority": "internal"
},
"importPath": {
"type": "string",

View File

@ -24,7 +24,8 @@
"project": {
"description": "Project name.",
"type": "string",
"x-prompt": "What project does the target belong to?"
"x-prompt": "What project does the target belong to?",
"x-dropdown": "projects"
},
"command": {
"description": "Command to run.",

View File

@ -17,8 +17,9 @@
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false
"default": false,
"x-priority": "internal"
}
},
"required": []
"required": ["name"]
}