Skip to content
Nate Fischer edited this page Mar 20, 2016 · 1 revision

A convenience script shelljs/make is also provided to mimic the behavior of a Unix Makefile. In this case all shell objects are global, and command line arguments will cause the script to execute only the corresponding function in the global target object. To avoid redundant calls, target functions are executed only once per script.

Example:

require('shelljs/make');

target.all = function() {
  target.bundle();
  target.docs();
};

target.bundle = function() {
  cd(__dirname);
  mkdir('-p', 'build');
  cd('src');
  cat('*.js').to('../build/output.js');
};

target.docs = function() {
  cd(__dirname);
  mkdir('-p', 'docs');
  var files = ls('src/*.js');
  for(var i = 0; i < files.length; i++) {
    var text = grep('//@', files[i]);     // extract special comments
    text = text.replace(/\/\/@/g, '');    // remove comment tags
    text.toEnd('docs/my_docs.md');
  }
};

To run the target all, call the above script without arguments: $ node make. To run the target docs: $ node make docs.

You can also pass arguments to your targets by using the -- separator. For example, to pass arg1 and arg2 to a target bundle, do $ node make bundle -- arg1 arg2:

require('shelljs/make');

target.bundle = function(argsArray) {
  // argsArray = ['arg1', 'arg2']
  /* ... */
}
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy