npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

development-core

v2.1.6

Published

development tools, generate gulp tasks, gulp task manager, run tasks in sequence via Promise. useful gulp task util: zipSequence, runSequence, runTaskSequence, toSequence, flattenSequence.

Downloads

193

Readme

packaged development-core

This repo is for distribution on npm. The source for this module is in the main repo. Please file issues and pull requests against that repo. This package use to develop kit for project development via gulp tasks.

development-core, generate gulp tasks, gulp task manager, run tasks in sequence via Promise. useful gulp task util: zipSequence, runSequence, runTaskSequence, toSequence, flattenSequence. core of development-tool.

Install

You can install this package either with npm.

npm


npm install development-core

You can import modules:

import module

import * as gulp from 'gulp';
import  { generateTask, runTaskSequence, runSequence } from 'development-core';

run task by sequence via Promise


    runSequence('taskA', ['taskb','taskc'], 'taskd');

New Features

  • v2.0.6 can execute dynamic work.

     let context = createContext({
        env: env,
        option: { src: 'src', dist: 'lib', buildDist: 'build' }
    });

    // console.log(context);

    context.runDynamic([
        {
            name: 'test', src: 'test/**/*spec.ts',
            oper: Operation.test | Operation.default,
            pipes: [mocha],
            output: null
        },
        {
            name: 'tscompile', src: 'src/**/*.ts', dist: 'lib',
            oper: Operation.build,
            pipes: [
                () => cache('typescript'),
                sourcemaps.init,
                (config) => {
                    let transform = tsProject();
                    transform.transformSourcePipe = (source) => source.pipe(transform)['js'];
                    return transform;
                },
                (config) => sourcemaps.write('./sourcemaps')
            ]
        },
        {
            name: 'tscompile', src: 'src/**/*.ts', dist: 'lib',
            oper: Operation.release | Operation.deploy,
            pipes: [
                () => cache('typescript'),
                sourcemaps.init,
                (config) => tsProject()
            ],
            output: [
                (tsmap, config, dt, gulp) => tsmap.dts.pipe(gulp.dest(config.getDist(dt))),
                (tsmap, config, dt, gulp) => tsmap.js
                    .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps'))
                    .pipe(gulp.dest(config.getDist(dt)))
            ]
        },
        { src: 'src/**/*.ts', name: 'watch', watchTasks: ['tscompile'] },
        { name: 'clean', order: 0, src: 'src', dist: 'lib', task: (config) => del(config.getDist()) }
    ]);

define shell task with dynamic task

@dynamicTask()
export class TestDynamicTask implements IDynamicTasks {
    tasks(): IDynamicTaskOption[] {
        return [
            {
                name: 'test-tscompile', src: 'src/**/*.ts', dist: 'lib',
                shell:'docker-compose down & docker-compose build'
            },
            {
                name: 'test-test', src: 'test/**/*spec.ts', order: total => 1 / total, //second.
                shell:['docker tag xxx  xxxx', 'docker tag xxx  xxxx']
            },
            {
                name: 'test-test', src: 'test/**/*spec.ts', order: total => 1 / total, //second.
                shell:(ctx)=>{
                    return ''
                }
            }
        ];
    }
}

define exec file task with dynamic task


@dynamicTask()
export class TestDynamicTask implements IDynamicTasks {
    tasks(): IDynamicTaskOption[] {
        return [
            {
                name: 'test-tscompile', src: 'src/**/*.ts', dist: 'lib',
                execFiles:'./a/task.ts'
            },
            {
                name: 'test-test', src: 'test/**/*task.ts', order: total => 1 / total, //second.
                execFiles:(ctx)=>{
                    return ctx.fileFilter(ctx.getSrc());
                }
            }
        ];
    }
}

define task and taskdefine

decorator not support function now, so refactor ITask interface.

v.9.1: refactor order, to set value between 0 and 1. to make sure right order config easy. default value 0.5; case order value lt than 0 will assign 0; case order value gt than 1, order = (order % sequence.length) / sequence.length;


// module A
import {PipeTask, IPipe, PipeTask, IAsserts, IAssertDist, taskdefine, createContext, Operation, IEnvOption, ITaskContext, ITaskDefine, ITask, ITaskInfo, TaskResult, task, dynamicTask, IDynamicTasks } from 'development-core';

@task()
export class TestPipeTask implements PipeTask {
   // override
   //source(context: ITaskContext, dist: IAssertDist, gulp: Gulp): TransformSource | Promise<TransformSource>{
   //    // todo create source.
   //    // sample as:
   //    return gulp.src(context.getSrc(this.getInfo()));
   //}
   // override
   pipes(context: ITaskContext, dist: IAssertDist, gulp?: Gulp): Pipe[]{
       //create pipes
       return pipes
   }
   // override
   //output(context: ITaskContext, dist: IAssertDist, gulp?: Gulp): OutputPipe[]{
   //    // output pipes.
   //    return outputs;
   //}
}


@task()
export class TestTaskA implements ITask {
   getInfo(): ITaskInfo { return this.info; }
   constructor(private info: ITaskInfo) {
   }
   setup(ctx: ITaskContext, gulp): TaskResult {
       // todo...
       return;
   }
}

@task({
   // build env task. when env.watch equals to true, auto create watch to this task.
   oper: Operation.build | Operation.autoWatch,
   order: 1, // last order.
})
export class TestTaskE implements ITask {
   private info:ITaskInfo;
   constructor() {
   }
   getInfo(): ITaskInfo { return this.info; }
   setInfo(info: ITaskInfo) { this.info = info; }
   setup(ctx: ITaskContext, gulp): TaskResult {
       // todo...
       return 'TestTaskE';
   }
}

@dynamicTask()
export class TestDynamicTask implements IDynamicTasks {
   tasks(): IDynamicTaskOption[] {
       return [
           {
               name: 'test-tscompile', src: 'src/**/*.ts', dist: 'lib',
               // auto create watch task for this asserts when watch in context.
               watch: true,
               pipes: [() => cache('typescript'), sourcemaps.init, tsProject],
               output: [
                   (tsmap, ctx, dt, gulp) => tsmap.dts.pipe(gulp.dest(ctx.getDist(dt))),
                   (tsmap, ctx, dt, gulp) => {
                       if (ctx.oper & Operation.release || ctx.oper & Operation.deploy) {
                           return tsmap.js.pipe(babel({ presets: ['es2015'] }))
                               .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps'))
                               .pipe(gulp.dest(ctx.getDist(dt)));
                       } else {
                           return tsmap.js.pipe(sourcemaps.write('./sourcemaps')).pipe(gulp.dest(ctx.getDist(dt)));
                       }
                   }
               ]
           },
           {
               name: 'test-test', src: 'test/**/*spec.ts', order: total => 1 / total, //second.
               oper: Operation.test | Operation.release | Operation.deploy,
               pipe(src) {
                   return src.pipe(mocha())
                       .once('error', () => {
                           process.exit(1);
                       });
               }
           },
           //{ name: 'test-watch', src: 'src/**/*.ts', watchTasks: ['tscompile'] },
           { name: 'test-clean', order: 0, src: 'src', dist: 'lib', task: (ctx) => del(ctx.getDist()) }
       ];
   }
}

import * as _ from 'lodash';
import { ITask, IAssertOption, IEnvOption, IContextDefine, ITaskContext, ITaskConfig, taskdefine } from 'development-core';

import { INodeTaskOption } from './NodeTaskOption';
export * from './NodeTaskOption';

import { CleanDynamicTasks, TestDynamicTasks } from './tasks/nodeDefaultTask';

@taskdefine()
export class NodeContextDefine implements IContextDefine {

    loadConfig(option: IAssertOption, env: IEnvOption): ITaskConfig {
        // register default asserts.
        option.asserts = _.extend({
            ts: { loader: 'development-assert-ts' }
        }, option.asserts || {});

        return <ITaskConfig>{
            option: option,
            env: env
        };
    }
    // set add component or same task for this context.
    setContext(ctx: ITaskContext) {
        let nodeOption = ctx.option as INodeTaskOption
        if (nodeOption.test === false) {
            return;
        }
        ctx.add(<ITaskConfig>{
            option: <IAssertOption>{
                name: 'test',
                order: nodeOption.testOrder || (total => 2 / total),
                loader: (ctx) => {
                    return ctx.findTasks(TestDynamicTasks);
                }
            }
        });
        //...
        //ctx.addTask(task)
        //ctx.removeTask(task)
    }
    // custome load current context tasks
    tasks(context: ITaskContext): Promise<ITask[]> {
        // current context tasks
        return context.findTasks(CleanDynamicTasks);
    }
}


