GithubHelp home page GithubHelp logo

powmedia / buildify Goto Github PK

View Code? Open in Web Editor NEW
123.0 9.0 21.0 337 KB

Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.

License: MIT License

JavaScript 100.00%

buildify's Introduction

buildify

Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.

Install

Requires NodeJS to run.

Then install buildify via npm:

npm install buildify

Create a file with your build script (see the example in 'Usage' below), call it something like build.js and then run it with:

node build.js

Usage

var buildify = require('buildify');

buildify()
  .load('base.js')
  .concat(['part1.js', 'part2.js'])
  .wrap('../lib/template.js', { version: '1.0' })
  .save('../distribution/output.js')
  .uglify()
  .save('../distribution/output.min.js');

API

buildify([dir, options])

Create a new Builder instance.

Takes the starting directory as the first argument, e.g. __dirname. If this is not set, the current working directory is used.

Options:

  • interpolate Underscore template settings. Default to mustache {{var}} style interpolation tags.
  • encoding File encoding (Default 'utf-8')
  • eol End of line character (Default '\n')
  • quiet Whether to silence console output

setDir(absolutePath)

Set the current working directory.

changeDir(relativePath)

Change the current working directory.

setContent(content)

Set the content to work with.

getContent()

Get the current content. Note: breaks the chain.

load(file)

Load file contents.

concat(files, [eol])

Concatenate the content of multiple files.

buildify()
    .concat(['file1.js', 'file2.js']);

wrap(template, [data])

Wrap the contents in a template.

Useful for creating AMD/CommonJS compatible versions of code, adding notes/comments to the top of the file etc.

By default the template uses Mustache-style tags and has a special tag, {{body}} which is where the contents are placed.

Other custom tags can be included and passed in the data argument.

//template.js
/*
 * This is a module for doing stuff.
 * Version {{version}}.
 */
(function() {
    //Setup code can go here

    {{body}}
});

//build.js
buildify()
    .load('src.js')
    .wrap('template.js', { version: '1.0' });

perform(fn)

Perform a function on the content. The content is set to what the function returns.

buildify()
    .load('src.js')
    .perform(function(content) {
        return content.replace(\assetpath\g, 'http://cdn.example.com');
     });

uglify(options)

Minimise your JS using uglifyJS.

Options:

  • mangle: Whether to mangle output from UglifyJS. Default: true

cssmin([maxLineLength])

Minimise your CSS using clean-css. Optionally a line break is inserted after 'maxLineLength' characters in the minimized css file.

save(file)

Save the contents to a file.

clear()

Reset/clear contents.

Tasks

Buildify supports tasks, allowing to separate a build script in different sections. Dependencies can be specified between tasks. By specifying tasks names as command line arguments, buildify will only run the specified tasks, taking into account their dependencies

For example create a script named buildify.js with the following contents:

var buildify = require('buildify');

buildify.task({
  name: 'task2',
  depends: ['task1'],
  task: function () {
    console.log('task2...');
  }
});

buildify.task({
  name: 'task1',
  task: function () {
    console.log('task1...');
  }
});

To run all tasks, just run the script:

node buildify.js

To run a specific task, specify the task name as command line arguments.

node buildify.js concat

Tasks API

buildify.task(options)

Create a task.

Options:

  • name A string containing the task name
  • desc An optional description of the task
  • depends An optional string or an array with strings containing the name(s) of tasks which this task depends on.
  • task: The function to be executed as task, doing the actual work. Optional.

Command Line Interface

When installed globally, the command line application buildify is available. Running buildify will execute the script named buildify.js in the current directory (typically the root of a project).

buildify [tasks]

Optionally, a list of task names can be provided to only execute specified tasks. If no tasks are provided, buildify will run the script including all tasks.

Changelog

0.4.0 Implemented tasks (josdejong)

0.3.1 Fix mangling (can be disabled with mangle: false option in uglify()) (powmedia, whadar)

0.3.0 Add cssmin() for minifying CSS (RustyMarvin) Fix tests under Windows (RustyMarvin)

0.2.0 Add perform() for custom functions (trevorgerhardt)

buildify's People

Contributors

gabeatwork avatar josdejong avatar mhweiner avatar powmedia avatar rustymarvin avatar trevorgerhardt 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

buildify's Issues

Support for filename patterns in concat

It would be very powerful when you could concatenate all files or a filtered set of files with buildify at once, something like:

var buildify = require('buildify');

buildify()
    .concat('./src/*.js')
    .wrap('../lib/template.js', { version: '1.0' })
    .save('../distribution/output.js')
    .uglify()
    .save('../distribution/output.min.js');

The functionality offered by the module fileset comes very close, though fileset works asynchronously.

Versioning and npm

Hey! Great little tool, thanks! Just wondered if you could bump the version number and publish to npm? Currently the version on npm is 0.2.0 (same as the master branch) but is missing the clean-css commits.

Just to make deploying to heroku a little easier :)

Cheers!

Support for tasks

Buildify covers what I typically need when building a library very well: concat, wrap, minify, etc. Building is not that complicated and I really like the minimalistic though flexible and powerful approach of Buildify.

However one feature that is really useful to me is tasks, so I can modularize my build process (have tasks like build, minify, test), so I have a way to only execute a part of it via the command line.

I'm not sure if and how tasks would fit in Buildify. Any thoughs on this?

Thank you

Came here to say that this library is beautiful. Thank you for your work. It helped me a lot. This is not really an issue though :)

App Cache Manifest Generation for HTML5 Apps

The HTML5 App Cache feature is usually associated with the ability of offline capability but in my opinion the strongest capability this brings is fast (really fast) app start up. That's especially important on mobile and brings Web Apps closer to parity with Native Apps.

I haven't found this around anywhere yet but I think it's an obvious killer feature.

It would provide a configurable way to walk through the build source tree and generate the manifest (or part of it).
It would also update the tag to reference the manifest.
It would be configurable in terms what to include/exclude, insert a version number and all that sort of stuff.

This would be great!

Release a new version including latest commits to avoid vulnerability with uglify-js

In 2017 this commit replaced the use of uglify-js by uglify-es : a14c305

However it has not been released and the latest version of buildify on npm registry, v0.4.0, still uses [email protected].

Moreover, GitHub security alerts detect that uglify-js should be used in version 2.6.0 or higher to avoid 2 vulnerabilities : CVE-2015-8857 & CVE-2015-8858

Hence, could you please publish a new version on npm registry to solve this security alert ?

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.