generated from threeal/nodejs-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6bf37a
Showing
16 changed files
with
5,157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yarn.lock -diff linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: daily | ||
commit-message: | ||
prefix: chore | ||
labels: [chore] | ||
|
||
- package-ecosystem: npm | ||
directory: / | ||
schedule: | ||
interval: daily | ||
commit-message: | ||
prefix: chore | ||
labels: [chore] | ||
versioning-strategy: increase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Build | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
jobs: | ||
build-library: | ||
name: Build Library | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout Project | ||
uses: actions/[email protected] | ||
|
||
- name: Setup Node.js | ||
uses: actions/[email protected] | ||
with: | ||
node-version-file: .nvmrc | ||
|
||
- name: Setup Yarn | ||
uses: threeal/[email protected] | ||
|
||
- name: Check Formatting | ||
run: | | ||
yarn format | ||
git diff --exit-code HEAD | ||
- name: Check Lint | ||
run: yarn lint | ||
|
||
- name: Test Library | ||
run: yarn test | ||
|
||
- name: Package Library | ||
run: yarn pack | ||
|
||
- name: Upload Package | ||
uses: actions/[email protected] | ||
with: | ||
path: package.tgz | ||
if-no-files-found: error | ||
overwrite: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.* | ||
!.git* | ||
!.nvmrc | ||
|
||
dist/ | ||
node_modules/ | ||
|
||
package.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v23.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
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 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. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Node.js Starter | ||
|
||
A minimalistic template for starting a new [Node.js](https://nodejs.org/en) project. | ||
|
||
This template provides a basic Node.js project containing a sample library written in [TypeScript](https://www.typescriptlang.org/), with support for formatting, linting, testing, and continuous integration. | ||
|
||
## Key Features | ||
|
||
- Minimal Node.js project written in TypeScript with [ESM](https://nodejs.org/api/esm.html) support. | ||
- Uses [Yarn](https://yarnpkg.com/) as the package manager, with [Plug'n'Play](https://yarnpkg.com/features/pnp) support. | ||
- Supports formatting with [Prettier](https://prettier.io/), linting with [ESLint](https://eslint.org/), and testing with [Jest](https://jestjs.io/). | ||
- Preconfigured workflows for [Dependabot](https://docs.github.com/en/code-security/dependabot) and [GitHub Actions](https://github.com/features/actions). | ||
|
||
## Usage | ||
|
||
This guide explains how to use this template to start a new Node.js project, from creation to release. | ||
|
||
### Create a New Project | ||
|
||
Follow [this link](https://github.com/new?template_name=nodejs-starter&template_owner=threeal) to create a new project based on this template. For more information about creating a repository from a template on GitHub, refer to [this documentation](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). | ||
|
||
Alternatively, you can also clone this repository locally to begin using this template. | ||
|
||
### Choose a License | ||
|
||
By default, this template is [unlicensed](https://unlicense.org/). Before modifying this template, it is recommended to replace the [`LICENSE`](./LICENSE) file with the license that will be used by the new project. For more information about licensing a repository, refer to [this documentation](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository). | ||
|
||
Alternatively, you can remove the `LICENSE` file or leave it as is to keep the new project unlicensed. | ||
|
||
### Update Project Information | ||
|
||
To replace the sample information in this template with your new project information, complete the following steps: | ||
|
||
- Replace the content of this [`README.md`](./README.md) file with a description of the new project. For more information on adding READMEs to a project, refer to [this documentation](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes). | ||
- Update project information in the [`package.json`](./package.json) file. For more details on the `package.json` schema, refer to [this documentation](https://docs.npmjs.com/cli/v10/configuring-npm/package-json). | ||
|
||
### Set Up Tools | ||
|
||
It is recommended to use [nvm](https://github.com/nvm-sh/nvm) to manage the Node.js version in the project. By default, this template uses the Node.js version specified in the [`.nvmrc`](./.nvmrc) file. Use the following command to install and use the correct Node.js version with nvm: | ||
|
||
```sh | ||
nvm install | ||
``` | ||
|
||
This template uses [Yarn](https://yarnpkg.com/) with [Plug'n'Play](https://yarnpkg.com/features/pnp) support as the package manager. If Yarn is not yet enabled, run the following command: | ||
|
||
```sh | ||
corepack enable yarn | ||
``` | ||
|
||
Then, install the project dependencies with: | ||
|
||
```sh | ||
yarn install | ||
``` | ||
|
||
For more information on Yarn, such as adding dependencies or running tools, refer to [this documentation](https://yarnpkg.com/getting-started). | ||
|
||
### Developing the Library | ||
|
||
This template provides two components: the library itself ([`src/index.ts`](./src/index.ts)) and an executable entry point ([`src/bin.ts`](./src/bin.ts)). Write code according to your project requirements. If you're new to [TypeScript](https://www.typescriptlang.org/), refer to [this documentation](https://www.typescriptlang.org/docs/) for guidance. | ||
|
||
If your project doesn’t need an executable, you can remove `src/bin.ts` and the `bin` entry from the [`package.json`](./package.json) file. | ||
|
||
Once the code is written, format it with: | ||
|
||
```sh | ||
yarn format | ||
``` | ||
|
||
Then, check linting with: | ||
|
||
```sh | ||
yarn lint | ||
``` | ||
|
||
To ensure the source code compiles correctly, use: | ||
|
||
```sh | ||
yarn build | ||
``` | ||
|
||
### Testing the Library | ||
|
||
Test files in this template are named `*.test.ts` and typically correspond to the source files being tested. This template uses [Jest](https://jestjs.io/) as the testing framework. For more information on testing with Jest, refer to [this documentation](https://jestjs.io/docs/getting-started). | ||
|
||
After creating your test files, run tests with: | ||
|
||
```sh | ||
yarn test | ||
``` | ||
|
||
### Release the Library | ||
|
||
When the project is complete, package the library by running: | ||
|
||
```sh | ||
yarn pack | ||
``` | ||
|
||
This will create a `package.tgz` file, which can be included in the release. Ensure the project is at the correct version and has been pushed to the upstream repository. For more information on releasing a project, refer to [this documentation](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import eslint from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default [ | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
...tseslint.configs.stylistic, | ||
{ | ||
ignores: [".*", "dist"], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"collectCoverage": true, | ||
"coverageReporters": ["text"], | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
} | ||
}, | ||
"moduleNameMapper": { | ||
"^(\\.{1,2}/.*)\\.js$": "$1" | ||
}, | ||
"preset": "ts-jest/presets/default-esm", | ||
"transform": { | ||
"^.+\\.ts$": ["ts-jest", { "useESM": true }] | ||
}, | ||
"verbose": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "my_fibonacci", | ||
"version": "0.0.0", | ||
"description": "A sample Node.js project", | ||
"keywords": [ | ||
"sample", | ||
"fibonacci" | ||
], | ||
"homepage": "https://github.com/threeal/nodejs-starter#readme", | ||
"bugs": { | ||
"url": "https://github.com/threeal/nodejs-starter/issues", | ||
"email": "[email protected]" | ||
}, | ||
"repository": "github:threeal/nodejs-starter", | ||
"license": "Unlicense", | ||
"author": "Alfi Maulana <[email protected]>", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"bin": "dist/bin.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"format": "prettier --write --cache .", | ||
"lint": "eslint", | ||
"prepack": "tsc", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.14.0", | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.9.0", | ||
"@types/yargs": "^17.0.33", | ||
"eslint": "^9.14.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.3.3", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.6.3", | ||
"typescript-eslint": "^8.13.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env node | ||
|
||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import { fibonacciSequence } from "./sequence.js"; | ||
|
||
yargs(hideBin(process.argv)) | ||
.scriptName("my_fibonacci") | ||
.version("0.0.0") | ||
.command( | ||
"$0 <n>", | ||
"Generate a Fibonacci sequence up to the given number of terms.", | ||
(yargs) => | ||
yargs.positional("n", { | ||
demandOption: true, | ||
describe: "The number of terms", | ||
type: "number", | ||
}), | ||
(argv) => { | ||
process.stdout.write(fibonacciSequence(argv.n).join(" ") + "\n"); | ||
}, | ||
) | ||
.parse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { fibonacciSequence } from "./sequence.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { fibonacciSequence } from "./sequence.js"; | ||
|
||
it("should generate a fibonacci sequence", () => { | ||
expect(fibonacciSequence(1)).toStrictEqual([1]); | ||
expect(fibonacciSequence(2)).toStrictEqual([1, 1]); | ||
expect(fibonacciSequence(5)).toStrictEqual([1, 1, 2, 3, 5]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Generate a Fibonacci sequence up to the given number of terms. | ||
* | ||
* @param n - The number of terms. | ||
* @returns A Fibonacci sequence. | ||
*/ | ||
export function fibonacciSequence(n: number): number[] { | ||
const sequence = [0, 1]; | ||
for (let i = 1; i < n; ++i) { | ||
sequence.push(sequence[i - 1] + sequence[i]); | ||
} | ||
return sequence.slice(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"include": ["src"], | ||
"exclude": ["**/*.test.*"], | ||
"compilerOptions": { | ||
"exactOptionalPropertyTypes": true, | ||
"strict": true, | ||
"module": "node16", | ||
"declaration": true, | ||
"outDir": "dist", | ||
"esModuleInterop": true, | ||
"target": "es2022", | ||
"skipLibCheck": true | ||
} | ||
} |
Oops, something went wrong.