Skip to content

Commit 76eea9c

Browse files
add color codes to help output
1 parent be56a8f commit 76eea9c

9 files changed

Lines changed: 284 additions & 126 deletions

File tree

dist/index.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/colorize.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const GREEN = '\x1b[32m' // For short options (-h)
2+
const CYAN = '\x1b[36m' // For long options (--help)
3+
const YELLOW = '\x1b[33m' // Could be used for parameter values
4+
const RESET = '\x1b[0m' // Reset to default color
5+
6+
export function short(text: string): string {
7+
return `${GREEN}${text}${RESET}`
8+
}
9+
10+
export function long(text: string): string {
11+
return `${CYAN}${text}${RESET}`
12+
}
13+
14+
export function heading(text: string): string {
15+
return underline(bold(`${YELLOW}${text}${RESET}`))
16+
}
17+
18+
export function bold(text: string): string {
19+
return `\x1b[1m${text}${RESET}`
20+
}
21+
22+
export function italic(text: string): string {
23+
return `\x1b[3m${text}${RESET}`
24+
}
25+
26+
export function underline(text: string): string {
27+
return `\x1b[4m${text}${RESET}`
28+
}
29+
30+
export function command(
31+
short_command: string | null,
32+
long_command: string,
33+
description: string
34+
): undefined {
35+
if (short_command) {
36+
console.log(short(short_command), bold(long(long_command)), description)
37+
} else {
38+
console.log(bold(long(long_command)), description)
39+
}
40+
}

src/export/android.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
import * as helper from './helper'
22

3+
import * as COLOR from '../colorize'
34
const path = require('path')
45
const fs = require('fs-extra')
56
const { exec } = require('child_process')
67

