Skip to content

Commit

Permalink
feat: node.js template
Browse files Browse the repository at this point in the history
  • Loading branch information
weiran authored and aladdin-add committed Oct 12, 2024
0 parents commit 78fe8bc
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install dependencies
run: npm install
- name: Lint files
run: npm run lint
test:
name: Test
strategy:
matrix:
os: [ubuntu-latest]
node: [22.x, 20.x]
include:
- os: windows-latest
node: "22.x"
- os: macOS-latest
node: "22.x"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules
dist
coverage/
npm-debug.log
.DS_Store
.idea
*.iml
.cache
.sublimelinterrc
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm run prettier
npm run lint
npm run test
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# set to true if you are developing an app.
package-lock=false
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2018 薛定谔的猫

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.
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import globals from "globals";
import pluginN from 'eslint-plugin-n'
import pluginJs from "@eslint/js";

export default [
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...pluginN.configs["flat/mixed-esm-and-cjs"],
];
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

export function add(a, b) {
return a + b;
}
11 changes: 11 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

import { strict as assert } from "node:assert";
import { describe, it } from "node:test";
import { add } from "./index.js";

describe("add", () => {
it("1 + 1 === 2", () => {
assert.equal(add(1, 1), 2);
});
});
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@weiran.zsd/js-starter",
"version": "0.0.0",
"private": true,
"description": "A full featured node.js starter.",
"keywords": [
"node.js",
"node",
"esm"
],
"license": "MIT",
"author": "唯然<[email protected]",
"type": "module",
"exports": "./lib/index.js",
"files": [
"LICENSE",
"README.md",
"lib",
"!**/*.test.{js,ts}"
],
"scripts": {
"lint": "eslint .",
"prepare": "husky",
"prettier": "prettier -w lib",
"release": "npm test && standard-version",
"test": "node --test",
"test:watch": "node --test --watch",
"test:coverage": "node --test --experimental-test-coverage"
},
"devDependencies": {
"@eslint/js": "^9.12.0",
"eslint": "^9.12.0",
"eslint-plugin-n": "^17.11.1",
"globals": "^15.11.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"standard-version": "^9.3.0"
},
"engines": {
"node": ">=20"
}
}
31 changes: 31 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Node.js starter

## Usage

```sh
$ npx degit weiran.zsd/node-starter
```

```sh
# run linting
$ npm run lint [-- --fix]

# run test
$ npm test

# watching test
$ npm run test:watch

# release
$ npm run release
```

## Features

- Node.js esm
- prettier
- eslint + eslint-plugin-node
- pre-commit with husky
- release with standard-version
- testing with jest
- gh actions

0 comments on commit 78fe8bc

Please sign in to comment.