All Projects → tomchen → example-typescript-package

tomchen / example-typescript-package

Licence: MIT license
Example TypeScript Package ready to be published on npm & Tutorial / Instruction / Workflow for 2021

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to example-typescript-package

botfuel-sample-starter
Starter bot using Botfuel Dialog
Stars: ✭ 24 (-66.2%)
Mutual labels:  starter-template, starter, starter-kit
node-boilerplate
Node Typescript Boilerplate for Microservices. Skeleton for Node.js Apps written in TypeScript (with Setup Instructions for ESLint, Prettier, and Husky)
Stars: ✭ 92 (+29.58%)
Mutual labels:  starter-template, starter-kit, typescript-boilerplate
noise-php
A starter-kit for your PHP project.
Stars: ✭ 52 (-26.76%)
Mutual labels:  starter-template, starter, starter-kit
Laravel Starter
A CMS like modular starter application project built with Laravel 8.x.
Stars: ✭ 299 (+321.13%)
Mutual labels:  starter-template, starter, starter-kit
Wordpress Starter
📦 A starter template for WordPress websites
Stars: ✭ 26 (-63.38%)
Mutual labels:  starter-template, starter, starter-kit
Next Js Blog Boilerplate
🚀 Nextjs Blog Boilerplate is starter code for your blog based on Next framework. ⚡️ Made with Nextjs, TypeScript, ESLint, Prettier, PostCSS, Tailwind CSS.
Stars: ✭ 134 (+88.73%)
Mutual labels:  starter-template, starter, starter-kit
SampleProject
A starter project for Sample Project in Objective C. Objective C version of https://github.com/xeieshan/SwiftySampleProject
Stars: ✭ 31 (-56.34%)
Mutual labels:  starter-template, starter, starter-kit
Pug Starter
Simple pug (jade) starter [framework] enabling faster delivery of HTML & CSS projects to a private server and/or automatic deployment of GitHub pages.
Stars: ✭ 328 (+361.97%)
Mutual labels:  starter-template, starter, starter-kit
Hartija Css Print Framework
Universal CSS for web printing
Stars: ✭ 509 (+616.9%)
Mutual labels:  starter-template, starter, starter-kit
Niklick
Rails Versioned API solution template for hipsters! (Ruby, Ruby on Rails, REST API, GraphQL, Docker, RSpec, Devise, Postgress DB)
Stars: ✭ 39 (-45.07%)
Mutual labels:  starter-template, starter, starter-kit
sass-starter-pack
Sass starter files using Gulp v4.0.0 🔥
Stars: ✭ 34 (-52.11%)
Mutual labels:  starter-template, starter, starter-kit
saas-react-starter-kit-boilerplate
SaaStr is a React SaaS boilerplate to kickstart your new SaaS adventure as fast as possible. Built on top of Adonis JS for the BackEnd and React Starter Kit for the Front-End
Stars: ✭ 100 (+40.85%)
Mutual labels:  starter-template, starter-kit
materializecss starter
A Starter Boilerplate for Materializecss, ionicons, font-awesome and Animatecss
Stars: ✭ 58 (-18.31%)
Mutual labels:  starter-template, starter-kit
angular-starter
🚀 Angular 14 Starter with Storybook, Transloco, Jest, TestCafe, Docker, ESLint, Material & Prettier 🚀
Stars: ✭ 124 (+74.65%)
Mutual labels:  starter, starter-kit
nest-typescript-starter
Nest framework TypeScript starter (node.js)
Stars: ✭ 35 (-50.7%)
Mutual labels:  starter, starter-kit
three-typescript-starter
Three.js + Typescript + Webpack Boilerplate
Stars: ✭ 105 (+47.89%)
Mutual labels:  starter, starter-kit
Dash-UI
Bootstrap 5 Admin & Dashboard Template - Dash-UI. Dash UI Kit is a free and open-source components and templates kit fully coded with Bootstrap 5.
Stars: ✭ 213 (+200%)
Mutual labels:  starter-template, starter-kit
starter-reactnative-nestjs-mysql
Starter mobile ReactNative NestJS MySQL with continuous integration and AWS deployment
Stars: ✭ 16 (-77.46%)
Mutual labels:  starter, starter-kit
angular-open-source-starter
This is a starter project for creating open-source libraries for Angular. It is a full fledged Angular workspace with demo application and easy library addition. It is designed to be used for open-sourcing libraries on Github and has everything you'd need ready for CI, code coverage, SSR testing, StackBlitz demo deployment and more.
Stars: ✭ 212 (+198.59%)
Mutual labels:  starter-template, starter
react-typescript-material-ui-with-auth-starter
React + Material UI + Auth starter using TypeScript
Stars: ✭ 27 (-61.97%)
Mutual labels:  starter-template, starter

Example TypeScript Package ready to be published on npm for 2021

This is an example TypeScript Package ready to be published on npm. It has been set up with automated tests and package publishing workflow using GitHub Actions CI/CD. It is made primarily for GitHub + VS Code (Windows / Mac / Linux) users who are about to write and publish their first TypeScript npm package. This package could serve as a starter / boilerplate / demo for them.

npm package version number Actions Status License

It uses npm, TypeScript compiler, Jest, webpack, ESLint, Prettier, husky, pinst, commitlint. The production files include CommonJS, ES Modules, UMD version and TypeScript declaration files.

Github Visual Studio Code Windows Mac OS Linux npm Typescript Jest webpack ESLint Prettier yarn

Development

Use as a template

Use the template

(Click the above button to use this example package as a template for your new GitHub repo, this will initialize a new repository and my commits will not be in your git history)

(If you do not use GitHub, you can download the archive of the example package)

Set up tools and environment

You need to have Node.js installed. Node includes npm as its default package manager.

Open the whole package folder with a good code editor, preferably Visual Studio Code. Consider installing VS Code extensions ES Lint and Prettier.

In the VS Code top menu: Terminal -> New Terminal

Install dependencies

Install dependencies with npm:

npm i

Write your code

Make necessary changes in package.json (name, version, description, keywords, author, homepage and other URLs).

Write your code in src folder, and unit test in test folder, replacing the original files there.

The VS Code shortcuts for formatting of a code file are: Shift + Alt + F (Windows); Shift + Option (Alt) + F (MacOS); Ctrl + Shift + I (Linux).

Change code linting and formatting settings in .prettierrc.js if you want.

Test

Test your code with Jest framework:

npm run test

Note: Example TypeScript Package uses husky, pinst and commitlint to automatically execute test and lint commit message before every commit.

Build

Build production (distribution) files in your dist folder:

npm run build

It generates CommonJS (in dist/cjs folder), ES Modules (in dist/esm folder), bundled and minified UMD (in dist/umd folder), as well as TypeScript declaration files (in dist/types folder).

Try it before publishing

Run:

npm link

npm link will create a symlink in the global folder, which may be {prefix}/lib/node_modules/example-typescript-package or C:\Users<username>\AppData\Roaming\npm\node_modules\example-typescript-package.

Create an empty folder elsewhere, you don't even need to npm init (to generate package.json). Open the folder with VS Code, open a terminal and just run:

npm link example-typescript-package

This will create a symbolic link from globally-installed example-typescript-package to node_modules/ of the current folder.

You can then create a, for example, testnum.ts file with the content:

import { Num } from 'example-typescript-package'
console.log(new Num(5).add(new Num(6)).val() === 11)

If you don't see any linting errors in VS Code, if you put your mouse cursor over Num and see its type, then it's all good.

Whenever you want to uninstall the globally-installed example-typescript-package and remove the symlink in the global folder, run:

npm uninstall example-typescript-package -g

Prepare to publish

Create an npm account.

Click to read this section if you do manual publishing

Manual publishing to npm

Log in:

npm adduser

And publish:

npm publish

This package is configured to use GitHub Actions CI/CD to automate both the npm and GitHub Packages publishing process. The following are what you have to do.

CI publishing to npm

Follow npm's official instruction to create an npm token. Choose "Publish" from the website, or use npm token create without argument with the CLI.

If you use 2FA, then make sure it's enabled for authorization only instead of authorization and publishing (Edit Profile -> Modify 2FA).

On the page of your newly created or existing GitHub repo, click Settings -> Secrets -> New repository secret, the Name should be NPM_TOKEN and the Value should be your npm token.

CI publishing to GitHub Packages

The default configuration of this example package assumes you publish package with an unscoped name to npm. GitHub Packages must be named with a scope name such as "@tomchen/example-typescript-package".

Change scope: '@tomchen' to your own scope in .github/workflows/publish.yml, also change addscope in package.json.

If you publish package with a scoped name to npm, change the name to something like "@tomchen/example-typescript-package" in package.json, and remove the - run: npm run addscope line in .github/workflows/publish.yml

If you publish your package to npm only, and don't want to publish to GitHub Packages, then delete the lines from - name: Setup .npmrc file to publish to GitHub Packages to the end of the file in .github/workflows/publish.yml.

(You might have noticed secret.GITHUB_TOKEN in .github/workflows/publish.yml. You don't need to set up a secret named GITHUB_TOKEN actually, it is automatically created)

Publish

Now everything is set. The example package has automated tests and upload (publishing) already set up with GitHub Actions:

  • Every time you git push or a pull request is submitted on your master or main branch, the package is automatically tested against the desired OS and Node.js versions with GitHub Actions.
  • Every time an annotated (not lightweight) "v*" tag is pushed onto GitHub, a GitHub release is automatically generated from this version, it also automatically publishes to the npm registry and/or GitHub Packages registry to update the package there.
    • npm version / yarn version is useful to create tags.
    • (npm or yarn v1, not yarn v2) You could also add "postversion": "git push --follow-tags" to package.json file to push it automatically after npm or yarn version.
    • (yarn v1, not v2) because yarn version doesn't check whether there are uncommitted changes, you can add "preversion": "git diff-index --quiet HEAD --" to package.json
      • Note: preversion, postversion doesn't work in yarn v2

For npm registry: you can unpublish a version or the whole package but can never re-publish the same version under the same name.

If you want to modify the description / README on the npm package page, you have to publish a new version. You can modify the description on GitHub Packages without publishing.

Notes

  • It uses npm but you can easily switch to yarn, of course (remember to change all "npm" in scripts in the file package.json)
    • Whether you use npm as your package manager ≠ Whether you can publish to the npm registry
  • Works fine in VS Code. In my configuration .eslintrc and .prettierrc cooperate perfectly
  • See scripts in package.json for other predefined script commands
  • pinst is used to solve a problem of husky
  • The installation of the package with npm, yarn v1 and yarn v2+ is ensured in this test

References

Btw, if you want to publish Python package, go to Example PyPI (Python Package Index) Package & Tutorial / Instruction / Workflow for 2021.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].