Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the cli? #221

Closed
ricardograca opened this issue May 20, 2016 · 11 comments
Closed

How to use the cli? #221

ricardograca opened this issue May 20, 2016 · 11 comments
Labels

Comments

@ricardograca
Copy link

  • I have assets in app/assets/javascripts and vendor/assets/javascripts
  • the file I want is in app/assets/javascripts/main.js
  • from the root of the project (the parent of app) I tried the commands:
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
Copy link
Collaborator

ixti commented May 20, 2016

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Collaborator

ixti commented May 20, 2016

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:

  • easier to read
  • easier to maintain
  • reliable
    etc... :D

@ricardograca
Copy link
Author

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
Copy link
Collaborator

ixti commented May 20, 2016

#!/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
Copy link
Collaborator

ixti commented May 20, 2016

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

@ricardograca
Copy link
Author

What is --enable?

@ixti
Copy link
Collaborator

ixti commented May 20, 2016

to enable different plugins, like autoprefixer for example

@ricardograca
Copy link
Author

Ah! Good point :)

@puzrin puzrin closed this as completed Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants