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

watch-compile

v0.3.4

Published

An watch-compile tool for nodejs.Useful for webdev real-time compilation such as less/coffee or what ever you want.

Downloads

27

Readme

node-watch-compile

Note

Only tested under linux.Nodejs's fs.watch is used to watch file changes,but these API is not gareteed in all platform.The availability can be found at http://nodejs.org/api/fs.html#fs_availability

An watch-compile tool for nodejs.Useful for webdev real-time compilation for less/coffee or what ever.

Install

sudo npm install -g watch-compile

Usage

# watchcompile or nwc
# create a template Watchfile
watchcompile -c
# Run it
watchcompile -s
# Or run with custom Watchfile
# watchcompile -f /path/to/Watchfile.server

-f is used to specify the Watchfile which contained watch rules. default is "./Watchfile" -s make watchcompile run initial compilation for all matched files.

#Watchfile

#create an default Watchfile at ./
watchcompile -c

A default Watchfile is like below

//{basename} /css/style.less => style.less
//{fullpath} /css/style.less => /css/style.less (unchanged)
//{filename} /css/style.less => style
//{extname}  /css/style.less => .less
//{directory} /css/style.less => /css/
exports.watchList = [
    // [testFunction,commandToRun]
    // [RegExp|(path:string)=>boolean,string]
    [/^.*\.coffee$/,'coffee -c {fullpath}'],
    [/^.*\.less$/,'lessc {fullpath} > {directory}{filename}.css'],
];

exports.serviceList = [
    //commandToRunOnceAtStart
    "echo WatchCompileStart",
    "echo 'start tsc watch' && tsc -p ./ --watch"
]

Watchfile's working directory is always based on pwd of your shell.

Watchfile is considered as an standard node module and latter running by require("vm").runInContext.

Consider the folder structure

/Watchfile  #this one is the example
/index.html
/js/code.coffee
/css/style.less

When running watchcompile at /

/js/code.coffee is matched by [/^.*coffee$/,"coffee -c {fullpath}"]
/css/style.less is matched by [/^.*less$/,"lessc {fullpath} > {directory}{basename}.css"]
]

Note that the RegExp can also be replaced by a function with signature (path:string)=>boolean.

When /css/style.less changed."lessc /css/style.less > /css/style.css" is excuted.

Supported macros are :

{basename} /css/style.less => style.less
{fullpath} /css/style.less => /css/style.less (unchanged)
{filename} /css/style.less => style
{extname}  /css/style.less => .less
{directory} /css/style.less => /css/

Since Watchfile is considered and excuted as node module. So you can do what ever you can with javascript to generate any exports.watchList you want.

ServiceList

Some compilation has it's own watch system and some of them, such as typescript, may have incremental compilation which lead to a huge performance boost than normal compilation. So we provide a exports.serviceList to run it at start of watchcompile. Also you can run any other command as you wish as a service. It is actually just a command run at start of the watchcompile as a child process.

Behavior

  1. Only one task is running at any moment.
  2. When multiple task with exactly the same command is triggered, they get merged, unless one of them is currently running, then we will queue it.

Notification

Watchcompile it self don't provide notification, but you may write it yourself using command like:

exports.watchList = [
    ["/*\.ts/","tsc -p ./ && notify-send '{fullpath} compile success' || notify-send 'something is wrong with {fullpath}'"]
]

notify-send is a desktop notification service provide by most desktop environment of Linux. OSX user may use applescript instead.