Coder Social home page Coder Social logo

digideskio / productionline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coreybutler/productionline

0.0 1.0 0.0 2.34 MB

An extendable class for creating builds (transpilation, minification, concatenation, etc).

License: MIT License

JavaScript 100.00%

productionline's Introduction

productionline Build Status Greenkeeper badge

npm install productionline --save-dev

An extendable build pipeline class, based on a "queue and run" strategy.

Demo

While gulp and grunt are mature tools with a large ecosystem, some build processes simply don't warrant the complexity. Plus, as awesome as streams are, it's typically easier for most developers think of build processes in sequential steps than stream manipulations. Furthermore, a global executable doesn't have to be a requirement for a build pipeline when Node/npm itself is a) suitable for the task and b) already installed. We prefer to configure npm scripts, executed as npm run build. This module provides an extendable JS Class, serving as a baseline for running any kind of build pipeline.

Examples

See the examples, and feel free to submit PR's with new examples.

Basic Use

The source code is well documented with several feature methods.

The following would go in a file called build.js.

const ProductionLine = require('productionline')
const builder = new ProductionLine({
  commands: {
    default: function (cmd) {
      console.log('No command specified!')
    },

    '--buildme': function (cmd) {
      console.log('Running Build Process:')

      // The following are not explicitly necessary since the source,
      // assets, and destination are all being set to their defaults.
      // However; the code is written so you can supply your own
      // folder structure.
      builder.source = path.resolve('./src')
      builder.assets = path.resolve('./assets') // Relative to source!
      builder.destination = path.resolve('./dist')

      // Queue the built-in make process.
      builder.addTask('My Build Task', function (next) {
        // Do something
        next()
      })
    }
  }
})

builder.run()

In the package.json file, add an npm command like:

{
  "scripts": {
    "test": "...",
    "build": "node build.js --buildme"
  }
}

The entire process can then be run using npm run build.

Extending the Production Line

This is the most anticipated use case, since most build processes are unique in some manner.

Basic ES 2016 class extension is the easiest way to create a custom build tool. The builder queues tasks using an internal shortbus instance, accessible via this.tasks. Once all tasks are queued, the build process can be run.

 const ProductionLine = require('productionline')

 class CustomBuilder extends ProductionLine {
   constructor {
     super()
   }

   // These tasks run before any others.
   before () {
     this.tasks.add('Custom Preprocessing Step', next => { ... })
   }

   // These tasks run after all others.
   after () {
     this.tasks.add('Custom Postprocessing Step', next => { ... })
   }

   make () {
     this.addStep('Custom step', (next) => {
       // Do something
       // ...

       // When complete, run the next queued task.
       next()
     })
   }

   makeDebuggableVersion () {
     this.tasks.add('Custom Step 1', next => {
        someAsynchrnousOperation(() => {
          next()
        })
     })
     this.tasks.add('Custom Step 2', next => { ... })
     this.tasks.add('Custom Step 3', next => { ... })
   }
 }

 const builder = new CustomBuilder({
   commands: {
     '--make': () => {
       console.log('Running Build Process:')

       // Queue the built-in make process.
       builder.make()
       builder.run() // This executes all of the queued tasks.
     },

     '--debug': () => {
       console.log('Running Building Process:')

       // Queue the custom debug process.
       builder.makeDebuggableVersion()
       builder.run() // This executes all of the queued tasks.
     },

     default: () => console.log('No command specified!')

   }
 })

Live Builds

During development, it's often useful to monitor source code and rebuild whenever a file changes. To support this, productionline contains a watch task, which will remain running and respond to file system changes.

For example:

builder.watch((action, filepath) => {
  builder.run()

  builder.watch((action, filepath) => {
    if (action === 'create') {
      console.log('New file created, rerun the build.')
      builder.run()
    }
  })
})

Extensions

productionline's People

Contributors

coreybutler avatar greenkeeper[bot] avatar

Watchers

 avatar

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.