create task with order

default order value 0.5


@task({
    order: total => 1 / total // second order.
})
export class TestTaskB implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskB');
    }
}



@task({
    order: 1, // last order.
    oper: Operation.build | Operation.test
})
export class TestTaskC implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskC');
    }
}

@task({
    order: 0, //first order.
    oper: Operation.release | Operation.deploy
})
export class TestTaskD implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskD');
    }
}


@task({
    order: (total, ctx) => (ctx.oper & Operation.release)?  1 / total : 4 / total,
    oper: Operation.build | Operation.test
})
export class TestTaskW implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskW');
    }
}

// run tasks  by parallel which value is same as 0.2
@task({
    order: <IOrder> { value: 0.2, runWay: RunWay.parallel  }
})
export class TestTaskB implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskor1');
    }
}

// run this task by parallel which value is same as 0.25 and in test env.
@task({
    order: (total, ctx) => ctx.env.test ? { value: 0.25, runWay: RunWay.parallel } : 1,
})
export class TestTaskB implements ITask {
    getInfo(): ITaskInfo { return this.info; }
    constructor(private info: ITaskInfo) {
    }
    setup(ctx: ITaskContext, gulp): TaskResult {
        // todo...

        return ctx.taskName('TestTaskor2');
    }
}

define task by group



@task({
    group: ['test', 'node']
    oper: Operation.build | Operation.test
    ...
})
export class TestTaskGA implements ITask {
    public decorator: ITaskInfo = {};
    constructor() {
    }
    setup(ctx: ITaskConfig, gulp): TaskResult {
        // todo...
        return 'TestTaskGA';
    }
}
@task({
    group: 'node',
    oper: Operation.build | Operation.test
    ...
})
export class TestTaskGB implements ITask {
    public decorator: ITaskInfo = {};
    constructor() {
    }
    setup(ctx: ITaskConfig, gulp): TaskResult {
        // todo...
        return 'TestTaskGB';
    }
}

@task({
    group: ['test', 'node'],
    oper: Operation.build | Operation.test
    ...
})
export class TestTaskGC implements ITask {
    public decorator: ITaskInfo = {};
    constructor() {
    }
    setup(ctx: ITaskConfig, gulp): TaskResult {
        // todo...
        return 'TestTaskGC';
    }
}

@dynamicTask({
    group: 'ts',
    oper: Operation.build | Operation.test
    ...
})
export class TestTaskC implements IDynamicTasks {
    tasks(): IDynamicTaskOption[]{
        return [
            {
                name: 'tscompile', src: 'src/**/*.ts', dist: 'lib',
                // auto create watch task for this asserts when watch in context.
                watch: true,
                pipes: [() => cache('typescript'), sourcemaps.init, tsProject],
                output: [
                    (tsmap, ctx, dt) => tsmap.dts.pipe(gulp.dest(ctx.getDist(dt))),
                    (tsmap, ctx, dt) => {
                        if (ctx.oper & Operation.release || ctx.oper & Operation.deploy) {
                            return tsmap.js.pipe(babel({ presets: ['es2015'] }))
                                .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps'))
                                .pipe(gulp.dest(ctx.getDist(dt)));
                        } else {
                            return tsmap.js.pipe(sourcemaps.write('./sourcemaps')).pipe(gulp.dest(ctx.getDist(dt)));
                        }
                    }
                ]
            }
        ]
    }
}

Compose Context, generateTask, loader in module or load in dir

special pipe work or add special output work with class implements IDynamicTasks, class extends PipeTask. also you can implements IPipeTask or ITask by youself.


// module use.
import { findTasks, createContext, Operation, runTaskSequence, findTaskDefine }  from 'development-core';

