Skip to content

Commit

Permalink
Merge pull request #45 from cfwheels/upgrade_box
Browse files Browse the repository at this point in the history
Incorporation with Updated CFWheels DS and Default Templates
  • Loading branch information
bpamiri authored Mar 21, 2024
2 parents 1ee67c0 + e8015f5 commit a49fa64
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 39 deletions.
4 changes: 2 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name":"CFWheels CLI Commands",
"version":"1.1.0",
"version":"3.0.0",
"author":"Tom King, Peter Amiri",
"location":"cfwheels/cfwheels-cli#v1.1.0",
"location":"cfwheels/cfwheels-cli#v3.0.0",
"directory":"",
"createPackageDirectory":true,
"packageDirectory":"cfwheels-cli",
Expand Down
26 changes: 13 additions & 13 deletions commands/wheels/base.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ component excludeFromHelp=true {
// we could also test for the existence of /wheels/dbmigrate, but that only gives us the major version.
string function $getWheelsVersion(){
// First, look for a wheels folder..
if(!directoryExists( fileSystemUtil.resolvePath("wheels") ) ){
if(!directoryExists( fileSystemUtil.resolvePath("vendor/wheels") ) ){
error("We're currently looking in #getCWD()#, but can't find a /wheels/ folder?");
}
if(fileExists(fileSystemUtil.resolvePath("wheels/box.json"))){
var output = command( 'cd wheels' ).run( returnOutput=true );
if(fileExists(fileSystemUtil.resolvePath("vendor/wheels/box.json"))){
var output = command( 'cd vendor\wheels' ).run( returnOutput=true );
local.boxJSON = packageService.readPackageDescriptorRaw( getCWD() );
var output = command( 'cd ../' ).run( returnOutput=true );
return local.boxJSON.version;
} else if(fileExists(fileSystemUtil.resolvePath("wheels/events/onapplicationstart.cfm"))) {
var output = command( 'cd wheels' ).run( returnOutput=true );
local.target=fileSystemUtil.resolvePath("events/onapplicationstart.cfm");
} else if(fileExists(fileSystemUtil.resolvePath("vendor/wheels/events/onapplicationstart.cfm"))) {
var output = command( 'cd vendor\wheels' ).run( returnOutput=true );
local.target=fileSystemUtil.resolvePath("app/events/onapplicationstart.cfm");
local.content=fileRead(local.target);
local.content=listFirst(mid(local.content, (find('application.$wheels.version',local.content)+31),20),'"');
var output = command( 'cd ../' ).run( returnOutput=true );
Expand Down Expand Up @@ -83,10 +83,10 @@ component excludeFromHelp=true {
// Inject CLI content into template
function $injectIntoView(required struct objectNames, required string property, required string type, string action="input"){
if(arguments.action EQ "input"){
local.target=fileSystemUtil.resolvePath("views/#objectNames.objectNamePlural#/_form.cfm");
local.target=fileSystemUtil.resolvePath("app/views/#objectNames.objectNamePlural#/_form.cfm");
local.inject=$generateFormField(objectname=objectNames.objectNameSingular, property=arguments.property, type=arguments.type);
} else if(arguments.action EQ "output"){
local.target=fileSystemUtil.resolvePath("views/#objectNames.objectNamePlural#/show.cfm");
local.target=fileSystemUtil.resolvePath("app/views/#objectNames.objectNamePlural#/show.cfm");
local.inject=$generateOutputField(objectname=objectNames.objectNameSingular, property=arguments.property, type=arguments.type);
}
local.content=fileRead(local.target);
Expand All @@ -101,7 +101,7 @@ component excludeFromHelp=true {

// Inject CLI content into index template
function $injectIntoIndex(required struct objectNames, required string property, required string type){
local.target=fileSystemUtil.resolvePath("views/#objectNames.objectNamePlural#/index.cfm");
local.target=fileSystemUtil.resolvePath("app/views/#objectNames.objectNamePlural#/index.cfm");
local.thead=" <th>#helpers.capitalize(arguments.property)#</th>";
local.tbody=" <td>" & cr & " ~[~#arguments.property#~]~" & cr & " </td>";

Expand Down Expand Up @@ -208,7 +208,7 @@ component excludeFromHelp=true {
}

// Wheels folder in expected place? (just a good check to see if the user has actually installed wheels...)
var wheelsFolder=fileSystemUtil.resolvePath("wheels");
var wheelsFolder=fileSystemUtil.resolvePath("vendor/wheels");
if(!directoryExists(wheelsFolder)){
error("We can't find your wheels folder. Check you have installed CFWheels, and you're running this from the site root: If you've not started an app yet, try wheels new myApp");
}
Expand All @@ -223,12 +223,12 @@ component excludeFromHelp=true {
// Wheels 2.x has dbmigrate + dbmigratebridge equivalents in core
if($isWheelsVersion(1, "major")){

var DBMigratePluginLocation=fileSystemUtil.resolvePath("plugins/dbmigrate");
var DBMigratePluginLocation=fileSystemUtil.resolvePath("app/plugins/dbmigrate");
if(!directoryExists(DBMigratePluginLocation)){
error("We can't find your plugins/dbmigrate folder? Please check the plugin is successfully installed; if you've not started the server using server start for the first time, this folder may not be created yet.");
}

var DBMigrateBridgePluginLocation=fileSystemUtil.resolvePath("plugins/dbmigratebridge");
var DBMigrateBridgePluginLocation=fileSystemUtil.resolvePath("app/plugins/dbmigratebridge");
if(!directoryExists(DBMigrateBridgePluginLocation)){
error("We can't find your plugins/dbmigratebridge folder? Please check the plugin is successfully installed; if you've not started the server using server start for the first time, this folder may not be created yet.");
}
Expand All @@ -249,7 +249,7 @@ component excludeFromHelp=true {
string function $getBridgeURL() {
var serverInfo=$getServerInfo();
var geturl=serverInfo.serverUrl;
getURL &= "/rewrite.cfm?controller=wheels&action=wheels&view=cli";
getURL &= "/public/rewrite.cfm?controller=wheels&action=wheels&view=cli";
return geturl;
}

Expand Down
8 changes: 4 additions & 4 deletions commands/wheels/destroy.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ component aliases='wheels d' extends="base" {
function run(required string name) {

var obj = helpers.getNameVariants(arguments.name);
var modelFile = fileSystemUtil.resolvePath("models/#obj.objectNameSingularC#.cfc");
var controllerFile = fileSystemUtil.resolvePath("controllers/#obj.objectNamePluralC#.cfc");
var viewFolder = fileSystemUtil.resolvePath("views/#obj.objectNamePlural#/");
var modelFile = fileSystemUtil.resolvePath("app/models/#obj.objectNameSingularC#.cfc");
var controllerFile = fileSystemUtil.resolvePath("app/controllers/#obj.objectNamePluralC#.cfc");
var viewFolder = fileSystemUtil.resolvePath("app/views/#obj.objectNamePlural#/");
var testmodelFile = fileSystemUtil.resolvePath("tests/models/#obj.objectNameSingularC#.cfc");
var testcontrollerFile = fileSystemUtil.resolvePath("tests/controllers/#obj.objectNamePluralC#.cfc");
var testviewFolder = fileSystemUtil.resolvePath("tests/views/#obj.objectNamePlural#/");
var routeFile = fileSystemUtil.resolvePath("config/routes.cfm");
var routeFile = fileSystemUtil.resolvePath("app/config/routes.cfm");
var resourceName = '.resources("' & obj.objectNamePlural & '")';

print.redBoldLine("================================================")
Expand Down
8 changes: 4 additions & 4 deletions commands/wheels/generate/app.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ component aliases="wheels g app" extends="../base" {

// Setting Application Name
print.greenBoldLine( 'Setting application name...' ).toConsole();
command( 'tokenReplace' ).params( path = 'config/app.cfm', token = '|appName|', replacement = arguments.name ).run();
command( 'tokenReplace' ).params( path = 'app/config/app.cfm', token = '|appName|', replacement = arguments.name ).run();
command( 'tokenReplace' ).params( path = 'server.json', token = '|appName|', replacement = arguments.name ).run();

// Setting Reload Password
print.greenBoldLine( 'Setting reload password...' ).toConsole();
command( 'tokenReplace' )
.params( path = 'config/settings.cfm', token = '|reloadPassword|', replacement = arguments.reloadPassword )
.params( path = 'app/config/settings.cfm', token = '|reloadPassword|', replacement = arguments.reloadPassword )
.run();

// Setting Datasource Name
print.greenBoldLine( 'Setting datasource name...' ).toConsole();
command( 'tokenReplace' )
.params( path = 'config/settings.cfm', token = '|datasourceName|', replacement = arguments.datasourceName )
.params( path = 'app/config/settings.cfm', token = '|datasourceName|', replacement = arguments.datasourceName )
.run();

// Setting cfml Engine Name
Expand Down Expand Up @@ -183,7 +183,7 @@ component aliases="wheels g app" extends="../base" {
// CLI-Appends-Here';
print.yellowline( datasourceConfig ).toConsole();
command( 'tokenReplace' )
.params( path = 'config/app.cfm', token = '// CLI-Appends-Here', replacement = datasourceConfig )
.params( path = 'app/config/app.cfm', token = '// CLI-Appends-Here', replacement = datasourceConfig )
.run();
print.greenline( '...Finished Adding Datasource to app.cfm.' ).toConsole();
}
Expand Down
9 changes: 7 additions & 2 deletions commands/wheels/generate/controller.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ component
function run(
required string name,
string actionList = '',
directory = 'controllers'
directory = 'app/controllers'
) {
var obj = helpers.getNameVariants( arguments.name );
arguments.directory = fileSystemUtil.resolvePath( arguments.directory );
Expand Down Expand Up @@ -55,7 +55,12 @@ component
actionContent = allactions;
} else {
// Do Crud: overrwrite whole controllerContent with CRUD template
controllerContent = fileRead( getTemplate( '/CRUDContent.txt' ) );
if(fileExists(fileSystemUtil.resolvePath('app/snippets/CRUDContent.txt'))){
controllerContent = fileRead(fileSystemUtil.resolvePath('app/snippets/CRUDContent.txt'));
}
else{
controllerContent = fileRead( getTemplate( '/CRUDContent.txt' ) );
}
print.yellowLine( 'Generating CRUD' );
}

Expand Down
9 changes: 7 additions & 2 deletions commands/wheels/generate/model.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ component aliases='wheels g model' extends="../base" {
){

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

Expand All @@ -44,7 +44,12 @@ component aliases='wheels g model' extends="../base" {
}

// Read in Template
var modelContent = fileRead( getTemplate('/ModelContent.txt'));
if(fileExists(fileSystemUtil.resolvePath('app/snippets/ModelContent.txt'))){
var modelContent = fileRead(fileSystemUtil.resolvePath('app/snippets/ModelContent.txt'));
}
else{
var modelContent = fileRead( getTemplate('/ModelContent.txt'));
}
var modelName = obj.objectNameSingularC & ".cfc";
var modelPath = directory & "/" & modelName;

Expand Down
4 changes: 2 additions & 2 deletions commands/wheels/generate/property.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ component aliases='wheels g property' extends="../base" {
// Quick Sanity Checks: are we actually adding a property to an existing model?
// Check for existence of model file: NB, DB columns can of course exist without a model file,
// But we should confirm they've got it correct.
if(!fileExists(fileSystemUtil.resolvePath("models/#obj.objectNameSingularC#.cfc"))){
if(!confirm("Hold On! We couldn't find a corresponding Model at /models/#obj.objectNameSingularC#.cfc: are you sure you wish to add the property '#arguments.columnName#' to #obj.objectNamePlural#? [y/n]")){
if(!fileExists(fileSystemUtil.resolvePath("app/models/#obj.objectNameSingularC#.cfc"))){
if(!confirm("Hold On! We couldn't find a corresponding Model at /app/models/#obj.objectNameSingularC#.cfc: are you sure you wish to add the property '#arguments.columnName#' to #obj.objectNamePlural#? [y/n]")){
print.line("Fair enough. Aborting!");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion commands/wheels/generate/route.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ component aliases='wheels g route' extends="../base" {
**/
function run(required string objectname) {
var obj = helpers.getNameVariants(listLast( arguments.objectname, '/\' ));
var target = fileSystemUtil.resolvePath("config/routes.cfm");
var target = fileSystemUtil.resolvePath("app/config/routes.cfm");
var content = fileRead(target);

var inject = '.resources("' & obj.objectNamePlural & '")';
Expand Down
7 changes: 6 additions & 1 deletion commands/wheels/generate/test.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ component aliases='wheels g test' extends="../base" {
}

// Get test content
var testContent= fileRead(getTemplate("tests/#type#.txt"));
if(fileExists(fileSystemUtil.resolvePath('app/snippets/tests/#type#.txt'))){
var testContent= fileRead(fileSystemUtil.resolvePath('app/snippets/tests/#type#.txt'));
}
else{
var testContent= fileRead(getTemplate("tests/#type#.txt"));
}
file action='write' file='#testPath#' mode ='777' output='#trim( testContent )#';
print.line( 'Created Test Stub #testPath#' );
}
Expand Down
18 changes: 14 additions & 4 deletions commands/wheels/generate/view.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ component aliases='wheels g view' extends="../base" {
string template=""
){
var obj = helpers.getNameVariants(listLast( arguments.objectname, '/\' ));
var viewdirectory = fileSystemUtil.resolvePath( "views" );
var directory = fileSystemUtil.resolvePath( "views" & "/" & obj.objectNamePlural);
var viewdirectory = fileSystemUtil.resolvePath( "app/views" );
var directory = fileSystemUtil.resolvePath( "app/views" & "/" & obj.objectNamePlural);
print.line( "Creating View File..." ).toConsole();

// Validate directory
Expand All @@ -46,9 +46,19 @@ component aliases='wheels g view' extends="../base" {
// Read in Template
var viewContent = "";
if(!len(arguments.template)){
viewContent = fileRead( getTemplate( '/viewContent.txt'));
if(fileExists(fileSystemUtil.resolvePath('app/snippets/viewContent.txt'))){
viewContent = fileRead(fileSystemUtil.resolvePath('app/snippets/viewContent.txt'));
}
else{
viewContent = fileRead( getTemplate( '/viewContent.txt'));
}
} else {
viewContent = fileRead( getTemplate( arguments.template & '.txt'));
if(fileExists(fileSystemUtil.resolvePath('app/snippets/' & arguments.template & '.txt'))){
viewContent = fileRead(fileSystemUtil.resolvePath('app/snippets/' & arguments.template & '.txt'));
}
else{
viewContent = fileRead( getTemplate( arguments.template & '.txt'));
}
}
// Replace Object tokens
viewContent=$replaceDefaultObjectNames(viewContent, obj);
Expand Down
2 changes: 1 addition & 1 deletion commands/wheels/init.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ component extends="base" {
}

var serverJsonLocation=fileSystemUtil.resolvePath("server.json");
var wheelsBoxJsonLocation=fileSystemUtil.resolvePath("wheels/box.json");
var wheelsBoxJsonLocation=fileSystemUtil.resolvePath("vendor/wheels/box.json");
var boxJsonLocation=fileSystemUtil.resolvePath("box.json");

var wheelsVersion = $getWheelsVersion();
Expand Down
2 changes: 1 addition & 1 deletion commands/wheels/reload.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ component aliases='wheels r' extends="base" {
var serverDetails = $getServerInfo();

getURL = serverDetails.serverURL &
"/rewrite.cfm?reload=#mode#&password=#password#";
"/public/rewrite.cfm?reload=#mode#&password=#password#";
var loc = new Http( url=getURL ).send().getPrefix();
print.line("Reload Request sent");
}
Expand Down
4 changes: 2 additions & 2 deletions interceptors/postInstall.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ component {
property name='packageService' inject='packageService';

function postInstall( required struct interceptData ) {
var pluginFolder = fileSystemUtil.resolvePath("plugins");
var isValidWheelsInstallation = directoryExists( fileSystemUtil.resolvePath("wheels")) ? true:false;
var pluginFolder = fileSystemUtil.resolvePath("app/plugins");
var isValidWheelsInstallation = directoryExists( fileSystemUtil.resolvePath("vendor/wheels")) ? true:false;
var isValidPluginsDirectory = directoryExists( pluginFolder ) ? true:false;

if(isValidWheelsInstallation && isValidPluginsDirectory){
Expand Down

0 comments on commit a49fa64

Please sign in to comment.