Factory Module Definition
Requirements:
- Node.js
- npm (Node.js package manager)
Install
npm install fmd
Use
var Fmd = ;
Quick start
target: "dist/lib" trim_whitespace: true new_line: "unix" indent: 2 vendor"bar" "Bar" ;
Files:
Input: "source/foo.js"
{ } Fooprototype = ; Fooprototypequx = "foo"; Fooprototype { }; Fooprototype { };
Output: "dist/lib/foo.js"
; { if typeof exports === "object" // CommonJS moduleexports = exports = ; else if typeof define === "function" && defineamd // AMD ; else // Global (browser) rootFoo = ; }this { { } Fooprototype = ; Fooprototypequx = "foo"; Fooprototype { }; Fooprototype { }; return Foo; };
Usage
New Factory Module Definition object
var fmd = settings;
- settings.target destination directory of modules
- settings.factories (optional) orderd array of definition types to use, at least one type is required Default:
["commonjs", "amd", "global"]
- settings.trim_whitespace (optional) boolean indication whether to trim trailing whitespace Default:
null
- settings.new_line (optional) new line char type
"unix"
,"mac"
,"windows"
,"\n"
,"\r"
,"\r\n"
(null: don't change) Default:null
- settings.indent (optional)
"\t"
," "
,1
,2,
3,...
(null: don't add indent, number: count of spaces) Default:null
- settings.amd_not_anonymous (optional) boolean indication whether to define amd not anonymous Default:
null
Factory
Factory adds a "Factory Module Definition" handle.
Predefined: commonjs
, amd
and global
.
- name name/identifier of the factory definiton handle
- when method which returns the if condition to check the enviroment
- define method which returns the definition
Example:
fmd ;// Or multiple factory definitionfmd ;
Vendor
Vendor doesn't create/build files, it adds just the ability to inherit (especially for global mode) from modules I don't want to create/build by my self.
vendor module global
- module path/name of the module
- global (optional) name of the global provided variable
Example:
fmd vendor"foo" "Foo"; vendor"foo/bar" "FooBar";// Or multiple vendor definitionfmd vendor "foo": "Foo" "foo/bar": "FooBar" ;
Import
Import loads/copies modules which include a definiton already.
- module path/name of the module
- sources array of file paths or (local, http or https locations), at least one source is required
- global (optional) name of the global provided variable
- concat (optional) an own method to concat the received contents of sources
Example:
fmd ;// Or multiple importfmd ;
Define
Define loads/copies scripts and wraps them in a factory module definition.
- module path/name of the module
- sources array of file paths or (local, http or https locations)
- options.depends (optional) key / value (module / local variable name) paired dependencies
- options.exports (optional) name of the variable to expose
- options.global (optional) name of the property to expose on global object (window in browser)
- concat (optional) an own method to concat the received contents of sources
Example:
fmd ;// Or multiple definefmd ;
Build
Build starts the (async) process of creating defined modules and copying imported modules.
- callback (optional) a callback handle which receive a list of the created file (relative to the target path)
Example:
fmd ;