1.3.13 • Published 5 years ago

productionline v1.3.13

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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

1.3.13

5 years ago

1.3.12

6 years ago

1.3.11

6 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.27

7 years ago

1.1.26

7 years ago

1.1.25

7 years ago

1.1.24

7 years ago

1.1.22

7 years ago

1.1.21

7 years ago

1.1.20

7 years ago

1.1.19

7 years ago

1.1.18

7 years ago

1.1.17

7 years ago

1.1.16

7 years ago

1.1.15

7 years ago

1.1.13

7 years ago

1.1.12

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago