Skip to content

Commit 4f9be0f

Browse files
authored
Merge pull request #40 from bpamiri/master
Latest changes to the CLI
2 parents 3de1ebc + 72580c5 commit 4f9be0f

9 files changed

Lines changed: 109 additions & 142 deletions

File tree

commands/wheels/base.cfc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ component excludeFromHelp=true {
226226

227227
// Get information about the currently running server so we can send commmands
228228
function $getServerInfo(){
229-
var serverDetails = serverService.resolveServerDetails( serverProps={ name=listLast( getCWD(), '/\' ) } );
229+
var serverDetails = serverService.resolveServerDetails( serverProps={ webroot=getCWD() } );
230230
local.host = serverDetails.serverInfo.host;
231231
local.port = serverDetails.serverInfo.port;
232232
local.serverURL = "http://" & local.host & ":" & local.port;
@@ -250,9 +250,11 @@ component excludeFromHelp=true {
250250

251251
loc = new Http( url=targetURL ).send().getPrefix();
252252
print.line("Sending: " & targetURL);
253+
253254
if(isJson(loc.filecontent)){
254255
loc.result=deserializeJSON(loc.filecontent);
255256
if(structKeyexists(loc.result, "success") && loc.result.success){
257+
print.line("Call to bridge was successful.");
256258
return loc.result;
257259
//if(structKeyExists(loc.result, "MESSAGE")){
258260
// return loc.result.message;

commands/wheels/generate/.cfformat.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

commands/wheels/generate/app.cfc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ component aliases="wheels g app" extends="../base" {
9494
}
9595
}
9696

97+
print.greenBoldLine( 'Currently working in #getCWD()#');
98+
9799
// If the template is one of our "shortcut" names
98100
if ( variables.templateMap.keyExists( arguments.template ) ) {
99101
// Replace it with the actual ForgeBox slug name.
@@ -164,17 +166,18 @@ component aliases="wheels g app" extends="../base" {
164166
var datadirectory = fileSystemUtil.resolvePath( 'db/h2/' );
165167

166168
if ( !directoryExists( datadirectory ) ) {
167-
print.greenline( 'Creating /db/h2/ path...' ).toConsole();
169+
print.greenline( 'Creating #arguments.directory# path...' ).toConsole();
168170
directoryCreate( datadirectory );
169171
}
170172

171173
print.greenline( 'Adding Datasource to app.cfm...' ).toConsole();
172174
var datasourceConfig = 'this.datasources[''#arguments.datasourceName#''] = {
173175
class: ''org.h2.Driver''
174-
, connectionString: ''jdbc:h2:file:#expandPath( '/db/h2/' )##arguments.datasourceName#;MODE=MySQL''
175-
, username = ''sa''
176+
, connectionString: ''jdbc:h2:file:#datadirectory##arguments.datasourceName#;MODE=MySQL''
177+
, username = ''sa''
176178
};
177-
// CLI-Appends-Here';
179+
// CLI-Appends-Here';
180+
print.yellowline( datasourceConfig ).toConsole();
178181
command( 'tokenReplace' )
179182
.params( path = 'config/app.cfm', token = '// CLI-Appends-Here', replacement = datasourceConfig )
180183
.run();
@@ -204,12 +207,12 @@ component aliases="wheels g app" extends="../base" {
204207

205208
// Remove the cfwheels-base from the dependencies
206209
command( 'tokenReplace' )
207-
.params( path = 'box.json', token = '"cfwheels-base":"^2.2"', replacement = '' )
210+
.params( path = 'box.json', token = '"cfwheels-base":"^2.2",', replacement = '' )
208211
.run();
209212

210213
// Remove the cfwheels-base from the install paths
211214
command( 'tokenReplace' )
212-
.params( path = 'box.json', token = '"cfwheels-base":"base/"', replacement = '' )
215+
.params( path = 'box.json', token = '"cfwheels-base":"base/",', replacement = '' )
213216
.run();
214217

215218
// Add the H2 Lucee extension to the dependencies

commands/wheels/generate/controller.cfc

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,75 @@
1313
* wheels generate controller user index,customaction
1414
* {code}
1515
**/
16-
component aliases='wheels g controller' extends="../base" {
16+
component
17+
aliases="wheels g controller"
18+
extends="../base"
19+
{
1720

18-
/**
19-
* @name.hint Name of the controller to create without the .cfc
20-
* @actionList.hint optional list of actions, comma delimited
21-
* @directory.hint if for some reason you don't have your controllers in /controllers/
22-
**/
23-
function run(
24-
required string name,
25-
string actionList="",
26-
directory='controllers'
27-
){
28-
var obj = helpers.getNameVariants(arguments.name);
29-
arguments.directory = fileSystemUtil.resolvePath( arguments.directory );
21+
/**
22+
* @name.hint Name of the controller to create without the .cfc
23+
* @actionList.hint optional list of actions, comma delimited
24+
* @directory.hint if for some reason you don't have your controllers in /controllers/
25+
**/
26+
function run(
27+
required string name,
28+
string actionList = '',
29+
directory = 'controllers'
30+
) {
31+
var obj = helpers.getNameVariants( arguments.name );
32+
arguments.directory = fileSystemUtil.resolvePath( arguments.directory );
3033

31-
print.line( "Creating Controller..." ).toConsole();
34+
print.line( 'Creating Controller...' ).toConsole();
3235

33-
// Validate directory
34-
if( !directoryExists( arguments.directory ) ) {
35-
error( "[#arguments.directory#] can't be found. Are you running this from your site root?" );
36-
}
36+
// Validate directory
37+
if ( !directoryExists( arguments.directory ) ) {
38+
error( '[#arguments.directory#] can''t be found. Are you running this from your site root?' );
39+
}
3740

38-
// If custom actions passed in as arguments, then use them, otherwise use CRUD
39-
var actionContent = "";
41+
// If custom actions passed in as arguments, then use them, otherwise use CRUD
42+
var actionContent = '';
4043

41-
if( len( arguments.actionList ) && arguments.actionList != "CRUD" ){
42-
var allactions = "";
43-
var controllerContent = fileRead( helpers.getTemplate('/ControllerContent.txt') );
44-
// Loop Over actions to generate them
45-
for( var thisAction in listToArray( arguments.actionList ) ) {
46-
if( thisAction == 'init' ) { continue; }
47-
allactions = allactions & $returnAction(thisAction);
48-
print.yellowLine( "Generated Action: #thisAction#");
49-
}
50-
actionContent = allactions;
51-
} else {
52-
// Do Crud: overrwrite whole controllerContent with CRUD template
53-
controllerContent = fileRead( helpers.getTemplate('/CRUDContent.txt') );
54-
print.yellowLine( "Generating CRUD");
55-
}
44+
if ( len( arguments.actionList ) && arguments.actionList != 'CRUD' ) {
45+
var allactions = '';
46+
var controllerContent = fileRead( helpers.getTemplate( '/ControllerContent.txt' ) );
47+
// Loop Over actions to generate them
48+
for ( var thisAction in listToArray( arguments.actionList ) ) {
49+
if ( thisAction == 'init' ) {
50+
continue;
51+
}
52+
allactions = allactions & $returnAction( thisAction );
53+
print.yellowLine( 'Generated Action: #thisAction#' );
54+
}
55+
actionContent = allactions;
56+
} else {
57+
// Do Crud: overrwrite whole controllerContent with CRUD template
58+
controllerContent = fileRead( helpers.getTemplate( '/CRUDContent.txt' ) );
59+
print.yellowLine( 'Generating CRUD' );
60+
}
5661

57-
// Inject actions in controller content
58-
controllerContent = replaceNoCase( controllerContent, '|actions|', actionContent, 'all' );
59-
// Replace Object tokens
60-
controllerContent=$replaceDefaultObjectNames(controllerContent, obj);
62+
// Inject actions in controller content
63+
controllerContent = replaceNoCase(
64+
controllerContent,
65+
'|actions|',
66+
actionContent,
67+
'all'
68+
);
69+
// Replace Object tokens
70+
controllerContent = $replaceDefaultObjectNames( controllerContent, obj );
6171

62-
var controllerName = obj.objectNamePluralC & ".cfc";
63-
var controllerPath = directory & "/" & controllerName;
72+
var controllerName = obj.objectNamePluralC & '.cfc';
73+
var controllerPath = directory & '/' & controllerName;
6474

65-
if(fileExists(controllerPath)){
66-
if( confirm( '#controllerName# already exists in target directory. Do you want to overwrite? [y/n]' ) ) {
67-
print.greenLine( 'Ok, going to overwrite...' ).toConsole();
68-
} else {
69-
print.boldRedLine( 'Ok, aborting!' );
70-
return;
71-
}
72-
}
73-
file action='write' file='#controllerPath#' mode ='777' output='#trim( controllerContent )#';
74-
print.line( 'Created #controllerName#' );
75-
}
75+
if ( fileExists( controllerPath ) ) {
76+
if ( confirm( '#controllerName# already exists in target directory. Do you want to overwrite? [y/n]' ) ) {
77+
print.greenLine( 'Ok, going to overwrite...' ).toConsole();
78+
} else {
79+
print.boldRedLine( 'Ok, aborting!' );
80+
return;
81+
}
82+
}
83+
file action="write" file="#controllerPath#" mode="777" output="#trim( controllerContent )#";
84+
print.line( 'Created #controllerName#' );
85+
}
7686

77-
}
87+
}

commands/wheels/generate/model.cfc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ component aliases='wheels g model' extends="../base" {
1818
/**
1919
* @name.hint Name of the model to create without the .cfc: assumes singluar can be foo/foo
2020
* @fields.hint Comma Delimited list of fields with type after semicolon
21+
* @db.hint Boolean attribute specifying if the database table should be generated as well
2122
**/
2223
function run(
2324
required string name,
2425
boolean db=true
2526
){
2627

27-
var obj = helpers.getNameVariants(arguments.name);
28+
var obj = helpers.getNameVariants(arguments.name);
2829
var directory = fileSystemUtil.resolvePath("models");
30+
//TODO: Refactor into a function that tries to get the app name from the server.json file
2931
var appName = listLast( getCWD(), '/\' );
3032

3133
if(db){

templates/ActionContent.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// |ActionHint|
1+
2+
/**
3+
* |ActionHint| Action
4+
**/
25
function |Action|() {
36

4-
}
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<cfscript>
2+
/*
3+
If you leave these settings commented out, CFWheels will set the data source name to the same name as the folder the application resides in.
4+
*/
5+
6+
// set(dataSourceName="");
7+
// set(dataSourceUserName="");
8+
// set(dataSourcePassword="");
9+
10+
/*
11+
If you leave this setting commented out, CFWheels will try to determine the URL rewrite capabilities automatically.
12+
The "URLRewriting" setting can bet set to "on", "partial" or "off".
13+
To run with "partial" rewriting, the "cgi.path_info" variable needs to be supported by the web server.
14+
To run with rewriting set to "on", you need to apply the necessary rewrite rules on the web server first.
15+
*/
16+
17+
// Added via CFWheels CLI
18+
set(dataSourceName="|datasourceName|");
19+
set(URLRewriting="On");
20+
// Reload your application with ?reload=true&password=|reloadPassword|
21+
set(reloadPassword="|reloadPassword|");
22+
// CLI-Appends-Here
23+
</cfscript>

templates/ControllerContent.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
component extends="Controller" {
22

3+
/**
4+
* Controller config settings
5+
**/
36
function config() {
47

58
}

0 commit comments

Comments
 (0)