node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

uicompile

uicompile

Build Status Build status codecov dependencies Status devDependencies Status

A compiler for web contents.

Install

$ npm install --save-dev uicompile

Usage

Write your configuration to a file.

const {
  readFile,
  appendHash,
  replaceRenamed,
  writeFile,
} 
module.exports = {
  entries: [
    {
      src: 'src/**/*.html',
      base: 'src',
      dest: 'dest',
      hooks: {
        read: [readFile],
        write: [replaceRenamed, writeFile],
      }
    },
    {
      src: 'src/**/*.@(js|css)',
      base: 'src',
      dest: 'dest',
      hooks: {
        read: [readFile, appendHash],
        write: [writeFile],
      }
    },
  ],
  hooks: {
    afterStart() {
      console.log('afterStart!');
    },
    beforeRead() {
      console.log('beforeRead!');
    },
    afterRead() {
      console.log('afterRead!');
    },
    beforeWrite() {
      console.log('beforeWrite!');
    },
    afterWrite() {
      console.log('afterWrite!');
    },
    beforeEnd() {
      console.log('beforeEnd!');
    },
  },
};

Then run the command.

uicompie --config path/to/config.js

API

  • config.entries: Array..
  • config.hooks.afterStart: Hook(Project).
  • config.hooks.beforeRead: Hook(Project).
  • config.hooks.afterRead: Hook(Project).
  • config.hooks.beforeWrite: Hook(Project).
  • config.hooks.afterWrite: Hook(Project).
  • config.hooks.beforeEnd: Hook(Project).

Interface: entry

  • entry.src: String|[String, Object]. It is passed to glob.
  • entry.base: String. It is used to get relative path.
  • entry.dest: String|fn(File) → String. A file path to where the result will be written.
  • entry.hooks.read: Hook(File). Functions for input.
  • entry.hooks.write: Hook(File). Functions for output.

Hook

A hook is a function or an array of functions. If a function returns a promise, the next function is called after the promise resolved.

License

MIT