78
export function help() {
8-
console.log('\nAndroid settings:')
9-
console.log('')
10-
console.log(
11-
'--android-sdk Specify sdk.dir which is required for building.'
9+
console.log('\n', COLOR.heading('Android settings:'), '\n')
10+
11+
COLOR.command(
12+
null,
13+
'--android-sdk',
14+
' Specify sdk.dir which is required for building.'
15+
)
16+
COLOR.command(
17+
null,
18+
'--android-appName',
19+
' Name of the App (Main-title is used as default).'
20+
)
21+
COLOR.command(
22+
null,
23+
'--android-appId',
24+
' Required to identify your App reverse url such as io.github.liascript'
1225
)
13-
console.log(
14-
'--android-appName Name of the App (Main-title is used as default).'
26+
COLOR.command(
27+
null,
28+
'--android-icon',
29+
' Optional icon with 1024x1024 px'
1530
)
16-
console.log(
17-
'--android-appId Required to identify your App reverse url such as io.github.liascript'
31+
COLOR.command(
32+
null,
33+
'--android-splash',
34+
' Optional splash image with 2732x2732 px'
1835
)
19-
console.log('--android-icon Optional icon with 1024x1024 px')
20-
console.log(
21-
'--android-splash Optional splash image with 2732x2732 px'
36+
COLOR.command(
37+
null,
38+
'--android-splashDuration',
39+
' Duration for splash-screen default 0 milliseconds'
2240
)
23-
console.log(
24-
'--android-splashDuration Duration for splash-screen default 0 milliseconds'
41+
COLOR.command(
42+
null,
43+
'--android-preview',
44+
' Open course in Android-Studio'
2545
)
26-
console.log('--android-preview Open course in Android-Studio')
2746
}
2847

2948
export async function exporter(

src/export/ims.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
import * as helper from './helper'
22
import * as RDF from './rdf'
3+
import * as COLOR from '../colorize'
34

45
const path = require('path')
56
const fs = require('fs-extra')
67

78
export function help() {
8-
console.log('\nIMS settings:')
9-
console.log('')
10-
console.log(
9+
console.log('\n', COLOR.heading('IMS settings:'), '\n')
10+
11+
COLOR.command(
12+
null,
1113
'--ims-indexeddb',
1214
' Use IndexedDB to store data persistently'
1315
)
1416

15-
console.log('\nWEB settings:')
17+
console.log('\n', COLOR.heading('WEB settings:'), '\n')
1618
console.log('')
17-
console.log(
18-
'--web-iframe Use an iframed version to hide the course URL.'
19+
COLOR.command(
20+
null,
21+
'--web-iframe',
22+
' Use an iframed version to hide the course URL.'
1923
)
20-
console.log(
21-
'--web-indexeddb This will allow to store data within the browser using indexeddb, you can optionally pass a unique key (by default one is generated randomly).'
24+
COLOR.command(
25+
null,
26+
'--web-indexeddb',
27+
' This will allow to store data within the browser using indexeddb, you can optionally pass a unique key (by default one is generated randomly).'
2228
)
23-
console.log(
24-
'--web-zip By default the result is not zipped, you can change this with this parameter.'
29+
COLOR.command(
30+
null,
31+
'--web-zip',
32+
' By default the result is not zipped, you can change this with this parameter.'
2533
)
2634
}
2735

src/export/pdf.ts

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,115 @@
11
import * as helper from './helper'
22

3+
import * as COLOR from '../colorize'
34
const path = require('path')
45
import puppeteer from 'puppeteer'
56

67
export function help() {
7-
console.log('\nPDF settings:\n')
8-
console.log(
9-
'--pdf-stylesheet Inject an local CSS for changing the appearance.'
8+
console.log('\n', COLOR.heading('PDF settings:'), '\n')
9+
10+
COLOR.command(
11+
null,
12+
'--pdf-stylesheet',
13+
' Inject an local CSS for changing the appearance.'
1014
)
11-
console.log(
12-
'--pdf-theme LiaScript themes: default, turquoise, blue, red, yellow'
15+
COLOR.command(
16+
null,
17+
'--pdf-theme',
18+
' LiaScript themes: default, turquoise, blue, red, yellow'
1319
)
14-
console.log(
15-
'--pdf-timeout Set an additional time horizon to wait until finished.'
20+
COLOR.command(
21+
null,
22+
'--pdf-timeout',
23+
' Set an additional time horizon to wait until finished.'
1624
)
1725
console.log(
1826
'\nhttps://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions\n'
1927
)
20-
console.log(
21-
'--pdf-preview Open preview-browser (default false), print not possible'
28+
COLOR.command(
29+
null,
30+
'--pdf-preview',
31+
' Open preview-browser (default false), print not possible'
2232
)
23-
console.log(
24-
'--pdf-scale Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.'
33+
COLOR.command(
34+
null,
35+
'--pdf-scale',
36+
' Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2.'
2537
)
26-
console.log(
27-
'--pdf-displayHeaderFooter Display header and footer. Defaults to false.'
38+
COLOR.command(
39+
null,
40+
'--pdf-displayHeaderFooter',
41+
' Display header and footer. Defaults to false.'
2842
)
29-
console.log(
30-
'--pdf-headerTemplate HTML template for the print header, inject classes date, title, url, pageNumber, totalPages'
43+
COLOR.command(
44+
null,
45+
'--pdf-headerTemplate',
46+
' HTML template for the print header, inject classes date, title, url, pageNumber, totalPages'
3147
)
3248

33-
console.log(
34-
'--pdf-footerTemplate HTML template for the print footer. Should use the same format as the headerTemplate'
49+
COLOR.command(
50+
null,
51+
'--pdf-footerTemplate',
52+
' HTML template for the print footer. Should use the same format as the headerTemplate'
3553
)
36-
console.log(
37-
'--pdf-printBackground Print background graphics. Defaults to false'
54+
COLOR.command(
55+
null,
56+
'--pdf-printBackground',
57+
' Print background graphics. Defaults to false'
3858
)
39-
console.log(
40-
'--pdf-landscape Paper orientation. Defaults to false.'
59+
COLOR.command(
60+
null,
61+
'--pdf-landscape',
62+
' Paper orientation. Defaults to false.'
4163
)
42-
console.log(
43-
'--pdf-pageRanges Paper ranges to print, e.g., "1-5, 8, 11-13"'
64+
COLOR.command(
65+
null,
66+
'--pdf-pageRanges',
67+
' Paper ranges to print, e.g., "1-5, 8, 11-13"'
4468
)
45-
console.log(
46-
'--pdf-format Paper format. If set, takes priority over width or height options. Defaults to a4.'
69+
COLOR.command(
70+
null,
71+
'--pdf-format',
72+
' Paper format. If set, takes priority over width or height options. Defaults to a4.'
4773
)
48-
console.log(
49-
'--pdf-width Paper width, accepts values labeled with units.'
74+
COLOR.command(
75+
null,
76+
'--pdf-width',
77+
' Paper width, accepts values labeled with units.'
5078
)
51-
console.log(
52-
'--pdf-height Paper height, accepts values labeled with units.'
79+
COLOR.command(
80+
null,
81+
'--pdf-height',
82+
' Paper height, accepts values labeled with units.'
5383
)
54-
console.log(
55-
'--pdf-margin-top Top margin, accepts values labeled with units.'
84+
COLOR.command(
85+
null,
86+
'--pdf-margin-top',
87+
' Top margin, accepts values labeled with units.'
5688
)
57-
console.log(
58-
'--pdf-margin-right Right margin, accepts values labeled with units.'
89+
COLOR.command(
90+
null,
91+
'--pdf-margin-right',
92+
' Right margin, accepts values labeled with units.'
5993
)
60-
console.log(
61-
'--pdf-margin-bottom Bottom margin, accepts values labeled with units.'
94+
COLOR.command(
95+
null,
96+
'--pdf-margin-bottom',
97+
' Bottom margin, accepts values labeled with units.'
6298
)
63-
console.log(
64-
'--pdf-margin-left Left margin, accepts values labeled with units. '
99+
COLOR.command(
100+
null,
101+
'--pdf-margin-left',
102+
' Left margin, accepts values labeled with units. '
65103
)
66-
console.log(
67-
'--pdf-preferCSSPageSize Give any CSS @page size declared in the page priority over what is declared in width and height or format options.'
104+
COLOR.command(
105+
null,
106+
'--pdf-preferCSSPageSize',
107+
' Give any CSS @page size declared in the page priority over what is declared in width and height or format options.'
68108
)
69-
console.log(
70-
'--pdf-omitBackground Hides default white background and allows capturing screenshots with transparency. Defaults to true. '
109+
COLOR.command(
110+
null,
111+
'--pdf-omitBackground',
112+
' Hides default white background and allows capturing screenshots with transparency. Defaults to true. '
71113
)
72114
}
73115

src/export/project.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as SCORM12 from './scorm12'
55
import * as SCORM2004 from './scorm2004'
66
import * as ANDROID from './android'
77
import * as RDF from './rdf'
8+
import * as COLOR from '../colorize'
89

910
const fs = require('fs-extra')
1011
const path = require('path')
@@ -63,32 +64,52 @@ export function storeNext(collection: any, data: any) {
6364
}
6465

6566
export function help() {
66-
console.log('\nProject settings:')
67-
console.log('')
68-
console.log(
69-
'--project-no-meta Disable the generation of meta information for OpenGraph and Twitter-cards.'
67+
console.log('\n', COLOR.heading('Project settings:'), '\n')
68+
69+
COLOR.command(
70+
null,
71+
'--project-no-meta',
72+
' Disable the generation of meta information for OpenGraph and Twitter-cards.'
73+
)
74+
COLOR.command(
75+
null,
76+
'--project-no-rdf',
77+
' Disable the generation of json-ld.'
7078
)
71-
console.log('--project-no-rdf Disable the generation of json-ld.')
72-
console.log(
73-
'--project-no-categories Disable the filter for categories/tags.'
79+
COLOR.command(
80+
null,
81+
'--project-no-categories',
82+
' Disable the filter for categories/tags.'
7483
)
75-
console.log(
76-
'--project-category-blur Enable this and the categories will be blurred instead of deleted.'
84+
COLOR.command(
85+
null,
86+
'--project-category-blur',
87+
' Enable this and the categories will be blurred instead of deleted.'
7788
)
78-
console.log(
79-
'--project-generate-scrom12 SCORM12 and pass additional scrom settings.'
89+
COLOR.command(
90+
null,
91+
'--project-generate-scrom12',
92+
'SCORM12 and pass additional scrom settings.'
8093
)
81-
console.log(
82-
'--project-generate-scrom2004 SCORM2004 and pass additional scrom settings.'
94+
COLOR.command(
95+
null,
96+
'--project-generate-scrom2004',
97+
'SCORM2004 and pass additional scrom settings.'
8398
)
84-
console.log(
85-
'--project-generate-ims IMS resources with additional config settings.'
99+
COLOR.command(
100+
null,
101+
'--project-generate-ims',
102+
' IMS resources with additional config settings.'
86103
)
87-
console.log(
88-
'--project-generate-pdf PDFs are automatically generated and added to every card.'
104+
COLOR.command(
105+
null,
106+
'--project-generate-pdf',
107+
' PDFs are automatically generated and added to every card.'
89108
)
90-
console.log(
91-
'--project-generate-cache Only generate new files, if they do not exist.'
109+
COLOR.command(
110+
null,
111+
'--project-generate-cache',
112+
' Only generate new files, if they do not exist.'
92113
)
93114
}
94115

0 commit comments

Comments
 (0)