generated from EdJoPaTo/typescript-node-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1d8e735
Showing
13 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = tab | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
open-pull-requests-limit: 30 | ||
schedule: | ||
interval: "weekly" | ||
day: "saturday" | ||
time: "02:42" # UTC | ||
commit-message: | ||
prefix: "build(npm):" | ||
ignore: | ||
- dependency-name: "@types/node" | ||
update-types: ["version-update:semver-major"] | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
day: "saturday" | ||
time: "02:42" # UTC | ||
commit-message: | ||
prefix: "ci(actions):" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Node.js | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
# Check if it works with current dependencies | ||
- cron: '42 2 * * 6' # weekly on Saturday 2:42 UTC | ||
|
||
jobs: | ||
test: | ||
name: Node.js | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 'lts/*' | ||
- uses: actions/checkout@v4 | ||
- run: npm install | ||
- run: npm test | ||
- run: npm pack | ||
|
||
publish: | ||
name: Publish on NPM | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
needs: test | ||
permissions: | ||
contents: write | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 'lts/*' | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm install | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
NPM_CONFIG_ACCESS: public | ||
NPM_CONFIG_PROVENANCE: true | ||
- name: Create GitHub release | ||
uses: softprops/action-gh-release@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*-*.*.*.tgz | ||
coverage | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) EdJoPaTo <typescript-node-module-boilerplate-npm-package@edjopato.de> (https://edjopato.de) | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# typescript-node-module-boilerplate | ||
|
||
[![NPM Version](https://img.shields.io/npm/v/typescript-node-module-boilerplate.svg)](https://www.npmjs.com/package/typescript-node-module-boilerplate) | ||
[![node](https://img.shields.io/node/v/typescript-node-module-boilerplate.svg)](https://www.npmjs.com/package/typescript-node-module-boilerplate) | ||
|
||
> | ||
## Install | ||
|
||
```bash | ||
npm install typescript-node-module-boilerplate | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import {myFunction} from 'typescript-node-module-boilerplate'; | ||
|
||
myFunction('unicorns'); | ||
//=> 'unicorns & rainbows' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# Usage | ||
# Go to the project you want to improve via this template | ||
# cd ~/git/my-project | ||
# Run this script from the working directory of that project | ||
# ~/git/typescript-node-module-boilerplate/copy-template-into-existing-project.sh | ||
|
||
name=$(basename "$PWD") | ||
templatedir="$(dirname "$0")" | ||
|
||
cp -r \ | ||
"$templatedir/"{package.json,tsconfig.json,.editorconfig,.gitattributes,.github,.gitignore,.npmrc} \ | ||
. | ||
|
||
echo "everything copied" | ||
|
||
# Replace template name with folder name | ||
# macOS: add '' after -i like this: sed -i '' "s/… | ||
sed -i "s/typescript-node-module-boilerplate/$name/g" package.json .github/**/*.yml | ||
|
||
git --no-pager status --short |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "typescript-node-module-boilerplate", | ||
"version": "0.0.0", | ||
"description": "", | ||
"keywords": [ | ||
"" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/EdJoPaTo/typescript-node-module-boilerplate.git" | ||
}, | ||
"author": { | ||
"name": "EdJoPaTo", | ||
"email": "typescript-node-module-boilerplate-npm-package@edjopato.de", | ||
"url": "https://edjopato.de" | ||
}, | ||
"scripts": { | ||
"build": "del-cli dist && tsc", | ||
"prepack": "npm run build", | ||
"test": "tsc --sourceMap && xo && c8 --all node --test --enable-source-maps" | ||
}, | ||
"type": "module", | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "^5.0.0", | ||
"@types/node": "^18.18.13", | ||
"c8": "^8.0.1", | ||
"del-cli": "^5.0.0", | ||
"typescript": "^5.0.2", | ||
"xo": "^0.56.0" | ||
}, | ||
"files": [ | ||
"dist", | ||
"!*.test.*", | ||
"!test.*" | ||
], | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"xo": { | ||
"rules": { | ||
"@typescript-eslint/prefer-readonly-parameter-types": "warn" | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.test.*", | ||
"**/test.*" | ||
], | ||
"rules": { | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function moduleName(input: string | undefined): string { | ||
if (typeof input !== 'string' && input !== undefined) { | ||
throw new TypeError(`Expected a string, got ${typeof input}`); | ||
} | ||
|
||
const sanetized = input?.trim() ?? 'Glitter'; | ||
return sanetized + ' & rainbows'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {strictEqual, throws} from 'node:assert'; | ||
import {test} from 'node:test'; | ||
import {moduleName} from './index.js'; | ||
|
||
await test('simple string input', () => { | ||
strictEqual(moduleName('unicorns'), 'unicorns & rainbows'); | ||
}); | ||
|
||
await test('javascript users without typings get error on number', () => { | ||
// @ts-expect-error moduleName expects a string not a number | ||
throws(() => moduleName(123), { | ||
message: 'Expected a string, got number', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@sindresorhus/tsconfig/tsconfig.json", | ||
"include": [ | ||
"source" | ||
], | ||
"compilerOptions": { | ||
"lib": ["ES2020"], | ||
"target": "ES2020", // Node.js 14 | ||
"outDir": "dist" | ||
} | ||
} |