Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
theurgi committed Apr 11, 2023
0 parents commit f10866f
Show file tree
Hide file tree
Showing 22 changed files with 5,337 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
.turbo
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"schema": "https://json.schemastore.org/prettierrc",
"printWidth": 80,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": true,
"overrides": [
{
"files": "*.{md,yaml,yml}",
"options": {
"useTabs": false
}
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",

"eslint.validate": [
"javascript",
"json",
"json5",
"jsonc",
"typescript",
]
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# templates

This monorepo contains a collection of templates for various languages and frameworks. Each template is designed to help you kickstart your projects with a modern development environment and best practices already set up.

## Available templates

- [node-typescript](./packages/node-typescript/) - A Node.js TypeScript template with essential tools and configurations.

## Installation

To create a new project using one of these templates, you can use degit to copy the repository without the Git history:

First, make sure you have degit installed globally:

```bash
pnpm install -g degit
```

Next, run the following command, replacing <TEMPLATE_NAME> with the name of the desired template, and <YOUR_PROJECT_NAME> with your desired project name:

```bash
degit theurgi/templates/packages/<TEMPLATE_NAME> <YOUR_PROJECT_NAME>
cd <YOUR_PROJECT_NAME>
```
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "templates",
"version": "0.0.0",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "turbo run format"
},
"devDependencies": {
"@theurgi/eslint-config": "^1.9.0",
"@types/node": "^18.15.11",
"eslint": "^8.38.0",
"prettier": "latest",
"turbo": "latest",
"typescript": "^5.0.4"
},
"packageManager": "pnpm@7.30.0",
"eslintConfig": {
"extends": "@theurgi/eslint-config"
}
}
48 changes: 48 additions & 0 deletions packages/node-typescript/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish
on:
push:
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Test
run: pnpm test

- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm dlx semantic-release --branches main
40 changes: 40 additions & 0 deletions packages/node-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# build output
dist
packages/*/packed-*.tgz

# cache
.cache
.swc/
.turbo
*.tsbuildinfo

# coverage
.nyc_output
coverage

# dependencies
.pnpm-store/
node_modules
package-lock.json
yarn.lock

# environment variables
*.env

# logs & pids
*.log
*.log
logs
npm-debug.log*
pids
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*

# runtime data
*.pid
*.seed
pids

# test output
.DS_Store
4 changes: 4 additions & 0 deletions packages/node-typescript/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
4 changes: 4 additions & 0 deletions packages/node-typescript/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm lint-staged
16 changes: 16 additions & 0 deletions packages/node-typescript/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"schema": "https://json.schemastore.org/prettierrc",
"printWidth": 80,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": true,
"overrides": [
{
"files": "*.{md,yaml,yml}",
"options": {
"useTabs": false
}
}
]
}
11 changes: 11 additions & 0 deletions packages/node-typescript/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",

"eslint.validate": [
"javascript",
"json",
"json5",
"jsonc",
"typescript",
]
}
21 changes: 21 additions & 0 deletions packages/node-typescript/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 <your-name>

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.
81 changes: 81 additions & 0 deletions packages/node-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# node-typescript

A Node.js TypeScript template that includes configurations and tools for a modern development environment. The template is set up with:

- TypeScript
- ESLint
- Prettier
- Vitest
- Husky
- lint-staged
- commitlint
- Conventional Commits
- tsup
- dotenv

Additionally, it includes a GitHub Actions workflow for publishing with semantic-release.

## Installation

To create a new project using this template, you can use [degit](https://github.com/Rich-Harris/degit) to copy the repository without the Git history:

First, make sure you have degit installed globally:

```bash
pnpm install -g degit
```

Next, run the following command, replacing <YOUR_PROJECT_NAME> with your desired project name:

```bash
degit theurgi/templates/packages/node-typescript <YOUR_PROJECT_NAME>
cd <YOUR_PROJECT_NAME>
```

## Set up

After you've installed the template, you need to install the dependencies:

```bash
pnpm install
```

Once you've installed the dependencies, run the following command to set up Husky:

```bash
pnpm run prepare
```

## Post-Installation Checklist

After installing the template, make sure to complete the following tasks to personalize and configure your project:

1. Update the `package.json` fields:

- [ ] `name`: Set this to your project name.
- [ ] `description`: Add a brief description of your project.
- [ ] `repository`: Update the repository URL to match your own project's repository.
- [ ] `author`: Add your name or your organization's name.
- [ ] `license`: Update the license field if needed.

2. Update the `LICENSE` file:

- [ ] Replace the placeholder name and year with your own name (or organization name) and the current year.

3. Set up environment variables:

- [ ] Update the `.env` file with any environment-specific values your project requires.

4. Set up a publishing workflow:

- [ ] Configure the `publish.yml` GitHub Actions workflow with the necessary secrets and settings for your project.

## Usage

Here are some useful scripts included in the template:

- `build`: Build the TypeScript project using tsup.
- `format`: Format the code using Prettier.
- `lint`: Lint the code using ESLint.
- `test`: Run the tests using Vitest.
- `type-check`: Type-check the code using TypeScript.
55 changes: 55 additions & 0 deletions packages/node-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "",
"version": "0.0.0-semantic-release",
"description": "",
"keywords": [],
"license": "MIT",
"repository": "",
"author": "",
"type": "module",
"files": [
"dist"
],
"main": "dist/main.js",
"module": "dist/main.js",
"types": "dist/main.d.ts",
"scripts": {
"build": "tsup",
"format": "prettier --ignore-path .gitignore --write '**/*.{js,json,md,ts}'",
"lint": "eslint --cache --fix --ignore-path .gitignore .",
"prepack": "pnpm build && clean-pkg-json",
"prepare": "husky install",
"test": "vitest",
"type-check": "tsc"
},
"engines": {
"node": ">=16.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@theurgi/eslint-config": "^1.9.0",
"@types/node": "^18.15.11",
"clean-pkg-json": "^1.2.0",
"dotenv": "^16.0.3",
"eslint": "^8.38.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.1",
"prettier": "^2.8.7",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"vitest": "^0.30.0"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"eslintConfig": {
"extends": "@theurgi/eslint-config/node"
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
"*.{js,json,md,ts}": "prettier --write"
}
}
14 changes: 14 additions & 0 deletions packages/node-typescript/src/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect } from 'vitest'

import { greet } from './main'

test('greet function returns the correct greeting', () => {
const name = 'John'
const result = greet(name)
expect(result).toBe(`Hello, ${name}!`)
})

test('greet function returns the default greeting when no name is provided', () => {
const result = greet('')
expect(result).toBe('Hello, !')
})
3 changes: 3 additions & 0 deletions packages/node-typescript/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function greet(name: string): string {
return `Hello, ${name}!`
}

0 comments on commit f10866f

Please sign in to comment.