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

grocer

v0.5.0

Published

Front end asset manager

Downloads

13

Readme

Grocer

Front end asset manager

Wiki

Reference

The purpose of Grocer is to provide an API to

  1. build, manage, and initialize Grunt config files based on a manifest file
  2. impose modularity on the application, each module having an optional main object (function, class, etc.) that the application can invoke when the module is loaded

Manifest structure

The top level defines the modules. Within each module, there is a container for assets, separated by function (eg. JavaScript or CSS). Optionally, modules might define a classPath, that identifies the path (relative to the global object) that the application is supposed to invoke after loading the module.

{
    "libraries": {
        "assets": {
            "js": [ "src/jquery.js" ]
        }
    },
    "common": {
        "assets": {
            "js": [ "src/app.js" ],
            "css": [ "src/app.css" ]
        }
    },
    "users": {
        "classPath": "app[\"pages\"].Users",
        "assets": {
            "js": [ "src/Users.js" ],
            "css": [ "src/Users.css" ]
        }
    }
}

Using the manifest API

Initializing manifest

var manifest = grocer.Manifest.create(manifestJson);

Fetching asset list for module

manifest.getAssetsForModule('common', 'js').getAssetNames();

/*
[ "src/app.js" ]
*/

Fetching all assets from manifest

manifest.getAssets('js').getAssetNames();

/*
[ "src/jquery.js", "src/app.js", "src/Users.js" ]
*/

Fetching script tag list from manifest

manifest.getAssets('js').toString();

/*
<script src="src/jquery.js"></script>
<script src="src/app.js"></script>
<script src="src/Users.js"></script>
*/

manifest.getAssets('css').toString();

/*
<link rel="stylesheet" href="src/app.css">
<link rel="stylesheet" href="src/Users.css">
*/

Using the config API

Creating and loading a multi task:

'foo'
    // setting task config
    .toMultiTask({
        target1: {},
        target2: {}
    })

    // associating NPM package
    .setPackageName('grunt-foo')

    // loading package
    .applyTask();

Creating and registering an alias task:

'foo'.toAliasTask()
    // adding subtasks
    .addSubTasks('copy:dev', 'uglify:dev')

    // registering task
    .applyTask();

Creating multi tasks w/ alias tasks for each target

var multiTasks = [
    'foo'.toMultiTask({dev: {}, prod: {}})
        .setPackageName('grunt-foo'),
    'bar'.toMultiTask({dev: {}, prod: {}})
        .setPackageName('grunt-bar')
].toMultiTaskCollection();

multiTasks.toGruntConfig()
    // applying (initializing/merging) config
    .applyConfig()

    // obtaining and adding alias tasks for each target
    .getAliasTasksGroupedByTarget()
    .mergeWith(multiTasks.toGruntTaskCollection())

    // applying (registering/loading) each task
    .applyTask();

As a result of the above, there will be a separate task for targets dev and prod, grouping all tasks that have those targets.

Eg. after setting up the Gruntfile like that, you may issue grunt dev or grunt prod to run all associated tasks.