-
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 59230a2
Showing
20 changed files
with
11,610 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,33 @@ | ||
'use strict' | ||
|
||
module.exports = function (api) { | ||
const targets = '>1% or node >=10 and not ie 11 and not dead' | ||
api.cache(true) | ||
api.cacheDirectory = true | ||
|
||
return { | ||
presets: [ | ||
'@babel/preset-typescript', | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
corejs: 3, | ||
useBuiltIns: 'entry', | ||
modules: 'commonjs', | ||
bugfixes: true, | ||
targets | ||
} | ||
] | ||
], | ||
plugins: [ | ||
'@babel/plugin-proposal-class-properties', | ||
[ | ||
'@babel/plugin-transform-runtime', | ||
{ | ||
helpers: false, | ||
regenerator: 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,108 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"extends": ["plugin:@typescript-eslint/recommended", "prettier", "plugin:prettier/recommended"], | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
|
||
"plugins": ["jest", "unused-imports", "@typescript-eslint"], | ||
"rules": { | ||
"indent": "off", | ||
"@typescript-eslint/indent": ["error", 2], | ||
"array-bracket-newline": ["error", "consistent"], | ||
"strict": ["error", "safe"], | ||
"block-scoped-var": "error", | ||
"complexity": "warn", | ||
"default-case": "error", | ||
"dot-notation": "warn", | ||
"eqeqeq": "error", | ||
"guard-for-in": "warn", | ||
"linebreak-style": ["warn", "unix"], | ||
"no-alert": "error", | ||
"no-case-declarations": "error", | ||
"no-console": "error", | ||
"no-constant-condition": "error", | ||
"no-continue": "warn", | ||
"no-div-regex": "error", | ||
"no-empty": "warn", | ||
"no-empty-pattern": "error", | ||
"no-implicit-coercion": "error", | ||
"prefer-arrow-callback": "warn", | ||
"no-labels": "error", | ||
"no-loop-func": "error", | ||
"no-nested-ternary": "warn", | ||
"no-script-url": "error", | ||
"no-warning-comments": "warn", | ||
"quote-props": ["error", "as-needed"], | ||
"require-yield": "error", | ||
"max-nested-callbacks": ["error", 4], | ||
"max-depth": ["error", 4], | ||
"space-before-function-paren": [ | ||
"error", | ||
{ | ||
"anonymous": "never", | ||
"named": "never", | ||
"asyncArrow": "always" | ||
} | ||
], | ||
"padding-line-between-statements": [ | ||
"error", | ||
{ "blankLine": "always", "prev": "*", "next": "if" }, | ||
{ "blankLine": "always", "prev": "*", "next": "function" }, | ||
{ "blankLine": "always", "prev": "*", "next": "return" } | ||
], | ||
"no-useless-constructor": "off", | ||
"no-dupe-class-members": "off", | ||
"no-unused-expressions": "off", | ||
"curly": ["error", "multi-line"], | ||
"object-curly-spacing": ["error", "always"], | ||
"comma-dangle": ["error", "always-multiline"], | ||
"@typescript-eslint/no-useless-constructor": "error", | ||
"@typescript-eslint/no-unused-expressions": "error", | ||
"@typescript-eslint/member-delimiter-style": [ | ||
"error", | ||
{ | ||
"multiline": { | ||
"delimiter": "none", | ||
"requireLast": true | ||
}, | ||
"singleline": { | ||
"delimiter": "semi", | ||
"requireLast": false | ||
} | ||
} | ||
], | ||
"@typescript-eslint/ban-ts-comment": [ | ||
"error", | ||
{ | ||
"ts-expect-error": "allow-with-description", | ||
"ts-ignore": "allow-with-description", | ||
"ts-nocheck": "allow-with-description", | ||
"ts-check": "allow-with-description", | ||
"minimumDescriptionLength": 6 | ||
} | ||
], | ||
"require-await": "off", | ||
"@typescript-eslint/promise-function-async": "error", | ||
"@typescript-eslint/require-await": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"unused-imports/no-unused-imports": "error", | ||
"unused-imports/no-unused-vars": [ | ||
"warn", | ||
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" } | ||
] | ||
} | ||
} |
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,19 @@ | ||
name: Publish on npmjs | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm ci | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
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,17 @@ | ||
name: Release Github | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
release-please: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: google-github-actions/release-please-action@v3 | ||
id: release | ||
with: | ||
token: ${{ secrets.REPO_GHA_PAT }} | ||
release-type: node | ||
bump-minor-pre-major: 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,39 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Create .env file | ||
run: | | ||
echo "SOMETHING=" >> .env | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Lint check | ||
run: npm run lint:check | ||
|
||
- name: Check types | ||
run: npm run check:types | ||
|
||
- name: Run tests | ||
run: npm run test |
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,2 @@ | ||
.env | ||
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,13 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true, | ||
"semi": false, | ||
"singleQuote": true, | ||
"quoteProps": "as-needed", | ||
"trailingComma": "all", | ||
"endOfLine": "lf", | ||
"arrowParens": "avoid", | ||
"proseWrap": "always" | ||
} |
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,53 @@ | ||
# MyLibrary: A TypeScript + Jest + Webpack Template for Node.js and Browser Libraries | ||
|
||
Welcome to MyLibrary, a ready-to-use TypeScript template for building libraries that can run in both Node.js and the browser. This project is bundled with Jest for testing and Webpack for building your library. | ||
|
||
## Table of Contents | ||
- [Getting Started](#getting-started) | ||
- [Project Structure](#project-structure) | ||
- [Available Scripts](#available-scripts) | ||
- [GitHub Actions](#github-actions) | ||
- [Customizing the Library](#customizing-the-library) | ||
|
||
## Getting Started | ||
To get started, clone this repository to your local machine and run `npm ci`. | ||
|
||
## Project Structure | ||
Here's a brief overview of the key files and directories in this template: | ||
|
||
- `src/`: The source code of your library. The entry point of the library is `src/index.ts`. | ||
- `test/`: Contains the tests for your library. | ||
- `.github/workflows/`: Contains configuration for GitHub Actions workflows. | ||
- `.babelrc.js`: Configures Babel, a JavaScript compiler. | ||
- `.eslintrc.json`: Configures ESLint, a tool for identifying and reporting on patterns in JavaScript. | ||
- `jest.config.js`: Configures Jest, a JavaScript testing framework. | ||
- `tsconfig.json`: Configures TypeScript for the project. | ||
- `webpack.config.ts`: Configures Webpack for bundling the library. | ||
|
||
## Available Scripts | ||
This template includes the following scripts: | ||
|
||
- `npm run prepublishOnly`: Cleans the `dist` directory and compiles TypeScript files to JavaScript. It also prepares the library for both Node.js and browser environments. | ||
- `npm run test`: Runs the Jest test suite. | ||
- `npm run lint:check`: Lints the codebase using ESLint and checks for formatting issues with Prettier. | ||
- `npm run check:types`: Checks for TypeScript type errors. | ||
- `npm run compile:node`: Compiles the code for Node.js using Webpack. | ||
- `npm run compile:types`: Compiles the TypeScript declarations. | ||
- `npm run compile:browser`: Compiles the code for the browser using Webpack. | ||
|
||
## GitHub Actions | ||
This template includes three GitHub Actions workflows: | ||
|
||
- `tests.yaml`: Runs tests, checks for type errors, and lints the code whenever changes are pushed or a pull request is created. | ||
- `publish_npmjs.yaml`: Publishes the package to npm when a new release is created on GitHub. You'll need to add your npm token to your repository's secrets under the name `NPM_TOKEN`. | ||
- `release_github.yaml`: Creates a new release on GitHub whenever changes are pushed to the `master` branch. For this to work, you'll need to add a personal access token to your repository's secrets under the name `REPO_GHA_PAT`. | ||
|
||
## Customizing the Library | ||
To make this library your own, you'll need to change the following: | ||
|
||
- Update `name`, `version`, `description`, and `author` in `package.json`. | ||
- If you want your library to be available under a different name in the `window` object when used in a browser, update the `library` key in the `output` object in `webpack.config.ts`. For example, if you want your library to be available as `MyNewLib`, you would set `library: 'MyNewLib'`. | ||
- Write your library's code in the `src/` directory. You can organize your code in this directory any way you want. Don't forget to update `src/index.ts` if you add or remove files. | ||
- Write tests for your library's code in the `test/` directory. Jest is configured to read all files in this directory that match the pattern `*.test.ts`. | ||
|
||
This template should give you a strong starting point for building a library that can run in both Node.js and the browser. Happy coding! |
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,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
testTimeout: 500000, | ||
} |
Oops, something went wrong.