Noogλe

From
To
On this page

writeJS

pkgs.writers.writeJS

Functor
Docs pulled from | This Revision | about 14 hours ago


writeJS takes a name an attributeset with libraries and some JavaScript sourcecode and returns an executable

Inputs

name

1. Function argument

attrs

2. Function argument

content

3. Function argument

Examples

pkgs.writers.writeJS usage example

writeJS "example" { libraries = [ pkgs.uglify-js ]; } ''
  var UglifyJS = require("uglify-js");
  var code = "function add(first, second) { return first + second; }";
  var result = UglifyJS.minify(code);
  console.log(result.code);
''

Noogle detected

This is a Functor

Learn about functors

Implementation

The following is the current implementation of this function.

writeJS =
    name:
    {
      libraries ? [ ],
    }:
    content:
    let
      node-env = pkgs.buildEnv {
        name = "node";
        paths = libraries;
        pathsToLink = [ "/lib/node_modules" ];
      };
    in
    writeDash name ''
      export NODE_PATH=${node-env}/lib/node_modules
      exec ${lib.getExe pkgs.nodejs} ${pkgs.writeText "js" content} "$@"
    '';