npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

buildfile

v1.2.22

Published

Cross-platform build task executor for Node projects with a syntax similar to Makefile

Downloads

38

Readme

buildfile

Build Status npm

This is a task runner utility similar to Makefile, but it does not check the files of the timestamps. It uses the familiar concept of targets, dependencies, and commands, but all targets are phony. Supports wildcards using the * character.

Additionally, a -p flag can be used to run them in parallel.

No dependencies. That's right, only Node.JS is required.

Install with: npm install -g buildfile

Run with: build [target1 target2 ...]

Why

Instead of having this in package.json:

  "scripts": {
    "test": "jest",
    "build": "npm-run-all *.build *.minify",
    "clean": "find src/ -type f -name '*.js' | xargs rm",
    "watch": "npm-run-all html.build css.build _watch",
    "_watch": "npm-run-all -p *.watch",
    "lint": "tslint --project .",

    "js.build": "browserify src/client/index.tsx -p [ tsify --project .] -g [ loose-envify purge --NODE_ENV production ] -v -o build/client.js",
    "js.watch": "watchify src/client/index.tsx -p [tsify --project .] -v -d -o build/client.js",
    "js.minify": "terser --ecma 5 --compress -o build/client.min.js --mangle -- build/client.js",

    "css.build": "node-sass -o build/ --output-style compressed src/scss/style.scss",
    "css.watch": "node-sass -o build/ --source-map true --source-map-contents true -w src/scss/style.scss",
    "html.build": "mustache src/views/index.json src/views/index.mustache > build/index.html",
  },

one can write a Buildfile with the following contents:

build: *.build *.minify

test:
  jest

clean:
  find src/ -type f -name '*.js' | xargs rm

watch: *.build --parallel *.watch

lint:
  tslint --project .

js.build:
  browserify src/client/index.tsx \
    -p [ tsify --project .] \
    -g [ loose-envify purge --NODE_ENV production ] \
    -v -o build/client.js
js.watch:
  watchify src/client/index.tsx -p [tsify --project .] -v -d -o build/client.js
js.minify:
  terser --ecma 5 --compress -o build/client.min.js --mangle -- build/client.js

css.build:
  node-sass -o build/ --output-style compressed src/scss/style.scss
css.watch:
  node-sass -o build/ --source-map true --source-map-contents true -w src/scss/style.scss

html.build:
  mustache src/views/index.json src/views/index.mustache > build/index.html

This is easier to read, line continuation is allowed, and tasks can be executed in parallel via the -p or --parallel flag.

To run a target, simply type:

build       # runs the first target (build)
build test  # runs test target
build watch # runs the watch target

If buildfile was installed locally, the provided build command can be run via: npx build, or ./node_modules/.bin/build.

Basic syntax

target: dependency
  echo target

dependency:
  echo dependency

running build should run the first available target: target:

==> target
==> dependency
> echo dependency
 dependency
> echo target
target

A custom target can be run by specifying it as build dependency.

Advanced Syntax

# Contents of "buildfile"
# Comments start with #

# Define an environment variable
var1 := value1

# Define an environment variable if it is not already defined
var2 ?= value2

# Define an environment varaible from an existing variable
var3 := $var2

target: dependency
  # var1 will not be expanded, by var2 will
  echo $$var1 $var2

dependency:
  echo  $var3 ${var4:$var3}

Running build echoes the following:

$ build
==> target
==> dependency
> echo value2 value2
value2 value2
> echo $var1 value2
value1 value2

Variables

Environment variables can be set:

echo:
  echo $args
$ build args=test
==> build
> echo test
test

The following also works:

var3 ?= value3
var4 := value4

test:
  echo $myvar1
  echo $myvar2
  echo $var1
  echo ${var4}
  echo ${var1:defaultValue}
  echo ${var1}
  echo ${var1:${fallback}}
  echo ${var1:$var2$var3}

If a variable needs to be passed without expansion, it can be escaped with $$:

  • $$var
  • $${var}

TODO

  • [x] Implement basic syntax parsing
  • [x] Add ability to execute syntax in parallel
  • [x] Add support for dependent targets
  • [x] Add ability to load custom files
  • [x] Add wildcard support
  • [x] Add support command line continuation via \
  • [x] Add support for different types of child_process stdio attachments
  • [x] Add support for comments beginning with #
  • [x] Add ability to replace environment variables
  • [x] Add ability to specify subprocess environment variables at the end
  • [x] Add ability to define env variables from within a Buildfile
  • [ ] Make error message during variable substitution more helpful

Have an idea? Let me know!

License

MIT