rollup-node 757 Bytes
Newer Older
Mike Bostock's avatar
Mike Bostock committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env node

var fs = require("fs"),
    rollup = require("rollup"),
    dependencies = require("../package.json").dependencies;

rollup.rollup({
  entry: "index.js",
  external: Object.keys(dependencies)
}).then(function(bundle) {
  var code = bundle.generate({
    format: "cjs"
  }).code.replace(
    /^exports\.event = (.*);$/m,
    "Object.defineProperty(exports, \"event\", {get: function() { return $1; }});"
  );
  return new Promise(function(resolve, reject) {
    fs.writeFile("build/d3.node.js", code, "utf8", function(error) {
      if (error) return reject(error);
      else resolve();
    });
  });
}).then(function() {
  console.warn("↳ build/d3.node.js");
}).catch(abort);

function abort(error) {
  console.error(error.stack);
}