Code Monkey home page Code Monkey logo

template-typescript-node-library's Introduction

How to setup a package from this template

  1. in github create a new project from this template with the Use this template button. NB the Coveralls git Action running from this commit will fail because the secret will not be present yet (see below)
  2. In package.json change the following to the values you need:
    • name
    • version
    • description
    • repository
    • keywords
    • author
    • license
  3. Delete the package-lock.json file (a new one will be automatically created)
  4. In README.md replace all references to template-typescript-node-library. A find replace on x-ware-ltd/template-typescript-node-library may be sufficient, but review each change. The badges will start working again once all the steps below have been completed.
  5. In a terminal run > npm install which will install all the dependencies and recreate the package-lock.json file. It will also run tests which should all pass.
  6. visit coveralls.io, create an account if you don't already have one, and add the project. Find the Token in coveralls.io and add it to github secrets: Settings/Secrets and variables/Actions/Repository secret (COVERALLS_REPO_TOKEN).
  7. create a Personal Access Token (classic) in GitHub to allow packages to be published (write:packages). Put this in the repository action secrets under PUBLISH_PACKAGES_TOKEN. You will now have 2 Repository secrets.
  8. in GitHub under Settings/Pages setup 'GitHub Pages' to be deployed by GitHub Actions. Then in Settings/Environments/github-page change the 'Deployment Branches' from 'Selected branches and tags' to 'No restriction'.
  9. Write and test your code:
    • install types depending on your target eg. > npm install @types/node --save-dev or > npm install @types/web --save-dev
    • edit/replace/remove the ./src/add.ts and ./src/subtract.ts files with the functionality you require
    • edit ./index.ts to export your new functionality
    • replace test files in ./tests with your own tests
    • update README.md to reflect your functionality - remove explanation regarding the template and use the Install and subsequent sections as guidance for your documenting package
  10. Delete this "How to setup a package from this template" section (these instructions for using the template).
  11. Commit, Push and Release your package (see the steps set out in the Development section in CONTRIBUTING.md)

Template ESM Typescript library

A template used for projects which produce both CommonJS and ESM packages from a common Typescript ESM codebase.

Includes testing, coverage, coveralls.io, linting, TSDoc and auto creation of a package on creating a github release.

If you are creating a new project from this template, instructions are here.

Typescript Node.js CI Node.js CI Coverage Status

Install

This is a github hosted package so you need to add an entry to your .npmrc file so the package manager knows where to download the package from:

@x-ware-ltd:registry=https://npm.pkg.github.com

Then:

> npm install @x-ware-ltd/template-typescript-node-library

If the package is private you need to authenticate to github by getting a Personal Access Token from github with read:packages permissions. Either login for the session, which will request your github username, and password (use your Personal Access Token):

> npm login --scope=@x-ware-ltd --registry=https://npm.pkg.github.com

Or, create a personal .npmrc file in your home directory:

//npm.pkg.github.com/:_authToken=aaa_abcDeFghIjklMNopqRSTuvWXYz

If you are running CI/CD on your package you will need to provide credentials for the server. Save a Personal Access Token in your Github secrets and in your github actions:

- name: Authenticate private github packages
  run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGE_READ_TOKEN }}" > ~/.npmrc

Features

  • Works with CommonJS and ESM
  • Provides Typescript types

Usage

ESM:

import {add} from '@x-ware-ltd/template-typescript-node-library';

console.log(add(3, 5)); // 8

CommonJS:

var lib = require('@x-ware-ltd/template-typescript-node-library');

console.log(lib.add(3, -1)); // 2

API Reference

Documentation can be found at:

Contributing

Make sure your code passes testing, and create a Pull Request

> npm test

template-typescript-node-library's People

Contributors

bkp7 avatar gilbertbw avatar

Watchers

 avatar

template-typescript-node-library's Issues

doc-tests

It would be nice to have Elixir/Rust style testing of @example tags in the documentation to ensure that all examples are valid

It would also be nice to have any code within ```js code tags in Markdown documents similarly tested.

There is currently no well used package that does this. There are a number of issues in providing such functionality, in particular it needs to be specific to the test environment (in this case mocha/chai) and it also needs to deal with imports/requires. It should also ideally work with both ts and js examples.

Would need to consider whether the examples should by linted??

Suggested easiest approach would be to only test code in markdown js or ts code blocks (which are allowed in TSDoc @example. Then create test files which can subsequently be run by test code. This way, any errors encountered can be easily seen in the generated test files.

Remove MyST recommendation

I can't see that we do anything involving MyST in this repository. If that is correct we should remove it from the .vscode recommendation file, and INSTRUCTIONS.md (or CONTRIBUTING.md if #2 is merged.)

Improve publish action

  • I think it should check that the tag name github.event.release.tag_name should be compared to the package version, in addition to the name. I also think the release name should only have to start with the version number

I would put this check in a .js file. My view is that as much as is possible Github Actions should just call script files

  • These are much easier to test locally without change/commit/push/release cycles
  • It is harder to read login in .yml files
  • It would be more portable to other 'forges' like GitLab in the future
  • If e.g. Github Actions is down you can manually deploy.

In this case it would stop us having to call an external action, as reading from package.json is easy in javascript. So I would set this up as the prepublishOnly script in npm/package.json, if the environment variables for the release name/tag are missing it should print a message to console (in case someone runs it manually, telling them to see the docs for publishing using a github release).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.