node package manager

uicompile

uicompile

Build Status Codacy Badge dependencies Status

A compiler for webpage development.

Install

$ npm install uicompile

CLI

# Builds an app. 
$ uicompile
 
# Builds an app and starts a webserver. 
$ uicompile --watch
 
# Minifies codes. 
$ uicompile --release

JavaScript API

const UICompiler = require('uicompile');
const compiler = new UICompiler({
  root: process.cwd(),
  src: 'src',
  dest: 'dest',
  release: 'release',
  ignore: [
    '**/mod/**',
    '**/lib/**'
  ],
  rename: [
    '.js',
    '.css'
  ],
  textFile: [
    '.js',
    '.css',
    '.txt',
    '.html',
    '.htm',
    '.json'
  ],
  chokidar: {},
  sable: {},
  processors: [
    {
      matcher: /\.styl/,
      processor: compileStyl
    },
    {
      matcher: /\.nunjucks/,
      processor: compileNunjucks
    },
    {
      matcher: /\.ejs/,
      processor: compileEjs
    },
    {
      matcher: /\.js$/,
      processor: compileJs
    },
    {
      matcher: /\.css$/,
      processor: compileCss
    },
    {
      matcher: function (file, {root, src}) {
        return (/\/static\//).test(path.relative(path.join(root, src), file));
      },
      processor: cp
    }
  ]
});

The script above shows default values.

name description
root A path to the project's root directory.
src A relative path to the src directory.
dest A relative path to the dest directory.
release A relative path to the release directory.
ignore An array of pattens of files ignored by uicompile.
rename An array of extensions which is renamed on minifying.
textFile An array of extensions which may contain renamed filenames.
chokidar An object passed to chokidar.
sable An object passed to sable
processors An array of processor declarations
before A function called before main process. It gets one argument compiler.
after A function called after main process. It gets one argument compiler.
beforeServer A function called before server setup. It gets one argument compiler.
afterServer A function called after server setup. It gets one argument compiler.
beforeRelease A function called before build. It gets one argument compiler.
afterRelease A function called after build. It gets one argument compiler.

Directories

  • src contains source codes and files.
  • dest contains codes and files processed by uicompile.
  • release contains minified codes and files.

Processor declaration

A processor declaration is an object which has matcher and processor.

  • matcher is a regular expression or a function which gets 2 arguments (filePath, compiler).
  • processor is a function which gets 3 arguments (src, dest, compiler).
    • src is an absolute path to the source.
    • dest is an absolute path to which processed file is put.
    • compiler is the compiler itself.

License

MIT