• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build Tool for Browser and Node Applications

Hammer

Build Tool for Browser and Node Applications

npm version

Install

$ npm install @sinclair/hammer -g

Usage

Create an index.html file

<!DOCTYPE html>
<html>
  <head>
    <link href="index.css" rel="stylesheet" />
    <script src="index.tsx"></script>
  </head>
  <body>
    <img src="banner.png" />
  </body>
</html>

Run Hammer

$ hammer build index.html

Done

Overview

Hammer is a command line tool for browser and node application development. It provides a command line interface to trivially run both browser and node applications and offers appropriate watch and reload workflows for each environment. It is designed with rapid application development in mind and requires little to no configuration to use.

Hammer was written to consolidate several disparate tools related to monitoring node processes (nodemon), building from HTML (parcel), mono repository support (lerna, nx) and project automation (gulp, grunt). It takes esbuild as its only dependency and is as much concerned with build performance as it is with dramatically reducing the number of development dependencies required for modern web application development.

License MIT

Serve

Use the serve command to start a development server that reloads pages on save.

<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="index.tsx"></script>
  </head>
  <body>
    <h1>Hello World</h1>
  </body>
</html>
$ hammer serve index.html

Run

Use the run command to start a node process that restarts on save.

$ hammer run index.ts

$ hammer run "index.ts arg1 arg2" # use quotes to pass arguments

$ hammer run index.mts            # node esm modules supported via .mts

Watch

Use the watch command to start a compiler watch process only.

$ hammer watch worker.ts

Monitor

Use the monitor command to execute shell commands on file change.

$ hammer monitor index.ts "deno run --allow-all index.ts"

Tasks

Hammer provides a built-in task runner for automating various workflow at the command line. Tasks are created with JavaScript functions specified in a file named hammer.mjs. Hammer will search for the hammer.mjs file in the current working directory and setup a callable command line interface to each exported function. Hammer provides a global shell(...) function that can be used to start command line processes within each task. Additional functionality can be imported via ESM import. The following shows running a Hammer website and server watch process in parallel.

//
// file: hammer.mjs
//
export async function start() {
    await Promise.all([
        shell(`hammer serve apps/website/index.html --dist dist/website`),
        shell(`hammer run apps/server/index.ts --dist dist/server`)
    ])
}
$ hammer task start

Libs

In mono repository projects, you can import shared libraries by using TypeScript tsconfig.json path aliasing.

/apps
  /server
    index.ts    ───────────┐
  /website                 │
    index.html             │
    index.ts    ───────────┤ depends on
/libs                      │
  /shared                  │
    index.ts    <──────────┘
tsconfig.json

To enable website and server to import the shared library. Configure tsconfig.json in the project root as follows.

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@libs/shared": ["libs/shared/index.ts"],
        }
    }
}

Once configured the server and website applications can import with the following.

import { Foo } from '@libs/shared'

Cli

Hammer provides the following command line interface.

Commands:

   $ hammer run     <script path>     <...options>
   $ hammer build   <file or folder>  <...options>
   $ hammer watch   <file or folder>  <...options>
   $ hammer serve   <file or folder>  <...options>
   $ hammer monitor <file or folder>  <shell command>
   $ hammer task    <name>            <...arguments>
   $ hammer version
   $ hammer help

Options:

   --target      targets     The es build targets.
   --platform    platform    The target platform.
   --dist        directory   The target directory.
   --port        port        The port to listen on.
   --external    packages    Omits external packages.
   --esm                     Use esm module target.
   --minify                  Minifies the output.
   --sourcemap               Generate sourcemaps.
   --sabs                    (serve) Enable shared array buffer.
   --cors                    (serve) Enable cors.

More Repositories

1

typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
TypeScript
4,648
star
2

zero

A 3D renderer written in JavaScript and rendered to the terminal.
TypeScript
2,413
star
3

smoke

Run Web Servers in Web Browsers over WebRTC
TypeScript
520
star
4

threadbox

Recursive Worker Threads in NodeJS
TypeScript
229
star
5

linqbox

Language Integrated Query for JavaScript
TypeScript
130
star
6

typescript-bundle

A Bundling Tool for TypeScript
TypeScript
125
star
7

typebox-codegen

Code Generation for TypeBox Types
TypeScript
120
star
8

sidewinder

Type Safe Micro Services for Node
TypeScript
59
star
9

blender-node

