Guest User

Untitled

a guest
Jan 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.75 KB | None | 0 0
  1. #paths to the project templates on your system
  2. $global:classTemplate = "D:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows Root\Windows\1033\ClassLibrary\csClassLibrary.vstemplate"
  3. $global:webTemplate = "D:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplatesCache\CSharp\Web\1033\WebApplicationProject40\EmptyWebApplicationProject40.vstemplate"
  4.  
  5. #variable used to store the path for the empty Habitat folder
  6. $global:helixPath =""
  7.  
  8. #empty variable used to store the solution name
  9. $global:solutionName = ""
  10.  
  11. #empty variable used to store the project names like Habitat to which we will add .Website
  12. $global:projectNames = New-Object System.Collections.ArrayList
  13.  
  14. #empty variable used to store the feature name prefix like Sitecore.Foundation to which we will add foundation projects
  15. $global:foundationNamePrefix = ""
  16.  
  17. #list of foundation projects to create
  18. $global:foundationNames = New-Object System.Collections.ArrayList
  19.  
  20.  
  21. #empty variable used to store the feature name prefix like Sitecore.Feature to which we will add feature projects
  22. $global:featureNamePrefix = ""
  23.  
  24. #list of features to create
  25. $global:featureNames = New-Object System.Collections.ArrayList
  26.  
  27.  
  28. #Setup the folders to create
  29. $global:folderPaths = @("\etc","\lib","\scripts","\specs","\src\Feature","\src\Foundation","\src\Project","\src\Project\Common\code","\src\Project","\src\Project\Common\code","\src\Project\Common\serialization")
  30.  
  31. $global:projectPath = "\src\Project\"
  32. $global:foundationPath = "\src\Foundation\"
  33. $global:featurePath = "\src\Feature\"
  34. $global:srcFolder = "\src"
  35. $global:codeFolder = "\code"
  36. $global:rolesFolder = "\roles"
  37. $global:serializationFolder = "\serialization"
  38. $global:testsFolder = "\Tests"
  39.  
  40.  
  41. $global:testProjectName = "Tests"
  42. $global:websiteName = "Website"
  43.  
  44. $global:ConfigFolderName = "Configuration"
  45. $global:FeatureFolderName = "Feature"
  46. $global:FoundationFolderName = "Foundation"
  47. $global:ProjectFolderName = "Project"
  48.  
  49.  
  50. $global:solution = $null
  51.  
  52. <#
  53. Prompt to confirm solution creation.
  54. #>
  55. function Confirm-Creation
  56. {
  57. param (
  58. [string]$Title = 'Create Helix Solution?'
  59. )
  60.  
  61. Write-Host "================ $Title ================"
  62.  
  63. Write-Host "1: Continue"
  64. Write-Host "q: Press 'q' to Quit"
  65. }
  66.  
  67. <#
  68. Prompt to accept Projects
  69. #>
  70. function Accept-Projects
  71. {
  72. param (
  73. [string]$Title = 'Enter Project Names/Tenants/Sites - Site1 etc'
  74. )
  75.  
  76. cls
  77. Write-Host "================ $Title ================"
  78.  
  79. Write-Host "1: Create a Project."
  80. Write-Host "q: Press 'q' to exit this prompt and continue to create Foundation projects."
  81. }
  82.  
  83. <#
  84. Prompt to accept Foundation projects
  85. #>
  86. function Accept-FoundationProjects
  87. {
  88. param (
  89. [string]$Title = 'Enter Foundation Project Name(s)'
  90. )
  91.  
  92. cls
  93. Write-Host "================ $Title ================"
  94.  
  95. Write-Host "1: Create a Foundation Project."
  96. Write-Host "q: Press 'q' to exit this prompt and continue to create Feature projects."
  97. }
  98.  
  99. <#
  100. Prompt to accept Feature projects
  101. #>
  102. function Accept-FeatureProjects
  103. {
  104. param (
  105. [string]$Title = 'Enter Feature Project Name(s)'
  106. )
  107. cls
  108. Write-Host "================ $Title ================"
  109.  
  110. Write-Host "1: Create a Feature Project."
  111. Write-Host "q: Press 'q' to exit this prompt and continue."
  112. }
  113.  
  114. <#
  115. Purpose is get the information for the folder in which we are going to create the folder structure
  116. #>
  117. function Get-HabitatFoundationFolder
  118. {
  119. #Get path and validate the path
  120. $global:helixPath = $input = Read-Host "Please specify the path to an empty folder"
  121.  
  122. if($global:helixPath -eq "")
  123. {
  124. Write-Host "Select a valid folder path."
  125. exit
  126. }
  127.  
  128. if ( -not (Test-Path $global:helixPath -PathType Container) )
  129. {
  130. Write-Host "Select a valid folder."
  131. exit
  132. }
  133.  
  134. $directoryInfo = Get-ChildItem $global:helixPath | Measure-Object
  135. if ($directoryInfo.count -gt 0)
  136. {
  137. Write-Host "Folder is not empty."
  138. exit
  139. }
  140. }
  141.  
  142. <#
  143. Purpose is to create the base folder structure of the Habitat solution. Step 1.
  144. #>
  145. function Create-HabitatFoundationFolders
  146. {
  147.  
  148. foreach ($path in $global:folderPaths)
  149. {
  150. $newFolder = $global:helixPath + $path
  151. New-Item -ItemType Directory -Path $newFolder -Force
  152. }
  153.  
  154. $solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
  155. $parentProject = $solution.AddSolutionFolder($global:FoundationFolderName)
  156. $parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder])
  157.  
  158. foreach ($foundation in $global:foundationNames)
  159. {
  160.  
  161. $newFolder = $global:helixPath + $global:foundationPath + $foundation + $global:codeFolder
  162. $projectName = $global:foundationNamePrefix + "." + $foundation
  163. $testsProjectName = $global:foundationNamePrefix + "." + $foundation + "." + $global:testProjectName
  164.  
  165. $childProject = $parentSolutionFolder.AddSolutionFolder($foundation)
  166. $childSolutionFolder = Get-Interface $childProject.Object ([EnvDTE80.SolutionFolder])
  167.  
  168. $projectFile = $childSolutionFolder.AddFromTemplate($global:webTemplate,$newFolder, $projectName);
  169.  
  170. $newFolder = $global:helixPath + $global:foundationPath + $foundation + $global:rolesFolder
  171. New-Item -ItemType Directory -Path $newFolder -Force
  172.  
  173. $newFolder = $global:helixPath + $global:foundationPath + $foundation + $global:serializationFolder
  174. New-Item -ItemType Directory -Path $newFolder -Force
  175.  
  176. $newFolder = $global:helixPath + $global:foundationPath + $foundation + $global:testsFolder
  177. $projectFile = $childSolutionFolder.AddFromTemplate($global:classTemplate,$newFolder, $testsProjectName);
  178. }
  179.  
  180. $solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
  181. $parentProject = $solution.AddSolutionFolder($global:FeatureFolderName)
  182. $parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder])
  183.  
  184. foreach ($feature in $global:featureNames)
  185. {
  186. $newFolder = $global:helixPath + $global:featurePath + $feature + $global:codeFolder
  187. $projectName = $global:featureNamePrefix + "." + $feature
  188. $testsProjectName = $global:featureNamePrefix + "." + $feature + "." + $global:testProjectName
  189.  
  190. $childProject = $parentSolutionFolder.AddSolutionFolder($feature)
  191. $childSolutionFolder = Get-Interface $childProject.Object ([EnvDTE80.SolutionFolder])
  192.  
  193. $projectFile = $childSolutionFolder.AddFromTemplate($global:webTemplate,$newFolder, $projectName);
  194.  
  195. $newFolder = $global:helixPath + $global:featurePath + $feature + $global:rolesFolder
  196. New-Item -ItemType Directory -Path $newFolder -Force
  197.  
  198. $newFolder = $global:helixPath + $global:featurePath + $feature + $global:serializationFolder
  199. New-Item -ItemType Directory -Path $newFolder -Force
  200.  
  201. $newFolder = $global:helixPath + $global:featurePath + $feature + $global:testsFolder
  202. $projectFile = $childSolutionFolder.AddFromTemplate($global:classTemplate,$newFolder, $testsProjectName);
  203. }
  204.  
  205. $solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
  206. $parentProject = $solution.AddSolutionFolder($global:ProjectFolderName)
  207. $parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder])
  208.  
  209. foreach ($project in $global:projectNames)
  210. {
  211. $newFolder = $global:helixPath + $global:projectPath + $project + $global:codeFolder
  212. $projectName = $global:solutionName + "." + $project + "." + $global:websiteName
  213.  
  214. $parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder])
  215. $childProject = $parentSolutionFolder.AddSolutionFolder($project)
  216. $childSolutionFolder = Get-Interface $childProject.Object ([EnvDTE80.SolutionFolder])
  217.  
  218. $projectFile = $childSolutionFolder.AddFromTemplate($global:webTemplate,$newFolder, $projectName);
  219.  
  220. $newFolder = $global:helixPath + $global:projectPath + $project + $global:rolesFolder
  221. New-Item -ItemType Directory -Path $newFolder -Force
  222.  
  223. $newFolder = $global:helixPath + $global:projectPath + $project + $global:serializationFolder
  224. New-Item -ItemType Directory -Path $newFolder -Force
  225. }
  226.  
  227. Write-Host "Done creating Habitat Foundation Structure."
  228. }
  229.  
  230. <#
  231. Purpose is to accept inputs
  232. #>
  233. function Accept-VSSolutionNames
  234. {
  235. do
  236. {
  237. cls
  238. $input = Read-Host "Please specify you solution name. This could be the company name or overall solution name. e.g. Acme or MSFT "
  239.  
  240. if([string]::IsNullOrWhiteSpace($input))
  241. {
  242. Write-Host "Empty solution name. Try again."
  243. }
  244. else
  245. {
  246. $global:solutionName = $input
  247. }
  248. }
  249. until (-not([string]::IsNullOrWhiteSpace($global:solutionName)))
  250.  
  251. do
  252. {
  253. $global:foundationNamePrefix = Read-Host "Please specify you foundation name prefix. e.g."$global:solutionName".Foundation"
  254.  
  255. if([string]::IsNullOrWhiteSpace($global:foundationNamePrefix))
  256. {
  257. Write-Host "Empty foundation name prefix. Try again."
  258. }
  259. }
  260. until (-not([string]::IsNullOrWhiteSpace($global:foundationNamePrefix)))
  261.  
  262. do
  263. {
  264. $global:featureNamePrefix = Read-Host "Please specify you feature name prefix. e.g."$global:solutionName".Feature"
  265.  
  266. if([string]::IsNullOrWhiteSpace($global:featureNamePrefix))
  267. {
  268. Write-Host "Empty feature name prefix. Try again."
  269. }
  270. }
  271. until (-not([string]::IsNullOrWhiteSpace($global:featureNamePrefix)))
  272.  
  273. do
  274. {
  275. Accept-Projects
  276. $input = Read-Host "Enter your Project name/Tenant/Site name or q to continue. (Habitat or Site1)"
  277. if ($input -eq 'q')
  278. {
  279. break
  280. }
  281. elseif (-not([string]::IsNullOrWhiteSpace($input)))
  282. {
  283. $global:projectNames.Add($input)
  284. #create foundation project
  285. }
  286. }
  287. until ($input -eq 'q')
  288.  
  289. do
  290. {
  291. Accept-FoundationProjects
  292. $input = Read-Host "Enter your Foundation project name or q to continue."
  293. if ($input -eq 'q')
  294. {
  295. break
  296. }
  297. elseif (-not([string]::IsNullOrWhiteSpace($input)))
  298. {
  299. $global:foundationNames.Add($input)
  300. #create foundation project
  301. }
  302. }
  303. until ($input -eq 'q')
  304.  
  305. do
  306. {
  307. Accept-FeatureProjects
  308. $input = Read-Host "Enter your Feature project name or q to continue."
  309. if ($input -eq 'q')
  310. {
  311. break
  312. }
  313. elseif (-not([string]::IsNullOrWhiteSpace($input)))
  314. {
  315. $global:featureNames.Add($input)
  316. #create feature project
  317. }
  318. }
  319. until ($input -eq 'q')
  320. }
  321.  
  322. <#
  323. Confirm selections/input
  324. #>
  325. function Confirm-VSSolutionNames
  326. {
  327. cls
  328. Write-Host "Solution Name:" $global:solutionName
  329. Write-Host "Project Names:" $global:projectNames
  330. Write-Host "Foundation Name Prefix:" $global:foundationNamePrefix
  331. Write-Host "Feature Name Prefix:" $global:featureNamePrefix
  332. Write-Host "Foundation Projects:" $global:foundationNames
  333. Write-Host "Feature Projects:" $global:featureNames
  334.  
  335. Confirm-Creation
  336.  
  337. $input = Read-Host "Enter 1 to continue or q to exit."
  338. if ($input -eq 'q')
  339. {
  340. exit
  341. }
  342. elseif ($input -eq '1')
  343. {
  344. $dte.Solution.Create($global:helixPath, $global:solutionName)
  345. $global:solution = $dte.Solution
  346. $dte.ExecuteCommand("File.SaveAll")
  347.  
  348. Create-HabitatFoundationFolders
  349.  
  350. $solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
  351. $parentFolder = $solution.AddSolutionFolder($global:ConfigFolderName)
  352. $dte.ExecuteCommand("File.SaveAll")
  353. }
  354. }
  355.  
  356. <#
  357. Start function
  358. #>
  359. function Lets-Rumble
  360. {
  361. Write-Host " ) ( ( "
  362. Write-Host " ( /( ( )\ ) ( ) )\ ) ) "
  363. Write-Host " )\()) ( )\( ) (()/( )\ ( ( /(( (()/( ( ( ( /( "
  364. Write-Host "((_)\ ))((_)\ ( /( /(_)) ( ((_)))\ )\())\ ( ( /(_)) ( )( )\ ` ) )\()) "
  365. Write-Host " _((_)/((_)((_))\()) (_)) )\ _ /((_|_))((_) )\ )\ ) (_)) )(()((_)/(/( (_))/ "
  366. Write-Host "| || (_))| |(_|(_)\ / __| ((_) (_))(| |_ (_)((_)_(_/( / __| ((_|(_|_|(_)_\| |_ "
  367. Write-Host "| __ / -_) || \ \ / \__ \/ _ \ | || | _|| / _ \ ' \)) \__ \/ _| '_| | '_ \) _| "
  368. Write-Host "|_||_\___|_||_/_\_\ |___/\___/_|\_,_|\__||_\___/_||_| |___/\__|_| |_| .__/ \__| "
  369. Write-Host " |_| "
  370.  
  371. Get-HabitatFoundationFolder
  372. Accept-VSSolutionNames
  373. Confirm-VSSolutionNames
  374. }
Add Comment
Please, Sign In to add comment