Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
spookyuser authored Dec 27, 2023
0 parents commit 1d8e735
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
26 changes: 26 additions & 0 deletions .github/dependabot.yml
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):"
45 changes: 45 additions & 0 deletions .github/workflows/nodejs.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*-*.*.*.tgz
coverage
dist
node_modules
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
9 changes: 9 additions & 0 deletions LICENSE
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.
21 changes: 21 additions & 0 deletions README.md
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'
```
23 changes: 23 additions & 0 deletions copy-template-into-existing-project.sh
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
59 changes: 59 additions & 0 deletions package.json
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"
}
}
]
}
}
8 changes: 8 additions & 0 deletions source/index.ts
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';
}
14 changes: 14 additions & 0 deletions source/test.ts
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',
});
});
11 changes: 11 additions & 0 deletions tsconfig.json
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"
}
}

0 comments on commit 1d8e735

Please sign in to comment.