Functional task runner for Node.js

// write tasks file once, publish it and then reuse or even extend

// in all projects using `start.preset` option in `package.json`,

// something like `my-start-preset` package with everything included


import sequence from '@start/plugin-sequence'

import parallel from '@start/plugin-parallel'

import xargs from '@start/plugin-xargs'

import find from '@start/plugin-find'

import findGitStaged from '@start/plugin-find-git-staged'

import remove from '@start/plugin-remove'

import read from '@start/plugin-read'

import rename from '@start/plugin-rename'

import write from '@start/plugin-write'

import babel from '@start/plugin-lib-babel'

import typescriptGenerate from '@start/plugin-lib-typescript-generate'

import eslint from '@start/plugin-lib-eslint'

import {

istanbulInstrument,

istanbulReport,

istanbulThresholds

} from '@start/plugin-lib-istanbul'

import tape from '@start/plugin-lib-tape'

import codecov from '@start/plugin-lib-codecov'


const babelConfig = {

babelrc: false,

presets: [

[

'@babel/preset-env',

{

targets: {

node: 6

},

modules: false

}

],

'@babel/preset-typescript'

]

}


// each named export is a "task"

export const build = (packageName: string) =>

sequence(

find(`packages/${packageName}/**/*.ts`),

read,

babel(babelConfig),

rename((file) => file.replace(/\.ts$/, '.js')),

write(`packages/${packageName}/build/`)

)


export const dts = (packageName: string) =>

sequence(

find(`packages/${packageName}/**/*.ts`),

typescriptGenerate(`packages/${packageName}/build/`)

)


export const pack = (packageName: string) =>

sequence(

find(`packages/${packageName}/build/`),

remove,

// child-processes

parallel(['build', 'dts'])(packageName)

)


// child processes

export const packs = xargs('pack')


export const dev = (packageName: string) =>

watch(`packages/${packageName}/**/*.ts`)(

build(packageName)

)


export const lint = () =>

sequence(

findGitStaged(['packages/*/{src,test}/**/*.ts']),

read,

eslint()

)


export const lintAll = () =>

sequence(

find(['packages/*/{src,test}/**/*.ts']),

read,

eslint()

)


export const test = () =>

sequence(

find(`coverage/`),

remove,

find('packages/*/src/**/*.ts'),

istanbulInstrument({ esModules: true, extensions: ['.ts'] }),

find('packages/*/test/**/*.ts'),

tape(),

istanbulReport(['lcovonly', 'html', 'text-summary']),

istanbulThresholds({ functions: 100 })

)


export const ci = () =>

sequence(

// nested task

lintAll(),

// nested task

test(),

find('coverage/lcov.info'),

read,

codecov

)