Skip to content

Commit

Permalink
chore: pnpm onboarding #66
Browse files Browse the repository at this point in the history
  • Loading branch information
la3rence committed Jan 2, 2024
1 parent 4eaecbc commit 2dcabc7
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 406 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Node.js CI by Github Workflow
name: Express CI
name: PNPM CI

on:
push:
Expand All @@ -12,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3

- uses: pnpm/action-setup@v2.2.4
- uses: pnpm/action-setup@v2.4.0
name: Install pnpm
id: pnpm-install
with:
Expand All @@ -40,16 +39,16 @@ jobs:
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
run: pnpm i

- name: Test
env: # repo secrets as environment variable
IFTTT_KEY: ${{ secrets.IFTTT_KEY }}
run: |
printenv
pnpm run format
pnpm run test:fmt
pnpm run test:coverage
pnpm fmt
pnpm test:fmt
pnpm test:coverage
- name: Test Summary
uses: test-summary/action@v2
Expand All @@ -73,7 +72,7 @@ jobs:

- name: Generate Swagger Spec JSON
run: |
pnpm run swagger
pnpm swagger
- uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
. "$(dirname "$0")/_/husky.sh"

git diff --check
npm run swagger
npm run test:coverage
npx lint-staged
pnpm swagger
pnpm test:coverage
pnpm lint-staged
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM node:20
FROM node:20-slim AS base

# Create app directory
WORKDIR /usr/src/app
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

ENV NODE_ENV=PRODUCTION
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN corepack enable
COPY . /app
WORKDIR /app

# building your code for production
RUN npm ci --only=production --ignore-scripts
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

# Bundle app source
COPY . .
FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules

EXPOSE 8080
CMD [ "npm", "start" ]
CMD [ "pnpm", "start" ]
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ podTemplate(label: label,
stage('Test') {
container('node') {
sh """
npm ci --ignore-scripts
npm run test:coverage
pnpm i
pnpm test:coverage
"""
publishHTML target: [allowMissing : false,
alwaysLinkToLastBuild: false,
Expand Down
2 changes: 1 addition & 1 deletion api/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sse = (req, res) => {
() => {
clearInterval(interval);
},
false
false,
);
};

Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.get("/sse", sse);
router.use(
swaggerUIPath,
swaggerUiExpress.serve,
swaggerUiExpress.setup(swaggerSpec)
swaggerUiExpress.setup(swaggerSpec),
);
app.use(BASEPATH, router);
app.use("/", express.static(resolve("public")));
Expand Down
4 changes: 2 additions & 2 deletions middleware/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const applyCorsHeaders = (res) => {
// or res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader(
"Access-Control-Allow-Methods",
"GET,OPTIONS,PATCH,DELETE,POST,PUT"
"GET,OPTIONS,PATCH,DELETE,POST,PUT",
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
);
return res;
};
Expand Down
4 changes: 2 additions & 2 deletions middleware/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (isProd && !isServerless) {
new winston.transports.File({
filename: "logs/winston.log",
timestamp: true,
})
}),
);
}
/* c8 ignore stop */
Expand All @@ -24,7 +24,7 @@ const logOptions = {
format: winston.format.combine(
winston.format.uncolorize({ all: !isProd }),
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
isProd ? winston.format.json() : winston.format.cli()
isProd ? winston.format.json() : winston.format.cli(),
),
meta: isProd,
msg: "{{res.responseTime}}ms {{res.statusCode}} {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
Expand Down
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
{
"name": "node-express-example",
"version": "0.0.1",
"private": true,
"exports": "./app.js",
"type": "module",
"engines": {
"node": ">=14.16"
"node": ">=16"
},
"author": "Lawrence Li",
"homepage": "https://github.com/Lonor/node-express-example",
"author": "Lawrence Li @la3rence",
"homepage": "https://github.com/la3rence/node-express-example",
"license": "MIT",
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
},
"scripts": {
"dev": "pnpm run swagger; pnpm start",
"dev": "pnpm swagger; pnpm start",
"start": "node server.js",
"test": "mocha --timeout 10000 --exit --reporter mocha-junit-reporter",
"test:coverage": "c8 --reporter=lcov -r html -r text pnpm test",
"test:grep": "pnpm test -- -g",
"swagger": "node ./swagger/autogen.js && pnpm run format",
"format": "prettier --write . --ignore-unknown",
"swagger": "node ./swagger/autogen.js && pnpm fmt",
"fmt": "prettier --write . --ignore-unknown",
"test:fmt": "prettier --check .",
"prepare": "husky install"
},
"dependencies": {
"dotenv": "16.0.3",
"dotenv": "^16.3.1",
"express": "4.18.2",
"express-winston": "4.2.0",
"node-fetch": "3.3.1",
"swagger-ui-express": "4.6.3",
"winston": "3.9.0"
"express-winston": "^4.2.0",
"node-fetch": "^3.3.2",
"swagger-ui-express": "^5.0.0",
"winston": "^3.11.0"
},
"devDependencies": {
"c8": "7.14.0",
"chai": "4.3.7",
"husky": "8.0.3",
"lint-staged": "13.2.2",
"mocha": "10.2.0",
"mocha-junit-reporter": "2.2.0",
"prettier": "2.8.8",
"supertest": "6.3.3",
"swagger-autogen": "2.23.1"
"c8": "^8.0.1",
"chai": "^5.0.0",
"husky": "^8.0.3",
"lint-staged": "^13.3.0",
"mocha": "^10.2.0",
"mocha-junit-reporter": "^2.2.1",
"prettier": "^3.1.1",
"supertest": "^6.3.3",
"swagger-autogen": "^2.23.7"
}
}
Loading

1 comment on commit 2dcabc7

@vercel
Copy link

@vercel vercel bot commented on 2dcabc7 Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.