ysmood / nokit

A light weight set of handy tools for real world program.
51 stars 6 forks source link

Overview

A light weight set of handy tools for real world program.

Reduce the gap between different systems. Such as watch directory changes on a network file system, operate spawn on Windows and Linux, handle async IO api with promise, etc.

Rather than help you decide what to do, it is designed to create possibilities. Even this document is generated by nokit itself.

NPM version Build Status Build status Deps Up to Date

Features

Installation

As a lib dependency, install it locally: npm i nokit.

Changelog

Goto changelog

API

Table of Content

CLI

Auto-Runner

noe is a dev tool to run / watch / reload program automatically. Run noe -h to see what you can do with it.

For more help, run: noe -h.

Static File Server

nos is a tool to statically serve a folder. Run nos -h to see what you can do with it.

For more help, run: nos -h.

Temote TTY

nor is a cross platform remote tty tool.

For more help, run: nor -h.

kit

proxy

sse

drives

Quick Start

Here it will automatically lint, compile, compress and cache files by their extensions. You can goto Drives section to see what extensions are supported, or write your own.

let kit = require('nokit');
let drives = kit.require('drives');

kit.warp('src/**/*.@(jade|less|coffee|ls)')
    // // To disable cache.
    // .load drives.reader isCache: false
    .load(drives.auto('lint'))
    .load(drives.auto('compile', { '.coffee': { bare: false } }))
    .load(drives.auto('compress'))
    .load(concat('main.js'))
.run('dist/path');

Write your own drives

Nokit has already provided some handy example drives, you can check them in the Drives section. It's fairly easy to write your own.

let kit = require('nokit');
let coffee = require('coffee-script');

// A drive for coffee, a simple curried function.
let compiler = (opts) => function () {
    // Change extension from '.coffee' to '.js'.
    this.dest.ext = '.js';
    this.set(coffee.compile(this.contents, opts));
};

// A drive to prepend lisence to each file.
// Here "fileInfo.set" is the same with the "@set".
let lisencer = (lisence) => function (fileInfo) {
    this.set(lisence + '\n' + this.contents)
}

// A drive to concat all files. It will override the default writer.
let concat = (outputFile) => {
    let all = '';

    // Object.assign
    return kit._.assign(function () {
        all += this.contents;
    }, { isWriter: true, onEnd: function () {
        // This will enable the auto-cache.
        this.deps = kit._.pluck(this.list, 'path');

        this.dest = this.to + '/' + outputFile;
        this.set(all);

        // Call the overrided writer.
        // Call two times and create two output files.
        this.super().then(() => {
            this.dest = this.dest + '.info';
            this.set = '/* info */\n' + all;
            this.super();
        });
    } });
};

kit.warp('src/**/*.coffee')
    .load(compiler(bare: true))
    .load(lisencer('/* MIT lisence */'))
    .load(concat('bundle.js'))
.run('dist')
.then(() => {
    kit.log('Build Done');
});

Contribution

Unit Test

npm test or npm run no -- test

Others

Run npm run no -- -h for all command you can use. Such as run npm run no -- build to build this project.

Docs

Edit the templete of the readme at doc/readme.jst.md.

Lisence

MIT