From b3b594f71739f632681ce6332ff1c27c30a65baf Mon Sep 17 00:00:00 2001 From: Arian Stolwijk Date: Fri, 27 Dec 2013 14:28:06 +0100 Subject: [PATCH] Using require-relative to resolve modules for transforms in the cli --- README.md | 3 +++ bin/cli.js | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 95f6c19..2138824 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,9 @@ wrup amd-combined --require ./main.js # piping the AST JSON into uglifyjs wrup browser --require ./main.js --ast | uglifyjs --spidermonkey -c -m +# use transforms, for example to compile coffeescript +wrup browser -r ./test.coffee --transform coffeeify + # source maps wrup browser -r ./main.js --output test.js --source-map test.map diff --git a/bin/cli.js b/bin/cli.js index 28065a3..521a254 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,11 +1,12 @@ "use strict"; -var path = require('path') -var program = require('commander') -var chalk = require('chalk') -var WrapUp = require('../lib/wrapup') -var json = require('../package') -var error = require('./errorHandler') +var path = require('path') +var program = require('commander') +var chalk = require('chalk') +var relative = require('require-relative').resolve +var WrapUp = require('../lib/wrapup') +var json = require('../package') +var error = require('./errorHandler') var wrapup = new WrapUp() @@ -22,6 +23,7 @@ program .option('-r, --require ', 'requires a module. Uses node to resolve modules. If the form namepace=path is used the module will use a namespace') .option('-t, --transform ', 'requires a module for transforming source code of modules') .option('-w, --watch', 'watch changes to every resolved module and wraps up') + .option('-t, --transform', 'a module that can transform source code or ASTs') .option('--in-path ', 'all required files should be in this path') program.on('require', function(option){ @@ -31,8 +33,7 @@ program.on('require', function(option){ }) program.on('transform', function(option){ - if (option.charAt(0) == '.') option = process.cwd() + '/' + option - wrapup.scanner.addTransform(require(option)) + wrapup.scanner.addTransform(require(relative(option))) }) program.on('in-path', function(option){