├── .editorconfig ├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── .npmrc ├── Makefile ├── README.md ├── __tests__ └── half.test.js ├── bin └── nodejs-package.js ├── eslint.config.ts ├── index.js ├── package-lock.json ├── package.json ├── sonar-project.properties ├── src └── half.js ├── tsconfig.json └── vitest.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | [Makefile] 2 | indent_style = tab 3 | 4 | [*.js] 5 | indent_style = space 6 | indent_size = 2 7 | -------------------------------------------------------------------------------- /.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 | 23 | steps: 24 | # Check-out repository under GitHub workspace 25 | # https://github.com/actions/checkout 26 | - uses: actions/checkout@v4 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@v5 41 | env: 42 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | *.log 3 | coverage 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | ; node-options=--no-warnings --experimental-vm-modules 2 | -------------------------------------------------------------------------------- /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 | publish: 23 | npx release-it 24 | 25 | .PHONY: test 26 | -------------------------------------------------------------------------------- /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 | ## Setup 11 | 12 | ```bash 13 | make install 14 | ``` 15 | 16 | ## Run tests 17 | 18 | ```bash 19 | make test 20 | ``` 21 | 22 | ## Run tests with coverage 23 | 24 | See [sonar-project.properties](./sonar-project.properties#1:2): 25 | 26 | ```bash 27 | make test-coverage 28 | # see ./coverage dir 29 | ``` 30 | 31 | --- 32 | 33 | [![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) 34 | 35 | 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). 36 | 37 | See most active contributors on [hexlet-friends](https://friends.hexlet.io/). 38 | -------------------------------------------------------------------------------- /__tests__/half.test.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { expect, test } from 'vitest' 4 | import half from '../index.js' 5 | 6 | test('half', () => { 7 | expect(half(6)).toBe(3) 8 | }) 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /eslint.config.ts: -------------------------------------------------------------------------------- 1 | import globals from 'globals' 2 | import pluginJs from '@eslint/js' 3 | import tseslint from 'typescript-eslint' 4 | import stylistic from '@stylistic/eslint-plugin' 5 | // import { Linter } from 'eslint' 6 | 7 | export default [ 8 | stylistic.configs.recommended, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommendedTypeChecked, 11 | ...tseslint.configs.stylisticTypeChecked, 12 | { 13 | files: [ 14 | '**/*.{js,ts,tsx}', 15 | ], 16 | }, 17 | { 18 | ignores: ['dist/'], 19 | }, 20 | { 21 | languageOptions: { 22 | globals: globals.node, 23 | parserOptions: { 24 | projectService: true, 25 | tsconfigRootDir: import.meta.dirname, 26 | }, 27 | }, 28 | rules: { 29 | '@typescript-eslint/no-unused-vars': 'off', 30 | }, 31 | }, 32 | ] // satisfies Linter.Config[] 33 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import half from './src/half.js' 4 | 5 | export default half 6 | -------------------------------------------------------------------------------- /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": ">=21" 13 | }, 14 | "scripts": { 15 | "test": "vitest run", 16 | "test:watch": "vitest" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/hexlet-boilerplates/nodejs-package.git" 21 | }, 22 | "author": "Kirill Mokevnin", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/hexlet-boilerplates/nodejs-package/issues" 26 | }, 27 | "type": "module", 28 | "homepage": "https://github.com/hexlet-boilerplates/nodejs-package#readme", 29 | "dependencies": { 30 | "@stylistic/eslint-plugin": "^4.1.0", 31 | "debug": "^4.4.0", 32 | "es-toolkit": "^1.32.0", 33 | "jiti": "^2.4.2", 34 | "vitest": "^3.0.7" 35 | }, 36 | "lint-staged": { 37 | "*.js": "eslint --fix" 38 | }, 39 | "devDependencies": { 40 | "@eslint/eslintrc": "^3.3.0", 41 | "@eslint/js": "^9.21.0", 42 | "@vitest/coverage-v8": "^3.1.1", 43 | "eslint": "^9.21.0", 44 | "eslint-plugin-import": "^2.31.0", 45 | "globals": "^16.0.0", 46 | "lint-staged": "^15.4.3", 47 | "npm-check-updates": "^17.1.15", 48 | "release-it": "^18.1.2", 49 | "simple-git-hooks": "^2.11.1", 50 | "typescript": "^5.7.3", 51 | "typescript-eslint": "^8.25.0" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "skipLibCheck": true, 4 | "allowJs": true, 5 | "noImplicitAny": false, 6 | "checkJs": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "moduleResolution": "Node", 10 | "module": "ESNext", 11 | "esModuleInterop": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true 14 | }, 15 | "include": [ 16 | "**/*", 17 | ], 18 | } 19 | -------------------------------------------------------------------------------- /vitest.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config' 2 | 3 | export default defineConfig({ 4 | test: { 5 | coverage: { 6 | reporter: ['text', 'html', 'lcov'], 7 | provider: 'v8', 8 | }, 9 | }, 10 | }) 11 | --------------------------------------------------------------------------------