Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Nov 14, 2023
0 parents commit 0a3a069
Show file tree
Hide file tree
Showing 16 changed files with 294 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
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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):"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "saturday"
time: "02:42" # UTC
commit-message:
prefix: "ci(actions):"
59 changes: 59 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deno

on:
push:
pull_request:
schedule:
# Check if it works with current versions
- cron: '42 2 * * 6' # weekly on Saturday 2:42 UTC

jobs:
denofmt-and-lint:
runs-on: ubuntu-latest
steps:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- uses: actions/checkout@v4

- run: deno lint
- run: deno fmt --check

test:
runs-on: ubuntu-latest
steps:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- uses: actions/checkout@v4

- run: deno cache source/*.ts
- run: deno check source/*.ts
- run: deno test

npm:
name: Node.js Package
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm pack
- run: npm publish
if: startsWith(github.ref, 'refs/tags/v')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_ACCESS: public
NPM_CONFIG_PROVENANCE: true
- name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/v')
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 @@
.vscode
/*-*.*.*.tgz
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) EdJoPaTo <deno-node-module-template-typescript-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.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# deno-node-module-template

[![NPM Version](https://img.shields.io/npm/v/deno-node-module-template.svg)](https://www.npmjs.com/package/deno-node-module-template)
[![node](https://img.shields.io/node/v/deno-node-module-template.svg)](https://www.npmjs.com/package/deno-node-module-template)
[![deno module](https://shield.deno.dev/x/deno_node_module_template)](https://deno.land/x/deno_node_module_template)

## Install

Node.js:

```bash
npm install deno-node-module-template
```

Deno:

```ts
import {/* ... */} from "https://deno.land/x/deno_node_module_template/mod.ts";
```

## Usage

```ts
import { myFunction } from "deno-node-module-template";

myFunction("unicorns");
//=> 'unicorns & rainbows'
```
29 changes: 29 additions & 0 deletions copy-template-into-existing-project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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/deno-node-module-template/copy-template-into-existing-project.sh

name=$(basename "$PWD")
denoname="${name/-/_}"
templatedir="$(dirname "$0")"

cp -r \
"$templatedir/"{deno.jsonc,package.json,tsconfig.json,.editorconfig,.gitattributes,.github,.gitignore,.npmrc} \
.
cp -r \
"$templatedir/source/"{deps.test.ts,README.md} \
./source/

echo "everything copied"

# Replace template name with folder name
# macOS: add '' after -i like this: sed -i '' "s/…
sed -i "s/deno-node-module-template/$name/g" package.json LICENSE ./**/*.md .github/**/*.yml
sed -i "s/deno_node_module_template/$denoname/g" ./**/*.md

git checkout -p .gitignore
git --no-pager status --short
39 changes: 39 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
// https://deno.land/manual/getting_started/configuration_file
"lock": false,
// https://deno.land/manual/advanced/typescript/configuration
// https://www.typescriptlang.org/tsconfig/
"compilerOptions": {
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"useUnknownInCatchVariables": true
},
"fmt": {
"useTabs": true
},
"lint": {
"rules": {
// https://lint.deno.land/?all=on
"include": [
"camelcase",
"default-param-last",
"eqeqeq",
"explicit-module-boundary-types",
"no-await-in-loop",
"no-eval",
"no-non-null-asserted-optional-chain",
"no-non-null-assertion",
"no-sparse-arrays"
]
}
},
"exclude": [
"./dist/",
"./node_modules/"
]
}
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "deno-node-module-template",
"version": "0.1.0",
"description": "",
"keywords": [
""
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/EdJoPaTo/deno-node-module-template.git"
},
"author": {
"name": "EdJoPaTo",
"email": "deno-node-module-template-typescript-package@edjopato.de",
"url": "https://edjopato.de"
},
"scripts": {
"prepare": "deno2node",
"test": "echo use deno test && exit 1"
},
"type": "module",
"engines": {
"node": ">=14"
},
"dependencies": {},
"devDependencies": {
"deno2node": "1.10.1"
},
"files": ["dist"],
"main": "./dist/mod.js",
"types": "./dist/mod.d.ts"
}
5 changes: 5 additions & 0 deletions source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# deno_node_module_template

See the
[README on GitHub](https://github.com/EdJoPaTo/deno-node-module-template#readme)
for more information on this package.
2 changes: 2 additions & 0 deletions source/deps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { assertEquals } from "https://deno.land/std@0.206.0/assert/assert_equals.ts";
export { assertThrows } from "https://deno.land/std@0.206.0/assert/assert_throws.ts";
17 changes: 17 additions & 0 deletions source/mod.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { assertEquals, assertThrows } from "./deps.test.ts";
import { moduleName } from "./mod.ts";

Deno.test("simple string input", () => {
assertEquals(moduleName("unicorns"), "unicorns & rainbows");
});

Deno.test("javascript users without typings get error on number", () => {
assertThrows(
() => {
// @ts-expect-error moduleName expects a string not a number
moduleName(123);
},
TypeError,
"Expected a string, got number",
);
});
8 changes: 8 additions & 0 deletions source/mod.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 tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"include": [
"source"
],
"exclude": [
"**/*.test.*",
"**/test.*"
],
"compilerOptions": {
"declaration": true,
"target": "ES2020", // Node.js 14
"outDir": "dist"
}
}

0 comments on commit 0a3a069

Please sign in to comment.