forked from getgauge/gauge-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
112 lines (94 loc) · 2.95 KB
/
build.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
Param(
[String]$TaskName # The name of the task to run
)
# Define the tasks
$tasks = @{}
$tasks.Add('build', @{
description = "Compiles typescript files to js with diclaration, add generated code to dist";
script = {
clean
npm run build
Copy-Item -Recurse .\src\gen .\dist
}
})
$tasks.Add('package', @{
description = "Generate gauge-ts plugin zip file";
script = {
Invoke-Command $tasks.Get_Item("build").script
mkdir -p deploy
Copy-Item launcher.* deploy
Copy-Item ts.json deploy
mkdir artifacts
$version = version
$src = Join-Path -Path (Get-Location).Path -ChildPath "deploy"
$artifacts = Join-Path -Path (Get-Location).Path -ChildPath "artifacts"
$dest = Join-Path -Path $artifacts -ChildPath "gauge-ts-$version.zip"
Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory($src, $dest)
}
})
$tasks.Add('install', @{
description = "Install's gauge-ts plugin from the files in artifacts dir";
script = {
Invoke-Command $tasks.Get_Item("package").script
$version = version
gauge install ts -f ".\artifacts\gauge-ts-$version.zip"
}
})
$tasks.Add('uninstall', @{
description = "UnInstall gauge-ts plugin's current version";
script = {
$version = version
gauge uninstall ts -v $version
}
})
$tasks.Add('forceinstall', @{
description = "Insatall gauge-ts plugin after uninstall the current version";
script = {
Invoke-Command $tasks.Get_Item("uninstall").script
Invoke-Command $tasks.Get_Item("install").script
}
})
# Helper functions
function version {
$runnerManifest = Get-Content .\ts.json | Out-String | ConvertFrom-Json
$version = $runnerManifest.version
return $version
}
function clean {
$dirs = "dist", "deploy", "artifacts"
foreach ($dir in $dirs) {
if (Test-Path $dir) {
Remove-Item -Recurse -Force $dir
}
}
}
# Some helpful strings for formatting output
$indent = (" " * 4);
$spacer = ("-" * 40);
function DisplayHelpText {
$help_text = Get-Help $MyInvocation.ScriptName
$syn = $help_text.Synopsis
Write-Output "build.ps1 - runtask TaskName"
DisplayTaskList
}
function DisplayTaskList {
Write-Output "`nList of Tasks:`n$spacer"
foreach ($task in $tasks.GetEnumerator()) {
Write-Output "$indent$($task.Key)"
Write-Output "$($indent * 2)$($task.Value.description)"
}
}
# Now process the given task name
if (-not $taskname) {
DisplayHelpText
exit
}
$task = $tasks.Get_Item($taskname)
if ($task) {
Invoke-Command $task.script
}
else {
Write-Output "'$taskname' is not a valid task name."
DisplayTaskList
}