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

dusterjs

v0.3.2

Published

A tool to watch and compile a directory of dust.js templates

Downloads

37

Readme

Duster.js - Watch & precompile dust.js templates

A simple Node script duster.js to watch a directory of .dust templates and compile them into .js files which can be included into an HTML file.

Why duster.js? Autocompile your templates to use dust.js in the browser

The dust.js documentation does not mentioned a clear way to work with dust templates in a purely client-side approach, instead focusing on server-side node.js applications.

For my backbone.js app, the only option was to include the dust-full.js file and compile the templates on each browser load. The file is much larger than the normal dust-core.js and this approach provides no extra value over other templating solutions (performance, browser caching, external file management etc).

So I wrote a script to pre-compile dust.js files whenever they are modified in a folder.

Install

npm install -g dusterjs

Usage

The most simple usage: compile a bunch of templates (the views directory) into a single JS file (templates.js). Only files with the .dust extension will be compiled.

$ duster views templates.js

To watch the input directories for changes and recompile, use the --watch (-w) option:

$ duster -w views templates.js

To generate one .js file per dust template, use the --no-concat option (for example, views/home.dust would become views-js/home.js and views/shared/nav.dust would become views-js/shared/nav.js):

$ duster --no-concat views views-js

A complete list of options:

  --verbose, -v   verbose mode
  --watch, -w     watch input directory(s) for changes
  --concat, -c    concatenate all compiled templates into one javascript file (turn off with --no-concat)  [string]  [default: true]
  --minify, -m    minify all the compiled templates (turn off with --no-minify)                            [default: true]
  --interval, -i  set the polling interval (in milliseconds)                                               [default: 100]
  --help          show usage information and exit
  --version       show program version and exit

As a library

Duster.js is now also available as a library.

duster.compileFile (fileName, callback)

Passes to callback the JavaScript resulting from compiling the dust template.

duster.compileFileSync (fileName)

Returns the JavaScript resulting from compiling the dust template.

duster.minify (js)

Returns a minified version of js (a piece of JavaScript code). Uses uglifyjs.

duster.compileAll (inputs, output, options)

Compiles all .dust templates in the array of directory names inputs, and writes them to output (which is either a file name or directory name, depending on whether or not options.concat is truthy). If options.minify is truthy, the javascript will be compressed. If options.concat is truthy, the javascript will all be written to one file (specified by output), otherwise each .dust template will get its own .js file in the directory specified by output.

If an error occurs, an array of strings is thrown. If no errors occur, an object is returned with the following properties:

{
    bytesRead: 54983, // The total number of JavaScript bytes produced by compiling the dust templates
    bytesWritten: 46563 // The total number of JavaScript bytes after compressing
}

duster.watch (inputs, output, [options], [callback])

Watches each of the directories in inputs recursively for changes. If any files or directories are added, changed or removed, the output is recompiled. options is passed to compileAll. callback should be a function taking two arguments; the first argument is the error (if an error occurred), the second argument is the result of compileAll.

duster.watch(["views", "../views"], "js/templates.js", {}, function (err, results) {
    if (err) 
        return console.error("** Error:", err);
    console.log("Templates updated at", new Date().toLocaleTimeString());
});

TODO

  • It would be more efficient when using --watch and --no-concat to only compile the one file that has changed (currently, it recompiles them all).
  • It would also be more efficient to do this in general with --no-concat, by looking at timestamps.

More information

Linkedin wrote a dust.js tutorial: https://github.com/linkedin/dustjs/wiki/Dust-Tutorial


by Dan McGrady http://dmix.ca