forked from ShepherdDev/rock-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupLinks.ps1
173 lines (157 loc) · 5.57 KB
/
SetupLinks.ps1
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
<# Right-click in Explorer and select 'Run In Powershell'
#
# Prepares a new project for use with either RockIt development kit or a production Rock
# installation by setting up windows hard links between the project folders and their corresponding
# folders under the RockIt or RockWeb folders. This allows you to maintain version control through
# git or another system of the plugin all in one folder tree while still having them show up directly
# in Rock.
#
# Note: Hard links requires NTFS and that both folders exist on the same drive letter.
#
# Expected project format:
# com.yourchurch.project_name/ - Linked to RockIt/com.yourchurch.project_name/
# |- com.yourchurch.project_name.csproj - Used to determine your church domain and the project name.
# |- Controls/ - Linked to RockIt/RockWeb/Plugins/com_yourchurch/project_name/
# |- Themes/* - Linked to RockIt/RockWeb/Themes/*/
# \- Webhooks/* - Linked to RockIt/RockWeb/Webhooks/*
#
# The Controls and Themes folders should be excluded from your project. You will be able to access them
# via the RockWeb project (you may need to refresh solution folders after running this script). If you do
# include them you will get errors as they will be compiled into the project DLL.
#
# You can run this script multiple times without errors. So if you add a new theme then you can re-run this
# script to link it into the RockIt folder.
#
# When creating a new theme it is recommended that you use Windows Explorer to copy the Stark theme from the
# RockWeb/Themes/ folder into your project's Themes/ folder (with a new name).
#
# Version History:
#
# Version 1.1:
#
# Add support for hard linking Webhooks.
#
# Version 1.0:
#
# Builds a hard link from the main project folder (containing this script) to the RockIt folder
# for easy ability of adding the project into theRockIt solution.
#
# Builds a hard link from the optional Controls folder to the RockWeb Plugins folder.
#
# Builds hard links from any themes in the optional Themes folder to the RockWeb Themes folder.
#
#>
<#
# Ask the user for a folder.
#>
Function Select-FolderDialog
{
param([string]$Description="Select Folder",[string]$RootFolder="C:\")
$app = new-object -com Shell.Application
$folder = $app.BrowseForFolder(0, $Description, 0, $RootFolder)
Return $folder.Self.Path
}
<#
# Ask the user where their RockIt folder is.
#>
$RockItPath = Select-FolderDialog("Select the RockIt folder for development or Rock root IIS folder for production.")
if ( $RockItPath -eq $null )
{
Return
}
<#
# Check if this is a RockIt folder or a production Rock site.
#>
$RockWebPath = Join-Path $RockItPath "RockWeb"
$HasRockIt = 1
if ( !(Test-Path $RockWebPath) )
{
$RockWebPath = $RockItPath
$HasRockIt = 0
}
<#
# Get some helpful variables for path references.
#>
$ProjectPath = Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path
$ProjectControlsPath = Join-Path $ProjectPath "Controls"
$ProjectThemesPath = Join-Path $ProjectPath "Themes"
$ProjectWebhooksPath = Join-Path $ProjectPath "Webhooks"
$ProjectFullName = (Get-ChildItem -Path $ProjectPath -Filter *.csproj).Name
$ProjectFullName = $ProjectFullName.Substring(0, $ProjectFullName.Length - 7)
$ProjectOrganziation = $ProjectFullName.Substring(0, $ProjectFullName.LastIndexOf('.'))
$ProjectName = $ProjectFullName.Substring($ProjectFullName.LastIndexOf('.') + 1)
$RockWebPluginsPath = Join-Path $RockWebPath "Plugins"
$RockWebThemesPath = Join-Path $RockWebPath "Themes"
$RockWebWebhooksPath = Join-Path $RockWebPath "Webhooks"
$RockWebPluginOrganizationPath = Join-Path $RockWebPluginsPath $ProjectOrganziation.Replace(".", "_")
$RockWebPluginProjectPath = Join-Path $RockWebPluginOrganizationPath $ProjectName
<#
# Make sure this is a RockIt path.
#>
if ( !(Test-Path $RockWebPluginsPath) -or !(Test-Path $RockWebThemesPath) -or !(Test-Path $RockWebWebhooksPath) )
{
throw "Path does not appear to be a valid RockIt path or Rock production path."
}
<#
# Create any intermediate folders we need.
#>
if ( !(Test-Path $RockWebPluginOrganizationPath) )
{
New-Item -Path $RockWebPluginsPath -Name $ProjectOrganziation.Replace(".", "_") -ItemType directory
}
<#
# Hard link the from the Plugins folder to the Project Controls.
#>
if ( Test-Path $ProjectControlsPath )
{
if ( !(Test-Path $RockWebPluginProjectPath) )
{
cmd /c mklink /J "$RockWebPluginProjectPath" "$ProjectControlsPath"
}
}
<#
# Hard link each theme if it doesn't already exist.
#>
if ( Test-Path $ProjectThemesPath )
{
$themes = (Get-ChildItem -Path $ProjectThemesPath)
Foreach ($theme in $themes)
{
$SourceTheme = Join-Path $ProjectThemesPath $theme
$TargetTheme = Join-Path $RockWebThemesPath $theme
if ( !(Test-Path $TargetTheme) )
{
cmd /c mklink /J "$TargetTheme" "$SourceTheme"
}
}
}
<#
# Hard link each webhook if it doesn't already exist.
#>
if ( Test-Path $ProjectWebhooksPath )
{
$webhooks = (Get-ChildItem -Path $ProjectWebhooksPath *.ashx)
Foreach ($webhook in $webhooks)
{
$SourceWebhook = Join-Path $ProjectWebhooksPath $webhook
$TargetWebhook = Join-Path $RockWebWebhooksPath $webhook
Write-Host $SourceWebhook
Write-Host $TargetWebhook
if ( !(Test-Path $TargetWebhook) )
{
cmd /c mklink /H "$TargetWebhook" "$SourceWebhook"
}
}
}
<#
# Hard link the actual project path if this is a RockIt install.
#>
if ( $HasRockIt -eq 1 )
{
$TargetProjectPath = Join-Path $RockItPath $ProjectFullName
if ( !(Test-Path $TargetProjectPath) )
{
cmd /c mklink /J "$TargetProjectPath" "$ProjectPath"
}
}
Read-Host -Prompt "All finished, press enter to close."