Skip to content

Commit 181819c

Browse files
committed
build: verify reusing npm-template-typescript to support developers better
0 parents  commit 181819c

23 files changed

Lines changed: 8916 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Enforce your MR | commit must follow best-practices: lint -> build -> test
2+
name: Verify-Commit
3+
run-name: Verify PR merge to ${{ github.base_ref }} by @${{ github.actor }}
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
pull_request:
9+
branches:
10+
- main
11+
- 'releases/**'
12+
push:
13+
branches:
14+
- main
15+
- 'releases/**'
16+
17+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
18+
jobs:
19+
# This workflow contains a single job called "verify"
20+
verify:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
# Setup .npmrc file to publish to npm
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 18
28+
- name: Install dependencies
29+
run: npm ci
30+
- name: Verify Lint
31+
run: npm run lint
32+
- name: Build package
33+
run: npm run build
34+
- name: Verify Unit test
35+
run: npm run test

.github/workflows/publish.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Release & Publish
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/tags
6+
tags:
7+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
# Number of commits to fetch. 0 indicates all history for all branches and tags.
17+
fetch-depth: 0
18+
- name: Changelog
19+
uses: Bullrich/generate-release-changelog@master
20+
id: Changelog
21+
env:
22+
REPO: ${{ github.repository }}
23+
- name: Create Release
24+
id: create_release
25+
uses: actions/create-release@latest
26+
env:
27+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ github.ref }}
31+
release_name: Release ${{ github.ref }}
32+
body: |
33+
${{ steps.Changelog.outputs.changelog }}
34+
draft: false
35+
prerelease: false
36+
37+
publish:
38+
strategy:
39+
matrix:
40+
os: [ubuntu-latest]
41+
version: [18]
42+
runs-on: ${{ matrix.os }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
# Setup .npmrc file to publish to npm
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: ${{ matrix.version }}
49+
registry-url: 'https://registry.npmjs.org'
50+
scope: '@make-everything-simple'
51+
env:
52+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
53+
- name: show npm config
54+
run: cat $NPM_CONFIG_USERCONFIG
55+
- name: Install dependencies
56+
run: npm ci
57+
- name: Build package
58+
run: npm run build
59+
- name: Publish package to NPM registry
60+
run: npm publish --access public

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Dependency directory
7+
node_modules
8+
9+
# Optional npm cache directory
10+
.npm
11+
12+
# History of installed package
13+
*.lock
14+
15+
build/
16+
.DS_Store
17+
.nvmrc # this breaks circleci builds
18+
.idea/
19+
.env
20+
.nvmrc
21+
22+
# coverage
23+
artifacts/
24+
.nyc_output
25+
26+
# Ignore test-related files
27+
/coverage.data
28+
/coverage/
29+
30+
# Build files
31+
/dist
32+
33+
# Trunk
34+
.trunk

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run test

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) 2024 Le Ngoc Duy
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: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# verify-npm-template-typescript
2+
3+
Verify reusing the [npm-template-typescript](https://github.com/lengocduy/npm-template-typescript) to supports javascript developers who use npm to publish and share package quicker. Less time to setup utility tools to follow best-practices and more time on the core features of the package.
4+
5+
## Prerequisites
6+
7+
The following tools need to be installed:
8+
9+
- [Git](http://git-scm.com/)
10+
- [Node.js 18+](http://nodejs.org/)
11+
12+
## Capabilities and Frameworks
13+
14+
| Capability | Module |
15+
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16+
| Dependence Framework | [`@tsconfig/node18`](https://www.npmjs.com/package/@tsconfig/node18) extend ts config node18+, [typescript](https://www.npmjs.com/package/typescript) adds optional types to JavaScript that support tools for large-scale JavaScript applications |
17+
| Build Tools | [`tsup`](https://tsup.egoist.dev) Bundle your TypeScript library with no config, powered by esbuild |
18+
| Coding Standard | [eslint](https://eslint.org/) statically analyzes your code to quickly find and fix problems based on opt-in [rules](https://eslint.org/docs/latest/rules/), [prettier](https://prettier.io/docs/en/) an opinionated code formatter to build and enforce a style guide on save, [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to turns off all rules that are unnecessary or might conflict with Prettier. |
19+
| Testing Framework | [Jest](https://jestjs.io/) a delightful JavaScript Testing Framework with a focus on simplicity. |
20+
| Useful Links | [npmtrends](https://npmtrends.com/) Compare package download counts over time, [act](https://nektosact.com/introduction.html) run your GitHub Actions locally, [Actionlint](https://marketplace.visualstudio.com/items?itemName=arahata.linter-actionlint) static checker for GitHub Actions workflow files |
21+
22+
## How to test
23+
24+
```bash
25+
npm test | yarn test
26+
```
27+
28+
## How to check lint
29+
30+
```bash
31+
# check lint's rules
32+
npm run lint | yarn lint
33+
# check lint's rules and try to fix
34+
npm run lint:fix | yarn lint:fix
35+
# format your code
36+
npm run prettier:format | yarn prettier:format
37+
```
38+
39+
## How to use
40+
41+
### Clone the repository
42+
43+
```bash
44+
git clone git@github.com:lengocduy/npm-template-typescript.git
45+
cd npm-template-typescript
46+
npm install | yarn install
47+
```
48+
49+
### Import and use
50+
51+
Check more in [example](./example/README.md)
52+
53+
## Collaboration
54+
55+
1. We use the git rebase strategy to keep tracking meaningful commit message. Help to enable rebase when pull `$ git config --local pull.rebase true`
56+
2. Follow TypeScript Style Guide [Google](https://google.github.io/styleguide/tsguide.html)
57+
3. Follow Best-Practices in coding:
58+
1. [Clean code](https://github.com/labs42io/clean-code-typescript) make team happy
59+
2. [Return early](https://szymonkrajewski.pl/why-should-you-return-early/) make code safer and use resource Efficiency
60+
3. [Truthy & Falsy](https://frontend.turing.edu/lessons/module-1/js-truthy-falsy-expressions.html) make code shorter
61+
4. [SOLID Principles](https://javascript.plainenglish.io/solid-principles-with-type-script-d0f9a0589ec5) make clean code
62+
5. [DRY & KISS](https://dzone.com/articles/software-design-principles-dry-and-kiss) avoid redundancy and make your code as simple as possible
63+
6. Make buildable commit and pull latest code from `main` branch frequently
64+
7. Use readable commit message [karma](http://karma-runner.github.io/6.3/dev/git-commit-msg.html)
65+
66+
```bash
67+
/‾‾‾‾‾‾‾‾
68+
🔔 < Ring! Please use semantic commit messages
69+
\________
70+
71+
72+
<type>(<scope>): ([issue number]) <subject>
73+
│ │ |
74+
| | | └─> subject in present tense. Not capitalized. No period at the end.
75+
| | |
76+
│ │ └─> Issue number (optional): Jira Ticket or Issue number
77+
│ │
78+
│ └─> Scope (optional): eg. Articles, Profile, Core
79+
80+
└─> Type: chore, docs, feat, fix, refactor, style, ci, perf, build, or test.
81+
```

configs/.eslintrc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
tsconfigRootDir: __dirname,
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin', 'import'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js', '**/*.test.ts'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'error',
21+
'@typescript-eslint/explicit-module-boundary-types': 'warn',
22+
'@typescript-eslint/no-explicit-any': 'error',
23+
'@typescript-eslint/no-non-null-assertion': 'error',
24+
'prettier/prettier': [
25+
'error',
26+
{
27+
tabWidth: 4,
28+
},
29+
],
30+
},
31+
};

configs/.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 4,
4+
"semi": true,
5+
"singleQuote": true,
6+
"useTabs": false
7+
}

0 commit comments

Comments
 (0)