js-kyle / mincer

Sprockets inspired web assets compiler for Node.js
http://js-kyle.github.io/mincer/
MIT License
628 stars 84 forks source link

How to use the cli? #221

Closed ricardograca closed 8 years ago

ricardograca commented 8 years ago
node_modules/.bin/mincer --include app/assets/javascripts --include vendor/assets/javascripts --output public main.js

# and

node_modules/.bin/mincer --include app/assets/javascripts --include vendor/assets/javascripts main.js

In the first case nothing happens. There is no error but no assets are compiled. In the second example I get Cannot find logical path: main.js. I tried all variations of paths possible to get to main.js, namely assets/main.js, app/assets/main.js, app/assets/javascripts/main.js.

So, how is this program supposed to be used?

ixti commented 8 years ago

Not sure why that happens for you, just tried and all succeeded:

mkdir /tmp/test && cd /tmp/test
echo '{ "dependencies": ["mincer"] }' > package.json
npm install
mkdir -p {app,vendor}/assets/javascripts
echo 'alert("BOOM");' > vendor/assets/javascripts/abc.js
echo '//= require abc' > app/assets/javascripts/main.js
node node_modules/.bin/mincer \
  --include app/assets/javascripts \
  --include vendor/assets/javascripts \
  --output public \
  main.js

find public -type f | while read filename; do
  echo "=== ${filename} ==="
  cat $filename
  echo
done

Outputs:

/tmp/test
`-- mincer@1.4.1 
  +-- argparse@1.0.7 
  | `-- sprintf-js@1.0.3 
  +-- compressible@2.0.8 
  | `-- mime-db@1.23.0 
  +-- hike@1.0.1 
  +-- lodash@3.10.1 
  +-- mimoza@1.0.0 
  +-- mkdirp@0.5.1 
  | `-- minimist@0.0.8 
  +-- pako@0.2.8 
  +-- shellwords@0.1.0 
  `-- source-map@0.5.6 

npm WARN test No description
npm WARN test No repository field.
npm WARN test No license field.
debug Compiled main.js (16ms)
Writing /tmp/test/public/main-cfa61cf97edbed15ba3d2a83208167b0.js
=== public/manifest.json ===
{
  "assets": {
    "main.js": "main-cfa61cf97edbed15ba3d2a83208167b0.js"
  },
  "files": {
    "main-cfa61cf97edbed15ba3d2a83208167b0.js": {
      "logical_path": "main.js",
      "mtime": "2016-05-20T11:57:42.000Z",
      "size": 34,
      "digest": "cfa61cf97edbed15ba3d2a83208167b0"
    }
  }
}
=== public/main-cfa61cf97edbed15ba3d2a83208167b0.js ===
alert("BOOM");//(=) require abc
;
ricardograca commented 8 years ago

I'm on mincer 1.3.0. I'll check if upgrading fixes this, and if not continue investigating what may be happening on my end.

ricardograca commented 8 years ago

I upgraded to the latest version and still no luck. Your example runs perfectly fine though, so I'll continue to investigate any possible differences and report back.

ricardograca commented 8 years ago

Obviously it was developer blindness/stupidity. The asset I was trying to compile was in a sub-directory of app/assets/javascripts so I was passing the wrong logical path in the command line. It should have been something like:

node_modules/.bin/mincer --include app/assets/javascripts --include vendor/assets/javascripts my-app/main.js

However it seems like the CLI utility has no way of compressing assets, or am I missing something?

ixti commented 8 years ago

Well, cli is pretty simple yeah. And honestly was implemented only as an attempt to match sprocket's CLI. But I don't see any realy practical usage of it. IMHO it's better to write your own runner that will be configure Mincer environment the way you need. And will be:

ricardograca commented 8 years ago

Well, I just needed a one time compression of assets, so I thought I'd use the CLI. Would you take a PR to add compression support to the CLI? Something like:

mincer --include something --js-compressor uglify asset.js
ixti commented 8 years ago
#!/usr/bin/env node

var Mincer = require("mincer"),
    environment = new Mincer.Environment(__dirname);

environment.appendPath("app/assets/javascripts");
environment.appendPath("vendor/assets/javascripts");

environment.enable("autoprefixer");

environment.jsCompressor = "uglify";
environment.cssCompressor = "csswring";

var manifest = new Mincer.Manifset(environment, "public");

manifest.compile(["main.js"]);
ixti commented 8 years ago

Yeah. I'm OK with PR that will allw configure js/css compressor on CLI, as well as --enable.

ricardograca commented 8 years ago

What is --enable?

ixti commented 8 years ago

to enable different plugins, like autoprefixer for example

ricardograca commented 8 years ago

Ah! Good point :)