glob-the-builder
Build files using glob targets and pull streams
Last updated 2 years ago by savelbr .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glob-the-builder 
SYNC missed versions from official npm registry.

Glob the Builder

A GNU Make and Gulp crossover, using pull-stream in the engine room.

Usage

// build.js

var Build = require('glob-the-builder')
var marked = require('marked')
var pull = require('glob-the-builder/pull')
var transform = require('prop-transform')

var build = Build.dest('public')

build.add('*.html', function html (params) {
  var name = params[0]

  return pull(
    build.src(`src/${name}.md`, 'utf8'),
    build.target(src => `${src.name}.html`),
    pull.map(transform('contents', marked)),
    build.write()
  )
})

build.command()

With this build script, the command node build.js --all will generate a html file in the public folder for all markdown files found in src. Running node build.js new-post.html will only convert src/new-post.md, if it exists. Using the --clean flag on either command will delete all generated files before rebuilding. Because of the way we define targets, files not recognized by Glob the Builder will be left untouched.

Creating sourceless files

If you want to create files programmatically, without a corresponding source file on the system, just define plain objects with the properties path, contents, and if necessary enc for the encoding.

build.add('dat.json', async function manifest () {
  var manifest = {
    url: 'dat://79f4eb8409172d6f1482044245c286e700af0c45437d191d99183743d0b91937/',
    title: 'Site name',
    description: 'Site description'
  }

  return build.write({
    path: 'dat.json',
    contents: JSON.stringify(manifest),
    enc: 'utf8'
  })
})

Pagination and concatenation

You can easily concatenate (or paginate) multiple files using the pull-group module and the file object model described in the previous section.

var group = require('pull-group')

build.add('index.html', function index () {
  return pull(
    build.src('test/src/*.md', 'utf8'),
    pull.map(transform('contents', marked)),
    group(Infinity),
    pull.map(function (files) {
      return {
        path: 'index.html',
        contents: files.map(file => file.contents).join('\n'),
        enc: 'utf8'
      }
    }),
    build.write()
  )
})

Using Gulp plugins

Most Gulp plugins can be used too, using the pull-vinyl and stream-to-pull-stream modules.

var cssnano = require('cssnano')
var postcss = require('gulp-postcss')
var toPull = require('stream-to-pull-stream')
var vinyl = require('pull-vinyl')

build.add('*.css', function styles (params) {
  var plugins = [cssnano]

  return pull(
    vinyl.src(`test/src/${params[0]}.css`),
    toPull.duplex(postcss(plugins)),
    build.target(src => src.base),
    build.write()
  )
})

License

Apache-2.0

Current Tags

  • 0.5.0                                ...           latest (2 years ago)

7 Versions

  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (6)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |