Skip to content

Commit 214ee02

Browse files
authored
Add full-stack e-commerce discount demo application (#1)
1 parent 57e7729 commit 214ee02

24 files changed

Lines changed: 5355 additions & 0 deletions

.devcontainer/devcontainer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Dev Container configuration for full-stack TypeScript development
2+
// Optimized for Node.js, React, Express.js, and TypeScript
3+
//
4+
// See https://aka.ms/devcontainer.json for more information.
5+
{
6+
"name": "Full-Stack TypeScript (Node.js 20)",
7+
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
8+
9+
// Configure tool-specific properties
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"dbaeumer.vscode-eslint",
14+
"esbenp.prettier-vscode",
15+
"ms-vscode.vscode-typescript-next",
16+
"bradlc.vscode-tailwindcss"
17+
],
18+
"settings": {
19+
"editor.defaultFormatter": "esbenp.prettier-vscode",
20+
"editor.formatOnSave": true,
21+
"editor.codeActionsOnSave": {
22+
"source.fixAll.eslint": "explicit"
23+
},
24+
"typescript.tsdk": "node_modules/typescript/lib",
25+
"typescript.enablePromptUseWorkspaceTsdk": true
26+
}
27+
}
28+
},
29+
30+
// Forward ports for backend and frontend
31+
"forwardPorts": [3000, 3001],
32+
"portsAttributes": {
33+
"3000": {
34+
"label": "Frontend (React)",
35+
"onAutoForward": "notify"
36+
},
37+
"3001": {
38+
"label": "Backend (Express)",
39+
"onAutoForward": "notify"
40+
}
41+
},
42+
43+
// Install dependencies on container creation
44+
"postCreateCommand": "cd app && npm install",
45+
46+
// Set environment variables
47+
"remoteEnv": {
48+
"NODE_ENV": "development"
49+
},
50+
51+
// Use 'features' to add additional tools
52+
"features": {
53+
"ghcr.io/devcontainers/features/git:1": {
54+
"version": "latest"
55+
}
56+
}
57+
}

.github/workflows/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# GitHub Actions Workflows
2+
3+
## CI Workflow
4+
5+
The CI workflow (`ci.yml`) ensures the application builds successfully before merging.
6+
7+
### Triggers
8+
9+
- **Push** to `main` branch only
10+
- **Pull requests** targeting `main`
11+
12+
### Node.js Version
13+
14+
- Node.js 20.x (Current LTS)
15+
16+
### Steps
17+
18+
1. **Checkout code** - Clone the repository
19+
2. **Setup Node.js** - Install Node.js 20.x with npm cache
20+
3. **Install dependencies** - Run `npm ci` in app directory (uses workspace)
21+
4. **Build backend** - Compile TypeScript backend to JavaScript
22+
5. **Build frontend** - Build React frontend with Vite
23+
6. **Verify artifacts** - Check that all expected build files exist
24+
7. **Upload artifacts** - Store build outputs for inspection (7 days retention)
25+
26+
### Why Only One Node.js Version?
27+
28+
The workflow uses Node.js 20.x (Current LTS) to:
29+
- Reduce CI runtime and resource usage
30+
- Avoid duplicate runs (push + PR would create 4 jobs with matrix)
31+
- Focus on the primary supported version
32+
- Keep feedback fast for developers
33+
34+
The devcontainer also uses Node.js 20, ensuring consistency between local development and CI.
35+
36+
### Build Verification
37+
38+
The workflow verifies these artifacts are created:
39+
40+
**Backend:**
41+
- `backend/dist/server.js`
42+
- `backend/dist/discount-rules.js`
43+
- `backend/dist/types.js`
44+
45+
**Frontend:**
46+
- `frontend/dist/index.html`
47+
- `frontend/dist/assets/` (CSS and JS bundles)
48+
49+
### Status Badge
50+
51+
Add to README.md:
52+
```markdown
53+
![CI](https://github.com/TypeFox/oct-playground-demo/workflows/CI/badge.svg)
54+
```
55+
56+
### Local Testing
57+
58+
To test the same build process locally:
59+
60+
```bash
61+
cd app
62+
npm ci
63+
npm run build --workspace=backend
64+
npm run build --workspace=frontend
65+
```
66+
67+
Ensure you're using Node.js 20.x:
68+
```bash
69+
node --version # Should show v20.x.x
70+
```
71+
72+
### Troubleshooting
73+
74+
**If CI fails:**
75+
76+
1. Check the workflow run logs on GitHub Actions tab
77+
2. Look for TypeScript compilation errors
78+
3. Verify all dependencies are in package.json
79+
4. Test the build locally with Node.js 20.x
80+
5. Ensure package-lock.json is committed
81+
82+
**Common issues:**
83+
84+
- Missing dependencies: Run `npm install` and commit updated package-lock.json
85+
- TypeScript errors: Fix type issues in source code
86+
- Build configuration: Check tsconfig.json and vite.config.ts

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20.x'
22+
cache: 'npm'
23+
cache-dependency-path: app/package-lock.json
24+
25+
- name: Install dependencies
26+
working-directory: ./app
27+
run: npm ci
28+
29+
- name: Build backend
30+
working-directory: ./app
31+
run: npm run build --workspace=backend
32+
33+
- name: Build frontend
34+
working-directory: ./app
35+
run: npm run build --workspace=frontend
36+
37+
- name: Verify build artifacts
38+
working-directory: ./app
39+
run: |
40+
echo "Checking backend build artifacts..."
41+
test -d backend/dist || (echo "Backend dist directory not found" && exit 1)
42+
test -f backend/dist/server.js || (echo "Backend server.js not found" && exit 1)
43+
test -f backend/dist/discount-rules.js || (echo "Backend discount-rules.js not found" && exit 1)
44+
45+
echo "Checking frontend build artifacts..."
46+
test -d frontend/dist || (echo "Frontend dist directory not found" && exit 1)
47+
test -f frontend/dist/index.html || (echo "Frontend index.html not found" && exit 1)
48+
49+
echo "✅ All build artifacts verified successfully"
50+
51+
- name: Upload build artifacts
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: build-artifacts
55+
path: |
56+
app/backend/dist/
57+
app/frontend/dist/
58+
retention-days: 7

0 commit comments

Comments
 (0)