Giter Club home page Giter Club logo

typescript-boilerplate's Introduction

TypeScript Boilerplate for 2022

Build and test status

TypeScript project boilerplate with modern tooling, for Node.js programs, libraries and browser modules. Get started quickly and right-footed 🚀

See also the introduction blog post: Starting a TypeScript Project in 2021.

Getting Started

# Clone the repository (you can also click "Use this template")
git clone https://github.com/metachris/typescript-boilerplate.git your_project_name
cd your_project_name

# Edit `package.json` and `tsconfig.json` to your liking
...

# Install dependencies
yarn install

# Now you can run various yarn commands:
yarn cli
yarn lint
yarn test
yarn build-all
yarn ts-node <filename>
yarn esbuild-browser
...
  • Take a look at all the scripts in package.json
  • For publishing to npm, use yarn publish (or npm publish)

esbuild

esbuild is an extremely fast bundler that supports a large part of the TypeScript syntax. This project uses it to bundle for browsers (and Node.js if you want).

# Build for browsers
yarn esbuild-browser:dev
yarn esbuild-browser:watch

# Build the cli for node
yarn esbuild-node:dev
yarn esbuild-node:watch

You can generate a full clean build with yarn build-all (which uses both tsc and esbuild).

  • package.json includes scripts for various esbuild commands: see here
  • esbuild has a --global-name=xyz flag, to store the exports from the entry point in a global variable. See also the esbuild "Global name" docs.
  • Read more about the esbuild setup here.
  • esbuild for the browser uses the IIFE (immediately-invoked function expression) format, which executes the bundled code on load (see also evanw/esbuild#29)

Tests with Jest

You can write Jest tests like this:

import { greet } from './main'

test('the data is peanut butter', () => {
  expect(1).toBe(1)
});

test('greeting', () => {
  expect(greet('Foo')).toBe('Hello Foo')
});

Run the tests with yarn test, no separate compile step is necessary.

Documentation, published with CI

You can auto-generate API documentation from the TypeScript source files using TypeDoc. The generated documentation can be published to GitHub / GitLab pages through the CI.

Generate the documentation, using src/main.ts as entrypoint (configured in package.json):

yarn docs

The resulting HTML is saved in docs/.

You can publish the documentation through CI:

This is the documentation for this boilerplate project: https://metachris.github.io/typescript-boilerplate/

References

Feedback

Reach out with feedback and ideas:

typescript-boilerplate's People

Contributors

eltronix avatar josephyi avatar lookfirst avatar metachris avatar robin-pham avatar stevenblack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescript-boilerplate's Issues

Test suite doesnt work with dependencies

Expected Behavior

Simple jest tests should work when there are project dependencies that use ESM syntax.

Actual Behavior

If any added dependency has ESM exports, jest tests will fail and complain about unexpected tokens

FAIL src/utils.test.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/seanaye/dev/coparse/filesystem/node_modules/idb/with-async-ittr.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './build/esm/index.js';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token 'export'

      1 | import { FileHandle, FileSource, FileSystemFile, LegacyFile } from "./file";
    > 2 | import { DBSchema, IDBPDatabase, openDB } from "idb/with-async-ittr.js";

I have tried all of the things suggested by the error message but nothing works.

Steps to Reproduce the Problem

  1. Add a project dependency with ESM exports in my case this is idb
  2. Try to run a jest test in which this dependency is imported
  3. Test failure

Specifications

  • Version: 0.4.2
  • Platform: MacOS, Node 16.1

Update @types/node to 15.0.1

Expected Behavior

Not especially applicable. $ yarn outdated presently returns one package, @types/node which has recently been upgraded to 15.0.1.

Since this is a boilerplate, it's easy to keep things current.

Steps to Reproduce the Problem

$ yarn outdated
yarn outdated v1.22.10
info Color legend :
 "<red>"    : Major Update backward-incompatible updates
 "<yellow>" : Minor Update backward-compatible features
 "<green>"  : Patch Update backward-compatible bug fixes
Package     Current  Wanted   Latest Package Type    URL
@types/node 14.14.43 14.14.43 15.0.1 devDependencies https://github.com/DefinitelyTyped/DefinitelyTyped.git
✨  Done in 1.98s.

TypeDoc failing in GitHub Actions

Expected Behavior

Typedoc will work correctly when run from the example Actions file deploy-gh-pages.yml

Actual Behavior

2021-11-19T12:10:40.5303299Z ##[group]Run npm docs
2021-11-19T12:10:40.5303938Z �[36;1mnpm docs�[0m
2021-11-19T12:10:40.5351103Z shell: /usr/bin/bash -e {0}
2021-11-19T12:10:40.5351586Z ##[endgroup]
2021-11-19T12:10:40.8514286Z npm ERR! code 3
2021-11-19T12:10:40.8542715Z npm ERR! Command failed: xdg-open https://github.com/lloydjatkinson/affirm#readme
2021-11-19T12:10:40.8553401Z npm ERR! /usr/bin/xdg-open: 869: www-browser: not found
2021-11-19T12:10:40.8554473Z npm ERR! /usr/bin/xdg-open: 869: links2: not found
2021-11-19T12:10:40.8555418Z npm ERR! /usr/bin/xdg-open: 869: elinks: not found
2021-11-19T12:10:40.8556312Z npm ERR! /usr/bin/xdg-open: 869: links: not found
2021-11-19T12:10:40.8557185Z npm ERR! /usr/bin/xdg-open: 869: lynx: not found
2021-11-19T12:10:40.8558039Z npm ERR! /usr/bin/xdg-open: 869: w3m: not found
2021-11-19T12:10:40.8559301Z npm ERR! xdg-open: no method available for opening 'https://github.com/lloydjatkinson/affirm#readme'
2021-11-19T12:10:40.8561052Z npm ERR! 
2021-11-19T12:10:40.8914363Z 
2021-11-19T12:10:40.8924434Z npm ERR! A complete log of this run can be found in:
2021-11-19T12:10:40.8928246Z npm ERR!     /home/runner/.npm/_logs/2021-11-19T12_10_40_853Z-debug.log
2021-11-19T12:10:40.9016097Z ##[error]Process completed with exit code 3.
2021-11-19T12:10:40.9120880Z Post job cleanup.

image

Steps to Reproduce the Problem

  1. Clone the repo
  2. Push to your own new repo
  3. Wait for GitHub Actions to fail

Changes

The only changes I've made from this setup is I have swapped over to npm and I specify Node 16 in the deploy_pages job step.

TypeDoc works fine locally.

File is not defined when creating a File Obect

should be able to create FIle Object which is available in Typescript

Actual Behavior

GIve error saying File is not defined :

Steps to Reproduce the Problem code sample

var file2 = new File(["asdasdsa"], 'metadata.json');
   console.log(file2.name);

Specifications

  • Version: 4.4
  • Platform:

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.