forked from Ortus-Solutions/DocBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generate.cfc
90 lines (76 loc) · 2.98 KB
/
Generate.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Creates documentation for CFCs JavaDoc style via DocBox
* .
* You can pass the strategy options by prefixing them with 'strategy-'. So if a strategy takes
* in a property of 'outputDir' you will pass it as 'strategy-outputdir='
* Examples
* {code:bash}
* docbox run source=/path/to/coldbox mapping=coldbox excludes=tests strategy-outputDir=/output/path strategy-projectTitle="My Docs"
* {code}
**/
component extends="commandbox.system.BaseCommand" aliases="" excludeFromHelp=false{
/**
* Constructor
*/
function init(){
super.init();
var mappings = getApplicationSettings().mappings;
mappings[ "/docbox" ] = getDirectoryFromPath( getMetadata( this ).path );
application action='update' mappings='#mappings#';
return this;
}
/**
* Run DocBox to generate your docs
* @strategy The strategy class to use to generate the docs.
* @strategy.options docbox.strategy.api.HTMLAPIStrategy,docbox.strategy.uml2tools.XMIStrategy
* @source Either, the string directory source, OR a JSON array of structs containing 'dir' and 'mapping' key
* @mapping The base mapping for the folder. Only required if the source is a string
* @excludes A regex that will be applied to the input source to exclude from the docs
* @properties A
**/
function run(
string strategy="docbox.strategy.api.HTMLAPIStrategy",
required string source,
string mapping,
string excludes
){
// Inflate source from JSON
if( isJSON( arguments.source ) ){ arguments.source = deserializeJSON( arguments.source ); }
// Verify mapping?
if( isSimpleValue( arguments.source ) and ( isNull( arguments.mapping ) OR !len( arguments.mapping ) ) ){
return error( "The mapping argument was not sent, please send it." );
}
// Inflate outputs
arguments.source = fileSystemUtil.resolvePath( arguments.source );
// Inflate strategy properties
var properties = {};
for( var thisArg in arguments ){
if( !isNull( arguments[ thisArg ] ) and reFindNoCase( "^strategy\-" , thisArg ) ){
properties[ listLast( thisArg, "-" ) ] = arguments[ thisArg ];
//print.yellowLine( "Adding strategy property: #listLast( thisArg, "-" )#" );
}
}
// Resolve Output Dir
if( structKeyExists( properties, "outputDir" ) ){
properties.outputDir = fileSystemUtil.resolvePath( properties.outputDir );
}
// init docbox with default strategy and properites
var docbox = new DocBox( strategy=arguments.strategy, properties=properties );
print.yellowLine( "Source: #arguments.source# ")
.yellowLine( "Mapping: #arguments.mapping#" )
.yellowLine( "Output: #properties.outputDir#")
.redLine( "Starting Generation, please wait..." )
.toConsole();
// Create mapping
var mappings = getApplicationSettings().mappings;
mappings[ "/#arguments.mapping#" ] = arguments.source;
application action='update' mappings='#mappings#';
// generate
docbox.generate(
source = arguments.source,
mapping = arguments.mapping,
excludes = arguments.excludes
);
print.greenLine( "Generation complete" );
}
}