Skip to content

Commit cab2607

Browse files
authored
Merge pull request #44 from AckeeCZ/feat/architecture-refactor
πŸ—οΈ Rework project to modular pattern and interactive CLI
2 parents f194a88 + c5e7fcf commit cab2607

140 files changed

Lines changed: 2923 additions & 3505 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Create project'
2+
description: 'Runs create-node-project and performs tests'
3+
inputs:
4+
options:
5+
description: 'create-node-app options'
6+
required: true
7+
dbConnection:
8+
description: 'DB_CONNECTION_STRING env var'
9+
default: 'postgresql://postgres:postgres@localhost:5432/postgres'
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Cache dependencies
17+
uses: actions/cache@v3
18+
with:
19+
path: ~/.npm
20+
key: npm-${{ hashFiles('package-lock.json') }}
21+
restore-keys: npm-
22+
23+
- name: Install dependencies
24+
run: npm ci --ignore-scripts
25+
shell: bash
26+
27+
- name: Build the project
28+
run: npm run build
29+
shell: bash
30+
31+
- name: Run npm link
32+
run: npm link
33+
shell: bash
34+
35+
- name: Create project
36+
run: create-node-app ${{ inputs.options }}
37+
shell: bash
38+
39+
- name: Build created project
40+
working-directory: ./node-app
41+
run: npm run build
42+
shell: bash
43+
44+
- name: Run lint
45+
working-directory: ./node-app
46+
run: npm run ci-lint
47+
shell: bash
48+
49+
- name: Run tests
50+
working-directory: ./node-app
51+
run: npm run ci-test
52+
shell: bash
53+
env:
54+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}
55+
56+
- name: Run start
57+
if: ${{ !contains(inputs.options, '--api none') }}
58+
working-directory: ./node-app
59+
run: |
60+
npm run start &
61+
start_pid=$!
62+
sleep 10
63+
kill $start_pid
64+
shell: bash
65+
env:
66+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}
67+
68+
- name: Run start
69+
if: ${{ contains(inputs.options, '--api none') }}
70+
working-directory: ./node-app
71+
shell: bash
72+
run: npm run start
73+
env:
74+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}

β€Ž.github/workflows/create-projects.ymlβ€Ž

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,48 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
create-app-command: ["create-node-app cloudrun", "create-node-app cloudrun-graphql"]
20+
create-app-options:
21+
- "--api rest --database none --pipeline cloudrun-gitlab"
22+
- "--api graphql --database none --pipeline cloudrun-gitlab"
23+
- "--api rest --database none --pipeline none"
24+
- "--api none --database none --pipeline cloudrun-gitlab"
2125
runs-on: ubuntu-latest
2226

2327
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v3
26-
27-
- name: Cache dependencies
28-
uses: actions/cache@v3
28+
- uses: actions/checkout@v4
29+
- id: create-node-app
30+
uses: ./.github/actions/test-create-project
2931
with:
30-
path: ~/.npm
31-
key: npm-${{ hashFiles('package-lock.json') }}
32-
restore-keys: npm-
33-
34-
- name: Install dependencies
35-
run: npm ci --ignore-scripts
36-
37-
- name: Build the project
38-
run: npm run build
39-
40-
- name: Run npm link
41-
run: npm link
42-
43-
- name: Create project
44-
run: ${{ matrix.create-app-command }}
45-
46-
- name: Build created project
47-
working-directory: ./node-app
48-
run: npm run build
32+
options: ${{ matrix.create-app-options }}
4933

50-
- name: Run lint
51-
working-directory: ./node-app
52-
run: npm run ci-lint
34+
create-projects-with-postgres:
35+
needs: "build"
36+
services:
37+
postgres:
38+
image: postgres:17
39+
env:
40+
POSTGRES_PASSWORD: postgres
41+
POSTGRES_DB: postgres
42+
POSTGRES_USER: postgres
43+
options: >-
44+
--health-cmd pg_isready
45+
--health-interval 10s
46+
--health-timeout 5s
47+
--health-retries 5
48+
ports:
49+
- 5432:5432
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
create-app-options:
54+
- "--api none --database postgres-knex --pipeline none"
55+
- "--api rest --database postgres-knex --pipeline cloudrun-gitlab"
56+
- "--api graphql --database postgres-knex --pipeline cloudrun-gitlab"
57+
runs-on: ubuntu-latest
5358

54-
- name: Run tests
55-
working-directory: ./node-app
56-
run: npm run ci-test
57-
58-
- name: Run start
59-
working-directory: ./node-app
60-
run: |
61-
npm run start &
62-
start_pid=$!
63-
sleep 10
64-
kill $start_pid
59+
steps:
60+
- uses: actions/checkout@v4
61+
- id: create-node-app
62+
uses: ./.github/actions/test-create-project
63+
with:
64+
options: ${{ matrix.create-app-options }}

β€ŽAUTHORSβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Jiri Smolik <jiri.smolik@ackee.cz>
22
Patrik Hoffmann <patrik.hoffmann@ackee.cz>
3-
Roman Filatov <roman.filatov@ackee.cz>
3+
Roman Filatov <roman.filatov@ackee.cz>
4+
Pavel Ε vagr <pavel.svagr@ackee.cz>

β€ŽREADME.mdβ€Ž

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,42 @@
66

