forked from dfinke/PowerShellNotebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerShellNotebookDSL.ps1
59 lines (50 loc) · 1.07 KB
/
PowerShellNotebookDSL.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
function Add-NotebookCode {
param($code)
$script:codeBlocks += [PSCustomObject][Ordered]@{
'cell_type' = 'code'
'source' = $code
} | ConvertTo-Json
}
function Add-NotebookMarkdown {
param($markdown)
$script:codeBlocks += [PSCustomObject][Ordered]@{
'cell_type' = 'markdown'
'source' = $markdown
} | ConvertTo-Json -Compress
}
function New-PSNotebook {
param(
[Scriptblock]$sb,
$nbFileName,
[Switch]$AsText
)
$script:codeBlocks = @()
&$sb
$result = @"
{
"metadata": {
"kernelspec": {
"name": "powershell",
"display_name": "PowerShell"
},
"language_info": {
"name": "powershell",
"codemirror_mode": "shell",
"mimetype": "text/x-sh",
"file_extension": ".ps1"
}
},
"nbformat_minor": 2,
"nbformat": 4,
"cells": [
$($script:codeBlocks -join ',')
]
}
"@
if ($AsText) {
return $result
}
else {
$result > $nbFileName
}
}