Skip to content

Commit

Permalink
bump to v2.0.0
Browse files Browse the repository at this point in the history
* 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
guppy0130 committed Sep 20, 2022
1 parent 18416c4 commit 3b4e4c8
Show file tree
Hide file tree
Showing 22 changed files with 4,889 additions and 3,010 deletions.
25 changes: 16 additions & 9 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ env:
node: true
es2020: true
extends:
- 'eslint:recommended'
- "eslint:recommended"
- "plugin:@typescript-eslint/recommended"
plugins:
- "@typescript-eslint"
parser: "@typescript-eslint/parser"
root: true
rules:
indent:
- error
- 4
- "error"
- 2
- SwitchCase: 1
linebreak-style:
- error
- unix
- "error"
- "unix"
quotes:
- error
- single
- "error"
- "single"
semi:
- error
- always
- "error"
- "always"
no-console: 0
"@typescript-eslint/ban-ts-comment": "off"
5 changes: 5 additions & 0 deletions .gitattributes
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
65 changes: 34 additions & 31 deletions .github/workflows/build.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
*.pdf
*.yml
*.jpg
.vscode
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ Give it a template + some YAML and output a resume. Amazing.
$ npm i
<npm output>

$ node index.js
Usage: index.js -d DATA -t TEMPLATE -o OUTPUT
$ ts-node index.ts
Usage: index.ts -d DATA -t TEMPLATE -o OUTPUT

Options:
--version Show version number [boolean]
-d, --data your data [required]
-t, --template the template [required]
-o, --output PDF output [required]
-g, --tag tag
-d, --data your data [string] [required]
-t, --template template to use [string] [required]
-o, --output output file (.pdf, .html) [string] [required]
-p, --position position to filter for [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]

Examples:
index.js -d content.yml -t fill out template/aeolyus with
index.ts -d content.yml -t fill out template/aeolyus with
templates/aeolyus -o output.pdf content.yml and output a PDF to
output.pdf
index.js -d content.yml -t fill out template/aeolyus with
index.ts -d content.yml -t fill out template/aeolyus with
templates/aeolyus -o output.html content.yml and output HTML to
output.html

Missing required arguments: d, t, o
Missing required arguments: data, template, output
```

## Using
Expand Down Expand Up @@ -132,7 +132,6 @@ experience:
The Big Head will work with other Heads to do boat things.
```


```yaml
# data/projects.yml
---
Expand All @@ -154,30 +153,35 @@ skills:

Then pass `-d data` to combine all `data/*.yml` files into a single object. These two examples are equivalent.

## Tag Magic ✨✨
## Position Magic ✨✨

If an object has a `tags` key containing an array of values, `-g` will filter that object based on its tag values. That is, given
If an object has a `positions` key containing an array of values, `-p` will
filter that object based on its `positions` values. That is, given:

```yaml
skills:
- name: Boating
tags:
positions:
- boat
- logistics
- name: Shipping
tags:
positions:
- logistics
```

And `-g boat`, will output `Boating` for `skills` and not include `Shipping`.
* `-p boat` will output `Boating` for `skills` and not include `Shipping`.
* `-p logistics` will output both skills, because `logistics` is present in both

Super handy for putting *all* your data in one place, and then filtering based on job position - tag a `skill` with a `job`, pass `-g JOB`, and build a job-specific resume.
Super handy for putting *all* your data in one place, and then filtering based
on position - tag a `skill` with a `position`, pass `-p POSITION`, and build a
position-specific resume.

## Template Designing

The following Handlebars helpers are available:

| name | description |
|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `descFixer` | If given an array, returns bulleted list of items. Otherwise, returns what it was given. Good for descriptions. |
| `stringify` | If given an array, returns items separated with commas. Otherwise, returns what it was given. Good for lists you want to be represented as a sentence or a singe line. |
| `base64Encode` | Reads in the argument as a filepath (relative to repo root) and converts it to base64. Good for image rendering in PDFs. |
12 changes: 12 additions & 0 deletions handlebars/helpers/base64Encode.ts
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;
14 changes: 14 additions & 0 deletions handlebars/helpers/descFixer.ts
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;
17 changes: 17 additions & 0 deletions handlebars/helpers/stringify.ts
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;
38 changes: 0 additions & 38 deletions index.js

This file was deleted.

75 changes: 75 additions & 0 deletions index.ts
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 };
Loading

0 comments on commit 3b4e4c8

Please sign in to comment.