Code Monkey home page Code Monkey logo

beelzebub's People

Contributors

fatkhi avatar jstty avatar reup-joe-sutton avatar valgaze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

beelzebub's Issues

Only an array of parallel tasks causes an error

bz.add(MyTasks);

bz.run( // all args run in sequence
  ['MyTasks.task1',
    'MyTasks.task2'
  ]);

image

(Full example):

'use strict';
// !-- FOR TESTS
let wrapper = function (options) {
// --!

// =====================================================
  let Beelzebub = require('../../');
  let bz = Beelzebub(options || { verbose: true });

  class MyTasks extends Beelzebub.Tasks {
    constructor (config) {
      super(config);
      this.$setName('MyTasks');

      this._delayTime = 500;
    }

    _delay (message, delay) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          this.logger.log(message);
          resolve();
        }, delay);
      });
    }

    /**
     * Promise based task
     */
    task1 () {
      this.logger.log('MyTasks task1: before');
      return this._delay('MyTasks task1: promise delay ' + this._delayTime, this._delayTime)
        .then(() => {
          this.logger.log('MyTasks task1: after');
        });
    }

    /**
     * generator based tasks
     */
    * task2 () {
      let delay = this._delayTime + 200;
      this.logger.log('MyTasks task2: before');
      yield this._delay('MyTasks task2: yield delay ' + delay, delay);
      this.logger.log('MyTasks task2: after');
    }

    /**
     * async/await based task
     */
    // async task3() {
    //    this.logger.log('MyTasks task3: before');
    //    await this._delay('MyTasks task3: await delay'+this._delayTime);
    //    this.logger.log('MyTasks task3: after');
    // }
}
  bz.add(MyTasks);

  bz.run( // all args run in sequence
    [ // arrays run in parallel
      'MyTasks.task1',
      'MyTasks.task2'
        //, 'MyTasks.task3'
    ]
);
// =====================================================

// !-- FOR TESTS
  return bz; };
module.exports = wrapper;
// if not running in test, then run wrapper
if (typeof global.it !== 'function') wrapper();
// --!

Beelzebub $init method to receive initial cli args

Imagine I have a lint task:

class Lint extends Beelzebub.Tasks {
    constructor(config) {
        super(config);
        this.$setName('lint');
        this.$setDefault('default');
    }

    default(options) {
        if (options.verbose) {
            this.$setGlobalVars({ verbose: true });
        }
        this.sequence('lint.frontend', 'lint.server');
    }

    frontend() {
        // lint for frontend
    }

    server() {
        // lint for server
    }
}

Now imagine I call bz lint --verbose, meaning I want verbose logs. The above example properly sets verbose as global since we are going through the default task.

However, if I go through bz lint.frontend --verbose or bz lint.server --verbose instead of bz lint --verbose, the global variable is no longer set. This means I need to add another verbose check to each task that could be invoked by beelzebub:

class Lint extends Beelzebub.Tasks {
    constructor(config) {
        super(config);
        this.$setName('lint');
        this.$setDefault('default');
    }

    default(options) {
        if (options.verbose) {
            this.$setGlobalVars({ verbose: true });
        }
        this.sequence('lint.frontend', 'lint.server');
    }

    frontend(options) {
        if (options.verbose) {
            this.$setGlobalVars({ verbose: true });
        }
        // lint for frontend
    }

    server(options) {
        if (options.verbose) {
            this.$setGlobalVars({ verbose: true });
        }
        // lint for server
    }
}

This works but is tedious, especially for classes with many tasks. Ideally there would be just one place where global variables are set. Is this currently possible with beelzebub? If not, I think a good place could be the $init method

class Lint extends Beelzebub.Tasks {
    constructor(config) {
        super(config);
        this.$setName('lint');
        this.$setDefault('default');
    }

    $init(options) {
        if (options.verbose) {
            this.$setGlobalVars({ verbose: true });
        }
    }

    default() {
        this.sequence('lint.frontend', 'lint.server');
    }

    frontend() {
        // lint for frontend
    }

    server() {
        // lint for server
    }
}

default task referanced by name does not work

let Beelzebub = require('beelzebub');
let bz = Beelzebub();

class MyTasks extends Beelzebub.Tasks {
    constructor (config) {
        super(config);
        this.$setDefault('task');
    }
   
   task () {
        this.logger.log('task');
   }
}

bz.add(MyTasks);
let p = bz.run('MyTasks'
, 'MyTasks.task' // this throws errors
);

Add Virtual file system

Adding a virtual file system would:

  1. improve creating task tests
  2. enable real task dry runs
  3. enable single shell file creation (bz-bundle)

globalVars not default to empty Object

let Beelzebub = require('beelzebub');
let bz = Beelzebub();

