forked from TcOpenGroup/tcopen-app-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaffold-from-template.ps1
60 lines (43 loc) · 2.16 KB
/
scaffold-from-template.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
param([string]$Branch = "dev",
[Parameter(Mandatory=$true)]
[string]$ProjectName,
[string]$TemplateId = "mts-s-template")
$baseDirectory = (Get-Location).Path
$projectDirectory = "$baseDirectory\$projectName"
if($projectName.Contains(".") -or $projectName.Contains(" "))
{
Write-Host "Library name cannot contain '.' or space ' ' "
return
}
$existingDir = Get-ChildItem $baseDirectory -Directory -Filter $projectName
if($existingDir.Name -eq $projectName)
{
Write-Host "Directory '"$projectName"' already exists."
return
}
#--------------------------------------------------------------------------
# Downloading template repository
#--------------------------------------------------------------------------
Invoke-WebRequest https://github.com/TcOpenGroup/tcopen-app-templates/archive/refs/heads/$branch.zip -OutFile .\tcopen-app-templates-$branch.zip
#--------------------------------------------------------------------------
# Extracting template from repository
#--------------------------------------------------------------------------
$templateLocationInRepo = $baseDirectory + "\tcopen-app-templates-$branch\templates\$templateId\"
7z x tcopen-app-templates-$branch.zip "tcopen-app-templates-$branch/templates/$templateId/"
mkdir $projectName
$templateLocationInRepo
$projectDirectory
xcopy $templateLocationInRepo $projectDirectory /e
Remove-Item "tcopen-app-templates-$branch.zip" -Force -ErrorAction SilentlyContinue
Remove-Item "tcopen-app-templates-$branch" -Force -ErrorAction SilentlyContinue -Recurse
#--------------------------------------------------------------------------
# Scaffolding project from template
#--------------------------------------------------------------------------
$projectDirectory
Set-Location $projectDirectory
./scaffold $projectName
#--------------------------------------------------------------------------
# Cleaning up
#--------------------------------------------------------------------------
Remove-Item t -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item *.* -Force -ErrorAction SilentlyContinue