let ctx = createContext({
    env: env,
    option: {
        src: 'src',dist: 'lib'
    }
});

// dynamic
ctx.generateTask([
    // dynamic
    {
        name: 'test', src: 'test/**/*spec.ts', order: 1,
        oper: Operation.test | Operation.release | Operation.deploy,
        pipe(src) {
            return src.pipe(mocha())
                .once('error', () => {
                    process.exit(1);
                });
        }
    },
    { src: 'src/**/*.ts', name: 'watch', watchTasks: ['tscompile'] },
    { name: 'clean', order: 0, src: 'src', dist: 'lib', task: (ctx)
    ...
]);

// compose context.
let ctx2 = createContext({
    env: env,
    option: {
        src: 'src',dist: 'lib'
    }
}, ctx);
//or
ctx.add(ctx2);
ctx.add(option);
ctx.add(ITaskConfig);

//find module or dir.
ctx.findTasks('module a')
    .then(module_task =>{
        // run task;
        return ctx.findTasksInDir('task path');
    })
    .then((dir_task)=>{
        return ctx.run();
    });

user task by task define


// module use.
import { findTasks, Operation, runTaskSequence, findTaskDefine }  from 'development-core';
let moduleA = require('module a');
let tasks = findTasks(moduleA);
let tdfs = findTaskDefine(moduleA);

// run task;
runTaskSequence(gulp, tasks, tdfs.loadConfig({src:'src', dist:'lib'}, {watch:true}));

Create development tool with dynamic tasks via Promise


import * as gulp from 'gulp';
import { createContext, generateTask, runTaskSequence, IEnvOption, Operation } from 'development-core';
import * as mocha from 'gulp-mocha';
import * as minimist from 'minimist';
import * as _ from 'lodash';

const del = require('del');
const cache = require('gulp-cached');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
let tsProject = ts.createProject('tsconfig.json');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');

gulp.task('build', () => {
    var options: IEnvOption = minimist(process.argv.slice(2), {
        string: 'env',
        default: { env: process.env.NODE_ENV || 'development' }
    });
    return createTask(options);
});

let createTask = (env) => {

    let ctx = createContext({
        env: env,
        option: {
            src: 'src',
            dist: 'lib',
            // auto create watch task for this asserts or special task.
            watch: true | [taskname|callback]
        }
    });

    ctx.generateTask([
        {
            name: 'tscompile', src: 'src/**/*.ts', dist: 'lib',
            // auto create watch task for this asserts when watch in context.
            watch: true,
            oper: Operation.build,
            pipes: [
                () => cache('typescript'),
                sourcemaps.init,
                (ctx) => {
                    let transform = tsProject();
                    transform.transformSourcePipe = (source) => source.pipe(transform)['js'];
                    return transform;
                },
                (ctx) => babel({ presets: ['es2015'] }),
                (ctx) => sourcemaps.write('./sourcemaps')
            ]
        },
        {
            name: 'tscompile', src: 'src/**/*.ts', dist: 'lib',
            oper: Operation.release | Operation.deploy,
            pipes: [
                () => cache('typescript'), sourcemaps.init, tsProject
            ],
            output: [
                (tsmap, ctx, dt, gulp) => tsmap.dts.pipe(gulp.dest(ctx.getDist(dt))),
                (tsmap, ctx, dt, gulp) => tsmap.js.pipe(babel({ presets: ['es2015'] }))
                    .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps'))
                    .pipe(gulp.dest(ctx.getDist(dt)))
            ]
        },
        {
            name: 'test', src: 'test/**/*spec.ts', order: 1,
            oper: Operation.test | Operation.release | Operation.deploy,
            pipe(src) {
                return src.pipe(mocha())
                    .once('error', () => {
                        process.exit(1);
                    });
            }
        },
        { src: 'src/**/*.ts', name: 'watch', watchTasks: ['tscompile'] },
        { name: 'clean', order: 0, src: 'src', dist: 'lib', task: (ctx) => del(ctx.getDist()) }
    ]);

    return ctx.run();
}

https://github.com/zhouhoujun/development-core.git The mocks are then available at jspm_components/development-core/development-core.js.

Documentation

Documentation is available on the development-core docs site.

License

MIT © Houjun