Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Transcript Postprocessor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evy Storozhenko
Transcript Postprocessor
Commits
a179051b
Commit
a179051b
authored
Aug 27, 2023
by
Evy Storozhenko
Browse files
Options
Downloads
Patches
Plain Diff
move imports up and apply changes
parent
c8253bc2
No related branches found
No related tags found
No related merge requests found
Pipeline
#186021
passed
Aug 27, 2023
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.ts
+88
-62
88 additions, 62 deletions
src/index.ts
with
88 additions
and
62 deletions
src/index.ts
+
88
−
62
View file @
a179051b
import
fs
from
"
node:fs/promises
"
;
// import { ParseResult, parse, parseFVV } from "./lib/parsing";
import
{
Protocol
,
ProtocolData
,
parseProtocol
}
from
"
./lib/parsing/utils
"
import
{
generateIndexHtml
,
generateResolutionsHtml
,
generateTranscriptsRssXml
,
renderTranscriptPageHtml
,
}
from
"
./lib/rendering
"
;
import
bootstrap
from
"
bootstrap/dist/css/bootstrap.min.css
"
;
import
{
Command
}
from
"
commander
"
;
import
{
Command
}
from
"
commander
"
;
import
*
as
Path
from
"
path
"
;
async
function
main
()
{
async
function
main
()
{
const
program
=
new
Command
();
const
program
=
new
Command
();
...
@@ -32,48 +43,58 @@ async function run(inputDir: string, outputDir: string, options: CliOptions) {
...
@@ -32,48 +43,58 @@ async function run(inputDir: string, outputDir: string, options: CliOptions) {
throw
"
Too many files to be read, something is off:
"
+
files
.
length
;
throw
"
Too many files to be read, something is off:
"
+
files
.
length
;
}
}
console
.
info
(
"
⚙️ Parsing
"
,
files
.
length
,
"
markdown files...
"
);
console
.
info
(
"
⚙️ Parsing
"
,
files
.
length
,
"
markdown files...
"
);
const
parseResults
=
await
Promise
.
all
(
files
.
map
((
file
)
=>
parseFileWithoutCrashing
(
file
))
const
protocols
=
await
async
function
()
{
// parse the protocols
const
protocolsWithErrors
=
await
Promise
.
all
(
files
.
map
(
file
=>
parseProtocol
(
file
))
);
);
const
errorResults
=
parseResults
.
filter
((
r
)
=>
!
r
.
ok
&&
r
.
data
==
undefined
);
if
(
errorResults
.
length
>
0
)
{
// extract errors and exit if any exist
console
.
error
(
errorResults
.
length
,
"
transcripts had errors. Aborting.
"
);
const
errors
=
protocolsWithErrors
.
filter
(
p
=>
typeof
p
===
"
string
"
);
if
(
errors
.
length
>
0
)
{
console
.
error
(
errors
.
length
,
"
transcripts had errors. Aborting.
"
);
process
.
exit
(
1
);
process
.
exit
(
1
);
}
}
// (3) Generate transcript pages
// there are no errors, so return as Protocol[]
return
protocolsWithErrors
.
map
(
p
=>
p
as
Protocol
);
}();
// Generate transcript pages
console
.
info
(
"
✏️ Writing individual HTML files...
"
);
console
.
info
(
"
✏️ Writing individual HTML files...
"
);
await
generateAllTranscriptPages
(
await
generateAllTranscriptPages
(
outputDir
,
outputDir
,
p
arseResults
.
map
((
res
)
=>
res
.
data
),
p
rotocols
.
map
(
p
=>
({
data
:
p
.
data
,
type
:
p
.
type
})
),
options
options
);
);
//
(4)
Generate index page
// Generate index page
console
.
info
(
"
✏️ Writing index file...
"
);
console
.
info
(
"
✏️ Writing index file...
"
);
await
generateIndexPage
(
await
generateIndexPage
(
outputDir
,
outputDir
,
p
arseResults
.
map
((
res
)
=>
res
.
data
)
,
p
rotocols
,
options
options
);
);
//
(5)
Generate resolution list
// Generate resolution list
console
.
info
(
"
✏️ Writing resolutions list file...
"
);
console
.
info
(
"
✏️ Writing resolutions list file...
"
);
await
generateResolutionsPage
(
await
generateResolutionsPage
(
outputDir
,
outputDir
,
p
arseResults
.
map
((
res
)
=>
res
.
data
),
p
rotocols
.
map
(
p
=>
p
.
data
).
filter
(
data
=>
data
.
data
.
resolutions
!==
undefined
),
options
options
);
);
await
fs
.
writeFile
(
outputDir
+
"
/bootstrap.min.css
"
,
bootstrap
,
"
utf8
"
);
await
fs
.
writeFile
(
outputDir
+
"
/bootstrap.min.css
"
,
bootstrap
,
"
utf8
"
);
//
(6)
Generate JSON of all data
// Generate JSON of all data
console
.
info
(
"
✏️ Writing Metadata as JSON file...
"
);
console
.
info
(
"
✏️ Writing Metadata as JSON file...
"
);
await
fs
.
writeFile
(
await
fs
.
writeFile
(
outputDir
+
"
/index.json
"
,
outputDir
+
"
/index.json
"
,
JSON
.
stringify
(
JSON
.
stringify
(
p
arseResult
s
.
map
(
(
res
)
=>
({
p
rotocol
s
.
map
(
p
=>
({
...
res
.
data
.
me
ta
,
...
p
.
data
.
da
ta
,
tags
:
null
,
tags
:
null
,
categories
:
null
,
categories
:
null
,
contents
:
"
gone_with_this_generator_sorry
"
,
contents
:
"
gone_with_this_generator_sorry
"
,
...
@@ -81,29 +102,20 @@ async function run(inputDir: string, outputDir: string, options: CliOptions) {
...
@@ -81,29 +102,20 @@ async function run(inputDir: string, outputDir: string, options: CliOptions) {
)
)
);
);
//
(7)
Create RSS file
// Create RSS file
console
.
info
(
"
✏️ Writing RSS feed index.xml...
"
);
console
.
info
(
"
✏️ Writing RSS feed index.xml...
"
);
const
rssXml
=
generateTranscriptsRssXml
(
const
rssXml
=
generateTranscriptsRssXml
(
p
arseResult
s
.
map
(
(
res
)
=>
res
.
data
),
p
rotocol
s
.
map
(
p
=>
p
.
data
),
options
.
baseUrl
??
process
.
env
.
CI_PAGES_URL
options
.
baseUrl
??
process
.
env
.
CI_PAGES_URL
);
);
await
fs
.
writeFile
(
outputDir
+
"
/index.xml
"
,
rssXml
);
await
fs
.
writeFile
(
outputDir
+
"
/protokolle/index.xml
"
,
rssXml
);
// (8) Be done
await
fs
.
writeFile
(
Path
.
join
(
outputDir
,
"
index.xml
"
),
rssXml
);
await
fs
.
writeFile
(
Path
.
join
(
outputDir
,
"
protokolle/index.xml
"
),
rssXml
);
// Be done
console
.
info
(
"
✅ All done!
"
);
console
.
info
(
"
✅ All done!
"
);
}
}
import
fs
from
"
node:fs/promises
"
;
import
{
parse
}
from
"
./lib/parsing
"
;
import
{
generateIndexHtml
,
generateResolutionsHtml
,
generateTranscriptsRssXml
,
renderTranscriptPageHtml
,
}
from
"
./lib/rendering
"
;
import
bootstrap
from
"
bootstrap/dist/css/bootstrap.min.css
"
;
async
function
getListOfFiles
(
rootPath
:
string
|
undefined
):
Promise
<
string
[]
>
{
async
function
getListOfFiles
(
rootPath
:
string
|
undefined
):
Promise
<
string
[]
>
{
if
(
typeof
rootPath
!==
"
string
"
)
{
if
(
typeof
rootPath
!==
"
string
"
)
{
throw
new
TypeError
(
"
Missing argument <filesDirectory>
"
);
throw
new
TypeError
(
"
Missing argument <filesDirectory>
"
);
...
@@ -114,22 +126,9 @@ async function getListOfFiles(rootPath: string | undefined): Promise<string[]> {
...
@@ -114,22 +126,9 @@ async function getListOfFiles(rootPath: string | undefined): Promise<string[]> {
.
reverse
();
.
reverse
();
}
}
async
function
parseFileWithoutCrashing
(
path
:
string
):
Promise
<
{
ok
:
boolean
;
data
:
any
;
error
:
any
}
>
{
try
{
const
fileContent
=
await
fs
.
readFile
(
path
,
"
utf-8
"
);
const
data
=
parse
(
fileContent
);
return
{
ok
:
true
,
data
:
data
,
error
:
undefined
};
}
catch
(
error
)
{
console
.
log
(
"
Error for file
"
,
path
,
error
);
return
{
ok
:
false
,
data
:
undefined
,
error
:
error
};
}
}
async
function
generateAllTranscriptPages
(
async
function
generateAllTranscriptPages
(
outputDir
:
string
,
outputDir
:
string
,
transcripts
:
{
me
ta
:
any
;
html
:
string
;
ast
:
any
}[],
transcripts
:
{
da
ta
:
ProtocolData
,
type
:
string
}[],
options
:
CliOptions
options
:
CliOptions
)
{
)
{
// make sure the dir exists and is empty
// make sure the dir exists and is empty
...
@@ -148,31 +147,56 @@ async function generateAllTranscriptPages(
...
@@ -148,31 +147,56 @@ async function generateAllTranscriptPages(
}
}
async
function
generateTranscriptPage
(
async
function
generateTranscriptPage
(
transcript
,
transcript
:
{
data
:
ProtocolData
,
type
:
string
}
,
outputDir
:
string
,
outputDir
:
string
,
options
:
CliOptions
options
:
CliOptions
)
{
)
{
const
{
meta
,
html
,
ast
}
=
transcript
;
const
{
data
,
html
,
ast
}
=
transcript
.
data
;
const
transcriptDir
=
`protokolle/fsr-sitzung-
${
meta
.
number
}
-
${
meta
.
date
}
`
;
const
type
=
transcript
.
type
;
const
makeDirPromise
=
fs
.
mkdir
(
outputDir
+
"
/
"
+
transcriptDir
,
{
recursive
:
true
,
if
(
type
===
"
fsr
"
)
{
});
const
transcriptDir
=
`protokolle/fsr-sitzung-
${
data
.
number
}
-
${
data
.
date
}
`
;
const
pageHtml
=
renderTranscriptPageHtml
(
html
,
meta
);
const
htmlFilePath
=
outputDir
+
"
/
"
+
transcriptDir
+
"
/index.html
"
;
const
dir
=
Path
.
join
(
outputDir
,
transcriptDir
);
await
makeDirPromise
;
await
fs
.
mkdir
(
dir
,
{
recursive
:
true
,
});
await
fs
.
writeFile
(
htmlFilePath
,
pageHtml
,
"
utf-8
"
);
await
fs
.
writeFile
(
Path
.
join
(
dir
,
"
index.html
"
),
html
,
"
utf-8
"
);
const
pageHtml
=
renderTranscriptPageHtml
(
html
,
data
,
"
fsr
"
);
await
fs
.
writeFile
(
Path
.
join
(
dir
,
"
index.html
"
),
pageHtml
,
"
utf-8
"
);
if
(
options
.
outputAst
)
{
if
(
options
.
outputAst
)
{
const
astFilePath
=
outputDir
+
"
/
"
+
transcriptDir
+
"
/ast.json
"
;
await
fs
.
writeFile
(
await
fs
.
writeFile
(
astFilePath
,
JSON
.
stringify
(
ast
,
null
,
2
),
"
utf-8
"
);
Path
.
join
(
dir
,
"
ast.json
"
),
JSON
.
stringify
(
ast
,
null
,
2
),
"
utf-8
"
);
}
}
else
{
const
transcriptDir
=
`protokolle/fvv-sitzung-
${
data
.
date
}
`
;
const
dir
=
Path
.
join
(
outputDir
,
transcriptDir
);
await
fs
.
mkdir
(
dir
,
{
recursive
:
true
,
});
const
pageHtml
=
renderTranscriptPageHtml
(
html
,
data
,
"
fvv
"
);
await
fs
.
writeFile
(
Path
.
join
(
dir
,
"
index.html
"
),
pageHtml
,
"
utf-8
"
);
if
(
options
.
outputAst
)
{
await
fs
.
writeFile
(
Path
.
join
(
dir
,
"
ast.json
"
),
JSON
.
stringify
(
ast
,
null
,
2
),
"
utf-8
"
);
}
}
}
}
}
async
function
generateIndexPage
(
async
function
generateIndexPage
(
outputDir
:
string
,
outputDir
:
string
,
parseResults
:
{
meta
:
any
;
html
:
string
;
ast
:
any
}
[],
parse
File
Results
:
Protocol
[],
options
:
CliOptions
options
:
CliOptions
)
{
)
{
const
html
=
generateIndexHtml
(
parseResults
);
const
html
=
generateIndexHtml
(
parse
File
Results
);
const
htmlFilePath
=
outputDir
+
"
/index.html
"
;
const
htmlFilePath
=
outputDir
+
"
/index.html
"
;
await
fs
.
writeFile
(
htmlFilePath
,
html
,
"
utf8
"
);
await
fs
.
writeFile
(
htmlFilePath
,
html
,
"
utf8
"
);
...
@@ -180,7 +204,7 @@ async function generateIndexPage(
...
@@ -180,7 +204,7 @@ async function generateIndexPage(
async
function
generateResolutionsPage
(
async
function
generateResolutionsPage
(
outputDir
:
string
,
outputDir
:
string
,
parseResults
:
{
meta
:
any
;
html
:
string
;
ast
:
any
}
[],
parseResults
:
ProtocolData
[],
options
:
CliOptions
options
:
CliOptions
)
{
)
{
const
html
=
generateResolutionsHtml
(
parseResults
);
const
html
=
generateResolutionsHtml
(
parseResults
);
...
@@ -189,3 +213,5 @@ async function generateResolutionsPage(
...
@@ -189,3 +213,5 @@ async function generateResolutionsPage(
const
htmlFilePath
=
outputDir
+
"
/resolutions/index.html
"
;
const
htmlFilePath
=
outputDir
+
"
/resolutions/index.html
"
;
await
fs
.
writeFile
(
htmlFilePath
,
html
,
"
utf8
"
);
await
fs
.
writeFile
(
htmlFilePath
,
html
,
"
utf8
"
);
}
}
export
{
Protocol
as
ParseFileResult
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment