-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReplacements.pas
150 lines (128 loc) · 5.77 KB
/
Replacements.pas
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
unit Replacements;
interface
uses
System.SysUtils, Settings;
resourcestring
// __RUNTIME_PROJECTS__
RuntimeProjects = ' <Projects Include="src\__COMPONENT__\__P4D____COMPONENT__.dproj">' + sLineBreak +
' <Dependencies/>' + sLineBreak +
' </Projects>' + sLineBreak;
// __COMPONENT_PROJECTS__
ComponentProjects = ' <Projects Include="src\__COMPONENT__\__DCL____P4D____COMPONENT__.dproj">' + sLineBreak +
' <Dependencies/>' + sLineBreak +
' </Projects>' + sLineBreak;
//__RUNTIME_TARGETS__
RuntimeTargets = ' <Target Name="__P4D____COMPONENT__">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__P4D____COMPONENT__.dproj"/>' + sLineBreak +
' </Target>' + sLineBreak +
' <Target Name="__P4D____COMPONENT__:Clean">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__P4D____COMPONENT__.dproj" Targets="Clean"/>' + sLineBreak +
' </Target>' + sLineBreak +
' <Target Name="__P4D____COMPONENT__:Make">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__P4D____COMPONENT__.dproj" Targets="Make"/>' + sLineBreak +
' </Target>' + sLineBreak;
//__COMPONENT_TARGETS__
ComponentTargets = ' <Target Name="__DCL____P4D____COMPONENT__">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__DCL____P4D____COMPONENT__.dproj"/>' + sLineBreak +
' </Target>' + sLineBreak +
' <Target Name="__DCL____P4D____COMPONENT__:Clean">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__DCL____P4D____COMPONENT__.dproj" Targets="Clean"/>' + sLineBreak +
' </Target>' + sLineBreak +
' <Target Name="__DCL____P4D____COMPONENT__:Make">' + sLineBreak +
' <MSBuild Projects="src\__COMPONENT__\__DCL____P4D____COMPONENT__.dproj" Targets="Make"/>' + sLineBreak +
' </Target>' + sLineBreak;
//__BUILD_COMPONENT_LIST__
BuildP4DComponentList = '__P4D____COMPONENT__';
BuildDCLComponentList = '__DCL____P4D____COMPONENT__';
//__CLEAN_COMPONENT_LIST__
CleanP4DComponentList = '__P4D____COMPONENT__:Clean';
CleanDCLComponentList = '__DCL____P4D____COMPONENT__:Clean';
// __MAKE_COMPONENT_LIST__
MakeP4DComponentList = '__P4D____COMPONENT__:Make';
MakeDCLComponentList = '__DCL____P4D____COMPONENT__:Make';
const
FileNameReplacements: TArray<String> = [
'__DCL__',
'__COMPONENT__',
'__P4D__',
'__PROJECT_GROUP_NAME__'
];
ConstructedReplacements: TArray<String> = [
'__DCL__',
'__COMPONENT__',
'__P4D__'
];
procedure ReplaceTokens(var AStr: String; const AToken: String; const Component: TComponentSettings = Nil);
procedure RenameTemplateFile(var ATokenisedFilename: String; const Component: TComponentSettings = Nil);
implementation
function GetRandomGUID(const PackageID: String; const IsPaletteGUID: Boolean): String;
var
newGUID: TGUID;
begin
CreateGUID(newGUID);
Result := TGUID.NewGuid.ToString;
end;
function ReplaceToken(const Token: String; const Component: TComponentSettings = Nil): String;
begin
Result := String.Empty;
if (Component <> Nil) then
begin
if Token = '__COMPONENT__' then
Result := Component.DelphiPackageName
else if Token = '__PUBLIC_PROPERTY__' then
Result := Component.PublicPackageName
else if Token = '__PACKAGE_NAME__' then
Result := Component.PythonPackageName
else if Token = '__PACKAGE_NAME_PIP__' then
Result := Component.PIPPackageName
else if Token = '__PACKAGE_NAME_CONDA__' then
Result := Component.CondaPackageName
else if Token = '__HOME_URL__' then
Result := Component.HomeURL
else if Token = '__PYPI_URL__' then
Result := Component.PyPiURL
else if Token = '__DOC_URL__' then
Result := Component.DocURL
else if Token = '__GITHUB_URL__' then
Result := Component.GithubURL
else if Token = '__PALETTE_GUID__' then
Result := GetRandomGUID(Component.DelphiPackageName, True)
else if Token = '__PACKAGE_GUID__' then
Result := GetRandomGUID(Component.DelphiPackageName, False);
end;
if Result = String.Empty then
begin
if Token = '__DCL__' then
Result := 'dcl'
else if Token = '__P4D__' then
Result := 'P4D'
else if Token = '__PALETTE_PAGE__' then
Result := ProjectSettings.PalettePage
else if Token = '__PROJECT_VERSION__' then
Result := ProjectSettings.ProjectVersion
else if Token = '__PROJECT_TITLE__' then
Result := ProjectSettings.ProjectTitle
else if Token = '__README__' then
Result := ProjectSettings.ReadMe
else if Token = '__PROJECT_GROUP_NAME__' then
Result := ProjectSettings.ProjectGroupName
else if Token = '__PROJECT_DESCRIPTION__' then
Result := ProjectSettings.ProjectDesc
else if Token = '__GROUPPROJ_GUID__' then
Result := GetRandomGUID(ProjectSettings.ProjectGroupName, False)
else if Token = '__PROJECT_HOMEPAGE__' then
Result := ProjectSettings.ProjectHomepage;
end;
end;
procedure ReplaceTokens(var AStr: String; const AToken: String; const Component: TComponentSettings = Nil);
begin
AStr := AStr.Replace(AToken, ReplaceToken(AToken, Component), [rfReplaceAll]);
end;
procedure RenameTemplateFile(var ATokenisedFilename: String; const Component: TComponentSettings = Nil);
var
I: Integer;
begin
for I := 0 to Length(FileNameReplacements) - 1 do
ReplaceTokens(ATokenisedFilename, FileNameReplacements[I], Component);
end;
end.