Skip to content

Commit

Permalink
Merge pull request #440 from kool-dev/presets-reeview
Browse files Browse the repository at this point in the history
NestJS preset updates
  • Loading branch information
fabriciojs authored Aug 11, 2022
2 parents 1a55b13 + 71877b7 commit 1b596be
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 54 deletions.
46 changes: 24 additions & 22 deletions docs/2-Presets/NestJS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Start a NestJS Project with Docker in 2 Easy Steps

1. Run `kool create nestjs my-project`
2. Run `kool run setup`
2. Run `cd my-project && kool run setup`

> Yes, using **kool** + Docker to create and work on new NestJS projects is that easy!
Expand All @@ -25,7 +25,7 @@ Use the [`kool create PRESET FOLDER` command](/docs/commands/kool-create) to cre
$ kool create nestjs my-project
```

Under the hood, this command will run `nest new my-project` to install NestJS.
Under the hood, this command will run `nest new my-project` to install NestJS with Typescript and NPM as the package manager.

After installing NestJS, `kool create` automatically runs the `kool preset nestjs` command, which helps you easily set up the initial tech stack for your project using an interactive wizard.

Expand All @@ -43,10 +43,6 @@ $ Preset nestjs is initializing!
Memcached 1.6
none

? Which package manager did you choose during Nest setup [Use arrows to move, type to filter]
> npm
yarn

$ Preset nestjs initialized!
```

Expand All @@ -61,6 +57,7 @@ The [`kool preset` command](/docs/commands/kool-preset) auto-generated the follo
```bash
+docker-compose.yml
+kool.yml
+.env.dist
```

> Now's a good time to review the **docker-compose.yml** file and verify the services match the choices you made earlier using the wizard.
Expand All @@ -75,24 +72,28 @@ To help get you started, **kool.yml** comes prebuilt with an initial set of scri

```yaml
scripts:
nest: kool exec app nest
npm: kool exec app npm # or yarn
npx: kool exec app npx

setup:
- kool docker kooldev/node:16 npm install # or yarn install
- kool start
# copy .env file
- cp .env.dist .env
# install backend deps
- kool docker kooldev/node:16 npm install

# helpers
npm: kool exec app npm
npx: kool exec app npx
nest: kool run npx @nestjs/cli
```
Go ahead and run `kool run setup` to start your Docker environment and finish setting up your project:

```bash
$ kool run setup
$ kool start
```

> As you can see in **kool.yml**, the `setup` script will do the following in sequence: run `npm install` to build your Node packages and dependencies (by spinning up and down a temporary Node container); and then start your Docker environment using **docker-compose.yml** (which includes a `command` to automatically run `npm run start:dev`).
> As you can see in **kool.yml**, the `setup` script will do the following in sequence: run `npm install` to build your Node packages and dependencies (by spinning up and down a temporary Node container). After that youo can start your Docker environment using **docker-compose.yml** with the command `kool start` (which includes a container to running `npm run start:dev`).

Once `kool run setup` finishes, you should be able to access your new site at [http://localhost:3000](http://localhost:3000) and see the NestJS "Hello World!" welcome page. Hooray!
Once `kool start` finishes, you should be able to access your new site at [http://localhost:3000](http://localhost:3000) and see the NestJS "Hello World!" welcome page.

Verify your Docker container is running using the [`kool status` command](/docs/commands/kool-status):

Expand All @@ -111,14 +112,15 @@ Run `kool logs app` to see the logs from the running `app` container, and confir

```bash
$ kool logs app
Attaching to my-project_app_1
app_1 |
app_1 | > [email protected] start:dev /app
app_1 | > nest start --watch
app_1 |
app_1 |
[6:13:28 PM] Starting compilation in watch mode...
app_1 |
[2:55:57 AM] Starting compilation in watch mode...
my-project-app-1 |
my-project-app-1 | [2:56:11 AM] Found 0 errors. Watching for file changes.
my-project-app-1 |
my-project-app-1 | [Nest] 32 - 08/11/2022, 2:56:14 AM LOG [NestFactory] Starting Nest application...
my-project-app-1 | [Nest] 32 - 08/11/2022, 2:56:14 AM LOG [InstanceLoader] AppModule dependencies initialized +85ms
my-project-app-1 | [Nest] 32 - 08/11/2022, 2:56:14 AM LOG [RoutesResolver] AppController {/}: +25ms
my-project-app-1 | [Nest] 32 - 08/11/2022, 2:56:14 AM LOG [RouterExplorer] Mapped {/, GET} route +8ms
my-project-app-1 | [Nest] 32 - 08/11/2022, 2:56:14 AM LOG [NestApplication] Nest application successfully started +6ms
```

---
Expand Down
21 changes: 7 additions & 14 deletions presets/nestjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]
tags: [ 'TS' ]

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new NestJS Application
actions:
- scripts:
- docker pull -q kooldev/node:16
- kool docker kooldev/node:16 npx -y @nestjs/cli new $CREATE_DIRECTORY
- kool docker kooldev/node:16 npx -y @nestjs/cli new -l Typescript -p npm $CREATE_DIRECTORY

# Preset defines the workflow for installing this preset in the current working directory
preset:
- name: 'Copy basic config files'
actions:
- copy: docker-compose.yml
- copy: kool.yml
- merge: app/node-nestjs.yml
- merge: docker-compose.nestjs.yml
dst: docker-compose.yml
- merge: kool.nestjs.yml
dst: kool.yml
- copy: env.dist
dst: .env.dist

- name: 'Customize your setup'
actions:
- recipe: pick-db
- recipe: pick-cache
- prompt: 'Which Javascript package manager do you want to use'
default: 'npm'
options:
- name: 'npm'
actions:
- merge: npm.yml
dst: kool.yml
- name: 'yarn'
actions:
- merge: yarn.yml
dst: kool.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
services:
app:
image: kooldev/node:16-nest
image: kooldev/node:16
command: ["npm", "run", "start:dev"]
ports:
- "${KOOL_APP_PORT:-3000}:3000"
- "${KOOL_APP_PORT:-3000}:${KOOL_APP_PORT:-3000}"
environment:
ASUSER: "${KOOL_ASUSER:-0}"
UID: "${UID:-0}"
KOOL_APP_PORT: "${KOOL_APP_PORT:-3000}"
volumes:
- .:/app:delegated
networks:
Expand Down
6 changes: 6 additions & 0 deletions presets/nestjs/env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#
# Kool variables - mostly used to tweak docker-compose.yml containers.
#
# KOOL_APP_PORT=
# KOOL_GLOBAL_NETWORK=
11 changes: 11 additions & 0 deletions presets/nestjs/kool.nestjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
scripts:
setup:
# copy .env file
- cp .env.dist .env
# install backend deps
- kool docker kooldev/node:16 npm install

# helpers
npm: kool exec app npm
npx: kool exec app npx
nest: kool run npx @nestjs/cli
8 changes: 0 additions & 8 deletions presets/nestjs/npm.yml

This file was deleted.

7 changes: 0 additions & 7 deletions presets/nestjs/yarn.yml

This file was deleted.

2 changes: 1 addition & 1 deletion presets/nuxtjs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tags: [ 'JS' ]

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Symfony Application
- name: Creating new Nuxt Application
actions:
- scripts:
- docker pull -q kooldev/node:16
Expand Down

0 comments on commit 1b596be

Please sign in to comment.