-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBaseCommand.cfc
More file actions
322 lines (294 loc) Β· 8.61 KB
/
Copy pathBaseCommand.cfc
File metadata and controls
322 lines (294 loc) Β· 8.61 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
* Base Command Handler
*/
component accessors="true" {
// DI
property name="utility" inject="utility@coldbox-cli";
property name="settings" inject="box:modulesettings:coldbox-cli";
property name="config" inject="box:moduleconfig:coldbox-cli";
property name="serverService" inject="serverService";
property name="packageService" inject="PackageService";
/**
* Initialize the BaseCommand
*/
function init(){
return this;
}
/**
* Detects the application layout and returns the appropriate path prefix.
* In a modern layout (app/ and public/ directories exist), returns "app/".
* In a flat layout, returns "".
*
* @cwd The current working directory
*
* @return string "app/" for modern layout, "" for flat layout
*/
function getAppPrefix( required cwd ){
return variables.utility.detectTemplateType( cwd ) == "modern" ? "app/" : "";
}
/**
* Detects the application layout and returns the appropriate path prefix.
* In a modern layout (app/ and public/ directories exist), returns "app/".
* In a flat layout, returns "".
*
* @cwd The current working directory
*
* @return string "app." for modern layout, "" for flat layout
*/
function getAppPrefixDot( required cwd ){
return variables.utility.detectTemplateType( cwd ) == "modern" ? "app." : "";
}
/**
* Detects the application layout and returns the appropriate modules directory path.
* In a modern layout (or BoxLang project), modules live under lib/modules.
* In a flat layout, modules live under modules.
*
* @cwd The current working directory
*
* @return string "lib/modules" for modern/BoxLang layout, "modules" for flat layout
*/
function getModulesPrefix( required cwd ){
var isModern = variables.utility.detectTemplateType( cwd ) == "modern" || isBoxLangProject( cwd );
return isModern ? "lib/modules" : "modules";
}
/**
* Resolves the base URL (host:port) of the local server for the given directory.
* Resolution order:
* 1. CommandBox server.json discovery (getServerInfoByDiscovery)
* 2. miniserver.json in the project directory
* 3. Fallback: localhost:8080
*
* @directory The project directory to resolve the server for
*
* @return string e.g. "localhost:8888" or "localhost:8080"
*/
function resolveServerBaseUrl( required string directory ){
// 1. Try CommandBox server.json discovery
var serverInfo = variables.serverService.getServerInfoByDiscovery(
serverConfigFile = arguments.directory & "/server.json"
);
if ( structCount( serverInfo ) && serverInfo.keyExists( "host" ) ) {
return "#serverInfo.host#:#serverInfo.port#";
}
// 2. Try miniserver.json in the project directory
var miniServerFile = arguments.directory & "/miniserver.json";
if ( fileExists( miniServerFile ) ) {
try {
var miniConfig = deserializeJSON( fileRead( miniServerFile ) );
var miniHost = miniConfig.keyExists( "host" ) ? miniConfig.host : "localhost";
var miniPort = miniConfig.keyExists( "port" ) ? miniConfig.port : 8080;
// Normalize bind-all address to localhost
if ( miniHost == "0.0.0.0" ) miniHost = "localhost";
return "#miniHost#:#miniPort#";
} catch ( any e ) {
// Ignore parse errors and fall through to default
}
}
// 3. Fallback
return "localhost:8080";
}
/**
* Determines if we are running on a BoxLang server
* or using the BoxLang runner.
*
* @cwd The current working directory
*
* @return boolean
*/
private function isBoxLangProject( required cwd ){
// Detect if it's a BoxLang server first.
var serverInfo = variables.serverService.resolveServerDetails( {} ).serverInfo;
if ( serverInfo.cfengine.findNoCase( "boxlang" ) ) {
return true;
}
// Detect if you have the BoxLang runner set.
var boxOptions = variables.packageService.readPackageDescriptor( arguments.cwd );
if (
boxOptions.testbox.keyExists( "runner" )
&& isSimpleValue( boxOptions.testbox.runner )
&& boxOptions.testbox.runner == "boxlang"
) {
return true;
}
// Language mode
if ( boxOptions.keyExists( "language" ) && boxOptions.language == "boxlang" ) {
return true;
}
// We don't know.
return false;
}
function printInfo( required message ){
variables.print
.green1onDodgerBlue2( " INFO " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function printError( required message ){
variables.print
.whiteOnRed2( " ERROR " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function printWarn( required message ){
variables.print
.blackOnWheat1( " WARN " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function printSuccess( required message ){
variables.print
.blackOnSeaGreen2( " SUCCESS " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function printTip( required string message ){
variables.print
.blackOnAquamarine2( " TIP " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function printHelp( required message ){
variables.print
.blackOnLightSkyBlue1( " HELP " )
.line( " #arguments.message#" )
.line()
.toConsole()
}
function toBoxLangClass( required content ){
return reReplaceNoCase(
arguments.content,
"component(\s|\n)?",
"class #chr( 13 )#",
"one"
);
}
/**
* Display the ColdBox ASCII art banner with random gradient colors
*
* @subTitle Optional subtitle to display below the banner
* @theme Optional gradient theme name (e.g., "Ocean", "Fire", "Sunset", "Purple", "Mint", "Gray")
*/
function showColdBoxBanner(
string subTitle = "",
string theme = ""
){
var lines = [
" βββββββ βββββββ βββ βββββββ βββββββ βββββββ βββ βββ",
"ββββββββ βββββββββ βββ ββββββββ ββββββββ βββββββββ ββββββββ",
"βββ βββ βββ βββ βββ βββ ββββββββ βββ βββ ββββββ ",
"βββ βββ βββ βββ βββ βββ ββββββββ βββ βββ ββββββ ",
"ββββββββ βββββββββ ββββββββ ββββββββ ββββββββ βββββββββ ββββ βββ",
" βββββββ βββββββ ββββββββ βββββββ βββββββ βββββββ βββ βββ"
]
var themes = {
"Ocean" : [
"color81",
"color75",
"color69",
"color63",
"color57",
"color21"
],
"Fire" : [
"color196",
"color160",
"color124",
"color88",
"color52",
"color88"
],
"Sunset" : [
"color214",
"color208",
"color202",
"color196",
"color160",
"color124"
],
"Purple" : [
"color213",
"color177",
"color141",
"color105",
"color69",
"color39"
],
"Mint" : [
"color158",
"color122",
"color86",
"color50",
"color44",
"color38"
],
"Gray" : [
"color250",
"color248",
"color245",
"color243",
"color240",
"color238"
],
"Forest" : [
"color154",
"color148",
"color142",
"color106",
"color70",
"color34"
],
"Gold" : [
"color226",
"color220",
"color214",
"color208",
"color172",
"color136"
]
}
// Randomly select a gradient theme if none provided
if ( arguments.theme == "" ) {
var themeNames = structKeyArray( themes )
var themeName = themeNames[ randRange( 1, arrayLen( themeNames ) ) ]
} else {
var themeName = arguments.theme
}
var gradient = themes[ themeName ]
variables.print.line()
for ( var i = 1; i <= arrayLen( lines ); i++ ) {
variables.print.line( lines[ i ], gradient[ i ] )
}
// Add subtitle block if provided
if ( len( arguments.subTitle ) ) {
var blockWidth = 48
var contentWidth = blockWidth - 4 // Subtract 4 for the ββ borders (2 chars each side)
var padding = contentWidth - len( arguments.subTitle )
var leftPad = int( padding / 2 )
var rightPad = padding - leftPad
var indent = repeatString( " ", 8 )
variables.print
.line(
indent & repeatString( "β", blockWidth ),
gradient.last()
)
.line(
indent & "ββ" &
repeatString( " ", leftPad ) &
arguments.subTitle &
repeatString( " ", rightPad ) &
"ββ",
"white"
)
.line(
indent & repeatString( "β", blockWidth ),
gradient.last()
)
}
variables.print.line().toConsole()
}
}