包详细信息

polvo

polvo1060.6.5

Polyvalent cephalopod mollusc. (aka ambitious app assember)

build, system, tool, assembler

自述文件

Polvo - Polyvalent cephalopod mollusc

Stories in Ready

Build Status Coverage Status

Dependency Status NPM version

What the ★★★★?

Polvo is a built system and an application assembler for the browser.

Yet another one.

Seriously?

Yes, built with simplicity in mind and based on a straightforward plugins architecture, Polvo is also agnostic to languages, libraries, frameworks and weather, like the majority of his competitors friends.

Philosophy (in short)

  1. Your scripts and templates become all one javascript, and your styles become one css

  2. Both scripts and templates are wrapped as CJS modules and thus can be require-d regularly as you'd do in NodeJS.

  3. You end up with 2 files, app.js and app.css

Include both in your html and you're done!

Installation

npm install -g polvo

Features

  • Auto-build on every change
  • LiveReload on every change
  • Syntax-check on every change
  • SourceMaps support [1]
  • Conditional-compilation for flexibility (if, elif, else, fi)
  • Partials supported for templates and styles
  • Simple Embeded Webserver [2] powered by Connect
  • Compression capabilities powered by UglifyJS and CleanCSS
  • Multi-purpose resolution algorithm for both files and partials
  • Simplistic Plugins architecture available for interoperability

[1] For languages that provide it
[2] Simple convenience (also for SPA, redirecting inexistent urls to index.html)

Contents

Dependency Resolution

Polvo uses the same resolution algorithm presented in NodeJS, so you can code your libraries doing global or local require-s as you wish, like if you were building a NodeJS app. In the end, everything will be ready for in-browser use.

★ Of couse, you won't be able to use NodeJS core modules once inside the Browser, such as fs, process, cluster and so on. The same applies to any other module you may find - if it uses any API not available for in-browser use, you won't be able to use it.

Packaging Systems

In order to not lock you up with one single packaging system, Polvo is intended to support some of them. It's not fully functional yet but the plans are there.

★ As each packaging system approaches the subject in its own opinionated way, it may be impossible to aggregate them all in an universal way. However its under serious study and implementation right now to check all possibilities.

At the moment you can use:

  • NPM Full support, hooray!
  • Component Partial support [1]
  • Bower Partial support, with some caveats [2]
  • Ender Yet to be done [3]

[1] Supporting only js and css for now, full implementation is a WIP
[2] TODO: Describe caveats
[3] Pondering the real benefits and possibilities of implementing Ender

Plugins (supported languages)

Again, Polvo is agnostic to languages -- however it needs individual plugins for each language in order to properly assemble it. Some of them is built in out of the box for you joy, and others should be done / installed separately.

Polvo will search and initialize aditional plugins present in the dependencies field of your package.json file.

Built in plugins

Each plugin is an independent repository.

Click the links to see individual README for each one.

★ Scripts

  1. Javascript (.js) Build Status Coverage Status
  2. CoffeeScript (.coffee) Build Status Coverage Status
    • ✓ Literate Coffeescript (.litcoffee, .coffee.md)
    • ✓ Source Maps

★ Styles

  1. CSS (.css) Build Status Coverage Status
    • partials supported
  2. Stylus (.styl) Build Status Coverage Status
    • nib available
    • partials supported

★ Templates

  1. HTML (.htm, .html) Build Status Coverage Status
    • partials supported
  2. Jade (.jade) Build Status Coverage Status
    • partials supported

CLI

Command line interface help screen.

Usage:
  polvo [options] [params]

Options:
  -w, --watch        Start watching/compiling in dev mode                
  -c, --compile      Compile project in development mode                 
  -r, --release      Compile project in release mode                     
  -s, --server       Serves project statically, options in config file   
  -f, --config-file  Path to a different config file                     
  -b, --base         Path to app's root folder (when its not the current)
  -x, --split        Compile files individually - useful for tests coverage
  -v, --version      Show Polvo's version                                
  -h, --help         Shows this help screen                              

Examples:
  polvo -c
  polvo -cs
  polvo -w
  polvo -ws
  polvo -wsf custom-config-file.yml

Config

Polvo's config file is simply a file named polvo.yml in your project.

You'll may need to setup six simple options to adjust Polvo to your needs:

  1. server
  2. input
  3. output
  4. alias
  5. minify
  6. boot

