diff --git a/docs/generated/manifests/menus.json b/docs/generated/manifests/menus.json index 9e8bc5784aa9e..7273a18b8f5e2 100644 --- a/docs/generated/manifests/menus.json +++ b/docs/generated/manifests/menus.json @@ -261,111 +261,6 @@ "children": [], "disableCollapsible": false }, - { - "name": "Core Tutorial", - "path": "/core-tutorial", - "id": "core-tutorial", - "isExternal": false, - "children": [ - { - "name": "1 - Create Blog", - "path": "/core-tutorial/01-create-blog", - "id": "01-create-blog", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "2 - Create CLI", - "path": "/core-tutorial/02-create-cli", - "id": "02-create-cli", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "3 - Share Assets", - "path": "/core-tutorial/03-share-assets", - "id": "03-share-assets", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "4 - Build Affected Projects", - "path": "/core-tutorial/04-build-affected-projects", - "id": "04-build-affected-projects", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "5 - Automatically Detect Dependencies", - "path": "/core-tutorial/05-auto-detect-dependencies", - "id": "05-auto-detect-dependencies", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "6 - Summary", - "path": "/core-tutorial/06-summary", - "id": "06-summary", - "isExternal": false, - "children": [], - "disableCollapsible": false - } - ], - "disableCollapsible": false - }, - { - "name": "1 - Create Blog", - "path": "/core-tutorial/01-create-blog", - "id": "01-create-blog", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "2 - Create CLI", - "path": "/core-tutorial/02-create-cli", - "id": "02-create-cli", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "3 - Share Assets", - "path": "/core-tutorial/03-share-assets", - "id": "03-share-assets", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "4 - Build Affected Projects", - "path": "/core-tutorial/04-build-affected-projects", - "id": "04-build-affected-projects", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "5 - Automatically Detect Dependencies", - "path": "/core-tutorial/05-auto-detect-dependencies", - "id": "05-auto-detect-dependencies", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, - { - "name": "6 - Summary", - "path": "/core-tutorial/06-summary", - "id": "06-summary", - "isExternal": false, - "children": [], - "disableCollapsible": false - }, { "name": "Features", "path": "/features", diff --git a/docs/generated/manifests/nx.json b/docs/generated/manifests/nx.json index 966e1362fee72..44282ae4351ad 100644 --- a/docs/generated/manifests/nx.json +++ b/docs/generated/manifests/nx.json @@ -73,7 +73,7 @@ "name": "React Standalone", "description": "", "mediaImage": "", - "file": "shared/react-standalone-tutorial/react-standalone", + "file": "shared/tutorials/react-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-standalone-tutorial", @@ -84,7 +84,7 @@ "name": "React Monorepo", "description": "", "mediaImage": "", - "file": "shared/react-tutorial/react-monorepo", + "file": "shared/tutorials/react-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-monorepo-tutorial", @@ -95,7 +95,7 @@ "name": "Angular Standalone", "description": "", "mediaImage": "", - "file": "shared/angular-standalone-tutorial/angular-standalone", + "file": "shared/tutorials/angular-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-standalone-tutorial", @@ -106,7 +106,7 @@ "name": "Angular Monorepo", "description": "", "mediaImage": "", - "file": "shared/angular-tutorial/angular-monorepo", + "file": "shared/tutorials/angular-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-monorepo-tutorial", @@ -117,7 +117,7 @@ "name": "Vue Standalone", "description": "", "mediaImage": "", - "file": "shared/vue-standalone-tutorial/vue-standalone", + "file": "shared/tutorials/vue-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/vue-standalone-tutorial", @@ -211,7 +211,7 @@ "name": "React Standalone", "description": "", "mediaImage": "", - "file": "shared/react-standalone-tutorial/react-standalone", + "file": "shared/tutorials/react-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-standalone-tutorial", @@ -222,7 +222,7 @@ "name": "React Monorepo", "description": "", "mediaImage": "", - "file": "shared/react-tutorial/react-monorepo", + "file": "shared/tutorials/react-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-monorepo-tutorial", @@ -233,7 +233,7 @@ "name": "Angular Standalone", "description": "", "mediaImage": "", - "file": "shared/angular-standalone-tutorial/angular-standalone", + "file": "shared/tutorials/angular-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-standalone-tutorial", @@ -244,7 +244,7 @@ "name": "Angular Monorepo", "description": "", "mediaImage": "", - "file": "shared/angular-tutorial/angular-monorepo", + "file": "shared/tutorials/angular-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-monorepo-tutorial", @@ -255,7 +255,7 @@ "name": "Vue Standalone", "description": "", "mediaImage": "", - "file": "shared/vue-standalone-tutorial/vue-standalone", + "file": "shared/tutorials/vue-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/vue-standalone-tutorial", @@ -293,7 +293,7 @@ "name": "React Standalone", "description": "", "mediaImage": "", - "file": "shared/react-standalone-tutorial/react-standalone", + "file": "shared/tutorials/react-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-standalone-tutorial", @@ -304,7 +304,7 @@ "name": "React Monorepo", "description": "", "mediaImage": "", - "file": "shared/react-tutorial/react-monorepo", + "file": "shared/tutorials/react-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/react-monorepo-tutorial", @@ -315,7 +315,7 @@ "name": "Angular Standalone", "description": "", "mediaImage": "", - "file": "shared/angular-standalone-tutorial/angular-standalone", + "file": "shared/tutorials/angular-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-standalone-tutorial", @@ -326,7 +326,7 @@ "name": "Angular Monorepo", "description": "", "mediaImage": "", - "file": "shared/angular-tutorial/angular-monorepo", + "file": "shared/tutorials/angular-monorepo", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/angular-monorepo-tutorial", @@ -337,7 +337,7 @@ "name": "Vue Standalone", "description": "", "mediaImage": "", - "file": "shared/vue-standalone-tutorial/vue-standalone", + "file": "shared/tutorials/vue-standalone", "itemList": [], "isExternal": false, "path": "/getting-started/tutorials/vue-standalone-tutorial", @@ -354,150 +354,6 @@ "path": "/getting-started/tutorials/gradle-tutorial", "tags": [] }, - "/core-tutorial": { - "id": "core-tutorial", - "name": "Core Tutorial", - "description": "Learn to use Nx with this core tutorial where you will learn about all its main feature with a real project.", - "mediaImage": "", - "file": "", - "itemList": [ - { - "id": "01-create-blog", - "name": "1 - Create Blog", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/01-create-blog", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/01-create-blog", - "tags": [] - }, - { - "id": "02-create-cli", - "name": "2 - Create CLI", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/02-create-cli", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/02-create-cli", - "tags": [] - }, - { - "id": "03-share-assets", - "name": "3 - Share Assets", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/03-share-assets", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/03-share-assets", - "tags": [] - }, - { - "id": "04-build-affected-projects", - "name": "4 - Build Affected Projects", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/04-build-affected-projects", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/04-build-affected-projects", - "tags": [] - }, - { - "id": "05-auto-detect-dependencies", - "name": "5 - Automatically Detect Dependencies", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/05-auto-detect-dependencies", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/05-auto-detect-dependencies", - "tags": [] - }, - { - "id": "06-summary", - "name": "6 - Summary", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/06-summary", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/06-summary", - "tags": [] - } - ], - "isExternal": false, - "path": "/core-tutorial", - "tags": [] - }, - "/core-tutorial/01-create-blog": { - "id": "01-create-blog", - "name": "1 - Create Blog", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/01-create-blog", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/01-create-blog", - "tags": [] - }, - "/core-tutorial/02-create-cli": { - "id": "02-create-cli", - "name": "2 - Create CLI", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/02-create-cli", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/02-create-cli", - "tags": [] - }, - "/core-tutorial/03-share-assets": { - "id": "03-share-assets", - "name": "3 - Share Assets", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/03-share-assets", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/03-share-assets", - "tags": [] - }, - "/core-tutorial/04-build-affected-projects": { - "id": "04-build-affected-projects", - "name": "4 - Build Affected Projects", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/04-build-affected-projects", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/04-build-affected-projects", - "tags": [] - }, - "/core-tutorial/05-auto-detect-dependencies": { - "id": "05-auto-detect-dependencies", - "name": "5 - Automatically Detect Dependencies", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/05-auto-detect-dependencies", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/05-auto-detect-dependencies", - "tags": [] - }, - "/core-tutorial/06-summary": { - "id": "06-summary", - "name": "6 - Summary", - "description": "", - "mediaImage": "", - "file": "shared/core-tutorial/06-summary", - "itemList": [], - "isExternal": false, - "path": "/core-tutorial/06-summary", - "tags": [] - }, "/features": { "id": "features", "name": "Features", diff --git a/docs/map.json b/docs/map.json index e91b0b1c18223..1f565171a98bb 100644 --- a/docs/map.json +++ b/docs/map.json @@ -48,27 +48,27 @@ { "name": "React Standalone", "id": "react-standalone-tutorial", - "file": "shared/react-standalone-tutorial/react-standalone" + "file": "shared/tutorials/react-standalone" }, { "name": "React Monorepo", "id": "react-monorepo-tutorial", - "file": "shared/react-tutorial/react-monorepo" + "file": "shared/tutorials/react-monorepo" }, { "name": "Angular Standalone", "id": "angular-standalone-tutorial", - "file": "shared/angular-standalone-tutorial/angular-standalone" + "file": "shared/tutorials/angular-standalone" }, { "name": "Angular Monorepo", "id": "angular-monorepo-tutorial", - "file": "shared/angular-tutorial/angular-monorepo" + "file": "shared/tutorials/angular-monorepo" }, { "name": "Vue Standalone", "id": "vue-standalone-tutorial", - "file": "shared/vue-standalone-tutorial/vue-standalone" + "file": "shared/tutorials/vue-standalone" }, { "name": "Gradle Monorepo", @@ -79,43 +79,6 @@ } ] }, - { - "name": "Core Tutorial", - "id": "core-tutorial", - "description": "Learn to use Nx with this core tutorial where you will learn about all its main feature with a real project.", - "itemList": [ - { - "name": "1 - Create Blog", - "id": "01-create-blog", - "file": "shared/core-tutorial/01-create-blog" - }, - { - "name": "2 - Create CLI", - "id": "02-create-cli", - "file": "shared/core-tutorial/02-create-cli" - }, - { - "name": "3 - Share Assets", - "id": "03-share-assets", - "file": "shared/core-tutorial/03-share-assets" - }, - { - "name": "4 - Build Affected Projects", - "id": "04-build-affected-projects", - "file": "shared/core-tutorial/04-build-affected-projects" - }, - { - "name": "5 - Automatically Detect Dependencies", - "id": "05-auto-detect-dependencies", - "file": "shared/core-tutorial/05-auto-detect-dependencies" - }, - { - "name": "6 - Summary", - "id": "06-summary", - "file": "shared/core-tutorial/06-summary" - } - ] - }, { "name": "Features", "id": "features", diff --git a/docs/shared/core-tutorial/01-create-blog.md b/docs/shared/core-tutorial/01-create-blog.md deleted file mode 100644 index b6c941dc08578..0000000000000 --- a/docs/shared/core-tutorial/01-create-blog.md +++ /dev/null @@ -1,212 +0,0 @@ -# Core Nx Tutorial - Step 1: Create Eleventy Blog - -In this tutorial you create multiple projects in a monorepo and take advantage of the core Nx features with a minimum of configuration. - -{% callout type="check" title="Package-Based Repo" %} -This tutorial sets up a [package-based repo](/concepts/integrated-vs-package-based). If you prefer an [integrated repo](/concepts/integrated-vs-package-based), check out the [React](/getting-started/tutorials/react-monorepo-tutorial) or [Angular](/getting-started/tutorials/angular-monorepo-tutorial) tutorials. -{% /callout %} - -## Contents: - -- [1 - Create Blog](/core-tutorial/01-create-blog) -- [2 - Create CLI](/core-tutorial/02-create-cli) -- [3 - Share Assets](/core-tutorial/03-share-assets) -- [4 - Build Affected Projects](/core-tutorial/04-build-affected-projects) -- [5 - Automatically Detect Dependencies](/core-tutorial/05-auto-detect-dependencies) -- [6 - Summary](/core-tutorial/06-summary) - -## Create a New Workspace - -**Start by creating a new workspace.** - -```shell -npx create-nx-workspace@latest -``` - -You then receive the following prompts in your command line: - -```shell -Workspace name (e.g., org name) myorg -What to create in the new workspace npm -``` - -> You can also choose to add [Nx Cloud](https://nx.app), but its not required for the tutorial. - -```treeview -myorg/ -├── packages/ -├── tools/ -├── nx.json -├── package.json -├── README.md -└── tsconfig.base.json -``` - -## Yarn workspaces - -The `package.json` file contains this property: - -```json - "workspaces": [ - "packages/**" - ] -``` - -Which tells yarn (or npm) and Nx to look in the `packages` folder for projects that will each be identified by a `package.json` file. - -## Adding Eleventy - -**Install Eleventy** - -To install Eleventy run: - -{% tabs %} -{% tab label="npm" %} - -```shell -npm add -D @11ty/eleventy@1.0.0 -``` - -{% /tab %} -{% tab label="yarn" %} - -```shell -yarn add -D @11ty/eleventy@1.0.0 -``` - -{% /tab %} -{% tab label="pnpm" %} - -```shell -pnpm add -D @11ty/eleventy@1.0.0 -``` - -{% /tab %} -{% /tabs %} - -{% callout type="check" title="Installing in workspace's root" %} -We are intentionally installing the package at the root of the workspace because this forces the organization to have the upfront cost of agreeing on the same versions of dependencies rather than the delayed cost of having projects using multiple different incompatible versions of dependencies. This is not a requirement of Nx, just a suggestion to help you maintain a growing repo. -{% /callout %} - -**Eleventy Hello World** - -Create a file at `packages/blog/package.json` with these contents: - -```json -{ - "name": "blog", - "description": "eleventy blog", - "version": "1.0.0", - "scripts": { - "build": "eleventy --input=./src --output=../../dist/packages/blog", - "serve": "eleventy --serve --input=./src --output=../../dist/packages/blog" - } -} -``` - -These scripts tell Eleventy to read from the `src` folder we'll create next and output to Nx's default location under `dist`. - -Next, add `packages/blog/src/index.html`: - -```html -
Hello, Eleventy
-``` - -## Clean Up - -If you have a `workspace.json` file in the root, delete it. - -## Running Eleventy with Nx - -Now that we have the bare minimum set up for Eleventy, you can run: - -```shell -nx serve blog -``` - -And you can see `Hello, Eleventy` at `http://localhost:8080`. - -Also, if you run: - -```shell -nx build blog -``` - -The build output will be created under `dist/packages/blog`. So far, Nx isn't doing anything special. If you run `nx build blog` again, though, you'll see it finish in less than 100 ms (instead of 1s). The caching doesn't matter yet, but as build times grow, it will become far more useful. - -The main value of Nx at this stage of the project is that it doesn't require any custom configuration on your project. The blog could have been built with any of a dozen different platforms and Nx would cache the output just the same. - -## Build a Basic Blog - -To actually create a blog, we'll have to change a few more files. This is all Eleventy specific configuration, so if you have questions consult [their documentation](https://www.11ty.dev/docs/config/) or [this tutorial](https://www.filamentgroup.com/lab/build-a-blog/). - -Update `index.html`: - -```html {% process=false %} ---- -layout: layout.liquid -pageTitle: Welcome to my blog ---- - -{% for post in collections.posts %} -- _____ -< moo > - ----- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || -- -Art courtesy of [cowsay](https://www.npmjs.com/package/cowsay). -``` - -`packages/blog/src/posts/posts.json`: - -```json -{ - "layout": "layout.liquid", - "tags": ["posts"] -} -``` - -Once these files are in place, run `nx serve blog` again. Navigate to `http://localhost:8080/posts/ascii/` in a browser and you should see the blog post. - -## What's Next - -- Continue to [Step 2: Create cli](/core-tutorial/02-create-cli) diff --git a/docs/shared/core-tutorial/02-create-cli.md b/docs/shared/core-tutorial/02-create-cli.md deleted file mode 100644 index 0bd7e839b1090..0000000000000 --- a/docs/shared/core-tutorial/02-create-cli.md +++ /dev/null @@ -1,159 +0,0 @@ -# Core Nx Tutorial - Step 2: Create Go CLI - -Great! you now have a simple blog set up. - -Next, you're going to create a CLI written in Go. - -## Install Go Locally - -Make sure you have Go installed locally by following [these instructions](https://go.dev/doc/install). - -You can verify that Go is installed correctly by running: - -```shell -go version -``` - -## Create the CLI Project - -Create a `project.json` file for your Go CLI. - -`packages/cli/project.json`: - -```json -{ - "root": "packages/cli", - "sourceRoot": "packages/cli/src", - "projectType": "application", - "targets": { - "build": { - "executor": "nx:run-commands", - "options": { - "command": "go build -o=../../dist/packages/cli/ ./src/ascii.go", - "cwd": "packages/cli" - } - }, - "serve": { - "executor": "nx:run-commands", - "options": { - "command": "go run ./src/ascii.go", - "cwd": "packages/cli" - } - } - } -} -``` - -You could have the exact same functionality with a `package.json` file with a `scripts` section like this: - -```json -{ - "scripts": { - "build": "go build -o ../../dist/packages/cli/ ./src/ascii.go", - "serve": "go run ./src/ascii.˙go" - } -} -``` - -There are a few reasons to choose `project.json` for the CLI project. - -1. The presence of `package.json` might cause other developers to think there is javascript code in this project. -2. As the scripts in the project get more complex, `project.json` tends to have a flatter structure - rather than a long horizontal line in `package.json` with all the cli flags. -3. The easiest method to run scripts provided in Nx plugins is to use a `project.json` file. - -All of these reasons are matters of preference. After this tutorial, you should have enough of a taste of both styles to make an informed decision about which format you prefer. Read more about [project configuration](/reference/project-configuration). - -### Project.json syntax - -- `root`, `sourceRoot` and `application` are properties that help Nx know more about your project. -- `targets` is similar to the `scripts` property in `package.json`. -- Just as in `package.json`, `build` and `serve` can be any string you pick. -- The `executor` is the code that runs the target. In this case, [`run-commands`](/nx-api/nx/executors/run-commands) launches a terminal process to execute whatever command you pass in. -- `options` contains whatever configuration properties the executor needs to run. - -## Create the CLI - -This CLI will display some ASCII art in the terminal. Create the following files: - -`packages/cli/src/ascii.go`: - -```go -package main - -import ( - "fmt" - "os" -) - -func check(e error) { - if e != nil { - panic(e) - } -} - -func main() { - fmt.Println("Hello, World!") - dat, err := os.ReadFile("src/cow.txt") - check(err) - fmt.Print(string(dat)) -} -``` - -`packages/cli/src/cow.txt`: - -```plaintext - _____ -< moo > - ----- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || -``` - -## Run the CLI - -Now if you run `nx serve cli`, you'll see a friendly message: - -```shell -❯ nx serve cli - -> nx run cli:serve - - -> cli@ serve /Users/isaac/Documents/code/myorg/packages/cli -> go run ./src/ascii.go - -Hello, World! - _____ -< moo > - ----- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || - -————————————————————————————————————————————————————————————————————————————————————————— - -NX Successfully ran target serve for project cli (2s) - -See Nx Cloud run details at https://nx.app/runs/THRW7SDRL9S - -``` - -Nx only caches the targets that you tell it to cache. `serve` is not in the default list of cached targets, so running this command a second time will take the same amount of time. You can see the current list of `cacheableOperations` in `nx.json`. - -```json -{ - //... - "cacheableOperations": ["build", "lint", "test", "e2e"] -} -``` - -If you run `nx build cli` twice, you'll see that Nx is able to cache the commands even though they're entirely written in Go. - -## What's Next - -- Continue to [Step 3: Share assets](/core-tutorial/03-share-assets) diff --git a/docs/shared/core-tutorial/03-share-assets.md b/docs/shared/core-tutorial/03-share-assets.md deleted file mode 100644 index 161a611dd2126..0000000000000 --- a/docs/shared/core-tutorial/03-share-assets.md +++ /dev/null @@ -1,183 +0,0 @@ -# Core Nx Tutorial - Step 3: Share Assets - -You probably noticed that you're using the same friendly cow ASCII art in the blog and CLI. Since both projects are in the same repo, it would be good to share that asset across both projects. - -## Create an Asset Library - -You can make a library project just for holding the ASCII asset files. Let Nx know about the project by creating a `package.json` file like this: - -`packages/ascii/package.json`: - -```json -{ - "name": "ascii" -} -``` - -Then move `cow.txt` out of the `cli` project to: - -`packages/ascii/assets/cow.txt`: - -```plaintext - _____ -< moo > - ----- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || -``` - -## Use the Shared Assets Library in the Blog - -In the eleventy blog, you need to add some configuration so that Eleventy knows how to read `.txt` files. - -`packages/blog/.eleventy.js`: - -```javascript -const { EleventyRenderPlugin } = require('@11ty/eleventy'); - -module.exports = function (eleventyConfig) { - eleventyConfig.addPlugin(EleventyRenderPlugin); - eleventyConfig.extensionMap = [ - { - key: 'txt', - extension: 'txt', - compile: function compile(str, inputPath, preTemplateEngine, bypass) { - return function render(data) { - return str; - }; - }, - }, - ]; -}; -``` - -Then you can reference that shared asset file in a blog post. - -`packages/blog/src/posts/ascii.md`: - -```markdown {% process=false %} ---- -pageTitle: Some ASCII Art ---- - -Welcome to [The Restaurant at the End of the Universe](https://hitchhikers.fandom.com/wiki/Ameglian_Major_Cow) - -
-{% renderFile "../ascii/assets/cow.txt" %} -- -Art courtesy of [cowsay](https://www.npmjs.com/package/cowsay). -``` - -## Use the Shared Assets Library in the CLI - -For the Go CLI, you only need to update the Go code. - -`packages/cli/src/ascii.go`: - -```go -package main - -import ( - "fmt" - "os" -) - -func check(e error) { - if e != nil { - panic(e) - } -} - -func main() { - fmt.Println("Hello, World!") - dat, err := os.ReadFile("../ascii/assets/cow.txt") - check(err) - fmt.Print(string(dat)) -} -``` - -## Tell Nx About the Dependencies - -Nx without plugins is unable to automatically detect dependencies in Go code or markdown, so you'll have to tell Nx about the dependencies manually. (For Go code, there is [@nx-go/nx-go](https://github.com/nx-go/nx-go) which will automatically detect dependencies between Go projects.) - -For the blog project, you'll need to add `ascii` as a `dependency` (or `devDependency`) in the `package.json` file. - -`packages/blog/package.json`: - -```json -{ - "name": "blog", - "description": "eleventy blog", - "version": "1.0.0", - "dependencies": { - "ascii": "*" - }, - "scripts": { - "build": "eleventy --input=./src --output=../../dist/packages/blog", - "serve": "eleventy --serve --input=./src --output=../../dist/packages/blog" - } -} -``` - -For the cli project, you add the implicit dependencies in the `project.json` file. - -`packages/cli/project.json`: - -```json -{ - "root": "packages/cli", - "sourceRoot": "packages/cli/src", - "projectType": "application", - "implicitDependencies": ["ascii"], - "targets": { - "build": { - "executor": "nx:run-commands", - "options": { - "command": "go build -o='../../dist/packages/cli/' ./src/ascii.go", - "cwd": "packages/cli" - } - }, - "serve": { - "executor": "nx:run-commands", - "options": { - "command": "go run ./src/ascii.go", - "cwd": "packages/cli" - } - } - } -} -``` - -## Test the Changes - -You should now be able to run - -```shell -nx serve blog -``` - -and - -```shell -nx serve cli -``` - -and get the same results as before. - -## View the Project Graph - -You can view a visual representation of the project graph by running: - -```shell -nx graph -``` - -When the graph opens in your browser, click the `Show all projects` button in the left sidebar. You should see dependency lines drawn from `blog` and `cli` to `ascii`. - -## What's Next - -- Continue to [Step 4: Build affected projects](/core-tutorial/04-build-affected-projects) diff --git a/docs/shared/core-tutorial/04-build-affected-projects.md b/docs/shared/core-tutorial/04-build-affected-projects.md deleted file mode 100644 index 590f2c4aaf7db..0000000000000 --- a/docs/shared/core-tutorial/04-build-affected-projects.md +++ /dev/null @@ -1,91 +0,0 @@ -# Core Nx Tutorial - Step 4: Build Affected Projects - -Nx scales your development by doing code change analysis to see what apps or libraries are affected by a particular pull request. - -**Commit all the changes in the repo**: - -```shell -git add . -git commit -am 'init' -git checkout -b testbranch -``` - -**Open `packages/cli/src/ascii.go` and change the go code:** - -```go -package main - -import ( - "fmt" - "os" -) - -func check(e error) { - if e != nil { - panic(e) - } -} - -func main() { - fmt.Println("Hello, Dish of the Day") - dat, err := os.ReadFile("../ascii/assets/cow.txt") - check(err) - fmt.Print(string(dat)) -} -``` - -**Run `nx print-affected --select=projects`**, and you should see `cli` printed out. The `nx print-affected` looks at what you have changed and uses the project graph to figure out which projects are affected by this change. - -**Now revert those changes** - -```shell -git checkout . -``` - -**Make a change to the shared ASCII art** - -Update `packages/ascii/assets/cow.txt`: - -```plaintext - _____ -< moo > - ----- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || -``` - -**Run `nx print-affected --select=projects`**, and this time you should see `cli`, `blog` and `ascii` printed out. - -## Build Affected Projects - -Printing the affected projects can be handy, but usually you want to do something with them. For instance, you may want to build everything that has been affected. - -**Run `nx affected -t build` to rebuild only the projects affected by the change.** - -```shell -✔ nx run blog:build (1s) -✔ nx run cli:build (2s) - -—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— - -NX Successfully ran target build for 2 projects (2s) - -See Nx Cloud run details at https://nx.app/runs/XfhRFaOyGCE -``` - -Note that Nx only built `blog` and `cli`. It didn't build `ascii` because there is no build script created for it. - -## Affected -t \* - -You can run any target against the affected projects in the graph like this: - -```shell -nx affected -t test -``` - -## What's Next - -- Continue to [Step 5: Auto detect dependencies](/core-tutorial/05-auto-detect-dependencies) diff --git a/docs/shared/core-tutorial/05-auto-detect-dependencies.md b/docs/shared/core-tutorial/05-auto-detect-dependencies.md deleted file mode 100644 index b1eb46445c92f..0000000000000 --- a/docs/shared/core-tutorial/05-auto-detect-dependencies.md +++ /dev/null @@ -1,133 +0,0 @@ -# Core Nx Tutorial - Step 5: Automatically Detect Dependencies - -Manually telling Nx about the dependencies between your projects is helpful, but as your repo grows it becomes difficult for a person to keep track of all the dependencies that are introduced. If you miss a dependency, the guarantees of the affected command are voided. - -Luckily, Nx core can automatically detect dependencies that are created in `.ts` or `.js` files. - -## Analyze Source Files - -Because we chose `npm` for the preset when we created the nx workspace, the `nx.json` is set to extend the npm preset settings. - -```jsonc -// nx.json -{ - "extends": "nx/presets/npm.json" -} -``` - -This preset is set to only load dependencies from `package.json` or `project.json` files. To enable automatically detecting dependencies from source code, you can add the following configuration to your `nx.json` file: - -```json -{ - "pluginsConfig": { - "@nx/js": { - "analyzeSourceFiles": true - } - } -} -``` - -Other presets default this property to true. - -**Side note:** If you want Nx to automatically detect dependencies for other languages, you can install a plugin for that language. There is a list of Nrwl maintained and third party plugins on the [community page](/community#plugin-directory). - -## Create Messages Library - -Make two files. - -`packages/messages/package.json`: - -```json -{ - "name": "messages" -} -``` - -`packages/messages/index.js`: - -```javascript -const message = 'Welcome to the Restaurant at the End of the Universe'; - -module.exports = { message }; -``` - -This library is exporting a single `message` string. - -## Create Cow Application - -Install the `cowsay` npm package at the root of the workspace. - -```shell -yarn add -W cowsay@1.5.0 -``` - -Make an application that uses the `messages` library. Note that you won't specify the dependency manually in the `package.json` file. - -`packages/cow/package.json`: - -```json -{ - "name": "cow", - "version": "0.0.1", - "scripts": { - "serve": "node index.js" - } -} -``` - -`packages/cow/index.js`: - -```javascript -var cowsay = require('cowsay'); -var { message } = require('../messages'); - -console.log( - cowsay.say({ - text: message, - }) -); -``` - -Now if you run `nx serve cow`, you'll see this: - -```{% command="node index.js" %} -______________________________________________________ -< Welcome to the Restaurant at the End of the Universe > ------------------------------------------------------- - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || - Done in 0.14s. - -—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— - -NX Successfully ran target serve for project cow - -See Nx Cloud run details at https://nx.app/runs/nZBYYBEuIfG -``` - -## View the Project Graph - -Run `nx graph` to view the new project graph. You'll see a dependency line has been drawn between `cow` and `messages` because Nx recognises that `cow` is referencing code inside the `messages` project. - -This line tells Nx about the dependency: - -```javascript -var { message } = require('../messages'); -``` - -If at some point in the future the code is refactored so that cow no longer references messages, the project graph will automatically update accordingly. - -## More Tooling - -If you want Nx to do more for you, you can install the `@nx/js` plugin to help with typescript or javascript tooling. This plugin provides out of the box: - -- Typescript alias paths -- Build with `tsc` or `swc` -- Jest and ESLint configuration - -## What's Next - -- Continue to [Step 6: Summary](/core-tutorial/06-summary) diff --git a/docs/shared/core-tutorial/06-summary.md b/docs/shared/core-tutorial/06-summary.md deleted file mode 100644 index 5bbb521e3cfca..0000000000000 --- a/docs/shared/core-tutorial/06-summary.md +++ /dev/null @@ -1,21 +0,0 @@ -# Core Nx Tutorial - Step 6: Summary - -In this tutorial you: - -- Built a blog using Eleventy -- Built a CLI with Go -- Shared asset files between projects -- Used Nx's computation caching to never build the same code twice -- Used Nx's affected commands to only rebuild affected projects -- Used Nx's ability to automatically detect dependencies between js/ts projects - -You created a workspace from scratch in this tutorial, but if you would like to add Nx to an existing repository, you can use the `npx nx@latest init` terminal command to get started. For more information see the [Adding Nx to Lerna/Yarn/PNPM/NPM Workspace](/recipes/adopting-nx/adding-to-monorepo) guide. - -## Learn more - -- [Free Nx Course on YouTube](https://www.youtube.com/playlist?list=PLakNactNC1dH38AfqmwabvOszDmKriGco) - -**Dive Deep:** - -- [Computation Caching](/concepts/how-caching-works) -- [Rebuilding What is Affected](/ci/features/affected) diff --git a/docs/shared/reference/sitemap.md b/docs/shared/reference/sitemap.md index 141f04f8e8973..781a8cc95f876 100644 --- a/docs/shared/reference/sitemap.md +++ b/docs/shared/reference/sitemap.md @@ -13,13 +13,6 @@ - [Angular Monorepo](/getting-started/tutorials/angular-monorepo-tutorial) - [Vue Standalone](/getting-started/tutorials/vue-standalone-tutorial) - [Gradle Monorepo](/getting-started/tutorials/gradle-tutorial) - - [Core Tutorial](/core-tutorial) - - [1 - Create Blog](/core-tutorial/01-create-blog) - - [2 - Create CLI](/core-tutorial/02-create-cli) - - [3 - Share Assets](/core-tutorial/03-share-assets) - - [4 - Build Affected Projects](/core-tutorial/04-build-affected-projects) - - [5 - Automatically Detect Dependencies](/core-tutorial/05-auto-detect-dependencies) - - [6 - Summary](/core-tutorial/06-summary) - [Features](/features) - [Run Tasks](/features/run-tasks) - [Cache Task Results](/features/cache-task-results) diff --git a/docs/shared/angular-tutorial/angular-monorepo.md b/docs/shared/tutorials/angular-monorepo.md similarity index 99% rename from docs/shared/angular-tutorial/angular-monorepo.md rename to docs/shared/tutorials/angular-monorepo.md index 70b1ab101c6bf..3ce320e1e2f6b 100644 --- a/docs/shared/angular-tutorial/angular-monorepo.md +++ b/docs/shared/tutorials/angular-monorepo.md @@ -448,7 +448,7 @@ export const appRoutes: Route[] = [ Serving your app (`nx serve angular-store`) and then navigating to `/products` should give you the following result: -![products route](/shared/angular-tutorial/app-products-route.png) +![products route](/shared/tutorials/app-products-route.png) Let's apply the same for our `orders` library. @@ -1241,7 +1241,7 @@ NX Ran target lint for 7 projects (3s) If you have the ESLint plugin installed in your IDE you should immediately see an error: -![ESLint module boundary error](/shared/angular-tutorial/module-boundary-lint-rule.png) +![ESLint module boundary error](/shared/tutorials/module-boundary-lint-rule.png) Learn more about how to [enforce module boundaries](/features/enforce-module-boundaries). diff --git a/docs/shared/angular-standalone-tutorial/angular-standalone.md b/docs/shared/tutorials/angular-standalone.md similarity index 100% rename from docs/shared/angular-standalone-tutorial/angular-standalone.md rename to docs/shared/tutorials/angular-standalone.md diff --git a/docs/shared/angular-tutorial/app-products-route.png b/docs/shared/tutorials/app-products-route.png similarity index 100% rename from docs/shared/angular-tutorial/app-products-route.png rename to docs/shared/tutorials/app-products-route.png diff --git a/docs/shared/angular-tutorial/module-boundary-lint-rule.png b/docs/shared/tutorials/module-boundary-lint-rule.png similarity index 100% rename from docs/shared/angular-tutorial/module-boundary-lint-rule.png rename to docs/shared/tutorials/module-boundary-lint-rule.png diff --git a/docs/shared/react-tutorial/react-monorepo.md b/docs/shared/tutorials/react-monorepo.md similarity index 100% rename from docs/shared/react-tutorial/react-monorepo.md rename to docs/shared/tutorials/react-monorepo.md diff --git a/docs/shared/react-standalone-tutorial/react-standalone.md b/docs/shared/tutorials/react-standalone.md similarity index 100% rename from docs/shared/react-standalone-tutorial/react-standalone.md rename to docs/shared/tutorials/react-standalone.md diff --git a/docs/shared/vue-standalone-tutorial/vue-standalone.md b/docs/shared/tutorials/vue-standalone.md similarity index 100% rename from docs/shared/vue-standalone-tutorial/vue-standalone.md rename to docs/shared/tutorials/vue-standalone.md