New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

glob-the-builder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-the-builder

Build files using glob targets and pull streams

latest
Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

build

FAQs

Package last updated on 17 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts