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

asset-pipe-client

v2.1.0

Published

Asset pipe client

Downloads

10

Readme

Greenkeeper badge

A client for reading an asset file entry point and uploading it as an asset feed to a asset-pipe-build-server and for triggering builds of executable asset bundles in the said server.

Creating asset bundles with asset-pipe is a two step process. The first step is to upload an asset feed to the asset-pipe-build-server. On upload the asset-feed will be persisted and the asset-pipe-build-server will return the generated filename of the uploaded asset-feed.

The second step is then to create a bundle out of one or multiple asset-feeds. This is done by providing the unique ID(s) of the asset-feeds one wants to use to build an asset bundle to the asset-pipe-build-server. The build server will then create an executable asset bundle out of these asset-feeds and persist this. It will respond with the URL to the bundle.

This client helps with remotely triggering these steps in the asset-pipe-build-server.

Installation

$ npm install asset-pipe-client

Example I

Read an CommonJS module entry point and upload it as an asset-feed to the asset-pipe-build-server:

const Client = require('asset-pipe-client');

const client = new Client({
    serverId: 'my-app-1',
    buildServerUri: 'http://127.0.0.1:7100',
});

client.uploadFeed(['path/to/myFrontendCode.js'])
    .then((content) => {
        // content contains filename of created the asset-feed
        console.log(content);
    })
    .catch((error) => {
        console.log(error);
    });

Example II

Read a CSS file entry point and upload it as an asset-feed to the asset-pipe-build-server:

const Client = require('asset-pipe-client');

const client = new Client({
    buildServerUri: 'http://127.0.0.1:7100',
});

client.uploadFeed(['/path/to/styles.css'])
    .then((content) => {
        // content contains filename of created the asset-feed
        console.log(content);
    })
    .catch((error) => {
        console.log(error);
    });

Example III

Build a javascript bundle out of two asset feeds:

const Client = require('asset-pipe-client');
const client = new Client({
    serverId: 'my-app-2',
    buildServerUri: 'http://127.0.0.1:7100',
});

bundle.createRemoteBundle([
    'f09a737b36b7ca19a224e0d78cc50222d636fd7af6f7913b01521590d0d7fe02.json',
    'c50ca03a63650502e1b72baf4e493d2eaa0e4aa38aa2951825e101b1d6ddb68b.json'
], 'js')
    .then((content) => {
        // content contains URI to the created bundle
        console.log(content);
    })
    .catch((error) => {
        console.log(error);
    });

Example IIII

Build a CSS bundle out of two asset feeds:

const Client = require('asset-pipe-client');
const client = new Client({
    buildServerUri: 'http://127.0.0.1:7100',
});

bundle.createRemoteBundle([
    'f09a737b36b7ca19a224e0d78cc50222d636fd7af6f7913b01521590d0d7fe02.json',
    'c50ca03a63650502e1b72baf4e493d2eaa0e4aa38aa2951825e101b1d6ddb68b.json'
], 'css')
    .then((content) => {
        // content contains URI to the created bundle
        console.log(content);
    })
    .catch((error) => {
        console.log(error);
    });

API

Under the hood, when working with javascript, the asset-pipe project builds on browserify. Multiple methods in this module are therefor underlaying Browserify methods where all features found in Browserify can be used. Such methods will in this documentation point to the related documentation in Browserify.

When working with CSS the underlying POST CSS is used but the implementation is not exposed so there are no additional supported methods.

This module has the following API:

constructor(options)

Supported arguments are:

  • options.buildServerUri - Required URI to the asset-pipe-build-server
  • options.serverId - An optional unique name to identify the deployed server (required for runtime optimistic bundling)

transform()

Same as the Browserify transform method. NOTE: Only applicable when uploading javascript feeds.

plugin()

Same as the Browserify plugin method. NOTE: Only applicable when uploading javascript feeds.

uploadFeed(files)

Read the CommonJS module or CSS file entry point and uploads it as an asset feed to the asset-pipe-build-server.

  • files - Array - Either list of CommonJS module entry points - Same as files in the Browserify constructor OR list of paths to CSS files

Returns a promise.

createRemoteBundle(feeds, type)

Creates an asset bundle on the asset-pipe-build-server.

  • feeds - Array - List of asset-feed filenames.
  • type - string - Either 'js' or 'css'

Transpilers

Since asset-pipe is built on browserify under the hood, its fully possible to take advantage of the different transpiers available for browserify when working with javascript.

As an example, here is how Babel is applied:

const babelify = require('babelify');
const Client = require('asset-pipe-client');

const client = new Client({
    files: ['path/to/myES6FrontendCode.js']
    buildServerUri: 'http://127.0.0.1:7100',
});

client.transform(babelify, { presets: ['es2015'] });

client.uploadFeed()
    .then((content) => {
        console.log(content);
    })
    .catch((error) => {
        console.log(error);
    });

Contributing

The contribution process is as follows:

  • Fork this repository.
  • Make your changes as desired.
  • Run the tests using npm test. This will also check to ensure that 100% code coverage is maintained. If not you may need to add additional tests.
  • Stage your changes.
  • Run git commit or, if you are not familiar with semantic commit messages, please run npm run cm and follow the prompts instead which will help you write a correct semantic commit message.
  • Push your changes and submit a PR.