diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..237ee307 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +coverage/ +dist/ +**/*.js diff --git a/.eslintrc b/.eslintrc index 29597add..6adf1e22 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,7 @@ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", + // "plugin:@typescript-eslint/recommended-type-checked", "prettier", // "plugin:import/errors", // "plugin:import/warnings", diff --git a/Dockerfile b/Dockerfile index 12b2d083..3e63fadd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,21 +20,63 @@ RUN npm install -g --ignore-scripts markdownlint-cli # [!TIP] Use a bind-mount to "/app" to override following "copys" # for lint and test against "current" sources in this stage +# YAML sources +COPY ./.github ${WORKDIR}/ +COPY ./compose.yaml ${WORKDIR}/ + +# Markdown sources +COPY ./docs ${WORKDIR}/ +COPY ./README.md ${WORKDIR}/ +COPY ./LICENSE.md ${WORKDIR}/ +COPY ./CODE_OF_CONDUCT.md ${WORKDIR}/ + +# Code source +COPY ./src ${WORKDIR}/src +COPY ./package.json ${WORKDIR}/package.json +COPY ./package-lock.json ${WORKDIR}/package-lock.json +COPY ./Makefile ${WORKDIR}/ + +# code linting conf +COPY ./.prettierrc ${WORKDIR}/ +COPY ./.prettierignore ${WORKDIR}/ +COPY ./.eslintrc ${WORKDIR}/ +COPY ./.eslintignore ${WORKDIR}/ + +# markdownlint conf +COPY ./.markdownlint.yaml ${WORKDIR}/ + +# yamllint conf +COPY ./.yamllint ${WORKDIR}/ +COPY ./.yamlignore ${WORKDIR}/ + CMD ["make", "lint"] ############################################################################### FROM base AS development -############################################################################### -FROM development AS builder +ENV WORKDIR=/app +WORKDIR ${WORKDIR} COPY ./src ${WORKDIR}/src COPY ./package.json ${WORKDIR}/package.json COPY ./package-lock.json ${WORKDIR}/package-lock.json COPY ./Makefile ${WORKDIR}/ COPY ./tsconfig.json ${WORKDIR}/tsconfig.json +COPY ./tsconfig.prod.json ${WORKDIR}/tsconfig.json RUN npm ci --verbose --ignore-scripts +RUN ls -alh + +# CMD [] +############################################################################### +FROM development AS builder + +ENV WORKDIR=/app +WORKDIR ${WORKDIR} + +RUN npm run build + +CMD ["ls", "-alh"] ############################################################################### ### In testing stage, can't use USER, due permissions issue @@ -42,38 +84,39 @@ RUN npm ci --verbose --ignore-scripts ## ## https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions ## -FROM builder AS testing +FROM development AS testing ENV LOG_LEVEL=info ENV BRUTEFORCE=false +ENV WORKDIR=/app +WORKDIR ${WORKDIR} -WORKDIR /app - -COPY ./.eslintrc /app/.eslintrc -COPY ./.prettierrc /app/.prettierrc COPY ./jest.config.ts /app/jest.config.ts -COPY --from=builder /app/node_modules /app/node_modules RUN ls -alh -CMD ["npm", "run", "test"] +CMD ["make", "test"] ############################################################################### ### In production stage ## in the production phase, "good practices" such as ## WORKSPACE and USER are maintained ## -FROM builder AS production +FROM base AS production +ENV NODE_ENV=production ENV LOG_LEVEL=info ENV BRUTEFORCE=false +ENV WORKDIR=/app +WORKDIR ${WORKDIR} -WORKDIR /app +COPY --from=builder /app/dist ${WORKDIR}/dist -COPY ./.eslintrc /app/.eslintrc -COPY ./.prettierrc /app/.prettierrc -COPY ./jest.config.ts /app/jest.config.ts -COPY --from=builder /app/node_modules /app/node_modules +COPY ./Makefile ${WORKDIR}/ +COPY ./package.json ${WORKDIR}/package.json +COPY ./package-lock.json ${WORKDIR}/package-lock.json + +RUN npm ci --verbose --omit=dev --omit=optional --ignore-scripts --no-cache RUN ls -alh USER node -CMD ["npm", "run", "test"] +CMD ["ls", "-alh"] diff --git a/Makefile b/Makefile index 91998795..88a3ac97 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,15 @@ env: clean: npm run jest:clean - rm -vfr ./node_modules rm -vfr ./coverage + rm -vfr ./dist + rm -vfr ./node_modules mkdir -p ./coverage touch ./coverage/.gitkeep +build: dependencies + ${NPM} run build + dependencies: @echo "################################################################################" @echo "## Dependencies: ###############################################################" diff --git a/jest.config.ts b/jest.config.ts index 37f3a255..ff2a71e6 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -177,7 +177,7 @@ const jestConfig = { '^.+\\.ts?$': 'ts-jest' }, // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - transformIgnorePatterns: ['/node_modules/'], + transformIgnorePatterns: ['/dist/', '/node_modules/'], // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them // unmockedModulePathPatterns: undefined, diff --git a/package.json b/package.json index f44182d4..b3d9d6a5 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "typescript": "^5.4.5" }, "scripts": { + "build": "tsc -p tsconfig.prod.json", "start": "npm run test", "lint": "npx --yes eslint . --color --max-warnings=0 && echo '✔ Your code looks good.'", "jest:ci": "node --experimental-vm-modules ./node_modules/.bin/jest --no-cache --ci --color --detectOpenHandles --forceExit --runInBand --debug", diff --git a/tsconfig.prod.json b/tsconfig.prod.json new file mode 100644 index 00000000..b29590cd --- /dev/null +++ b/tsconfig.prod.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig", + "exclude": ["jest.config.ts", "**/*.test.ts", "**/*.mock.ts"] +}