A Polvo's complete config file look such as:

polvo.yml

server:
  port: 3000
  root: ./public

input:
  - src

output:
  js: ./public/app.js
  css: ./public/app.css

alias:
  app: ./src/app

minify:
  js: false
  css: false

boot: ./src/app/app

Server

Basic infos to serve your application, just inform desired port and your public folder.

When using the option -s a basic webserver will be launched to serve the app.

Input

Project's input src folders, can be one or many.

Output

Project's output files, at least one should be specified.

★ If you're using conditional compilation, make sure you're aware that you can reuse the conditional variables to compose the output path for your files.

Alias

It's a handy option that lets you map some names to specific dirs. These names will make folders act like gobal modules in your node_modules folder with all dirs listed in package.json directories field, so you can require them as such.

For example, imagine a structure like this:

myapp
├── polvo.yml
├── src
│   └── app
│       ├── app.coffee
│       ├── controllers
│       │   └── controller.coffee
│       ├── models
│       │   └── model.coffee
│       └── views
│           └── views.coffee
└── vendors
    └── myframework
        └── src
            └── lib
                ├── controller.coffee
                ├── model.coffee
                └── view.coffee

The app's controller.coffee can require the framework's controller.coffee as easy as:

Controller = require '../../../vendors/myframework/src/lib/controller'

However, sometimes these relative paths can get nasty. In these cases, aliases can help the way. Imagine this one:

alias:
  myframework: ./vendors/myframework/src

With this, myframework folder will act as if it was a NPM module present in your node_modules folder, and require calls can be made in global-style regardless of which file is requiring it:

Controller = require 'myframework/lib/controller'

Note that:

  1. The myframework keywork is the virtual alias in the config file
  2. It points to the folder vendors/myframework/src
  3. So requiring myframewok/**/* will be the same as requiring vendors/myframework/src/**/*
  4. Be cautious while using aliases. For instance if you have have an alias with the same name of a module you have in your node_modules folder, you'll end up with serious problems - hopefully you'll notice this immediately.

Minify

In some cases you may want to disable minification in release mode, even though in both development and release mode you'll always have a single .js and .css file.

So what's the catch?

In development mode other things will be injected among your scripts in the app.js file. For example, the LiveReload embedded functionality.

In release mode it's removed, nothing special is injected. So you may want to have a production ready release file (that doesn't includes magic), but at the same time keep it uncompressed. In case you do, that's the way to go.

Boot

By default, Polvo will wrap all your scripts and templates in CJS module and register them all at startup. However, none will be require-d and therefore none will be initialized.

You need to specify your app's entry point within the boot property. With this Polvo will do a simple require to this file at startup, after everything is registered.

Following the config presented above, it'd be:

require( 'src/app/app' );

Conditional compilation

Looking forward for greater flexibility when compiling something for multiple targets, there's 4 directives available to control conditional compilation:

  • polvo:if
  • polvo:elif
  • polvo:else
  • polvo:fi

You can use these in any kind of file you have, be it a template, a style or a script.

These conditionals are processed before files are compiled with each its respective pre-processor and also before their output is scanned for dependencies.

So just insert these directives in form of a comment for the language your are using and they will be processed accordingly.

You can use both equality and inequality operators:

# polvo:if ENV = browser
equality = 'is browser'
# polvo:fi

# polvo:if ENV != browser
inequality = 'is not browser'
# polvo:fi

Example 1 (Browser x NodeJS)

# polvo:if ENV=node
request = require 'node-request-library'
# polvo:elif ENV=browser
request = require 'browser-request-library'
# polvo:fi

request.do_stuff [...]

With this code, you can compile the project in a few different ways, saying which build do you want, i.e.:

Targeting NodeJS

$ ENV=node polvo -c
`

Targeting Browser

$ ENV=browser polvo -c
`

The same example in plain Javascript:

// polvo:if ENV=node
var request = require('node-request-library');
// polvo:elif ENV=browser
var request = require('browser-request-library');
// polvo:fi

request.do_stuff( /* ... */ );

Example 2 (Desktop x Mobile)

Many people choses between JQuery or Zepto depending on what target, lets check how it'd be done easily for having hybrid builds.

# polvo:if ENV=desktop
$ = require 'jquery'
# polvo:elif ENV=mobile
$ = require 'zepto'
# polvo:fi

