Skip to content

Commit f575dd2

Browse files
committed
Add pdf output
1 parent 2e0912e commit f575dd2

File tree

11 files changed

+1395
-13
lines changed

11 files changed

+1395
-13
lines changed

gtt-report.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const Report = require('./models/report');
1010
const Output = {
1111
table: require('./output/table'),
1212
csv: require('./output/csv'),
13+
pdf: require('./output/pdf'),
1314
markdown: require('./output/markdown')
1415
};
1516

@@ -199,14 +200,16 @@ new Promise(resolve => {
199200

200201
// print report
201202
.then(() => new Promise(resolve => {
203+
Cli.list(`${Cli.print} Printing report`);
202204
if (config.get('file')) {
203-
output.toFile(config.get('file'));
205+
output.toFile(config.get('file'), resolve);
204206
} else {
205207
output.toStdOut();
208+
resolve();
206209
}
207-
resolve();
208210
}))
209211
.catch(error => Cli.x(`could not print report.`, error))
212+
.then(() => Cli.mark())
210213

211214
// time for a beer
212215
.then(() => Cli.done());

include/cli.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class cli {
1818
/*
1919
* emojis
2020
*/
21+
static get print() {
22+
return '🖨';
23+
}
24+
2125
static get look() {
2226
return '🔍';
2327
}
@@ -27,7 +31,7 @@ class cli {
2731
}
2832

2933
static get process() {
30-
return '⚙';
34+
return '⚙';
3135
}
3236

3337
static get output() {

output/base.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class base {
8888
/**
8989
* render to file
9090
*/
91-
toFile(file) {
91+
toFile(file, resolve) {
9292
fs.writeFileSync(file, this.out);
93+
resolve();
9394
}
9495

9596
/**

output/csv.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class csv extends Base {
4545
this.csvRecords = Csv.stringify(times);
4646
}
4747

48-
toFile(file) {
48+
toFile(file, resolve) {
4949
let fileName = path.basename(file);
5050
let extName = path.extname(file);
5151

@@ -64,6 +64,8 @@ class csv extends Base {
6464
if (this.config.get('report').includes('records')) {
6565
fs.writeFileSync(file.replace(fileName, fileName.replace(extName, `.records${extName}`)), this.csvRecords);
6666
}
67+
68+
resolve();
6769
}
6870

6971
toStdOut() {

output/markdown.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const Base = require('./base');
55

66
const format = {
77
headline: h => `\n### ${h}\n`,
8-
warning: w => `> ${w}`
8+
warning: w => `${w}`
99
};
1010

1111
/**
1212
* stdout table output
1313
*/
14-
class table extends Base {
14+
class markdown extends Base {
1515
constructor(config, report) {
1616
super(config, report);
1717
this.format = format;
@@ -62,4 +62,4 @@ class table extends Base {
6262
}
6363
}
6464

65-
module.exports = table;
65+
module.exports = markdown;

output/pdf.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
const markdownpdf = require('markdown-pdf');
3+
4+
const markdown = require('./markdown');
5+
const Cli = require('./../include/cli');
6+
7+
class pdf extends markdown {
8+
toFile(file, resolve, style = 'default') {
9+
if (fs.existsSync(file)) fs.unlinkSync(file);
10+
11+
markdownpdf({
12+
cssPath: `${__dirname}/styles/layout/${style}.css`,
13+
highlightCssPath: `${__dirname}/styles/highlight/${style}.css`
14+
}).from.string(this.out).to(file, () => resolve());
15+
}
16+
17+
toStdOut() {
18+
Cli.error(`Can't output pdf to std out`);
19+
}
20+
}
21+
22+
module.exports = pdf;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.hljs {
2+
display: block;
3+
overflow-x: auto;
4+
padding: 0.5em;
5+
background: #f0f0f0;
6+
-webkit-text-size-adjust: none
7+
}
8+
9+
.hljs, .hljs-subst, .hljs-tag .hljs-title, .nginx .hljs-title {
10+
color: black
11+
}
12+
13+
.hljs-string, .hljs-title, .hljs-constant, .hljs-parent, .hljs-tag .hljs-value, .hljs-rules .hljs-value, .hljs-preprocessor, .hljs-pragma, .haml .hljs-symbol, .ruby .hljs-symbol, .ruby .hljs-symbol .hljs-string, .hljs-template_tag, .django .hljs-variable, .smalltalk .hljs-class, .hljs-addition, .hljs-flow, .hljs-stream, .bash .hljs-variable, .apache .hljs-tag, .apache .hljs-cbracket, .tex .hljs-command, .tex .hljs-special, .erlang_repl .hljs-function_or_atom, .asciidoc .hljs-header, .markdown .hljs-header, .coffeescript .hljs-attribute {
14+
color: #800
15+
}
16+
17+
.smartquote, .hljs-comment, .hljs-annotation, .diff .hljs-header, .hljs-chunk, .asciidoc .hljs-blockquote, .markdown .hljs-blockquote {
18+
color: #888
19+
}
20+
21+
.hljs-number, .hljs-date, .hljs-regexp, .hljs-literal, .hljs-hexcolor, .smalltalk .hljs-symbol, .smalltalk .hljs-char, .go .hljs-constant, .hljs-change, .lasso .hljs-variable, .makefile .hljs-variable, .asciidoc .hljs-bullet, .markdown .hljs-bullet, .asciidoc .hljs-link_url, .markdown .hljs-link_url {
22+
color: #080
23+
}
24+
25+
.hljs-label, .hljs-javadoc, .ruby .hljs-string, .hljs-decorator, .hljs-filter .hljs-argument, .hljs-localvars, .hljs-array, .hljs-attr_selector, .hljs-important, .hljs-pseudo, .hljs-pi, .haml .hljs-bullet, .hljs-doctype, .hljs-deletion, .hljs-envvar, .hljs-shebang, .apache .hljs-sqbracket, .nginx .hljs-built_in, .tex .hljs-formula, .erlang_repl .hljs-reserved, .hljs-prompt, .asciidoc .hljs-link_label, .markdown .hljs-link_label, .vhdl .hljs-attribute, .clojure .hljs-attribute, .asciidoc .hljs-attribute, .lasso .hljs-attribute, .coffeescript .hljs-property, .hljs-phony {
26+
color: #88f
27+
}
28+
29+
.hljs-keyword, .hljs-id, .hljs-title, .hljs-built_in, .css .hljs-tag, .hljs-javadoctag, .hljs-phpdoc, .hljs-dartdoc, .hljs-yardoctag, .smalltalk .hljs-class, .hljs-winutils, .bash .hljs-variable, .apache .hljs-tag, .hljs-type, .hljs-typename, .tex .hljs-command, .asciidoc .hljs-strong, .markdown .hljs-strong, .hljs-request, .hljs-status {
30+
font-weight: bold
31+
}
32+
33+
.asciidoc .hljs-emphasis, .markdown .hljs-emphasis {
34+
font-style: italic
35+
}
36+
37+
.nginx .hljs-built_in {
38+
font-weight: normal
39+
}
40+
41+
.coffeescript .javascript, .javascript .xml, .lasso .markup, .tex .hljs-formula, .xml .javascript, .xml .vbscript, .xml .css, .xml .hljs-cdata {
42+
opacity: 0.5
43+
}

0 commit comments

Comments
 (0)