Skip to content

Commit 40243ad

Browse files
authored
Initial commit
0 parents  commit 40243ad

9 files changed

Lines changed: 407 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Build and Deploy
2+
3+
on:
4+
create:
5+
push:
6+
branches:
7+
- master
8+
- main
9+
- develop
10+
- dev
11+
- feature/*
12+
- feat/*
13+
- release/*
14+
- hotfix/*
15+
paths:
16+
- '**.js'
17+
- '**.jsx'
18+
- '**.ts'
19+
- '**.tsx'
20+
- '**.json'
21+
release:
22+
types: [published]
23+
24+
jobs:
25+
setup:
26+
if: github.run_number == 1 && github.event_name == 'create'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Initialize
32+
run: |
33+
tmp=$(mktemp)
34+
jq --arg author "${{ github.repository_owner }}" '.author = $author' package.json > $tmp
35+
jq --arg url "git+${{ github.event.repository.clone_url }}" '.repository.url = $url' $tmp > package.json
36+
jq --arg name "${{ github.event.repository.name }}" '.name = $name' package.json > $tmp
37+
jq --arg description "${{ github.event.description }}" '.description = $description' $tmp > package.json
38+
jq --arg homepage "${{ github.event.repository.html_url }}#readme" '.homepage = $homepage' package.json > $tmp
39+
jq --arg bugs "${{ github.event.repository.html_url }}/issues" '.bugs.url = $bugs' $tmp > package.json
40+
echo "# ${{ github.event.repository.name }}" > README.md
41+
rm -rf LICENSE
42+
43+
- uses: stefanzweifel/git-auto-commit-action@v4
44+
with:
45+
commit_message: "Setup project for ${{ github.event.repository.name }} [skip ci]"
46+
47+
ci:
48+
if: github.run_number != 1 && github.event_name != 'create' && !contains(github.event.head_commit.message, '[skip ci]')
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
53+
# extract `engines.node` from package.json and save it to output
54+
- name: Get Node.JS version from package.json
55+
id: get-versions
56+
run: |
57+
echo node=$(jq -r '.engines.node // "lts/*"' ./package.json) >> $GITHUB_OUTPUT
58+
echo pkg=$(jq -r '(.engines | select(.pnpm != null) | "pnpm") // (.engines | select(.yarn != null) | "yarn") // "npm"' ./package.json) >> $GITHUB_OUTPUT
59+
60+
- name: Setup Node.JS
61+
uses: actions/setup-node@v3
62+
with:
63+
node-version: ${{steps.get-versions.outputs.node}}
64+
65+
- name: Setup pnpm
66+
if: steps.get-versions.outputs.pkg == 'pnpm'
67+
uses: pnpm/action-setup@v2
68+
with:
69+
version: latest
70+
71+
- name: Install dependencies
72+
run: ${{steps.get-versions.outputs.pkg}} install
73+
74+
- name: Test
75+
run: ${{steps.get-versions.outputs.pkg}} run test
76+
77+
- name: Build
78+
id: build
79+
env:
80+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
81+
if: github.event_name == 'release' && env.NPM_TOKEN != null
82+
run: |
83+
${{steps.get-versions.outputs.pkg}} run build
84+
tmp=$(mktemp)
85+
jq --arg version "${{ github.event.release.tag_name }}" '.version = $version' package.json > $tmp
86+
mv $tmp package.json
87+
echo version=$(jq -r '.version' package.json) >> $GITHUB_OUTPUT
88+
89+
- name: Publish
90+
uses: JS-DevTools/npm-publish@v1
91+
if: steps.build.outputs.version != null
92+
with:
93+
token: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# Build files
107+
lib/

.mocharc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extension: ['ts', 'tsx'] # add tsx if you use react
2+
spec: 'src/**/*.spec.ts'
3+
require: 'ts-node/register'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 joyqi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# TypeScript Module Template
2+
3+
This is a template for creating a npm module written in TypeScript.
4+
5+
## Usage
6+
7+
Just click the "Use this template" button and create a new repository.
8+
9+
## Initialization
10+
11+
1. Change these lines in `package.json`:
12+
```json
13+
{
14+
"keywords": ["your", "keywords", "<"],
15+
"description": "Your module description here <",
16+
"license": "Your license here <",
17+
```
18+
2. Change the `README.md` file to your needs.
19+
3. Add LICENSE file if you want to.
20+
21+
## `engines` field in `package.json`
22+
23+
### `node`
24+
25+
You can specify a node version in this field. We'll use this version to set up the CI environment.
26+
27+
### `npm` / `yarn` / `pnpm`
28+
29+
You can specify a package manager in this field. We'll use this package manager to install dependencies.
30+
31+
## Project Structure
32+
33+
Just like a normal TypeScript project, but with a `src` folder.
34+
We use [mocha](https://mochajs.org/) for testing, all test files should be ended with `.spec.ts`.
35+
36+
```
37+
src/
38+
index.ts
39+
your-module.ts
40+
your-module.spec.ts
41+
```
42+
43+
## Publishing to npm
44+
45+
Generate a new npm token and add it to the repository secrets as `NPM_TOKEN`. Then, create a new release and the CI will automatically publish the package to npm.

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "typescript-module-template",
3+
"keywords": [],
4+
"author": "",
5+
"license": "",
6+
"description": "",
7+
"repository": {
8+
"type": "git",
9+
"url": ""
10+
},
11+
"homepage": "",
12+
"bugs": {
13+
"url": ""
14+
},
15+
16+
"version": "0.0.1",
17+
18+
"main": "lib/index.js",
19+
"module": "lib/index.js",
20+
"types": "lib/index.d.ts",
21+
"scripts": {
22+
"build": "npx tsc",
23+
"test": "npx mocha"
24+
},
25+
"devDependencies": {
26+
"@types/mocha": "latest",
27+
"assert": "latest",
28+
"mocha": "latest",
29+
"ts-node": "latest",
30+
"typescript": "latest"
31+
}
32+
}

src/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO: add tests

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO: export your library

0 commit comments

Comments
 (0)