2020-05-28 22:35:45 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2024-01-02 17:04:27 +01:00
|
|
|
// Copyright (c) 2010-2024 Daniele Teti and the DMVCFramework Team
|
2020-05-28 22:35:45 +02:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// This IDE expert is based off of the one included with the DUnitX
|
2024-04-12 12:28:34 +02:00
|
|
|
// project. Original source by Robert Love. Adapted by Nick Hodges and Daniele Teti.
|
2020-05-28 22:35:45 +02:00
|
|
|
//
|
|
|
|
// The DUnitX project is run by Vincent Parrett and can be found at:
|
|
|
|
//
|
|
|
|
// https://github.com/VSoftTechnologies/DUnitX
|
|
|
|
// ***************************************************************************
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
unit DMVC.Expert.ProjectWizardEx;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
ToolsApi,
|
|
|
|
VCL.Graphics,
|
|
|
|
PlatformAPI;
|
|
|
|
|
|
|
|
type
|
|
|
|
TDMVCNewProjectWizard = class
|
|
|
|
private
|
|
|
|
class function GetUnitName(aFilename: string): string;
|
|
|
|
public
|
|
|
|
class procedure RegisterDMVCProjectWizard(const APersonality: string);
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2023-10-03 14:34:38 +02:00
|
|
|
{$I ..\sources\dmvcframework.inc}
|
2023-02-27 12:51:33 +01:00
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
uses
|
|
|
|
DccStrs,
|
|
|
|
System.IOUtils,
|
2018-08-05 20:31:33 +02:00
|
|
|
VCL.Controls,
|
|
|
|
VCL.Forms,
|
2016-02-23 01:41:13 +01:00
|
|
|
WinApi.Windows,
|
|
|
|
System.SysUtils,
|
|
|
|
DMVC.Expert.Forms.NewProjectWizard,
|
|
|
|
DMVC.Expert.CodeGen.NewDMVCProject,
|
|
|
|
DMVC.Expert.CodeGen.NewControllerUnit,
|
|
|
|
DMVC.Expert.CodeGen.NewWebModuleUnit,
|
2024-04-12 12:28:34 +02:00
|
|
|
ExpertsRepository,
|
|
|
|
JsonDataObjects,
|
2024-04-29 13:35:07 +02:00
|
|
|
DMVC.Expert.Commons, DMVC.Expert.CodeGen.SourceFile,
|
|
|
|
DMVC.Expert.Commands.Templates;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
resourcestring
|
2016-02-24 22:37:13 +01:00
|
|
|
sNewDMVCProjectCaption = 'DelphiMVCFramework Project';
|
|
|
|
sNewDMVCProjectHint = 'Create New DelphiMVCFramework Project with Controller';
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2017-05-17 22:32:45 +02:00
|
|
|
{ TDUnitXNewProjectWizard }
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
class function TDMVCNewProjectWizard.GetUnitName(aFilename: string): string;
|
|
|
|
begin
|
|
|
|
Result := TPath.GetFileNameWithoutExtension(aFilename);
|
|
|
|
end;
|
|
|
|
|
|
|
|
class procedure TDMVCNewProjectWizard.RegisterDMVCProjectWizard(const APersonality: string);
|
|
|
|
begin
|
2018-08-05 20:31:33 +02:00
|
|
|
RegisterPackageWizard(TExpertsRepositoryProjectWizardWithProc.Create(APersonality, sNewDMVCProjectHint, sNewDMVCProjectCaption,
|
|
|
|
'DMVC.Wizard.NewProjectWizard', // do not localize
|
2017-05-17 22:32:45 +02:00
|
|
|
'DMVCFramework', 'DMVCFramework Team - https://github.com/danieleteti/delphimvcframework', // do not localize
|
2016-02-23 01:41:13 +01:00
|
|
|
procedure
|
|
|
|
var
|
2017-05-17 22:32:45 +02:00
|
|
|
WizardForm: TfrmDMVCNewProject;
|
|
|
|
ModuleServices: IOTAModuleServices;
|
|
|
|
Project: IOTAProject;
|
|
|
|
Config: IOTABuildConfiguration;
|
|
|
|
ControllerUnit: IOTAModule;
|
2022-07-25 10:36:30 +02:00
|
|
|
JSONRPCUnit: IOTAModule;
|
2024-04-29 17:49:54 +02:00
|
|
|
ServicesUnit: IOTAModule;
|
2017-05-17 22:32:45 +02:00
|
|
|
WebModuleUnit: IOTAModule;
|
2024-04-29 13:35:07 +02:00
|
|
|
MustacheHelperUnit: IOTAModule;
|
2024-08-24 16:32:38 +02:00
|
|
|
TemplateProHelperUnit: IOTAModule;
|
2017-05-17 22:32:45 +02:00
|
|
|
ControllerCreator: IOTACreator;
|
2024-04-29 17:49:54 +02:00
|
|
|
EntityCreator: IOTACreator;
|
2022-07-25 10:36:30 +02:00
|
|
|
JSONRPCUnitCreator: IOTACreator;
|
2024-04-29 17:49:54 +02:00
|
|
|
ServicesUnitCreator: IOTACreator;
|
2024-08-24 16:32:38 +02:00
|
|
|
HelpersUnitCreator: IOTACreator;
|
2017-05-17 22:32:45 +02:00
|
|
|
WebModuleCreator: IOTAModuleCreator;
|
|
|
|
lProjectSourceCreator: IOTACreator;
|
2023-08-03 17:05:04 +02:00
|
|
|
lJSONRPCUnitName: string;
|
2024-04-29 17:49:54 +02:00
|
|
|
lServicesUnitName: string;
|
2024-04-12 12:28:34 +02:00
|
|
|
lJSON: TJSONObject;
|
2024-04-29 17:49:54 +02:00
|
|
|
lMustacheHelpersUnitName: string;
|
2024-08-24 16:32:38 +02:00
|
|
|
lTemplateProHelpersUnitName: string;
|
2024-04-29 17:49:54 +02:00
|
|
|
lEntityUnitName: string;
|
|
|
|
EntityUnit: IOTAModule;
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
|
|
|
WizardForm := TfrmDMVCNewProject.Create(Application);
|
|
|
|
try
|
|
|
|
if WizardForm.ShowModal = mrOk then
|
|
|
|
begin
|
|
|
|
if not WizardForm.AddToProjectGroup then
|
|
|
|
begin
|
|
|
|
(BorlandIDEServices as IOTAModuleServices).CloseAll;
|
|
|
|
end;
|
|
|
|
ModuleServices := (BorlandIDEServices as IOTAModuleServices);
|
2024-04-12 12:28:34 +02:00
|
|
|
lJSON := WizardForm.GetConfigModel;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
// Create Project Source
|
2024-04-12 12:28:34 +02:00
|
|
|
lProjectSourceCreator := TDMVCProjectFile.Create(APersonality, lJSON);
|
2016-02-24 22:37:13 +01:00
|
|
|
ModuleServices.CreateModule(lProjectSourceCreator);
|
2017-05-17 22:32:45 +02:00
|
|
|
Project := GetActiveProject;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
Config := (Project.ProjectOptions as IOTAProjectOptionsConfigurations).BaseConfiguration;
|
2017-05-17 22:32:45 +02:00
|
|
|
Config.SetValue(sUnitSearchPath, '$(DMVC)');
|
2024-04-19 18:19:08 +02:00
|
|
|
Config.SetValue(sFramework, 'FMX');
|
2024-04-29 17:49:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
lEntityUnitName := '';
|
|
|
|
// Create ENTITY Unit
|
|
|
|
if lJSON.B[TConfigKey.controller_crud_methods_generate] then
|
|
|
|
begin
|
|
|
|
EntityCreator := TNewGenericUnitFromTemplate.Create(
|
|
|
|
lJSON,
|
|
|
|
FillEntitiesTemplates,
|
|
|
|
TConfigKey.entity_unit_name,
|
|
|
|
APersonality);
|
|
|
|
EntityUnit := ModuleServices.CreateModule(EntityCreator);
|
|
|
|
ChangeIOTAModuleFileNamePrefix(EntityUnit, 'Entity.' + lJSON.S[TConfigKey.entity_classname].Substring(1));
|
|
|
|
lEntityUnitName := GetUnitName(EntityUnit.FileName);
|
|
|
|
lJSON.S[TConfigKey.entity_unit_name] := lEntityUnitName;
|
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(EntityUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
lServicesUnitName := '';
|
|
|
|
// Create Services Unit
|
|
|
|
if lJSON.B[TConfigKey.program_service_container_generate] then
|
|
|
|
begin
|
|
|
|
ServicesUnitCreator := TNewGenericUnitFromTemplate.Create(
|
|
|
|
lJSON,
|
|
|
|
FillServicesTemplates,
|
|
|
|
TConfigKey.program_service_container_unit_name,
|
|
|
|
APersonality);
|
|
|
|
ServicesUnit := ModuleServices.CreateModule(ServicesUnitCreator);
|
|
|
|
ChangeIOTAModuleFileNamePrefix(ServicesUnit, 'Services');
|
|
|
|
lServicesUnitName := GetUnitName(ServicesUnit.FileName);
|
|
|
|
lJSON.S[TConfigKey.program_service_container_unit_name] := lServicesUnitName;
|
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(ServicesUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
// Create Controller Unit
|
|
|
|
if WizardForm.CreateControllerUnit then
|
|
|
|
begin
|
2024-04-16 00:22:41 +02:00
|
|
|
ControllerCreator := TNewControllerUnitEx.Create(lJSON, APersonality);
|
2017-05-17 22:32:45 +02:00
|
|
|
ControllerUnit := ModuleServices.CreateModule(ControllerCreator);
|
2024-04-16 11:09:02 +02:00
|
|
|
ChangeIOTAModuleFileNamePrefix(ControllerUnit, 'Controllers.' + lJSON.S[TConfigKey.controller_classname].SubString(1));
|
|
|
|
lJSON.S[TConfigKey.controller_unit_name] := TPath.GetFileNameWithoutExtension(ControllerUnit.FileName);
|
2017-05-17 22:32:45 +02:00
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(ControllerUnit.FileName, True);
|
|
|
|
end;
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
2024-04-29 17:49:54 +02:00
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
lJSONRPCUnitName := '';
|
|
|
|
// Create JSONRPC Unit
|
2024-04-12 12:28:34 +02:00
|
|
|
if lJSON.B[TConfigKey.jsonrpc_generate] then
|
2022-07-25 10:36:30 +02:00
|
|
|
begin
|
2024-04-29 13:35:07 +02:00
|
|
|
JSONRPCUnitCreator := TNewGenericUnitFromTemplate.Create(
|
2024-04-12 12:28:34 +02:00
|
|
|
lJSON,
|
2024-04-29 13:35:07 +02:00
|
|
|
FillJSONRPCTemplates,
|
|
|
|
TConfigKey.jsonrpc_unit_name,
|
2022-07-25 10:36:30 +02:00
|
|
|
APersonality);
|
|
|
|
JSONRPCUnit := ModuleServices.CreateModule(JSONRPCUnitCreator);
|
2024-04-16 11:09:02 +02:00
|
|
|
ChangeIOTAModuleFileNamePrefix(JSONRPCUnit, 'JSONRPC.' + lJSON.S[TConfigKey.jsonrpc_classname].Substring(1));
|
2022-07-25 10:36:30 +02:00
|
|
|
lJSONRPCUnitName := GetUnitName(JSONRPCUnit.FileName);
|
2024-04-16 11:09:02 +02:00
|
|
|
lJSON.S[TConfigKey.jsonrpc_unit_name] := lJSONRPCUnitName;
|
2022-07-25 10:36:30 +02:00
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(JSONRPCUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2024-04-29 13:35:07 +02:00
|
|
|
|
2024-08-24 16:32:38 +02:00
|
|
|
|
2024-04-29 13:35:07 +02:00
|
|
|
lMustacheHelpersUnitName := '';
|
|
|
|
// Create Mustache Helpers Unit
|
|
|
|
if lJSON.B[TConfigKey.program_ssv_mustache] then
|
|
|
|
begin
|
2024-08-24 16:32:38 +02:00
|
|
|
HelpersUnitCreator := TNewGenericUnitFromTemplate.Create(
|
2024-04-29 13:35:07 +02:00
|
|
|
lJSON,
|
|
|
|
FillMustacheTemplates,
|
|
|
|
TConfigKey.mustache_helpers_unit_name,
|
|
|
|
APersonality);
|
2024-08-24 16:32:38 +02:00
|
|
|
MustacheHelperUnit := ModuleServices.CreateModule(HelpersUnitCreator);
|
2024-04-29 13:35:07 +02:00
|
|
|
ChangeIOTAModuleFileNamePrefix(MustacheHelperUnit, 'MustacheHelpers');
|
|
|
|
lMustacheHelpersUnitName := GetUnitName(MustacheHelperUnit.FileName);
|
|
|
|
lJSON.S[TConfigKey.mustache_helpers_unit_name] := lMustacheHelpersUnitName;
|
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(MustacheHelperUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2024-08-24 16:32:38 +02:00
|
|
|
lTemplateProHelpersUnitName := '';
|
|
|
|
// Create TemplatePro Helpers Unit
|
|
|
|
if lJSON.B[TConfigKey.program_ssv_templatepro] then
|
|
|
|
begin
|
|
|
|
HelpersUnitCreator := TNewGenericUnitFromTemplate.Create(
|
|
|
|
lJSON,
|
|
|
|
FillTemplateProTemplates,
|
|
|
|
TConfigKey.templatepro_helpers_unit_name,
|
|
|
|
APersonality);
|
|
|
|
TemplateProHelperUnit := ModuleServices.CreateModule(HelpersUnitCreator);
|
|
|
|
ChangeIOTAModuleFileNamePrefix(TemplateProHelperUnit, 'TemplateProHelpers');
|
|
|
|
lTemplateProHelpersUnitName := GetUnitName(TemplateProHelperUnit.FileName);
|
|
|
|
lJSON.S[TConfigKey.templatepro_helpers_unit_name] := lTemplateProHelpersUnitName;
|
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(TemplateProHelperUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2024-04-29 17:49:54 +02:00
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
// Create Webmodule Unit
|
2022-07-25 10:36:30 +02:00
|
|
|
WebModuleCreator := TNewWebModuleUnitEx.Create(
|
2024-04-12 12:28:34 +02:00
|
|
|
lJSON,
|
2022-07-25 10:36:30 +02:00
|
|
|
APersonality);
|
2016-02-23 01:41:13 +01:00
|
|
|
WebModuleUnit := ModuleServices.CreateModule(WebModuleCreator);
|
2024-04-16 11:09:02 +02:00
|
|
|
ChangeIOTAModuleFileNamePrefix(WebModuleUnit, lJSON.S[TConfigKey.webmodule_classname].SubString(1));
|
|
|
|
lJSON.S[TConfigKey.webmodule_unit_name] := TPath.GetFileNameWithoutExtension(WebModuleUnit.FileName);
|
2016-02-23 01:41:13 +01:00
|
|
|
if Project <> nil then
|
|
|
|
begin
|
|
|
|
Project.AddFile(WebModuleUnit.FileName, True);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
WizardForm.Free;
|
|
|
|
end;
|
|
|
|
end,
|
2017-05-17 22:32:45 +02:00
|
|
|
function: Cardinal
|
|
|
|
begin
|
|
|
|
Result := LoadIcon(HInstance, 'DMVCNewProjectIcon');
|
2023-02-27 12:51:33 +01:00
|
|
|
end, TArray<string>.Create(cWin32Platform, cWin64Platform
|
|
|
|
{$IF Defined(TOKYOORBETTER)}
|
|
|
|
, cLinux64Platform
|
|
|
|
{$ENDIF}
|
|
|
|
), nil));
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|