-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update all deps * migrate to typescript + add types * improve documentation * minor refactoring * improve template * rename `tags` arg to `positions` * update GH actions
- Loading branch information
Showing
22 changed files
with
4,889 additions
and
3,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.ts text eol=lf | ||
*.yml text eol=lf | ||
*.md text eol=lf | ||
*.hbs text eol=lf | ||
*.scss text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
--- | ||
name: test | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
test: | ||
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node_version: | ||
- 12 | ||
- 14 | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
|
||
steps: | ||
- name: Normalize line endings | ||
run: | | ||
git config --global core.autocrlf input | ||
git config --global core.eol lf | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node_version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node_version }} | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm test | ||
--- | ||
name: "test" | ||
|
||
on: | ||
- "push" | ||
- "pull_request" | ||
|
||
jobs: | ||
test: | ||
name: "Test on node ${{ matrix.node_version }} and ${{ matrix.os }}" | ||
runs-on: "${{ matrix.os }}" | ||
strategy: | ||
matrix: | ||
node_version: | ||
- 16 | ||
- 18 | ||
os: | ||
- "ubuntu-latest" | ||
- "windows-latest" | ||
- "macOS-latest" | ||
steps: | ||
- uses: "actions/checkout@v3" | ||
- name: "Use Node.js ${{ matrix.node_version }}" | ||
uses: "actions/setup-node@v3" | ||
with: | ||
node-version: "${{ matrix.node_version }}" | ||
- run: "npm ci" | ||
- run: "npm run lint" | ||
- run: "npm test" | ||
- name: "release" | ||
uses: "softprops/action-gh-release@v1" | ||
if: "startsWith(github.ref, 'refs/tags/')" | ||
with: | ||
draft: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
*.yml | ||
*.jpg | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { readFileSync } from 'fs'; | ||
|
||
/** | ||
* Reads in a file and encodes it as base64 | ||
* @param filePath file to read in and encode as base64 | ||
* @returns base64 encoding of file | ||
*/ | ||
const base64Encode = (filePath: string) => { | ||
return readFileSync(filePath).toString('base64'); | ||
}; | ||
|
||
export default base64Encode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import hbs, { SafeString } from 'handlebars'; | ||
|
||
/** | ||
* Make `content` suitable for rendering | ||
* @param {string|Array<string>} content - some description, in list or string format | ||
* @returns {string|SafeString} HTML to render | ||
*/ | ||
const descFixer = (content: string | Array<string>): string | SafeString => { | ||
return Array.isArray(content) | ||
? new hbs.SafeString(`<ul><li>${content.join('</li><li>')}</li></ul>`) | ||
: content; | ||
}; | ||
|
||
export default descFixer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import hbs, { SafeString } from 'handlebars'; | ||
import type { GenericFilterableNamedObject } from '../../lib'; | ||
|
||
/** | ||
* Render `content` as a comma-separated list | ||
* @param {string|Array<GenericFilterableNamedObject>} content - some description, in list or string format | ||
* @returns {string | SafeString} HTML to render | ||
*/ | ||
const stringify = ( | ||
content: string | Array<GenericFilterableNamedObject> | ||
): string | SafeString => { | ||
return Array.isArray(content) | ||
? new hbs.SafeString(content.map((elem) => elem.name).join(', ')) | ||
: content; | ||
}; | ||
|
||
export default stringify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { setupHtml, renderToPDF, renderToHTML } from './lib'; | ||
import path from 'path'; | ||
import yargs from 'yargs/yargs'; | ||
import { hideBin } from 'yargs/helpers'; | ||
|
||
interface Arguments { | ||
[x: string]: unknown; | ||
_: unknown; | ||
data: string; | ||
template: string; | ||
output: string; | ||
position: string | undefined; | ||
} | ||
|
||
const options = { | ||
data: { | ||
alias: 'd', | ||
demandOption: true, | ||
describe: 'your data', | ||
type: 'string', | ||
nargs: 1, | ||
}, | ||
template: { | ||
alias: 't', | ||
demandOption: true, | ||
describe: 'template to use', | ||
type: 'string', | ||
nargs: 1, | ||
}, | ||
output: { | ||
alias: 'o', | ||
demandOption: true, | ||
describe: 'output file (.pdf, .html)', | ||
type: 'string', | ||
nargs: 1, | ||
}, | ||
position: { | ||
alias: 'p', | ||
describe: 'position to filter for', | ||
type: 'string', | ||
nargs: 1, | ||
}, | ||
}; | ||
|
||
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28061 | ||
const argv: Arguments = yargs(hideBin(process.argv)) | ||
.usage('Usage: $0 -d DATA -t TEMPLATE -o OUTPUT') | ||
.example( | ||
'$0 -d content.yml -t templates/aeolyus -o output.pdf', | ||
'fill out template/aeolyus with content.yml and output a PDF to output.pdf' | ||
) | ||
.example( | ||
'$0 -d content.yml -t templates/aeolyus -o output.html', | ||
'fill out template/aeolyus with content.yml and output HTML to output.html' | ||
) | ||
// @ts-ignore | ||
.options(options) | ||
.help('h') | ||
.alias('h', 'help') | ||
.version('v') | ||
.alias('v', 'version') | ||
.parseSync() as unknown as Arguments; | ||
|
||
setupHtml(argv).then((html) => { | ||
switch (path.extname(argv.output)) { | ||
case '.pdf': | ||
return renderToPDF(html, argv); | ||
case '.html': | ||
return renderToHTML(html, argv); | ||
default: | ||
return renderToHTML(html, argv); | ||
} | ||
}); | ||
|
||
export { Arguments }; |
Oops, something went wrong.