class MyTasks extends Beelzebub.Tasks {
    default () {
       var globalVars = this.$getGlobalVars() // will result return "null", it should be an empty object
       this.logger.log('globalVars:', globalVars);
   }
}
bz.add(MyTasks);
bz.run('MyTasks');

$init behavior

If we run 1 separate task, $init methods of every task would be invoked. It strongly decreases performance in cases, when we have yanpm installing modules in this $init hooks.

Add bz task bundle cli tool

Something like

bz-bundle --type=sh --in=mytasks.js --out=bundle.sh

Would bundle all the js code into one single bundled file that is marked executable and wrapped to execute shell script (# !/bin/sh)
There is lots of ways the file(s) could be bundled/compressed as well. So an optimzation flag could be added later.

$beforeAll, $beforeEach, $afterEach in parent is not invoked when subtask is called directly.

imagine we have:

class MyBaseTasks extends Beelzebub.Tasks {
    
    $beforeEach () {
        console.log('MyBaseTasks beforeEach');
    }

    $afterEach () {
        console.log('MyBaseTasks afterEach');
    }

    $beforeAll () {
        console.log('MyBaseTasks beforeAll');
    }

    $afterAll () {
        console.log('MyBaseTasks afterAll');
    }

    task() {}
}

class MyTasks extends Beelzebub.Tasks {
    
    $init () {
        console.log('MyTasks init');
        this.$addSubTasks(MyBaseTasks);
    }
    
    default() {
        return this.$sequence('.MyBaseTasks.task');
    }

    $beforeEach () {
        console.log('MyTasks beforeEach');
    }

    $afterEach () {
        console.log('MyTasks afterEach');
    }

    $beforeAll () {
        console.log('MyTasks beforeAll');
    }

    $afterAll () {
        console.log('MyTasks afterAll');
    }
}

bz.add(MyTasks);
let p = bz.run('MyTasks.MyBaseTasks.task');

output would be:

MyTasks init
MyBaseTasks beforeAll
MyBaseTasks beforeEach
[00:00.014] └─┐ task
[00:00.017] ┌─┘ task (0.23ms)
MyBaseTasks afterEach
MyBaseTasks afterAll
MyTasks afterAll

should be at least with $beforeAll hook, because it's used for initialization that subtask could rely on :

MyTasks init
MyTasks beforeAll
MyBaseTasks beforeAll
MyBaseTasks beforeEach
[00:00.014] └─┐ task
[00:00.017] ┌─┘ task (0.23ms)
MyBaseTasks afterEach
MyBaseTasks afterAll
MyTasks afterAll

(feature) pipe in file contents

could be used for CLI and making your own scripts
Example:

#!/bin/env bz
const bz = require('bz');
class MyTask extends bz {
...
}

(feature) show task logs as tree like

[2016...] Test 1
[2016...] -> Starting Task
[2016...] | Test 1 Logs...
[2016...] | Sub Test 1
[2016...] | -> Starting Task
[2016...] | | Sub Test 1 Logs...
[2016...] | <- Finished Task []
[2016...] | Sub Test 2
[2016...] | -> Starting Task
[2016...] | | Sub Test 2 Log 1...
[2016...] | | Sub Test 2 Log 2...
[2016...] | <- Finished Task []
[2016...] <- Finished Task []
[2016...] Summary
[2016...] Total Time: <>

Maybe use:
https://github.com/substack/node-archy
or
https://github.com/MrRaindrop/tree-cli

add interface transparency for tasks

let Beelzebub = require('beelzebub');
let bz = Beelzebub();

class MyRealTasks extends Beelzebub.Tasks {
    task1 () {
       this.logger.log('MyRealTasks task1');
   }

   task2 () {
       this.logger.log('MySubTasks task2');
   }
}

class MyTaskInterface extends Beelzebub.Tasks {
    constructor (config) {
        super(config);
    }

    $beforeAll () {
        // this allows for dynamic interfacing base on configuration
        this.$isInterfactFor(MyRealTasks);
    }

    task1 () {
       this.logger.error('should be overriden');
    }

    task2 () {
       this.logger.error('should be overriden');
    }
}
bz.add(MyTaskInterface);
bz.run('MyTaskInterface.task1');

allow for $addSubTasks in $beforeAll

let Beelzebub = require('beelzebub');
let bz = Beelzebub();

class MySubTasks extends Beelzebub.Tasks {
    default () {
       this.logger.log('MySubTasks default');
   }
}

class MyTasks extends Beelzebub.Tasks {
    $beforeAll () {
        this.$addSubTasks(MySubTasks);
    }

    default () {
       this.logger.log('MyTasks default');
   }
}
bz.add(MyTasks);
bz.run('MyTasks.MySubTasks');

add more examples

add more examples with each example highlighting each features
possible get rid of "kitchen sink" example

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.