Coder Social home page Coder Social logo

smoosh's Introduction

SMOOOOSH

How would you smoosh a lion and a tiger? A tialiganer, right?

smoosh

SMOOSH is a tool for packaging your CSS & JavaScript projects. It will lint your JavaScript with JSHint, then build and minify your files (if you'd like) with UglifyJS for JavaScript, and Sqwish for CSS.

Smoosh is available as an npm package. To install, run the following command:

$ npm install smoosh

CONFIG

Currently, smoosh requires a config.json file to work. Your config file should look something like this (check the examples folder for a working example):

{
  "VERSION": "0.1", // optional
  "JSHINT_OPTS": { ... }
  "JAVASCRIPT": {
    "DIST_DIR": "dist", // optional
    "base": [ ... ],
    "secondary": [ ... ]
  },
  "CSS": {
    "core": [ ... ]
  }
}

Your config options include:

  • VERSION: an optional version number which will be appended to your built files
  • JAVASCRIPT|CSS:
  • key: the name of your compiled file (ie: 'mootools-core', 'base-bundle', etc.)
  • value: an array of file paths to be bundled (ie. ['./src/drag.js', './src/drop.js'])
  • DIST_DIR: the directory to output your files to (if no directory is specified, 'dist' will be used)
  • JSHINT_OPTS: the options to use if running jshint

USING SMOOSH WITH TERMINAL

once installed with npm, smoosh can be accessed easily from the command line! Just create your config file (shown above), then run commands. Here's a list of some of them:

//any of these commands will execute all smoosh tasks with config.json
$ smoosh ./config.json
$ smoosh make ./config.json
$ smoosh -m ./config.json

//executing either of these commands will destroy the dist folder
$ smoosh clean ./config.json
$ smoosh -d ./config.json

//these will generate ugliyjs minified versions of your packaged source
$ smoosh compressed ./config.json
$ smoosh -c ./config.json

//these will generate full, uncompressed version of your packaged source
$ smoosh uncompressed
$ smoosh -f ./config.json

//executing either of these commands will build both compressed and uncompressed versions of your source
$ smoosh build ./config.json
$ smoosh -b ./config.json

//these will run jshint against your uncompressed source
$ smoosh run ./config.json
$ smoosh -r ./config.json

//the -a flag will run analyze.. you must include a build type for analyze to work
$ smoosh -ca ./config
$ smoosh -ba ./config
$ smoosh -fa ./config

//as you might have guessed, you can specify multiple flags at the same time
$ smoosh -dba ./config //<-- this will clean the dist folder, build new files, and then analyze them

USING SMOOSH WITH THE CODEZ

once installed, smoosh is pretty easy to use...

var smoosh = require('smoosh');

Once required there are several methods available to you:

config

As stated above, smoosh requires that you pass it the path to your configuration json file. To do that, you would do:

smoosh.config('./config.json')

clean

The clean method will remove your distribution directory. Warning This will empty your entire DIST directory. So this may be unwanted behavior if your DIST directory is "./". It is preferred that this is only used when you have a dedicated dist folder. Eg: "./src/build" or "./dist"

smoosh.clean();

run

Run takes one argument; a string which specifies what to run. Currently run only works with jslint, therefore you can do either:

smoosh.run('jslint');
//or
smoosh.run();

In the future we may add more useful things here.

build

Build is used to build your sources together. You can build uncompressed or compressed files or both! You can use it like this:

smoosh.build('uncompressed');
//or
smoosh.build('compressed');
//or
smoosh.build() // <-- this will build both compressed and uncompressed

analyze

Analyze is useful when you're curious if you're making your files larger or smaller. It will return relevant file size for uncompressed, compressed, or gzipped files.

smoosh.analyze('uncompressed');
//or
smoosh.analyze('compressed');
//or
smoosh.analyze('gzipped'); //it gzips the compressed files only
//or
smoosh.analyze(); //which will do analyze all types

done

Done is used to execute a callback at a certain point in the smoosh command chain. Typically, it is used at the end of the chain when smoosh has completed, but it can also be added between steps.

smoosh.config('smoosh.json').clean().run().build.done(function() {
  console.log('Smoosh is finished!');
});

make

Make can currently be used as a shortcut to run all smoosh methods... It requires one argument, the path to the config file.json.

smoosh.make('./config.json');

//is the same as
smoosh.config('./config.json').run().build().analyze();

Happy Smooshing!

smoosh's People

Contributors

ded avatar fat avatar rvagg avatar tauren avatar voxpelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smoosh's Issues

UglifyJS

Hi,

It will be great to have support for uglifyjs options within the json config file ;)

css compression

Hi, is support for css compression planned anytime in the future?

Don't remove the DIST_DIR from options

When sending in a config object to Smoosh it seems that Smoosh removes the DIST_DIR from it somewhere. This has the result that if the same config object is used to execute two Smoosh calls then the second Smoosh call will not get the configured DIST_DIR.

