diff --git a/docs/bin/build-preview-site.sh b/docs/bin/build-preview-site.sh index 4f0c1cd6981a..587c97158cbe 100755 --- a/docs/bin/build-preview-site.sh +++ b/docs/bin/build-preview-site.sh @@ -63,7 +63,9 @@ mkdir $JEKYLL_DIR/pages (TARGET="$PWD/$JEKYLL_DIR/pages" && cd "$PWD/site" && pax -rwlpe . $TARGET) echo "Copying external README pages" +mkdir -p $JEKYLL_DIR/_includes/readmes cp $SOURCE_DIR/pages/en/lb4/readmes/*.md $JEKYLL_DIR/pages/readmes/ +cp $SOURCE_DIR/pages/en/lb4/readmes/*.md $JEKYLL_DIR/_includes/readmes/ echo "Setting up sidebar(s)" rm -rf $JEKYLL_DIR/_data/sidebars diff --git a/docs/site/Create-your-first-app copy.md b/docs/site/Create-your-first-app copy.md new file mode 100644 index 000000000000..c58af501766f --- /dev/null +++ b/docs/site/Create-your-first-app copy.md @@ -0,0 +1,118 @@ +--- +lang: en +title: 'Create your first app' +keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI +sidebar: lb4_sidebar +permalink: /doc/en/lb4/Create-your-first-app.html +summary: Write and run a LoopBack 4 "Hello World" project in TypeScript. +--- + +## Create Your First App + +### Create a new project + +The LoopBack 4 CLI scaffolds a new project by setting up the project structure, +configuring the TypeScript, and installing required dependencies. + +To create a new project, run the following command and follow the prompts: + +```sh +lb4 app +``` + +Provide the following inputs when prompted: + +```sh +? Project name: getting-started +? Project description: Getting started tutorial +? Project root directory: getting-started +? Application class name: StarterApplication +? Select features to enable in the project: +❯◉ Enable eslint: add a linter with pre-configured lint rules + ◉ Enable prettier: install prettier to format code conforming to rules + ◉ Enable mocha: install mocha to run tests + ◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-eslint) + ◉ Enable editorconfig: add EditorConfig files + ◉ Enable vscode: add VSCode config files + ◉ Enable docker: include Dockerfile and .dockerignore + ◉ Enable repositories: include repository imports and RepositoryMixin + ◉ Enable services: include service-proxy imports and ServiceMixin +``` + +### Starting the project + +The generated project includes a built-in `/ping` endpoint for testing. + +Start the application: + +```sh +cd getting-started +npm install +npm start +``` + +Open your brower and navigate to: +[http://127.0.0.1:3000/ping](http://127.0.0.1:3000/ping). + +### Add a Controller + +Next, add a custom [controller](Controller.md). In this example, you’ll create a +simple “Hello World” endpoint. + +Run: + +```sh +lb4 controller +``` + +- _Note: If your application is running, press **CTRL+C** to stop it before + running the command._ + +Respond to the prompts: + +```sh +? Controller class name: hello +? What kind of controller would you like to generate? Empty Controller + create src/controllers/hello.controller.ts + update src/controllers/index.ts + +Controller hello was now created in src/controllers/ +``` + +### Implement the Controller + +Replace the contents of `src/controllers/hello.controller.ts` with the +following: + +```ts +import {get} from '@loopback/rest'; + +export class HelloController { + @get('/hello') + hello(): string { + return 'Hello world!'; + } +} +``` + +### Test the Endpoint + +Restart the application: + +```sh +npm start +``` + +Open your browser and navigate to: +[http://127.0.0.1:3000/hello](http://127.0.0.1:3000/hello) + +You should see: + +``` +Hello world! +``` + +### Code sample + +View the complete example project here: +[https://github.com/loopbackio/loopback-next/tree/master/examples/hello-world](https://github.com/loopbackio/loopback-next/tree/master/examples/hello-world) diff --git a/docs/site/Getting-started.md b/docs/site/Getting-started.md deleted file mode 100644 index 89eb2be6a9a8..000000000000 --- a/docs/site/Getting-started.md +++ /dev/null @@ -1,117 +0,0 @@ ---- -lang: en -title: 'Getting started' -keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI -sidebar: lb4_sidebar -permalink: /doc/en/lb4/Getting-started.html -summary: Write and run a LoopBack 4 "Hello World" project in TypeScript. ---- - -## Prerequisites - -Install [Node.js](https://nodejs.org/en/download/) (version 16 or higher) if it -is not already installed on your machine. - -## Install LoopBack 4 CLI - -The LoopBack 4 CLI is a command-line interface that scaffolds a project or an -extension by generating the basic code. The CLI provides the fastest way to get -started with a LoopBack 4 project that adheres to best practices. - -Install the CLI globally by running - -```sh -npm i -g @loopback/cli -``` - -## Create a new project - -The CLI tool will scaffold the project, configure the TypeScript compiler, and -install all the required dependencies. To create a new project, run the CLI as -follows and answer the prompts. - -> We also have a specific generator to generate LoopBack projects. Run -> `npm create loopback` - -```sh -lb4 app -``` - -Answer the prompts as follows: - -```sh -? Project name: getting-started -? Project description: Getting started tutorial -? Project root directory: getting-started -? Application class name: StarterApplication -? Select features to enable in the project: -❯◉ Enable eslint: add a linter with pre-configured lint rules - ◉ Enable prettier: install prettier to format code conforming to rules - ◉ Enable mocha: install mocha to run tests - ◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-eslint) - ◉ Enable editorconfig: add EditorConfig files - ◉ Enable vscode: add VSCode config files - ◉ Enable docker: include Dockerfile and .dockerignore - ◉ Enable repositories: include repository imports and RepositoryMixin - ◉ Enable services: include service-proxy imports and ServiceMixin -``` - -### Starting the project - -The project comes with a "ping" route to test the project. Let's try it out by -running the project. - -```sh -cd getting-started -npm i -npm start -``` - -In a browser, visit . - -## Adding your own controller - -Now that we have a basic project created, it's time to add our own -[controller](Controller.md). Let's add a simple "Hello World" controller as -follows: - -```sh -lb4 controller -``` - -- _Note: If your application is still running, press **CTRL+C** to stop it - before calling the command_ - -- Answer the prompts as follows: - - ```sh - ? Controller class name: hello - ? What kind of controller would you like to generate? Empty Controller - create src/controllers/hello.controller.ts - update src/controllers/index.ts - - Controller hello was now created in src/controllers/ - ``` - -- Paste the following contents into the file - `/src/controllers/hello.controller.ts`: - - ```ts - import {get} from '@loopback/rest'; - - export class HelloController { - @get('/hello') - hello(): string { - return 'Hello world!'; - } - } - ``` - -- Start the application using `npm start`. - -- Visit to see `Hello world!` - -## Code sample - -You can view the generated code for this example at: -[hello-world](https://github.com/loopbackio/loopback-next/tree/master/examples/hello-world) diff --git a/docs/site/Installation.md b/docs/site/Installation.md new file mode 100644 index 000000000000..32cf2159dc67 --- /dev/null +++ b/docs/site/Installation.md @@ -0,0 +1,25 @@ +--- +lang: en +title: 'Installation' +keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI +sidebar: lb4_sidebar +permalink: /doc/en/lb4/Installation.html +summary: Write and run a LoopBack 4 "Hello World" project in TypeScript. +--- + +## Prerequisites + +Ensure that [Node.js](https://nodejs.org/en/download/) (version 22 or later) is +installed on your machine. + +## Install LoopBack 4 CLI + +The LoopBack 4 CLI is a command-line tool that scaffolds projects and extensions +by generating the required code. It provides the fastest way to get started with +a LoopBack 4 project while following best practices. + +To install the CLI globally, run: + +```sh +npm i -g @loopback/cli +``` diff --git a/docs/site/sidebars/lb4_sidebar.yml b/docs/site/sidebars/lb4_sidebar.yml index 68e20be19eb3..79e2e255017f 100644 --- a/docs/site/sidebars/lb4_sidebar.yml +++ b/docs/site/sidebars/lb4_sidebar.yml @@ -16,8 +16,21 @@ children: output: 'web, pdf' - title: 'Getting started' - url: Getting-started.html output: 'web, pdf' + expand: 'true' + + children: + - title: 'Installation' + url: Installation.html + output: 'web, pdf' + + - title: 'Create your first app' + url: Create-your-first-app.html + output: 'web, pdf' + + - title: 'Project structure' + url: Loopback-application-layout.html + output: 'web, pdf' - title: 'Inside a LoopBack Application' url: Inside-LoopBack-Application.html @@ -801,10 +814,6 @@ children: output: 'web, pdf' children: - - title: 'LoopBack 4 Application Layout' - url: Loopback-application-layout.html - output: 'web, pdf' - - title: 'API docs' url: apidocs.index.html output: 'web, pdf'