├── .npmrc ├── .gitignore ├── index.js ├── .editorconfig ├── bin └── nodejs-package.js ├── src └── half.js ├── __tests__ └── half.test.js ├── Makefile ├── eslint.config.js ├── jest.config.js ├── sonar-project.properties ├── .github ├── workflows │ └── nodejs.yml └── dependabot.yml ├── package.json └── README.md /.npmrc: -------------------------------------------------------------------------------- 1 | node-options=--no-warnings --experimental-vm-modules 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | *.log 3 | coverage 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import half from './src/half.js' 4 | 5 | export default half 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [Makefile] 2 | indent_style = tab 3 | 4 | [*.js] 5 | indent_style = space 6 | indent_size = 2 7 | -------------------------------------------------------------------------------- /bin/nodejs-package.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import half from '../index.js' 4 | 5 | console.log(half(Number(process.argv[process.argv.length - 1]))) 6 | -------------------------------------------------------------------------------- /src/half.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | /** 4 | * @param {Number} num 5 | */ 6 | export default (num) => { 7 | const result = num / 2 8 | return result 9 | } 10 | -------------------------------------------------------------------------------- /__tests__/half.test.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { expect, test } from '@jest/globals' 4 | import half from '../index.js' 5 | 6 | test('half', () => { 7 | expect(half(6)).toBe(3) 8 | }) 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | install: deps-install 2 | npx simple-git-hooks 3 | 4 | run: 5 | bin/nodejs-package.js 10 6 | 7 | deps-install: 8 | npm ci 9 | 10 | deps-update: 11 | npx ncu -u 12 | 13 | test: 14 | npm test 15 | 16 | test-coverage: 17 | npm test -- --coverage 18 | 19 | lint: 20 | npx eslint . 21 | 22 | lint-fix: 23 | npx eslint . --fix 24 | 25 | publish: 26 | npx release-it 27 | 28 | .PHONY: test 29 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import js from '@eslint/js' 2 | import globals from 'globals' 3 | import { defineConfig } from 'eslint/config' 4 | import stylistic from '@stylistic/eslint-plugin' 5 | 6 | export default defineConfig([ 7 | stylistic.configs.recommended, 8 | { 9 | files: ['**/*.{js,mjs,cjs}'], 10 | plugins: { js }, 11 | extends: ['js/recommended'], 12 | languageOptions: { globals: globals.node }, 13 | }, 14 | ]) 15 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('jest').Config} */ 2 | export default { 3 | testEnvironment: 'node', 4 | // Тестовые файлы 5 | testMatch: ['**/__tests__/**/*.test.js'], 6 | // Генерация покрытия кода 7 | collectCoverage: false, 8 | coverageDirectory: 'coverage', // папка для отчётов 9 | coverageReporters: ['json', 'lcov', 'text', 'clover'], 10 | 11 | // Какие файлы включать в покрытие 12 | collectCoverageFrom: [ 13 | 'src/**/*.js', 14 | ], 15 | transform: {}, 16 | } 17 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=hexlet-boilerplates_nodejs-package 2 | sonar.organization=hexlet-boilerplates 3 | 4 | # NOTE: for cover coverage 5 | sonar.javascript.lcov.reportPaths=./coverage/lcov.info 6 | sonar.sources=src 7 | 8 | # This is the name and version displayed in the SonarCloud UI. 9 | #sonar.projectName=nodejs-package 10 | #sonar.projectVersion=1.0 11 | 12 | 13 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 14 | 15 | # Encoding of the source code. Default is default system encoding 16 | #sonar.sourceEncoding=UTF-8 17 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # Name of workflow 2 | name: Node CI 3 | 4 | # Trigger the workflow on push or pull request 5 | on: 6 | - push 7 | - pull_request 8 | 9 | env: 10 | CI: true 11 | 12 | jobs: 13 | build: 14 | 15 | # The type of machine to run the job on 16 | runs-on: ubuntu-latest 17 | 18 | strategy: 19 | # Node versions list 20 | matrix: 21 | node-version: [20.x, 22.x, 24.x] 22 | 23 | steps: 24 | # Check-out repository under GitHub workspace 25 | # https://github.com/actions/checkout 26 | - uses: actions/checkout@v5 27 | # Step's name 28 | - name: Use Node.js ${{ matrix.node-version }} 29 | # Configures the node version used on GitHub-hosted runners 30 | # https://github.com/actions/setup-node 31 | uses: actions/setup-node@v4 32 | # The Node.js version to configure 33 | with: 34 | node-version: ${{ matrix.node-version }} 35 | cache: 'npm' 36 | - run: make install 37 | - run: make lint 38 | - run: make test-coverage 39 | - name: SonarQube Scan 40 | uses: SonarSource/sonarqube-scan-action@v6 41 | env: 42 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@hexlet/nodejs-package", 3 | "version": "0.0.3", 4 | "description": "Node.js boilerplate package", 5 | "bin": { 6 | "nodejs-package": "bin/nodejs-package.js" 7 | }, 8 | "simple-git-hooks": { 9 | "pre-push": "npx lint-staged" 10 | }, 11 | "engines": { 12 | "node": ">=22" 13 | }, 14 | "scripts": { 15 | "test": "jest", 16 | "test:watch": "jest --watch", 17 | "test:coverage": "jest --coverage" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/hexlet-boilerplates/nodejs-package.git" 22 | }, 23 | "author": "Kirill Mokevnin", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/hexlet-boilerplates/nodejs-package/issues" 27 | }, 28 | "type": "module", 29 | "homepage": "https://github.com/hexlet-boilerplates/nodejs-package#readme", 30 | "dependencies": { 31 | "es-toolkit": "^1.39.10" 32 | }, 33 | "lint-staged": { 34 | "*.js": "eslint --fix" 35 | }, 36 | "devDependencies": { 37 | "@eslint/eslintrc": "^3.3.1", 38 | "@eslint/js": "^9.34.0", 39 | "@jest/globals": "^30.0.5", 40 | "@stylistic/eslint-plugin": "^5.2.3", 41 | "eslint": "^9.34.0", 42 | "eslint-plugin-import": "^2.32.0", 43 | "globals": "^16.3.0", 44 | "jest": "^30.0.5", 45 | "lint-staged": "^16.1.5", 46 | "npm-check-updates": "^18.0.2", 47 | "release-it": "^19.0.4", 48 | "simple-git-hooks": "^2.13.1" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nodejs-package 2 | 3 | [![Node CI](https://github.com/hexlet-boilerplates/nodejs-package/workflows/Node%20CI/badge.svg)](https://github.com/hexlet-boilerplates/nodejs-package/actions) 4 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=hexlet-boilerplates_nodejs-package&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=hexlet-boilerplates_nodejs-package) 5 | [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=hexlet-boilerplates_nodejs-package&metric=bugs)](https://sonarcloud.io/summary/new_code?id=hexlet-boilerplates_nodejs-package) 6 | [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=hexlet-boilerplates_nodejs-package&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=hexlet-boilerplates_nodejs-package) 7 | [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=hexlet-boilerplates_nodejs-package&metric=coverage)](https://sonarcloud.io/summary/new_code?id=hexlet-boilerplates_nodejs-package) 8 | [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=hexlet-boilerplates_nodejs-package&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=hexlet-boilerplates_nodejs-package) 9 | 10 | ## Requirements 11 | 12 | * Unix system (Macos/Linux) 13 | * Nodejs 22.x+ 14 | * Make 15 | 16 | ## Description 17 | 18 | Boilerplate for javascript projects with: 19 | 20 | * Javascript (nodejs) 21 | * Eslint 22 | * Jest 23 | 24 | For Typescript boilerplate see [typescript-package](https://github.com/hexlet-boilerplates/typescript-package) 25 | 26 | ## Setup 27 | 28 | ```bash 29 | make install 30 | ``` 31 | 32 | ## Run tests 33 | 34 | ```bash 35 | make test 36 | ``` 37 | 38 | See other commands in [Makefile](./Makefile) 39 | 40 | ## Run tests with coverage 41 | 42 | See [sonar-project.properties](./sonar-project.properties#1:2): 43 | 44 | ```bash 45 | make test-coverage 46 | # see ./coverage 47 | ``` 48 | 49 | --- 50 | 51 | [![Hexlet Ltd. logo](https://raw.githubusercontent.com/Hexlet/assets/master/images/hexlet_logo128.png)](https://hexlet.io/?utm_source=github&utm_medium=link&utm_campaign=nodejs-package) 52 | 53 | This repository is created and maintained by the team and the community of Hexlet, an educational project. [Read more about Hexlet](https://hexlet.io/?utm_source=github&utm_medium=link&utm_campaign=nodejs-package). 54 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Dependabot configuration 3 | # 4 | # This file configures automated dependency updates. 5 | # The goal is to: 6 | # - keep tooling (devDependencies) up to date without noise 7 | # - separate runtime (production) dependencies for safer review 8 | # - reduce the number of PRs by batching minor and patch updates 9 | # - highlight potentially breaking (major) updates in dedicated PRs 10 | # 11 | # Recommended documentation: 12 | # 13 | # 1) Dependabot Options Reference — full list of available keys, 14 | # including "dependency-type", "groups", "update-types", etc. 15 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 16 | # 17 | # 2) Optimizing pull request creation — best practices for grouping updates, 18 | # controlling frequency, and limiting noise in development teams. 19 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/optimizing-pr-creation-version-updates 20 | # 21 | # These links explain *why* we split dev/prod dependencies, 22 | # *how* grouping works, and what update strategies GitHub recommends 23 | # for real-world projects. 24 | # 25 | version: 2 26 | updates: 27 | # 1) Keep GitHub Actions workflows up to date 28 | - package-ecosystem: github-actions 29 | directory: / # Look for workflow files in the repo root 30 | schedule: 31 | interval: weekly # Check for updates once a week 32 | labels: [dependencies, automated, actions] # Labels added to PRs 33 | groups: 34 | actions-minor-patch: 35 | # Group all non-breaking (minor + patch) updates into a single PR 36 | update-types: [minor, patch] 37 | actions-major: 38 | # Major updates are potentially breaking → separate PR 39 | update-types: [major] 40 | # 2) Dev dependencies: tools only (lint, tests, build, etc.) 41 | - package-ecosystem: npm 42 | directory: / 43 | schedule: 44 | interval: weekly # Weekly check for npm devDependencies 45 | allow: 46 | # Only dependencies from "devDependencies" in package.json 47 | - dependency-type: development 48 | labels: [dependencies, automated, dev] 49 | groups: 50 | npm-dev-minor-patch: 51 | # Group dev minor + patch updates to reduce PR noise 52 | update-types: [minor, patch] 53 | npm-dev-major: 54 | # Keep major dev updates separate so they can be tested carefully 55 | update-types: [major] 56 | # 3) Runtime / production dependencies used by the package itself 57 | - package-ecosystem: npm 58 | directory: / 59 | schedule: 60 | interval: weekly # Weekly check for npm runtime deps 61 | allow: 62 | # Only dependencies from "dependencies" in package.json 63 | - dependency-type: production 64 | labels: [dependencies, automated, prod] 65 | groups: 66 | npm-runtime-minor-patch: 67 | # Group non-breaking runtime updates together 68 | update-types: [minor, patch] 69 | # (Major runtime updates will be opened as separate PRs by default) 70 | --------------------------------------------------------------------------------