component-api

API for creating, building, and installing components

npm install component-api
6 downloads in the last week
24 downloads in the last month

component-api

API for creating, building, and installing components. If you're looking for a command line interface, see component(1)

Installation

$ npm install component-api

Usage

var api = require('component-api');

api.build(directory, options, callback)

Build a component in the given directory. It returns an event emitter so you can view progress.

arguments:

directory
string path for the directory containing the component you wish to build
options
dev
True to include development dependencies
standalone
If present, indicates that a standalone build should be created which exports the global with name standalone
out

The output directory for built files, defaults to ./build.

You can alternatively pass an object of the form: {js: Stream, css: Stream}

name
The base name for the output files - defaults to build
prefix
prefix css asset urls with prefix
callback(err, duration)
Gets passed how long the build took in milliseconds.

events:

writing to
Gets called with {js, css} containing the streams being written to. Use js.path to get the path of the JavaScript file being written.
writing
Gets called with {js, css} containing the number of bytes being written to each file.

api.convert(file, callback)

Convert a text file into require'able JavaScript

arguments:

file
Path to the file as a string
callback(err)
Called once the converted file is written to disk

api.fetch(packageName, version, destination, options, callback)

Download a repo into a folder and return the component.json file as parsed json. N.B. This doesn't download dependencies, you'll need to use install for that.

example:

api.fetch('component/emitter', '*', './', {}, function (err) {
  if (err) throw err;
  api.install('./', [], {}, function (err) {
    if (err) throw err;
    api.build('./', {standalone: 'EventEmitter'}, function (err) {
      if (err) throw err;
      console.log('built standalone event emitter');
    })
  });
})

arguments:

packageName
:user/:repo the package name to download
version
The version of the package to download.
destination
The directory to download the package to.
options
remote
The remote to fetch from (defaults to https://raw.github.com)
OR
remotes
The remotes to fetch from. Takes precedence over remote if both are present. Each remote in the array will be tried until one of them returns JavaScript or there are no more left to try.
And
force
re-install modules even if they aren't out of date.
ignore
An object hash of any modules you want to ignore, used internally.
auth
{user, pass}

api.install(directory, pkgs, options, callback)

Install a module including dependencies.

arguments:

directory
string path for the directory containing the component you wish to install
pkgs
Array of package names to install (and save into component.json)
options
destination
Sub-folder to put dependencies in (defaults to components)
dev
Include development dependencies
force
re-install modules even if they aren't out of date.
callback(err)
Called once the module's been installed

api.ls(directory, callback)

List the dependency of a component.

npm loves you