77
# Create Node App
88

9-
CLI to help you set up Node.js TypeScript project. Set up project includes
9+
CLI to help you set up a Node.js TypeScript project. The setup includes:
1010

1111
- code style tools (prettier, lint)
12-
- testing (using jest)
13-
- infrastructure files of your choice (Docker, etc.)
14-
- GitLab CI and npm ci-\* scripts (for Ackee CI/CD pipelines)
12+
- testing (using mocha)
13+
- infrastructure files of your choice (PostgreSQL etc.)
14+
- CI pipeline templates (based on Ackee GitLab CI/CD pipelines)
1515

1616
## Usage
1717

1818
Run directly from GitHub repo via npx:
1919

2020
```
21-
Usage: npm exec --ignore-scripts -- github:AckeeCZ/create-node-app STARTER [OPTIONS] [DIRECTORY]
22-
23-
STARTER Which template to setup (required)
21+
Usage: npm exec --ignore-scripts -- github:AckeeCZ/create-node-app [OPTIONS]
2422
2523
Options:
26-
--dir, -d DIR Destination directory (default: ./node-app)
27-
--project-name, -n NAME Google Cloud project name (default: directory basename)
28-
--force, -f Overwrite existing destination directory if it's not empty
29-
--help, -h Show this help message
30-
31-
Starters available:
32-
cloudrun Cloud Run + express
33-
cloudrun-graphql Cloud Run + graphql
24+
-d, --dir Destination directory [string] [default: "./node-app"]
25+
-D, --debug Enables debug logs [boolean] [default: false]
26+
-n, --project-name Google Cloud project name [string] [default: "node-app"]
27+
-f, --force Overwrite existing destination if it's not empty
28+
[boolean] [default: false]
29+
--api Selects API
30+
[string] [choices: "graphql", "rest"]
31+
--database Selects database as database
32+
[string] [choices: "postgres-knex"]
33+
--pipeline Selects pipeline
34+
[string] [choices: "cloudrun-gitlab"]
35+
--version Show version number [boolean]
36+
--help Show help [boolean]
3437
```
3538

36-
Supported starter templates:
39+
## Setup options
3740

38-
- [Cloud Run](./starter/cloudrun/README.md)
39-
- [GraphQL Cloud Run](./starter/cloudrun-graphql/README.md)
41+
- API layer
42+
- [RESTful](starter/api/rest/)
43+
- [GraphQL](starter/api/graphql/)
44+
- Database
45+
- [PostgreSQL](starter/infra/postgresql-knex/) using [Knex](https://github.com/knex/knex)
46+
- Pipelines
47+
- [GitLab CloudRun](starter/pipeline/cloudrun-gitlab/)

β€Ždocs/development.mdβ€Ž

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Development πŸ‘·
2+
3+
## Starters
4+
5+
Starters are folders containing files and structure that can be optionally added to the final created repository by `create-node-app` (cna). The base folder structure and tooling that should be available in every application created by cna is located in the [\_base](../starter/_base) folder.
6+
7+
Each additional starter is an addition to this base. When a user selects a specific starter, all contents are copied into the final directory **except for specific files that require content merging**. Every file that is merged uses its own merger defined in the [Mergers](../src/Mergers/) directory.
8+
9+
Each starter directory must contain a `node-app.jsonc` configuration file that defines the starter's metadata for the cna.
10+
11+
### Grouping and sorting
12+
13+
Starters are grouped into categories called "modules". These indicate that only one starter should be selected from each group. For example, under the API module there can be GraphQL and RESTful API starters, but the created application can have only one of those.
14+
15+
The order for injection into the final repository is alphabetical based on the module fields. The logic for grouping and sorting is as follows:
16+
17+
1. **Base Starter**: The `_base` starter is always built first
18+
2. **Selected Starters**: Each selected starter is built in the order of user selection
19+
3. **npm install**: Dependencies are installed
20+
4. **Prebuild Scripts**: All `prebuild` scripts from selected starters are executed
21+
5. **Final Build**: `npm run build` is executed
22+
23+
### Configuration
24+
25+
The `node-app.jsonc` file is a JSON with Comments file that configures how a starter behaves during the build process. The structure is as follows (fields with \* are required):
26+
27+
- `id`\* (`string`): Unique identifier
28+
- `name`\* (`string`): Displayed in the CLI in the form of `<name> <module>` e.g. `RESTful API`
29+
- `module`\* (`string`): The category this starter belongs to (e.g., "API", "database")
30+
- `prebuild` (`string[]`): Array of npm script names to run before the main build
31+
- `replace` (`string[]`): Array of file paths (relative to project root) where string replacements should be applied
32+
33+
#### Example RESTful API `node-app.jsonc`
34+
35+
```jsonc
36+
{
37+
"module": "API",
38+
"id": "rest",
39+
"name": "RESTful",
40+
"prebuild": ["generate:api"],
41+
}
42+
```

β€Žlib/Bootstrap.jsβ€Ž

Lines changed: 0 additions & 91 deletions
This file was deleted.

β€Žlib/Bootstrap.js.mapβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žlib/Logger.jsβ€Ž

Lines changed: 0 additions & 12 deletions
This file was deleted.

β€Žlib/Logger.js.mapβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
Β (0)