JamieMason / shrinkpack

Fast, resilient, reproducible builds with npm install.
https://www.npmjs.com/package/shrinkpack
MIT License
793 stars 38 forks source link

Document that shrinkpack has a Node.js API #67

Closed JamieMason closed 8 years ago

JamieMason commented 8 years ago

Add to the README that it is possible to call shrinkpack from within node.

1. Node API

Shrinkpack works in 2 phases;

  1. Analyse the project and gather all the diffing information between the file system and the shrinkwrap.
  2. Use the diffing information to bring the file system in sync with the shrinkwrap.
var shrinkpack = require('shrinkpack');

shrinkpack.analyse({
  compress: false,
  directory: process.cwd(),
  keepOptional: false
}).then(function (data) {
  shrinkpack.update(data);
});

2. Internal API for the CLI

TODO expose cli.run() as shrinkpack.cli() in ./index.js.

This approach does the same as the above, but also writes out all the additional logging that you see when using shrinkpack normally.

var cli = require('shrinkpack/src/cli');

cli.run({
  compress: false,
  directory: process.cwd(),
  keepOptional: false
});