Skip to content

Commit 436d3fd

Browse files
authored
feat: fullstack (#92)
* chore: init * chore: flow to prisma * chore: module * chore: eslint * chore: read from db * feat: schedule * chore: ts & data fetch * chore: image * feat: project * feat: article reader * chore: layout & image * chore: background * chore: module * chore: postgresql * fix: page navigation * chore: code optimize * chore: transition * chore: use pnpm in dockerfile * chore: apply multiple stages to reduce size * chore: change lint to pnpm * chore: version
1 parent e6dbb21 commit 436d3fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3805
-2458
lines changed

.dockerignore

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# .dockerignore
2-
/.nuxt
3-
/.output
4-
/node_modules
5-
6-
.gitignore
7-
README.md
1+
node_modules
2+
npm-debug*
3+
.nuxt
4+
dist
5+
tests
6+
.output

.eslintignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dist
2+
public
3+
4+
# ignore generate imports
5+
auto-imports.d.ts
6+
components.d.ts
7+
8+
dist
9+
.output
10+
node_modules

.github/workflows/ci.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
testCodebase:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Use Node.js 20
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 20
18+
19+
# Install pnpm and packages
20+
- run: npm install -g pnpm
21+
- run: pnpm install
22+
23+
# Generate prisma client & push to db
24+
- run: echo "DATABASE_URL=file:./db.sqlite" > .env
25+
- run: npx prisma db push
26+
- run: npx prisma generate
27+
28+
# Run linting and typechecking
29+
- run: pnpm run lint
30+
- run: pnpm run typecheck
31+
32+
# Run tests
33+
- run: pnpm run test
34+
35+
testAppBuildsAndStarts:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
- name: Use Node.js 20
40+
uses: actions/setup-node@v3
41+
with:
42+
node-version: 20
43+
44+
# Install pnpm and packages
45+
- run: npm install -g pnpm
46+
- run: pnpm install
47+
48+
# Generate prisma client & push to db
49+
- run: echo "DATABASE_URL=file:./db.sqlite" > .env
50+
- run: npx prisma db push
51+
- run: npx prisma generate
52+
53+
# Start app in dev mode and load `/`-index page
54+
- run: '(timeout 60 pnpm run dev & (sleep 10 && curl --fail localhost:3000)) && echo Run development check successful'
55+
56+
# Build & start app in production mode and load `/`-index page
57+
- run: 'pnpm run build && (timeout 60 pnpm run preview & (sleep 10 && curl --fail localhost:3000)) && echo Run production check successful'

.gitignore

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,83 @@
1-
# Nuxt dev/build outputs
2-
.output
1+
# Logs and databases #
2+
######################
3+
*.log
4+
*.sql
5+
*.sqlite
6+
*.db
7+
*.sqlite-journal
8+
/logs
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# OS generated files #
14+
######################
15+
.DS_Store
16+
.DS_Store?
17+
._*
18+
.Spotlight-V100
19+
.Trashes
20+
ehthumbs.db
21+
Thumbs.db
22+
23+
# helmsman generated tmp folder
24+
.helmsman-tmp
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
29+
# Dependency directories
30+
node_modules/
31+
jspm_packages/
32+
33+
# Optional npm cache directory
34+
.npm
35+
36+
# Optional eslint cache
37+
.eslintcache
38+
39+
# Optional REPL history
40+
.node_repl_history
41+
42+
# Output of 'npm pack'
43+
*.tgz
44+
45+
# Yarn Integrity file
46+
.yarn-integrity
47+
48+
# dotenv environment variables file
49+
.env
50+
51+
# parcel-bundler cache (https://parceljs.org/)
52+
.cache
53+
54+
# next.js build output
55+
.next
56+
57+
# Nuxt
58+
*.log*
359
.nuxt
460
.nitro
561
.cache
62+
.output
63+
.env
664
dist
765

8-
# Node dependencies
9-
node_modules
66+
# vuepress build output
67+
.vuepress/dist
1068

11-
# Logs
12-
logs
13-
*.log
69+
# Serverless directories
70+
.serverless
1471

15-
# Misc
16-
.DS_Store
17-
.fleet
72+
# IDE / Editor
1873
.idea
1974

20-
# Local env files
21-
.env
22-
.env.*
23-
!.env.example
75+
# Service worker
76+
sw.*
77+
78+
# Vim swap files
79+
*.swp
80+
81+
# Auto generate on postinstall step
82+
auto-imports.d.ts
83+
components.d.ts

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
shamefully-hoist=true
22
strict-peer-dependencies=false
3-
43
sharp_binary_host="https://npmmirror.com/mirrors/sharp"
54
sharp_libvips_binary_host="https://npmmirror.com/mirrors/sharp-libvips"

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.14.2

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"editorconfig.editorconfig",
4+
"dbaeumer.vscode-eslint",
5+
"vue.volar",
6+
"bradlc.vscode-tailwindcss",
7+
"Prisma.prisma-insider"
8+
]
9+
}

