Basic Usage

Install via npm

You can install Eustia using Node Package Manager(npm).

npm install -g eustia

Syntax supported

Eustia scans code files to find the modules you need with three types of syntax supported, global, commonjs and es6.

<html>
<head>
    ...
    <script src="util.js"></script>
</head>
<body>
    <script>
    var projectName = _.trim(' Eustia ');
    // Some code...
    </script>
</body>
</html>
var util = require('./util');

var projectName = util.trim(' Eustia ');
// Some code...
import {trim} from './util'

var projectName = trim(' Eustia ');
// Some code...

Run in command prompt

You can use Eustia with command lines totally. It usually follows the same pattern described below:

eustia <command> [<options>]

For example:

eustia build -o util.js index.html *.js ...<list of files to be scanned>

Run through configuration file

It's also possible to use a configuration file to save settings. This is pretty helpful especially when you want to generate multiple utility libraries for different sections of your website.

Just create a file named .eustia in your project root.

{
    "files": "./layout/**/*.jade",
    "output": "./static/js/eustia.js"
}

Running Eustia without any sub commands, the tool will find .eustia under current working directory to read configuration to generate libraries. It is almost the same as running build command from console, just a different way of passing options.

Configuration can be written in json format or js format.

module.exports = {
    page: {
        files: "./layout/**/*.jade",
        output: "./static/js/eustia.js"
    },
    node: {
        files: ["./lib/*.js", "./tool/**/*.js"],
        output: "./lib/util.js"
    },
    ...
};

Obviously, multiple configuration is also supported. To specify which task to run, just append the task name after command name.

eustia <task-name>

Configuration could be overwritten by command line options. And it's possible to specify another configuration path using config options.

Use in JavaScript

To use Eustia from JavaScript(NodeJs), install it locally first.

npm install eustia --save-dev

Then require and run it by passing options just the same as a configuration file.

var eustia = require('eustia');

eustia.build({
    files: './layout/**/*.jade',
    output: './static/js/eustia.js',
    ...
}, function ()
{
    // callback
});

Commands

Build Command

Build JavaScript libraries by scanning files. When used in command line, the rest arguments will be treated as files.

eustia build [<options>]
eustia build index.html
eustia build index.html src/*.js
eusita build index.html src/*.js -o lib.js
NameShorthandDefaultDesc
encodingutf-8Input file encoding
excludeeFunctions excluded
extensionjsModule extension, useful for transpilers
files['*.html', '*.js']Files to scan
formatfumdModule pattern, commonjs, umd, es or global
includeiFunctions included
ignoreFiles excluded
librarylExternal library paths
namespacen_Namespace of generated library
outputoutil.jsOutput path
transpilersUse for writing modules in different formats
watchwfalseWatch files to regenerate automatically
tsfalseOutput typescript definition file
proxyRequest proxy

Transpilers and extension are not available via command line arguments, use them only in configurations.

Doc Command

Generate documentation from generated utiltiy libraries.

eustia doc [<options>]
eustia doc util.js -o doc.html
NameShorthandDefaultDesc
descriptiondExtra description markdown file path
formatfhtmlOutput format, html, json or markdown
outputodocs.htmlOutput path
titletEustia DocumentationDocumentation title

Create Module

Materials must be prepared first to cook a good meal. Right now, our materials is a bunch of small modules. Eustia provides many utilities itself(currently under development). Still, there are times you want to add your own ones. To achieve that, create a directory named eustia in the root directory.

Now, let's say I want to have a function to compare version numbers. The first step is to create a js file named compareVersion.js in eustia directory. Then fills it with actual codes to finish the procedure.

// eustia/compareVersion.js
_('isStr each'); // dependencies

// export object
exports = function (v1, v2)
{
    if (!isStr(v1) || !isStr(v2)) return;
    ...
};

Now you can use compareVersion anywhere in your project.

Using option library allows you to search functions in other paths, quite useful when sharing functions among several projects. Besides, Lodash functions is available by using eustia-lodash.

Relative Projects

licia: Eustia official modules(updated everyday)

eustia-babel: Allow modules to be written in es6.

eustia-component: Allow modules to be written in html-like style.

eustia-json: Allow modules to be writen in json format.

eustia-lodash: Allow using lodash functions.