forked from melke/features2html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateDocs.ps1
187 lines (146 loc) · 5.99 KB
/
GenerateDocs.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
174
175
176
177
178
179
180
181
182
183
184
185
186
param ([Parameter(Mandatory)]$pathToFeatureFiles, [Parameter(Mandatory)]$productName, [Parameter(Mandatory)]$companyName)
$directories = Get-ChildItem -Path $pathToFeatureFiles -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
$mainDir = "features" # default to features
if(Test-Path .\output)
{
Remove-Item .\output -recurse
}
New-Item -path .\output -ItemType Directory
## handle feature files in main feature folder
$rootFeatureFiles = (Get-ChildItem -Path $pathToFeatureFiles -force | Where-Object Extension -in ('.feature') | Measure-Object).Count
if(!$rootFeatureFiles -eq 0)
{
$files = Get-ChildItem -Path $($pathToFeatureFiles) -File -Force | Where-Object Extension -in ('.feature') -ErrorAction SilentlyContinue | Select-Object Name
foreach($file in $files)
{
$fileName = $file -replace '@{Name=', "" -replace '.feature', "" -replace '}', ""
node features2html.js -p $productName -a $companyName create -i $pathToFeatureFiles -o output\$fileName.html
}
}
## handle feature files in directories
foreach($dir in $directories)
{
$d = $dir -replace '@{FullName=', '' -replace '}', ''
$parentDir = (Get-Item $d).Parent
if($parentDir.Name -eq $mainDir)
{
# handle features, example structure features\featureNameFolder\featurefile.feature
$o = $d.split('\')[-1]
New-Item -path .\output\$o -ItemType Directory
$file = (Get-ChildItem -Path $d -force | Where-Object Extension -in ('.feature') | Measure-Object).Count
if(!$file -eq 0)
{
node features2html.js -p $productName -a $companyName -i $d create -o output\$o\$o.html
}
}
else
{
# handle nested features, sometimes file structures can go something like: features\featureNameFolder\specificPartOfFeatureFolder\featurefile.feature
$o = $d.split('\')[-1]
New-Item -path .\output\$parentDir\$o -ItemType Directory
$file = (Get-ChildItem -Path $d -force | Where-Object Extension -in ('.feature') | Measure-Object).Count
if(!$file -eq 0)
{
node features2html.js -p $productName -a $companyName -i $d create -o output\$parentDir\$o\$o.html
}
}
}
### files to HTML elements ###
$content = ""
## handle feature files in main output folder
$mainOutputFeatures = Get-ChildItem -Path ".\output" -File -Force -ErrorAction SilentlyContinue | Select-Object Name
if(!$mainOutputFeatures -eq 0)
{
$mainOutputFiles = Get-ChildItem -Path ".\output" -File -Force -ErrorAction SilentlyContinue | Select-Object Name
foreach($outputFeatureFile in $mainOutputFiles)
{
$mainOutputFileName = Split-Path $outputFeatureFile -leaf
$mainOutputFileLinkText = $mainOutputFileName -replace '.html}', '' -replace '@{Name=', ''
$mainOutputLink = $outputFeatureFile -replace '@{Name=', '<a href ="' -replace '}', "`">$($mainOutputFileLinkText)</a></br></br>"`
$content += $mainOutputLink
}
}
## Do stuff with folders that have sub folders
$outputFeatureFolders = Get-ChildItem -Path ".\output" -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
foreach($folder in $outputFeatureFolders)
{
$folderName = Split-Path $folder -leaf
$fn = $folderName -replace '}', ""
$f = $folder -replace '@{FullName=', '' -replace '}', ''
$hasAnySubdir = Get-ChildItem -Path $f -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
Write-Host $fn 'has' $hasAnySubdir.count 'subfolders, creating html for index page'
# create main folder button
$button = "<button type='button' class='collapsible'>$($fn)</button><div class='content'>"
$content += $button
#get feature files in that folder
$path = $folder -replace '@{FullName=', "" -replace '}', ""
$outputFeatureFiles = Get-ChildItem -Path $($path) -File -Force -ErrorAction SilentlyContinue | Select-Object FullName
foreach($file in $outputFeatureFiles)
{
$fileName = Split-Path $file -leaf
$linkText = $fileName -replace '.html}', ''
$link = "<a href ='$($fn)\$($linkText).html'>$($linkText)</a></br></br>"
$content += $link
}
foreach($sub in $hasAnySubdir)
{
$subName = Split-Path $sub -leaf
$sn = $subName -replace '}', ""
$sd = $sub -replace '@{FullName=', '' -replace '}', ''
Write-Host 'Creating index html for' $fn '/' $sn
$subButton = "<button type='button' class='collapsible2'>$($sn)</button><div class='content2'>"
$content += $subButton
$subOutputFeatureFiles = Get-ChildItem -Path $($sd) -File -Force -ErrorAction SilentlyContinue | Select-Object FullName
foreach($subFile in $subOutputFeatureFiles)
{
$subFileName = Split-Path $subFile -leaf
$subLinkText = $subFileName -replace '.html}', ''
$subLink = "<a href ='$($fn)\$($sn)\$($subLinkText).html'>$($subLinkText)</a></br></br>"
$content += $subLink
if ($subFile -eq $subOutputFeatureFiles[-1])
{
$content += "</div>"
}
}
}
$content += "</div>"
}
### create index page for all of our feature files to be displayed
New-Item -path .\output\index.html -ItemType File -Force
$html = "<html><head><title>Feature documentation</title><link rel='stylesheet' href= '../default/templates/style.css'></head><header>
<div>Feature documentation</div></header>
<body><h1>Feature Index</h1>
<p>To gain an understanding of product functionality please select a feature</p>
<div class='contentIndex'>$($content)</div>
<script>
var coll = document.getElementsByClassName('collapsible');
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener('click', function () {
this.classList.toggle('active');
var content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + 'px';
}
});
}
</script>
<script>
var coll = document.getElementsByClassName('collapsible2');
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener('click', function () {
this.classList.toggle('active');
var content = this.nextElementSibling;
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + 'px';
}
});
}
</script>
</html>"
Set-Content -Path .\output\index.html -Value $html