$('element').do_something [...]

Targeting Desktop

$ ENV=desktop polvo -c
`

Targeting Mobile

$ ENV=mobile polvo -c
`

Example 3 (Advanced)

You can have multiple conditions as well, many elifs and also a final else directive, depending on your needs:

# polvo:if ENV=desktop
$ = require 'jquery'
# polvo:elif ENV=mobile
$ = require 'zepto'
# polvo:elif ENV=node
$ = require 'cheerio'
# polvo:else
$ = require 'god-help'
# polvo:fi

$('element').do_something [...]

Variables naming

In the examples above we used the var ENV to get around the conditionals. However you can use any var you want:


# polvo:if ANIMAL=carnivore
food = require 'meat'
# polvo:elif ANIMAL=herbivore
food = require 'vegetables'
# polvo:fi

[...code here...]

And compile your project using the variables you just declared inside your code:

$ ANIMAL=carnivore polvo -c
$ ANIMAL=herbivore polvo -c
`

Final notes

Some final considerations:

Supported languages

Remember that every language is supported, you just need to add the explained directives in your source file in a form of a comment, so they doesn't affect your code.

All of them will be processed.

Output files

You can use a single polvo.yml with multiple targets, by setting your output file according the vars you're using for conditional compilation.

Example

input:
  - ./src

output:
  js: ./lib/app-{ENV}.js

When compiled with ENV=browser polvo -c, the output js file will be saved as ./lib/app-browser.js.

Or ./lib/app-node.js when compiled with ENV=node polvo -c, and so on.

The same applies for styles.

License

The MIT License (MIT)

Copyright (c) 2013 Anderson Arboleya

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge

更新日志

0.6.5 / 2014-07-01

  • Handling folders with names ending as '.js'

0.6.4 / 2014-01-23

  • Fixing dynamic requires' lookup

0.6.3 / 2013-12-12

  • Improving resolution algorithm for components(io)'s components

0.6.2 / 2013-12-02

  • Handling inequality operator in conditional compilation (closes#29)

0.6.1 / 2013-11-25

  • Fixing conditional compilation (adding line breaks)
  • Fixing relative paths computation for split-mode's script loader
  • Fixing split-mode's script loader (for IE)
  • Improving config parser

0.6.0 / 2013-11-21

  • Adding conditional compilation feature

0.5.7 / 2013-11-13

  • Fixing --split mode (closes #28)
  • Improving sourcemaps computation
  • Segmenting and re-structure whole test suite

0.5.6 / 2013-10-28

  • Fixing LiveReload for styles
  • Fixing config file validation

0.5.5 / 2013-09-20

  • Fixing folder's evaluation when searching for modules
  • Adding no cache for styles-refresh when in dev mode

0.5.4 / 2013-09-16

  • Checking CSS existence before compressing it

0.5.3 / 2013-09-12

  • Using modules cache again to speed up things
  • Adding partial support for Component
  • Adding partial support for Bower

0.5.2 / 2013-09-06

  • Adding --split option (essential for specific tests-coverage approaches)

0.5.1 / 2013-09-06

  • Fixing command line usage
  • Upgrading dependencies
  • Improving polvo-general test

0.5.0 / 2013-09-05

  • Redesigning and rewriting Polvo from the ground up
  • Optimizing everything
  • Adding plugins support
  • Adding full test coverage
  • Switching concept to CJS instead of AMD
  • Building always single JS file, for both production and development modes
  • Mimicking NodeJS resolution algorithm for local and global modules
  • Drastically reducing config file
  • And a lot of more things

0.4.4 / 2013-08-07

  • Fixing optimization routine to properly handle cases when one single dep is required, and this dep is not in AMD format (very specific case)

0.4.3 / 2013-07-30

  • Fixing regexp to match only exact require(...) calls

0.4.2 / 2013-07-29

  • Upgrading dependencies
  • Applying gemnasium conventions to History.md file

0.4.1 / 2013-07-24

  • Fixing regex to find partial's dependents for stylus and jade

0.4.0 / 2013-07-19

  • Adding support for pure CSS, HTML and JS files

0.3.17 / 2013-07-01

  • Simplifying whole test structure, updating testing libraries, fixing everything, green sign

0.3.16 / 2013-06-30

  • Upgrading outdated dependencies

0.3.15 / 2013-06-30

  • Addiong stdio flag, useful for libraries forking polvo as a child process

0.3.14 / 2013-06-20

  • Fixing dumb rush-written code (aka adding method params)
  • Adding status.compiled notification for parent processes

0.3.13 / 2013-06-20

  • Cleaning up all log messages
  • Handling console.* differently when running as a forked process
  • Adding notifications when running as forked process, to provide useful info to parent processes

0.3.12 / 2013-06-18

  • Adding almond to the party, using it instead of standard requirejs for optimized builds (saving some kbs)

0.3.11 / 2013-06-10

  • Adding approach for creating and applying dynamic styles tags in IE8

0.3.10 / 2013-06-09

  • Fixing critical error in Optimizer.reorder (don't know how things were working before, ask God)
  • Cleaning up a bunch of things in Optimizar

0.3.9 / 2013-06-02

  • Fixing indentation / apply of coffeescript files during compile.

0.3.8 / 2013-05-31

  • Fixing helpers merging routine with a simple line break (how did this never broken anything till now? oh my..)

0.3.7 / 2013-05-31

  • Detaching socket.io from polvo server in order to provide livereload across different applications running in different servers (rails for instance, etc)

0.3.6 / 2013-05-23

  • Fixing optimization routine for apps using multiple languages

0.3.5 / 2013-05-23

  • Fixing live reload to work across any machine or device viewing the app

0.3.4 / 2013-05-17

  • Dumb hotfix, publishing compiled file as src maps for core/optimizer/loader

0.3.3 / 2013-05-15

  • Fixing livereload approach for templates [merging #4]

0.3.2 / 2013-05-08

  • Fixing stupid engine version error in 'package.json'

0.3.1 / 2013-05-08

  • Fixing CSS live reload, removing the element first instead of just adding the changed one

0.3.0 / 2013-05-08

  • Handling partials dependency chain recursively.

0.2.9 / 2013-05-08

  • Fixing handling of newly created files
  • Adding properly handling for deleted files

0.2.8 / 2013-05-07

  • Properly handling partials (files starting with '_') for Stylus and Jade.
  • Upgrading 'chai' and 'uglify-js' dependencies.

0.2.7 / 2013-04-26

  • Removing postinstall routine in favor of greater compatibility.

0.2.6 / 2013-04-23

  • Fixing postinstall routine (works corss-platform)

0.2.5 / 2013-04-22

  • Handing 404 links
  • Automatically injecting helpers for the used compilers

0.2.4 / 2013-04-21

  • Upgrading jade dependency.

0.2.3 / 2013-04-21

  • Fixing post-install script
  • Improving builtin server for Single Page Applications

0.2.2 / 2013-04-12

  • Adding LiveReload for development mode

0.2.1 / 2013-04-12

  • Fixing lib version evaluation
  • Removing options not yet ready
  • Fixing memory leak with source-map-support for NodeJS

0.2.0 / 2013-04-12

  • Added Stylus support
  • Added Jade support
  • Added SourceMaps support for CoffeeScript
  • Added support for Literate CoffeeScript (files ending with .coffee.md and .litcoffee)

0.1.0 / 2013-04-04

  • Complete port of Coffee-Toaster to Polvo.

Past forked Project

0.6.12 / NEVER - Coffee-Toaster was discontinued.

  • Fixing Toaster.reset when using Toaster as lib, initializing it with the options hash.
  • Properly segmenting compilation and execution with more combinations using different options combos.
  • Individualizing compile routines between release and debug versions.

0.6.11 / 2012-12-29

  • Listening for changes also in vendors
  • Adding autorun mode (-a) [closing#56] • Thanks to Giacomo Trezzi

0.6.10 / 2012-12-24

  • Fixing aliases again, now in Builder class

0.6.9 / 2012-12-22

  • Fixing path's evaluation also when aliases are in use

0.6.8 / 2012-12-22

  • Fixing path's evaluation for import directives

0.6.7 / 2012-12-20

  • Fixing custom config file evaluation

0.6.6 / 2012-12-15

  • Desmistifying conflicts betweeen Toaster and VIM [closing issue #46]
  • Making toaster cross-platform (Osx, Linux, Win7) [closing issues #29 and #30]
  • Effectively restarting toaster after toaster.coffee file is edited.

0.6.5 / 2012-11-27

  • Fixing generators [closing issue #46]

0.6.4 / 2012-11-18

  • Adding test for initializing existent projects
  • Fixing GROWL icons path

0.6.3 / 2012-07-01

  • Fixing example 'package.' again (the zombie bug)
  • Fixing line number evaluation [closing issue #26]
  • Fixing 'c' / '--compile' option [closing issue #27]
  • Adding first test (finally)

0.6.2 / 2012-06-25

  • Fixing last upgrade in self-toasting system
  • Adjusting everything for self-toasting at version 0.6.2

0.6.1 / 2012-06-16

  • Adjusting everything for self-toasting at version 0.6.0
  • Fixing example package.json file that was broken npm installation

0.6.0 / 2012-06-16

  • Adding 'exclude' property to config file
  • Improving and fixing a bunch of things
  • Completely refactoring fs-util to improve it's usage and avoid memory-leak
  • Organizing single-folder and multi-folder examples
  • Standardizing API for javascript usage
  • Adding 'introspection' example with many javascript uses

0.5.5 / 2012-04-19

  • Config file was re-written to be more practical
  • Build routines removed in favor of simplicity
  • Multi-modules option is default now, without configuring anything
  • HTTP Folder property added to 'toaster.coffee' config file
  • Scaffolding routines improved according the design changes

0.5.0 / 2012-04-12

  • Packaging system completely revamped
  • Added some beauty to log messages
  • Growl integration implemented
  • Expose / Export aliases - export/expose your definitions to another scope
  • Minify support added
  • On/Off switches for:
    • Bare option to compile CoffeeScript with the 'bare' option
    • Packaging system
    • Minify

0.3.8 / 2011-10-29

  • Fixing bugs in generators
  • Fixing a bunch of small emergencial bugs

0.3.7 / 2011-10-29

  • Simplify config file syntax [feature done #8]
  • Adding buid routines [feature done #9]
  • Adding support for vendors across modules and build configs [feature #10]

0.3.6 / 2011-10-25

  • Critical bugfixes in the reorder routine
  • Optimizing architecture
  • Condensing src scructure

0.3.5 / 2011-10-24

  • Avoiding tmp files from being watched [closing issue #4]
  • Adding support for ordinary files again (with no class definitions inside)
  • Now all requirements must to be done based on filepath with slash
    notation "foldera/folderb/filename"
  • Adding extra base class validation
  • Lots of improvements and bugfixes

0.3.0 / 2011-10-16

  • Refactoring entire Script class
  • Support for extends directive have been removed, now all dependencies
    must be informed through '#<< package.name.ClassName'
  • Support for files without class declarations was (sadly) removed
  • Adding full package support automagically
  • Implementing wild-cards on requirements '#<< package.name.*'

0.2.2 / 2011-10-02

  • Starting tests implementation (using Vows BDD)
  • Implementing debug mode (-d --debug). Files are compiled individually
    plus a boot file (toaster.js) file that will load everything in the right order.
  • Improving interactive processes to become good guessers
  • Adding support for file requirements based on 'a/b/c/filepath'
    simultaneously with class requirements based in 'ClassName' notation (both
    are case sensitive)
  • Bumping 'build/coffee-toaster' submodule to use tag 0.2.2 (level up)

0.2.1 / 2011-09-22

  • Implementing OptionParser (using Optimist)

0.2.0 / 2011-09-18

  • Tag 0.1.2 is now used as submodule in order to self-toast (aka manage
    dependencies) of new versions of CoffeeToaster itself, starting from now
  • Refactoring everything, classes are now one per file, using dependency
    directives from CoffeeToaster itself. From now on, things should evolve
    a little easier.
  • Individualizing CoffeeScript handling
  • Starting plans for CoffeeKup and CoffeeCss support

0.1.2 / 2011-09-17

  • Fixing compilation method that was requiring coffee-script to be installed
  • Adding precise error handling
  • Checking circular dependency conflicts [closing issue #2]

0.1.1 / 2011-09-16

  • Adding basic error handling [closing issue #1]

0.1.0 / 2011-09-11

  • Scaffolding routine for new projects
  • Scaffolding routine for configuration file (toaster.coffee)
  • Dependency handlers:
    • Extends directive (class A extends B)
    • Include directive (#<< ClassNameA, ClassNameB..)