.vscode/settings.json

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,46 @@
11
{
2+
"[vue]": {
3+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
4+
},
5+
"[js]": {
6+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
7+
},
8+
"[ts]": {
9+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
10+
},
11+
"tailwindCSS.experimental.configFile": ".nuxt/tailwind.config.cjs",
212
"files.associations": {
313
"*.css": "tailwindcss"
414
},
5-
"editor.quickSuggestions": {
6-
"strings": true
7-
},
8-
"tailwindCSS.experimental.classRegex": [
9-
[
10-
"ui:\\s*{([^)]*)\\s*}",
11-
"[\"'`]([^\"'`]*).*?[\"'`]"
12-
],
13-
[
14-
"/\\*ui\\*/\\s*{([^;]*)}",
15-
":\\s*[\"'`]([^\"'`]*).*?[\"'`]"
16-
]
17-
],
18-
"tailwindCSS.classAttributes": [
19-
"class",
20-
"className",
21-
"ngClass",
22-
"ui"
23-
],
24-
"nuxt.isNuxtApp": false,
15+
"volar.autoCompleteRefs": true,
16+
"prisma.fileWatcher": true,
2517
// Enable the ESlint flat config support
2618
"eslint.experimental.useFlatConfig": true,
19+
2720
// Disable the default formatter, use eslint instead
2821
"prettier.enable": false,
2922
"editor.formatOnSave": false,
23+
3024
// Auto fix
3125
"editor.codeActionsOnSave": {
32-
"source.fixAll": "explicit",
26+
"source.fixAll.eslint": "explicit",
3327
"source.organizeImports": "never"
3428
},
29+
3530
// Silent the stylistic rules in you IDE, but still auto fix them
3631
"eslint.rules.customizations": [
37-
{
38-
"rule": "style/*",
39-
"severity": "off"
40-
},
41-
{
42-
"rule": "*-indent",
43-
"severity": "off"
44-
},
45-
{
46-
"rule": "*-spacing",
47-
"severity": "off"
48-
},
49-
{
50-
"rule": "*-spaces",
51-
"severity": "off"
52-
},
53-
{
54-
"rule": "*-order",
55-
"severity": "off"
56-
},
57-
{
58-
"rule": "*-dangle",
59-
"severity": "off"
60-
},
61-
{
62-
"rule": "*-newline",
63-
"severity": "off"
64-
},
65-
{
66-
"rule": "*quotes",
67-
"severity": "off"
68-
},
69-
{
70-
"rule": "*semi",
71-
"severity": "off"
72-
}
32+
{ "rule": "style/*", "severity": "off" },
33+
{ "rule": "format/*", "severity": "off" },
34+
{ "rule": "*-indent", "severity": "off" },
35+
{ "rule": "*-spacing", "severity": "off" },
36+
{ "rule": "*-spaces", "severity": "off" },
37+
{ "rule": "*-order", "severity": "off" },
38+
{ "rule": "*-dangle", "severity": "off" },
39+
{ "rule": "*-newline", "severity": "off" },
40+
{ "rule": "*quotes", "severity": "off" },
41+
{ "rule": "*semi", "severity": "off" }
7342
],
43+
7444
// Enable eslint for all supported languages
7545
"eslint.validate": [
7646
"javascript",
@@ -82,6 +52,7 @@
8252
"markdown",
8353
"json",
8454
"jsonc",
85-
"yaml"
55+
"yaml",
56+
"toml"
8657
]
8758
}

Dockerfile

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
# 第一阶段:构建阶段
2-
FROM node:20.11.1-alpine as build
1+
# Use a smaller base image
2+
ARG NODE_VERSION=node:20-alpine
33

4-
WORKDIR /src
4+
# Stage 1: Build dependencies
5+
FROM $NODE_VERSION AS dependency-base
56

6-
# 将依赖项安装到单独的图层中
7-
COPY package.json pnpm-lock.yaml .npmrc ./
8-
RUN npm config set registry https://registry.npmmirror.com && \
9-
npm install -g pnpm && \
10-
pnpm install
7+
# Create app directory
8+
WORKDIR /app
119

12-
# 复制应用程序代码并构建
10+
# Install pnpm
11+
RUN npm install -g pnpm
12+
13+
# Copy the package files
14+
COPY package.json pnpm-lock.yaml ./
15+
16+
# Install dependencies using pnpm
17+
RUN pnpm install --frozen-lockfile
18+
19+
# Stage 2: Build the application
20+
FROM dependency-base AS production-base
21+
22+
# Copy the source code
1323
COPY . .
14-
RUN pnpm build
1524

16-
# 第二阶段:运行阶段
17-
FROM node:20.11.1-alpine as base
25+
# Build the application
26+
RUN pnpm run build
1827

19-
EXPOSE 3000
28+
# Stage 3: Production image
29+
FROM $NODE_VERSION AS production
30+
31+
# Copy built assets from previous stage
32+
COPY --from=production-base /app/.output /app/.output
2033

21-
WORKDIR /src
34+
# Define environment variables
35+
ENV NUXT_HOST=0.0.0.0 \
36+
NUXT_APP_VERSION=latest \
37+
DATABASE_URL=file:./db.sqlite \
38+
NODE_ENV=production
2239

23-
# 复制构建阶段生成的代码和依赖项(仅复制构建所需的文件和依赖项)
24-
COPY --from=build /src/.output /src/.output
40+
# Set the working directory
41+
WORKDIR /app
42+
43+
EXPOSE 3000
2544

26-
CMD [ "node", ".output/server/index.mjs" ]
45+
# Start the app
46+
CMD ["node", "/app/.output/server/index.mjs"]

app.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export default defineAppConfig({
33
primary: 'red',
44
gray: 'cool',
55
icons: {
6-
dynamic: true
7-
}
6+
dynamic: true,
7+
},
88

99
},
1010
})

0 commit comments

Comments
 (0)