bunbun
v3.0.3
Published
Node.JS based simple, lightweight task bunner... I mean runner\*
Downloads
4
Readme
bunbun
Node.JS based simple, lightweight task bunner... I mean runner
Why?
⏱ Lightweight and very fast - very simple in design, without any library compilers that you will never use, just plain task runner
📐 Ready to use - just add to your project, create file and prepare your first task
🔌 Extendable - "extends-by-code" philosophy - you are owner of your build flow, without any magic and invisible parts/configurations etc., neither no compilers included
✨ Universal - this library contains only language/tool/framework agnostic tools, all compilations/copying things are in your hands
🎈 Without magic - all of your tasks are just JS code, without any configs, 3rd-party plugins etc. just plain source code, therefore the learning curve is very low
🐞 Debuggable - debugging is very simple because none of all tasks are done invisibly underhood, it's easy to find erroring part if you see all steps of build process, also you can enable debugging mode in Bunbun to log all things
🧰 Safe versioning - version of Bunbun will never break any of building processes because Bunbun don't conains any API for them, updating Bunbun will need from you only update your building script - it's all, you will never have to wait for a some plugin to be updated
Requirements
Node.JS >= 7.6v
- ...because of default support of async/await syntax
- or
Node.JS >= 10v
- ...for execution and handling processes
NPM
How to install?
Simplest way is just using npm:
npm install --save-exact --save-dev bunbun
Real example
Example code:
const { build } = require('esbuild');
const nodeSass = require('node-sass');
const Bunbun = require('./../dist/main.js');
const sass = args => new Promise((res, rej) => {
nodeSass.render(args, (err, data) => {
err ? rej(err) : res(data);
});
});
const hash = async file => {
const res = await $.fs.hash(file, 'md5', 'base64');
return res.replace(/[^a-z0-9]/gi, '');
};
const SOURCE_EXTS = '(scss|ts|tsx|js|jsx|html)';
const $ = new Bunbun;
$.task('build:typescript', async () => {
await $.until('hash');
await build({
sourcemap: true,
format: 'iife',
minify: true,
bundle: true,
outfile: './build/index.js',
entryPoints: ['./src/index.tsx'],
platform: 'browser',
tsconfig: './tsconfig.json',
define: {
'process.env.NODE_ENV': '"develop"',
},
});
$.run('hash');
});
$.task('build:scss', async () => {
await $.until('hash');
const result = await sass({
file: './src/index.scss',
sourceMap: './index.css.map',
outFile: './index.css',
outputStyle: 'compressed',
sourceMapContents: true,
});
await $.fs.write('./build/index.css', result.css || '');
await $.fs.write('./build/index.css.map', result.map || '');
$.run('hash');
});
$.task('hash', async () => {
await $.fs.edit('./src/index.html', async html => {
const jsHash = await hash('./build/index.js');
const cssHash = await hash('./build/index.css');
return html
.replace('__JS_HASH__', jsHash)
.replace('__CSS_HASH__', cssHash);
});
});
$.alias('build', ['build:typescript', 'build:scss']);
$.task('assets', async () => {
let list = await $.fs.list(['./src/**/*.*', `!**/*.${SOURCE_EXTS}`]);
for (const x of list) {
await $.fs.copy(x, x.replace(/^\.\/src/, './build'));
}
});
$.task('watch', async () => {
const server = $.serve('./build', 8080);
$.fs.watch(`./src/**/*.${SOURCE_EXTS}`, async () => {
await $.run('build');
server.reload();
});
$.fs.watch(`./src/**/*.!${SOURCE_EXTS}`, async () => {
await $.run('assets');
server.reload();
});
});
$.start('build');
Table of Contents
class Bunbun
fs
- filesystem APIlogger
- logger APIalias()
- regiser alias of multiple tasksdebounce()
- allows to debounce by promise and timeexec()
- execute terminal commandhash()
- hash given filerescue()
- catch exception making result optionalrun()
- run registered taskstart()
- run tasks byprocess.argv
serve()
- create new http servertask()
- register new taskuntil()
- waits until task has been donewait()
-setTimeout
but inawait
/async
convention
class Logger
class Fs
cwd
- current working directorycopy()
- copy (also recursive and glob option) files/dirscreateDir()
- create dircreateTempDir()
- create unique temporary diredit()
- reads and writes back fileexists()
- check whenever file/dir exists and returns typehash()
- hash given filelist()
- list files/dirsread()
- reads data from fileremove()
- removes file/dirrename()
- renames (also moves) file/dirwatch()
- watches files/dirs for changeswrite()
- writes data into file
class HttpServer
reload()
- reloads all html pages