NodeJS binding to Blenders Python Scripting Environment
TypeScript
59
star
10

typebox-workbench

Type Transform Tool for Runtime Type Systems
TypeScript
46
star
11

reactor

Asynchronous Event Driven IO for .NET
C#
44
star
12

ts-8-bit

Using TypeScript's Type System to do 8-bit Arithmetic
TypeScript
37
star
13

tesseract

WebGL 2.0 GPGPU compute library for JavaScript.
TypeScript
32
star
14

fastify-typebox

Enhanced TypeBox support for Fastify
TypeScript
31
star
15

typescript.api

A typescript 0.9 compiler as a service api for nodejs.
TypeScript
27
star
16

black

A Software Rasterizer written in Rust
Rust
25
star
17

servicebox

Typed Web Services for NodeJS
TypeScript
22
star
18

esbuild-wasm-resolve

File Resolution for Esbuild running in the Browser
TypeScript
20
star
19

appex

develop nodejs web applications with typescript
TypeScript
16
star
20

carbon

Compatibility Layer for Node Deno and Bun
TypeScript
16
star
21

drift

Run Chrome from the Terminal
TypeScript
15
star
22

fs-effects

A library for composing various file, folder, shell and watch operations in node.
TypeScript
10
star
23

smoke-task

Runs JavaScript functions from a terminal
TypeScript
9
star
24

neuron

Neural network implemented in JavaScript
TypeScript
9
star
25

corsa

Asynchronous uni-directional channels in node using async iteration.
TypeScript
9
star
26

smoke-rs

lightweight async task and stream library for Rust
Rust
8
star
27

stream-cortex

real-time live video streaming experiments with node + ffmpeg
TypeScript
8
star
28

magnum

general purpose template engine for nodejs.
TypeScript
7
star
29

runtime-type-benchmarks

High Performance Validation Benchmarks for JavaScript
TypeScript
6
star
30

vector-cs

.NET opengl graphics library
C#
6
star
31

tasksmith

Task automation library for node.
TypeScript
5
star
32

phantom-network-service

run phantomjs as a network service
TypeScript
5
star
33

neuron-render

An experiment using neural networks to approximate various stages of graphics pipeline for the purpose of creating interesting things.
TypeScript
5
star
34

neuron-gpgpu

GPGPU based implementation of a multi layer perceptron network for the browser.
TypeScript
5
star
35

fpv32

Benchmarks for fast 32-bit floating point vector math for JavaScript.
TypeScript
5
star
36

statebox

An observable JavaScript state container
TypeScript
4
star
37

hexagon

WebGL 2.0 graphics renderer written in TypeScript
TypeScript
4
star
38

smoke-run

Runs shell commands on file system watch events.
TypeScript
4
star
39

crimson-rust

CSP experiments in the rust programming language
Rust
4
star
40

fsweb

Static HTTP development server with live reload on save.
TypeScript
4
star
41

pubsub-rs

simple tcp based pubsub for rust
Rust
3
star
42

crimson

Actor system in JavaScript
TypeScript
3
star
43

merc

blender scene renderer demo
TypeScript
3
star
44

bayes

An implementation of a naive bayes classifier in TypeScript
JavaScript
3
star
45

three-instanced-mesh

A reference project enabling geometry instancing for threejs materials
TypeScript
3
star
46

signature

Overloaded function signatures in JavaScript.
TypeScript
2
star
47

smoke-web

A static file server that live reloads on file change.
TypeScript
2
star
48

smoke-hub-appengine

messaging hub for webrtc targeting the google app engine standard environment.
Go
2
star
49

fsrun

Restart OS processes on file system watch events.
JavaScript
2
star
50

smoke-pack

A npm project provisioning and build system for browser, electron, node and library projects.
TypeScript
1
star
51

vlc.web.stream

Example and documentation about streaming from VLC to a browser.
JavaScript
1
star
52

taxman

simple book keeping application for nodejs
JavaScript
1
star
53

neuron-function-approximation

An experiment using neural networks to approximate pure functions
TypeScript
1
star
54

nx-transform

angular + threejs + css experiment
HTML
1
star
55

deno-minifb

Render 32-bit RGBA Buffers to Desktop Windows
Rust
1
star
56

vector-rs

vector math library and utilities for Rust.
Rust
1
star
57

brainfuck-rs

A brainfuck interpreter implemented in Rust.
Rust
1
star
58

pang

A simple dependency injection library for node
TypeScript
1
star