diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a05749c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a0d4ce0 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/coverage/**/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..42926ee --- /dev/null +++ b/.eslintrc @@ -0,0 +1,4 @@ +{ + "extends": "@voxpelli/eslint-config/esm", + "root": true +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..f3015ee --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,18 @@ +name: Linting + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + lint: + uses: voxpelli/ghatemplates/.github/workflows/lint.yml@main diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..d59b9e4 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,21 @@ +name: Node CI + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + test: + uses: voxpelli/ghatemplates/.github/workflows/test.yml@main + with: + node-versions: '16,18,20' + os: 'ubuntu-latest' diff --git a/.github/workflows/ts-internal.yml b/.github/workflows/ts-internal.yml new file mode 100644 index 0000000..1d90243 --- /dev/null +++ b/.github/workflows/ts-internal.yml @@ -0,0 +1,23 @@ +name: Type Checks, Internal Types + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + schedule: + - cron: '14 5 * * 1,3,5' + +permissions: + contents: read + +jobs: + type-check: + uses: voxpelli/ghatemplates/.github/workflows/type-check.yml@main + with: + ts-versions: ${{ github.event.schedule && 'next' || '5.1,next' }} + ts-libs: 'es2020;esnext' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50b7450 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Basic ones +/coverage +/coverage-ts +/node_modules +/.env +/.nyc_output + +# We're a library, so please, no lock files +/package-lock.json +/yarn.lock + +# Generated types +*.d.ts +*.d.ts.map +!/lib/advanced-types.d.ts +!/index.d.ts + +# Library specific ones diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..610c2a5 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npm test diff --git a/.knip.jsonc b/.knip.jsonc new file mode 100644 index 0000000..29a4eb8 --- /dev/null +++ b/.knip.jsonc @@ -0,0 +1,4 @@ +{ + "$schema": "https://unpkg.com/knip@2/schema.json", + "ignoreDependencies": ["@types/mocha", "mocha"] +} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3b55abc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Pelle Wessman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..711975a --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Node Module Template + +A GitHub template repo for node modules + + +[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/voxpelli/eslint-config) +[![Module type: ESM](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm) +[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js) +[![Follow @voxpelli@mastodon.social](https://img.shields.io/mastodon/follow/109247025527949675?domain=https%3A%2F%2Fmastodon.social&style=social)](https://mastodon.social/@voxpelli) + +## Usage + +### Simple + +```javascript +import { something } from '@voxpelli/node-module-template'; + +// Use that something +``` + +## API + +### `something(input, { configParam }) => Promise` + +Takes a value (`input`), does something configured by the config (`configParam`) and returns the processed value asyncly(`output`) + +## Similar modules + +* [`example`](https://example.com/) – is similar in this way + +## See also + +* [Announcement blog post](#) +* [Announcement tweet](#) diff --git a/declaration.tsconfig.json b/declaration.tsconfig.json new file mode 100644 index 0000000..a7d1d9a --- /dev/null +++ b/declaration.tsconfig.json @@ -0,0 +1,14 @@ + +{ + "extends": "./tsconfig", + "files": [], + "exclude": [ + "test/**/*.js" + ], + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "noEmit": false, + "emitDeclarationOnly": true + } +} diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..917aa9b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +export type * from './lib/advanced-types.d.ts'; + +export { default } from './lib/main.js'; diff --git a/index.js b/index.js new file mode 100644 index 0000000..208e8e5 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +export { default } from './lib/main.js'; diff --git a/lib/advanced-types.d.ts b/lib/advanced-types.d.ts new file mode 100644 index 0000000..f8e514f --- /dev/null +++ b/lib/advanced-types.d.ts @@ -0,0 +1,2 @@ +// TODO: Replace with proper types or remove file +import {} from 'node:path'; diff --git a/lib/main.js b/lib/main.js new file mode 100644 index 0000000..64291b0 --- /dev/null +++ b/lib/main.js @@ -0,0 +1,6 @@ +/** + * @returns {Promise} + */ +export default async function () { + // TODO: Extend or replace +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..bd55173 --- /dev/null +++ b/package.json @@ -0,0 +1,72 @@ +{ + "name": "@voxpelli/node-module-template", + "version": "0.0.0", + "description": "A GitHub template repo for node modules", + "homepage": "http://github.com/voxpelli/node-module-template", + "repository": { + "type": "git", + "url": "git://github.com/voxpelli/node-module-template.git" + }, + "keywords": [], + "author": "Pelle Wessman (http://kodfabrik.se/)", + "license": "MIT", + "engines": { + "node": ">=16.0.0" + }, + "type": "module", + "exports": "./index.js", + "types": "index.d.ts", + "files": [ + "/index.js", + "/index.d.ts", + "/index.d.ts.map", + "lib/*.js", + "lib/*.d.ts", + "lib/*.d.ts.map" + ], + "scripts": { + "build:0": "run-s clean", + "build:1-declaration": "tsc -p declaration.tsconfig.json", + "build": "run-s build:*", + "check:installed-check": "installed-check -i eslint-plugin-jsdoc -i knip -i installed-check", + "check:knip": "knip", + "check:lint": "eslint --report-unused-disable-directives .", + "check:tsc": "tsc", + "check:type-coverage": "type-coverage --detail --strict --at-least 99 --ignore-files 'test/*'", + "check": "run-s clean && run-p check:*", + "clean:declarations-top": "rm -rf $(find . -maxdepth 1 -type f -name '*.d.ts*' ! -name 'advanced-types.d.ts' ! -name 'index.d.ts')", + "clean:declarations-lib": "rm -rf $(find lib -type f -name '*.d.ts*' ! -name 'advanced-types.d.ts')", + "clean": "run-p clean:*", + "prepare": "husky install", + "prepublishOnly": "run-s build", + "test:mocha": "c8 --reporter=lcov --reporter text mocha 'test/**/*.spec.js'", + "test-ci": "run-s test:*", + "test": "run-s check test:*" + }, + "devDependencies": { + "@types/chai": "^4.3.5", + "@types/mocha": "^10.0.1", + "@types/node": "^16.18.38", + "@voxpelli/eslint-config": "^18.0.0", + "@voxpelli/tsconfig": "^8.0.0", + "c8": "^8.0.0", + "chai": "^4.3.7", + "eslint": "^8.45.0", + "eslint-plugin-es-x": "^7.1.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jsdoc": "^46.4.4", + "eslint-plugin-mocha": "^10.1.0", + "eslint-plugin-n": "^16.0.1", + "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-security": "^1.7.1", + "eslint-plugin-sort-destructure-keys": "^1.5.0", + "eslint-plugin-unicorn": "^47.0.0", + "husky": "^8.0.3", + "installed-check": "^8.0.0", + "knip": "^2.16.0", + "mocha": "^10.2.0", + "npm-run-all2": "^6.0.6", + "type-coverage": "^2.26.0", + "typescript": "~5.1.6" + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..63a262e --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "github>voxpelli/renovate-config" + ] +} diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..d8a372c --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "@voxpelli/eslint-config/mocha" +} diff --git a/test/main.spec.js b/test/main.spec.js new file mode 100644 index 0000000..1f700c0 --- /dev/null +++ b/test/main.spec.js @@ -0,0 +1,12 @@ +import chai from 'chai'; + +// TODO: Replace with proper setup +import something from '../index.js'; + +chai.should(); + +describe('something', () => { + it('should work', async () => { + await something(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7372853 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "@voxpelli/tsconfig/node16.json", + "files": [ + "index.js" + ], + "include": [ + "lib/**/*", + "test/**/*", + ] +}