I've found myself in a situation where I'm having to run a single command e.g. node compile.js
that .js file needs to run the following
browserify -t jadeify client/app.js -o bundle.js
All the dependencies are installed, and by running this command in the CLI works fine, just need to figure out how to execute it from within a node script.
We've also got inside our package.json the following which contains something similar to
"script" : [ "compile": "browserify -t jadeify client/app.js -o bundle.js" ]
this works perfectly when you execute cd /project && npm run compile
via ssh however not via exec
Thanks
You should be able use the api-example and extend it with the transform as suggested by the jadeify setup paragraph.
var browserify = require('browserify');
var fs = require('fs');
var b = browserify();
b.add('./client/app.js');
// from jadeify docs
b.transform(require("jadeify"));
// simple demo outputs to stdout, this writes to a file just like your command line example.
b.bundle().pipe(fs.createWriteStream(__dirname + '/bundle.js'));
You can access script arguments via process.argv.
An array containing the command line arguments. The first element will be 'node', the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.
You can then use the browserify api together with jadeify to get what you need.
var browserify = require('browserify')();
var fs = require('fs');
var lang = process.argv[2];
console.log('Doing something with the lang value: ', lang);
browserify.add('./client/app.js');
browserify.transform(require("jadeify"));
browserify.bundle().pipe(fs.createWriteStream(__dirname + '/bundle.js'));
Run it with $ node compile.js enGB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With