Haven't had time to look where this happens in the code so I've no patch for you. Reporting anyway so that you're aware of the issue.

add .reset() or make .config() reset state

Use case: I have a project where I want to build the source doing the normal .config({..}).run().build().analyze() but I also want to do a .config({...}).run() on the test files without building and analysing them. Unfortunately because _files is global to smoosh, when you run subsequent .config({})s you're just appending to the files lists, so depending on the order, you either do a double .run() on all files specified in both .config()'s or you do a full .run().build().analyze() on everything.

My quick and dirty solution to this is to leave an empty var _files; in place and move the _files = { ...} into _config.init() so it's an effective reset. But of course that only works for me and not anyone else who runs smoosh on my project.

I'm happy to do the work on this and submit a PR if you let me know what direction you'd be happy to take: let .config() do an implicit reset or make an explicit .reset().

There is one odd thing I haven't figured out yet which you might be able to give me a pointer to. I'm doing .config({ .. 1st .. }).run().build().analyze().config({ .. 2nd .. }).run() and it works fine (using my _files change) with the jshint, build and analysis (only 'uncompressed' and 'compressed') at the top or the first config and then the jshint for the 2nd under that yet there's the 'gzipped' bit for the analysis for the 1st config! Very strange that the gzipped analysis is split from the other analyses and it comes after my 2nd config where my 2nd config doesn't contain the file being gzipped or an .analysis().

Add callbacks

In my application's build process, I have the following tasks:

  • compile - compiles coffeescript, stylus, etc.
  • smoosh - smooshes everything
  • deploy - deploys resources to the right places

As far as I can tell, smoosh doesn't have any sort of callbacks. This means I cannot detect when smoosh has finished so that I can start the deploy task.

What am I missing? The commands can be chained and run in sequence, so internally it must be running synchronously or using callbacks. Could these callbacks be exposed? Or could a new chained function be created, maybe after() or finished():

smoosh.after(functin() {})

I've tried the following to see if it is synchronous, and the text "Smoosh Done" prints before the smoosh output:

smoosh.make './smoosh.json'
sys.print 'Smoosh Done'

As a workaround, I'm doing this (in coffee-script):

{spawn, exec} = require 'child_process'
sys = require 'sys'
smoosh = require 'smoosh'

printOutput = (process) ->
  process.stdout.on 'data', (data) -> sys.print data
  process.stderr.on 'data', (data) -> sys.print data

smoosh = (cb) ->
  cmd = 'smoosh ./smoosh.json'
  tasks = exec cmd, (err, stdout, stderr) ->
    cb err,stdout,stderr
  printOutput(tasks)

Exclude .gitignore from npm-package?

I installed this module locally through npm and thought I should commit it together with my project in my own git-repo. Unfortunately there's a gitignore-file in the smoosh-package that excludes smoosh's dependencies from any git-repo so it's not possible to commit a local package for npm into a git-repo as the dependencies of smoosh won't be fulfilled.

Feature Proposal: Runing Unit Tests

I would like to be able to run tests when I build my package, and make the process fail if any test fails (maybe this could be configurable)

UglifyJS2

uglifyJS is now uglifyJS2. The new module has a slightly different API, and this breaks the 'compressed' option

Skip JSHint on individual files

As far as I can tell, there is no way to skip individual files from JSHint processing with Smoosh. Also, there doesn't seem to be a jshint comment directive to skip a file. It would be nice if smoosh could skip running jshint on only certain files, but still run it on the others.

The problem is that I'd like to include some precompiled Jade templates, but they fail jshint and I haven't been able to find a directive to exclude them. You can see the issue here:
jshint/jshint#234

JSHint just processes what is given to it, so having a way to exclude files within the smoosh configuration is probably the right solution.

css compression

Hi, is support for css compression planned anytime in the future?

Append hash to generated file

It would be nice to have a hash appended to the generated file so for caching purposes when serving the files for web. The hash would only change if the contents of the file change, so you could, theoretically, put an infinite caching time on all js/css assets.

Thoughts?

Add license file

Would it be possible to add the appropriate license file to this package?

I have submitted a pull request with an MIT license file (#26) but if another license is more applicable would it be possible to add that instead?

Many thanks :)

users getting errors on build()

we should implement a pre-check that you can't build() unless run() passes.

since build() assumes a valid linted file - uglify will fail causing smoosh to break.

can't install with v0.6.6 due to jshint

This is jshint's issue 404 impacting you. It installs ok with with v0.4.12. But after switching back to v0.6.6 I get UNMET DEPENDENCY with npm ls:

─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── UNMET DEPENDENCY jshint >= 0.1.4
│ ├── [email protected] 
│ └── [email protected]

Better than smoosh being unmet. I won't be smooshing just yet, because I'm in a dirty branch state. If smoosh doesn't have to run jshint, I guess I'll be ok.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.