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

stratosphere

v2.4.4

Published

Shrink wrap your dynamically generated assets

Downloads

11

Readme

Stratosphere

Build Status

Shrink wrap your dynamically generated assets. If you use tools like browserify to build your front-end code, you should consider saving the output to disk as part of your deploy process. This allows you to freeze an entire version of your app inside a container like Docker and test the release with confidence that things will not change in the future because the app was built with a different browserify version, or in a different environment.

Quick Usage


// See Full Usage for all options
var instance = stratosphere(app, {assets: 'assets.json', root: 'cachedir'})

// Save assets to disk
instance.writeAssets(function () {
  // Intercept requests for assets and serve from memory
  instance.intercept().listen(8080)
})

Full Usage

var stratosphere = require('stratosphere')

// app is your http server.
var app = require('./your-app')

// Stratosphere options
var opts = {
      // The assets you want to freeze are declared here.
      // Required.
      assets: './assets.json'

      // The directory where you want to save the frozen assets to.
      // Required.
    , root: './assets'

      // This is the route that you want to serve your manifest file on.
      // Optional.
    , route: 'manifest.json'

      // When true, will disable Stratosphere, passing all requests
      // straight to the app.
      // Default: false.
    , disable: false

      // When true, will not empty the root asset directory on initialization.
      // Default: false.
    , noFlush: false

      // Used to override manifest defaults. Default: {}.
    , manifestOpts: {version: '1.0.0'}
    }

// Stratosphere wraps your server using the rules in your manifest
// The callback is optional, and will be called if preload == true
// when preloading is complete
var instance = stratosphere(app, opts, function (err, assets) {
                    if(err)
                      console.error(err)
                    else
                      console.log('Preloading complete')

                    // assets is an object containing the preloaded assets
                    // note the leading slashes -- routes are normalized
                    // {'/route/1': 'asset data', '/route/2': 'dat'} etc...
                  })

// The `intercept` method will modify its `request` listeners to respond
// with cached data from the filesystem when possible, and return the server
instance.intercept().listen(8080)


/*
* If you want to write your assets to disk
*
* Gotcha: Calling this method on a server that is not listening on any
* ports will bind it to an ephremeral one. If you plan to use the server
* to handle actual requests you'll want to bind it to a port before
* calling this method.
*/
instance.writeAssets(function (err) {
  // Handle the error
})

/*
* If you want to load all assets into memory
*
* Gotcha: Calling this method on a server that is not listening on any
* ports will bind it to an ephremeral one. You almost definitely want
* to call this only after binding your server to a port of your choice.
*/
instance.preload(function (err, assets, manifest) {
  // Handle the error
})

// To flush the asset cache that is in memory (not the one on disk!)
instance.flush()

The Assets File

You can either use a JSON file, or a .js file that exports an array.

// If you serve lots of static assets like fonts, it might be helpful
// to glob for them
var fonts = require('glob').sync('./fonts/*')

// Should export an array of strings that represent routes on the server
// Routes without a leading slash will be have one added to them
module.exports = [
  // shorthand syntax is just a string
  'app/bundle.js'

  // shorthand is expanded into the equivalent verbose syntax
  // which is useful when fine control over the manifest is desired
, {
    source: '/app/bundle.js'
  , destination: 'app/bundle.js'
  , key: 'app/bundle.js'
  }
].concat(fonts)

The Manifest File

The manifest that Stratosphere serves is Phonegap Air compatible.