mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-15 10:07:07 +01:00
Compare commits
259 Commits
Author | SHA1 | Date | |
---|---|---|---|
fa29f9794d | |||
07915002bb | |||
fbcc06dcda | |||
7413a3a257 | |||
e6d2255291 | |||
2840ec3f87 | |||
05cd863ebf | |||
20961afb62 | |||
1256095e25 | |||
f073c79b8d | |||
ac9e4aa1a0 | |||
915f35b1e6 | |||
4fe74057f9 | |||
5a1ec033bb | |||
6801e39f97 | |||
f6f383751f | |||
43ed564a6e | |||
7b3364c356 | |||
58a7fc09e5 | |||
01c053702d | |||
a935fe7dc2 | |||
c9825fa016 | |||
9eb9207348 | |||
6b171e69db | |||
5b0ee89e34 | |||
8bd3ddc7fd | |||
984ae95576 | |||
f77cced7f3 | |||
57787f1bc7 | |||
9419f905df | |||
001fd893c1 | |||
babe4b4b31 | |||
201f39442e | |||
47f6aff561 | |||
cef9a92cb6 | |||
2253e4ead7 | |||
2f628f8564 | |||
23cd52885b | |||
181419ae28 | |||
a81ad0fef2 | |||
d220cedfeb | |||
e72564162b | |||
c98d05270e | |||
3e3803ed85 | |||
c8d8e566f8 | |||
712cba57b8 | |||
c9e45d4991 | |||
e9edc0d15c | |||
b99a09c88a | |||
5c95fe7af1 | |||
17f2ebb753 | |||
fc67f680ee | |||
88879257e6 | |||
fff45e1431 | |||
934d8a6123 | |||
defe9b6e95 | |||
4c5ccc001a | |||
de5c2ecb95 | |||
dbb95aef3a | |||
c9ae2ffef3 | |||
86af2a2c4f | |||
37ea6cf804 | |||
a9c685c6a4 | |||
7765e85336 | |||
7af50c51f6 | |||
19b30d55ec | |||
eddda8146e | |||
1a0b91a58f | |||
1b94ada709 | |||
1966b0a862 | |||
8ced6a730a | |||
6cd1e60e79 | |||
be691e4230 | |||
07b23109f9 | |||
32769a2b0b | |||
280977cb62 | |||
ddceec68a2 | |||
b961fd1c07 | |||
342b960f63 | |||
f965bf456a | |||
69be38110f | |||
3800e19418 | |||
e29ed58a1c | |||
11bfcd4bef | |||
fbc2e9a4db | |||
7814786957 | |||
542776fd2e | |||
815ee3dc7e | |||
376e720f4b | |||
b224c8939b | |||
0ecac98cff | |||
1416f57d0b | |||
65c7e41c53 | |||
c8cc673ad5 | |||
656dbe2fc2 | |||
a4ee7127ee | |||
fee21a7b17 | |||
32fd8dc636 | |||
2c8f444d42 | |||
bd8b587c5b | |||
4c954b79df | |||
b7fffbcf73 | |||
0829800b65 | |||
d7cfc76636 | |||
311030474d | |||
ec69e668ff | |||
f18910f490 | |||
540ad48d61 | |||
540c745069 | |||
c5b8eec33a | |||
bece335a64 | |||
3aabb5028d | |||
732bc9809a | |||
d77b484e55 | |||
43564bf380 | |||
88c71f6e9c | |||
47e8605f50 | |||
9466a8c0dd | |||
d878270bc6 | |||
3b38c4818f | |||
62c967526f | |||
6e5a44798b | |||
1fbfe2507b | |||
d6a3aab68a | |||
9fdfd1b5a6 | |||
f4e763bd9c | |||
fbfff2a4e4 | |||
1c93932737 | |||
cba29511bc | |||
1d655a4ddb | |||
ca94513630 | |||
971d4a5439 | |||
f3dcbd9081 | |||
29c53af843 | |||
8d24087faa | |||
95df8e5af4 | |||
8a1da777b0 | |||
44555da00f | |||
46bd5d51cc | |||
3964d300aa | |||
d6280e6d89 | |||
4a2a47f551 | |||
ae51930c9c | |||
fb33455bea | |||
28c703daf7 | |||
0246a5da19 | |||
840d17c67b | |||
9f22e94cf7 | |||
97ebecd84a | |||
96b9bb68e3 | |||
c5a5d3761d | |||
c147403b1c | |||
a2723452c2 | |||
cb3488276d | |||
43419c27cf | |||
0f0c399dd5 | |||
cb46497346 | |||
850c640368 | |||
60e455b36d | |||
af896c85ea | |||
6a7bb5ea5b | |||
3b6f2ad37e | |||
101eebdd95 | |||
830c36818e | |||
39e995213f | |||
37a053722d | |||
12fcf3b0cb | |||
43ad9c1c71 | |||
4f9207a868 | |||
3d1f589bc1 | |||
ae436a3b84 | |||
202bb44c76 | |||
041c609ff0 | |||
712b504168 | |||
bc9f0d468f | |||
2d20077c08 | |||
f61deda4e8 | |||
8203fa50ae | |||
c5eab0fd9c | |||
40e71238ac | |||
9d75b207d1 | |||
9b52c396d3 | |||
2759727984 | |||
e230d640cb | |||
d69688697c | |||
9f7ec62b18 | |||
b1a02918ff | |||
ec05f6737a | |||
da5db6477b | |||
0f580efb2b | |||
ff23ee508b | |||
2819faeb6f | |||
d205e882f6 | |||
3f40441b0a | |||
6185f20ec9 | |||
6a61989eb4 | |||
d658a069cd | |||
25688dbe8e | |||
98362b9687 | |||
4c31c96891 | |||
219209c6ca | |||
eff9fc51cb | |||
2ba23ee80d | |||
0f83f8f5c2 | |||
4ba3a3f2a9 | |||
db486a48aa | |||
2cab1195e8 | |||
ce75f09210 | |||
a8fed1b69b | |||
62ca2020d8 | |||
f65cf8880e | |||
c8d4a3deb3 | |||
d5e2a45034 | |||
2465f2ce1c | |||
f2001bcbb1 | |||
d5afb3eb2e | |||
c711cb7922 | |||
e45e0316f6 | |||
08ab512f4c | |||
f2bf09bf96 | |||
75e2b1c131 | |||
0b7ef16a41 | |||
247eec396c | |||
46c7fa9838 | |||
b3fb2c7130 | |||
c3ec3f28bd | |||
0a8ee721e8 | |||
8d7cf32988 | |||
655ecebaa5 | |||
8fc0fa99d3 | |||
69e8adc1cc | |||
6b3396e01b | |||
a95b52acd0 | |||
47553b6def | |||
e4a549ed30 | |||
dd2148bb92 | |||
d8b9d86896 | |||
889bd4bfc5 | |||
13fc903b2b | |||
8c8dbfed72 | |||
2b669cf35c | |||
5a2d892b85 | |||
37a7c318d5 | |||
43873efcab | |||
bb28e5aa8e | |||
c17261cd25 | |||
49e56cc226 | |||
84ad6cf356 | |||
b96526da31 | |||
cb14452df3 | |||
d54b9a6d6c | |||
6285c2db3b | |||
3453293c79 | |||
fb32cb0d78 | |||
baccb75256 | |||
5c39c1c93d | |||
48cc315fc8 | |||
ea8da6811a | |||
dbda48c16d |
36
.gitignore
vendored
36
.gitignore
vendored
@ -1,4 +1,40 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
tests/sandbox/
|
tests/sandbox/
|
||||||
|
doc/
|
||||||
docs/
|
docs/
|
||||||
|
local/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
|
# Emacs detritus
|
||||||
|
# -*- mode: gitignore; -*-
|
||||||
|
*~
|
||||||
|
\#*\#
|
||||||
|
/.emacs.desktop
|
||||||
|
/.emacs.desktop.lock
|
||||||
|
*.elc
|
||||||
|
auto-save-list
|
||||||
|
tramp
|
||||||
|
.\#*
|
||||||
|
|
||||||
|
# Org-mode
|
||||||
|
.org-id-locations
|
||||||
|
*_archive
|
||||||
|
|
||||||
|
# flymake-mode
|
||||||
|
*_flymake.*
|
||||||
|
|
||||||
|
# eshell files
|
||||||
|
/eshell/history
|
||||||
|
/eshell/lastdir
|
||||||
|
|
||||||
|
# elpa packages
|
||||||
|
/elpa/
|
||||||
|
|
||||||
|
# reftex files
|
||||||
|
*.rel
|
||||||
|
|
||||||
|
# AUCTeX auto folder
|
||||||
|
/auto/
|
||||||
|
|
||||||
|
# cask packages
|
||||||
|
.cask/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
|
- "0.10"
|
||||||
- "0.11"
|
- "0.11"
|
||||||
- "0.12"
|
- "0.12"
|
||||||
- "4.0"
|
- "4.0"
|
||||||
|
306
CHANGELOG.md
Normal file
306
CHANGELOG.md
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
CHANGELOG
|
||||||
|
=========
|
||||||
|
## v1.6.0
|
||||||
|
|
||||||
|
### Major Improvements
|
||||||
|
|
||||||
|
- Better consistency and coverage for all FRESH resumes and themes ([#45][i45]).
|
||||||
|
|
||||||
|
- Initial support for overridable fonts in FRESH themes. Like a particular
|
||||||
|
theme, but want to change the typography? The specific fonts used by a theme
|
||||||
|
can now be overridden by the user. (FRESH themes only).
|
||||||
|
|
||||||
|
- New resume sections! Support for `projects` and `affiliation` resume sections
|
||||||
|
for technical and creative projects and memberships / clubs / associations,
|
||||||
|
respectively ([#92][i92]).
|
||||||
|
|
||||||
|
- New command! `PEEK` at any arbitrary field or entry on your `.json` resume.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Improved handling of start and end dates on `employment`, `projects`,
|
||||||
|
`education`, and other sections with start/end dates.
|
||||||
|
|
||||||
|
- Support for an `.ignore` property on any FRESH or JSON Resume section or field.
|
||||||
|
Ignored properties will be treated by HackMyResume as if they weren't present.
|
||||||
|
|
||||||
|
- Emit extended status and error info with the `--debug` or `-d` switch.
|
||||||
|
|
||||||
|
- The `-o` or `--options` switch can now handle either the path to a **JSON
|
||||||
|
settings file** or **raw JSON/JavaScript**. Since the JSON double quote syntax
|
||||||
|
is a bit cumbersome from the command line, HackMyResume accepts regular
|
||||||
|
JavaScript object literal syntax:
|
||||||
|
|
||||||
|
hackmyresume build resume.json -o "{ theme: 'compact', silent: 'true' }"
|
||||||
|
|
||||||
|
- Ability to disable sorting of resume sections (employments, projects, etc.)
|
||||||
|
with the `--no-sort` option. HMR will respect the order of items as they appear
|
||||||
|
in your resume `.json` file.
|
||||||
|
|
||||||
|
- Improvements to the starter resume emitted by `hackmyresume new`.
|
||||||
|
|
||||||
|
- Theme Authoring: Annotated the HTML and MS Word (XML) formats of the Modern
|
||||||
|
theme for FRESH theme authors.
|
||||||
|
|
||||||
|
- Theme Authoring: Support for templatized CSS files in FRESH themes. CSS files
|
||||||
|
are now expanded via Handlebars or Underscore prior to copying to the
|
||||||
|
destination.
|
||||||
|
|
||||||
|
- Added CHANGELOG.md (this file).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Rewrote the HackMyResume man/help page.
|
||||||
|
|
||||||
|
- Minor incremental updates to the [FRESCA][fresca] schema.
|
||||||
|
|
||||||
|
- PDF generation now uses asynchronous `spawn()` which has better compatibility
|
||||||
|
with old or boutique versions of Node.js.
|
||||||
|
|
||||||
|
- Refactored colors in HackMyResume output. Errors will now display as red,
|
||||||
|
warnings as yellow, successful operations as green, and informational messages
|
||||||
|
as cyan.
|
||||||
|
|
||||||
|
- Theme messages and usage tips will no longer display during resume generation
|
||||||
|
by default. Use the `--tips` option to view them.
|
||||||
|
|
||||||
|
- The `--no-tips` option (default: false) has been replaced with the `--tips`
|
||||||
|
option, also defaulting to false.
|
||||||
|
|
||||||
|
- Removed the `hello-world` theme from the [prebuilt themes][themes] that ship
|
||||||
|
with HackMyResume. It can be installed separately from NPM:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install fresh-theme-hello-world
|
||||||
|
hackmyresume resume.json -t node_modules/fresh-theme-hello-world
|
||||||
|
```
|
||||||
|
|
||||||
|
- sd
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- PDF generation issues on older versions of Node.
|
||||||
|
|
||||||
|
- Stack traces not being emitted correctly.
|
||||||
|
|
||||||
|
- Missing `speaking` section will now appear on generated resumes ([#101][i101]).
|
||||||
|
|
||||||
|
- Incomplete `education` details will now appear on generated resumes ([#65][i65]).
|
||||||
|
|
||||||
|
- Missing employment end date being interpreted as "employment ends today"
|
||||||
|
([#84][i84]).
|
||||||
|
|
||||||
|
- Merging multiple source resumes during `BUILD` sometimes fails.
|
||||||
|
|
||||||
|
- Document `--pdf` flag in README ([#111][i111]).
|
||||||
|
|
||||||
|
### Internal
|
||||||
|
|
||||||
|
- Logging messages have been moved out of core HackMyResume code ahead of
|
||||||
|
localization support.
|
||||||
|
|
||||||
|
- All HackMyResume console output is described in `msg.yml`.
|
||||||
|
|
||||||
|
- Relaxed pure JavaScript requirement. CoffeeScript will now start appearing
|
||||||
|
in HackMyResume and FluentCV sources!
|
||||||
|
|
||||||
|
- Additional tests.
|
||||||
|
|
||||||
|
## v1.5.2
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Tweak stack trace under `--debug`.
|
||||||
|
|
||||||
|
## v1.5.1
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Preliminary support for `-d` or `--debug` flag. Forces HackMyResume to emit a stack trace under error conditions.
|
||||||
|
|
||||||
|
## v1.5.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- HackMyResume now supports **CLI-based generation of PDF formats across multiple engines (Phantom, wkhtmltopdf, etc)**. Instead of talking to these engines over a programmatic API, as in prior versions, HackMyResume 1.5+ speaks to them over the same command-line interface (CLI) you'd use if you were using these tools directly.
|
||||||
|
|
||||||
|
- HackMyResume will now (attempt to) **generate a PDF output for JSON Resume themes** (in addition to HTML).
|
||||||
|
|
||||||
|
- Minor README and FAQ additions.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Cleaner, quicker installs**. Installing HackMyResume with `npm install hackmyresume -g` will no longer trigger a lengthy, potentially error-prone install for Phantom.js and/or wkhtmltopdf for PDF support. Instead, users can install these engines externally and HMR will use them when present.
|
||||||
|
|
||||||
|
- Minor error handling improvements.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an error with generating specific formats with the `BUILD` command (#97).
|
||||||
|
|
||||||
|
- Fixed numerous latent/undocumented bugs and glitches.
|
||||||
|
|
||||||
|
## v1.4.2
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Introduced [FAQ](https://github.com/hacksalot/HackMyResume/blob/master/FAQ.md).
|
||||||
|
- Additional README notes.
|
||||||
|
|
||||||
|
## v1.4.1
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `hackmyresume new` now generates a [valid starter resume with sample data](https://github.com/fluentdesk/fresh-resume-starter).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed warning message when `hackmyresume new` is run without a filename.
|
||||||
|
|
||||||
|
## v1.4.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **"Projects" support**: FRESH resumes and themes can now store and display
|
||||||
|
open source, commercial, private, personal, and creative projects.
|
||||||
|
- **New command: ANALYZE**. Inspect your resume for gaps, keyword counts, and other metrics. (Experimental.)
|
||||||
|
- **Side-by-side PDF generation** with Phantom and wkhtmltopdf. Use the `--pdf` or `-p` flag to pick between `phantom` and `wkhtmltopdf` generation.
|
||||||
|
- **Disable PDF generation** with the `--pdf none` switch.
|
||||||
|
- **Inherit formats between themes**. Themes can now inherit formats (Word, HTML, .txt, etc.) from other themes. (FRESH themes only.)
|
||||||
|
- **Rename resume sections** to different languages or wordings.
|
||||||
|
- **Specify complex options via external file**. Use with the `-o` or `--opts` option.
|
||||||
|
- **Disable colors** with the `--no-color` flag.
|
||||||
|
- **Theme messages and usage tips** instructions will now appear in the default HackMyResume output for the `build` command. Run `hackmyresume build resume.json -t awesome` for an example. Turn off with the `--no-tips` flag.
|
||||||
|
- **Treat validation errors as warnings** with the `--assert` switch (VALIDATE command only).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed a minor glitch in the FRESCA schema.
|
||||||
|
- Fixed encoding issues in the `Highlights` section of certain resumes.
|
||||||
|
- Fix behavior of `-s` and `--silent` flags.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- PDF generation now defaults to Phantom for all platforms, with `wkhtmltopdf`
|
||||||
|
accessible with `--pdf wkhtmltopdf`.
|
||||||
|
- Resumes are now validated, by default, prior to generation. This
|
||||||
|
behavior can be disabled with the `--novalidate` or `--force` switch.
|
||||||
|
- Syntax errors in source FRESH and JSON Resumes are now captured for all
|
||||||
|
commands.
|
||||||
|
- Minor updates to README.
|
||||||
|
- Most themes now inherit Markdown and Plain Text formats from the **Basis**
|
||||||
|
theme.
|
||||||
|
|
||||||
|
### Internal
|
||||||
|
|
||||||
|
- Switched from color to chalk.
|
||||||
|
- Command invocations now handled through commander.js.
|
||||||
|
- Improved FRESH theme infrastructure (more partials, more DRY).
|
||||||
|
|
||||||
|
## v1.3.1
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add additional Travis badges.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix extraneous console log output when generating a FRESH theme to MS Word.
|
||||||
|
- Fix Travis tests on `dev`.
|
||||||
|
|
||||||
|
## v1.3.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Local generation of JSON Resume themes**. To use a JSON Resume theme, first install it with `npm install jsonresume-theme-[blah]` (most JSON Resume themes are on NPM). Then pass it into HackMyResume via the `-t` parameter:
|
||||||
|
|
||||||
|
`hackmyresume BUILD resume.json TO out/somefile.all -t node_modules/jsonresume-theme-classy`
|
||||||
|
- **Better Markdown support.** HackMyResume will start flowing basic Markdown styles to JSON Resume (HTML) themes. FRESH's existing Markdown support has also been improved.
|
||||||
|
- **.PNG output formats** will start appearing in themes that declare an HTML output.
|
||||||
|
- **Tweak CSS embedding / linking via the --css option** (`<style></style>` vs `<link>`). Only works for HTML (or HTML-driven) formats of FRESH themes. Use `--css=link` to link in CSS assets and `--css=embed` to embed the styles in the HTML document. For example `hackmyresume BUILD resume.json TO out/resume.all --css=link`.
|
||||||
|
- **Improved Handlebars/Underscore helper support** for FRESH themes. Handlebars themes can access helpers via `{{helperName}}`. Underscore themes can access helpers via the `h` object.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Distinguish between validation errors and syntax errors** when validating a FRESH or JRS resume with `hackmyresume validate <blah>`.
|
||||||
|
- **Emit line and column info** for syntax errors during validation of FRESH and JRS resumes.
|
||||||
|
- **FRESH themes now embed CSS into HTML formats by default** so that the HTML resume output doesn't have an external CSS file dependency by default. Users can specify normal linked stylesheets by setting `--css=link`.
|
||||||
|
- **Renamed fluent-themes repo to fresh-themes** in keeping with the other parts of the project.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix various encoding errors in MS Word outputs.
|
||||||
|
- Fix assorted FRESH-to-JRS and JRS-to-FRESH conversion glitches.
|
||||||
|
- Fix error when running HMR with no parameters.
|
||||||
|
- Other minor fixes.
|
||||||
|
|
||||||
|
## v1.3.0-beta
|
||||||
|
|
||||||
|
- Numerous changes supporting v1.3.0.
|
||||||
|
|
||||||
|
## v1.2.2
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Various in-passing fixes.
|
||||||
|
|
||||||
|
## v1.2.1
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix `require('FRESCA')` error.
|
||||||
|
- Fix `.history` and `.map` errors on loading incomplete or empty JRS resumes.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Better test coverage of incomplete/empty resumes.
|
||||||
|
|
||||||
|
## v1.2.0
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the `new` command: Generate a new FRESH-format resume with `hackmyresume new resume.json` or a new JSON Resume with `hackmyresume new resume.json -f jrs`.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Introduced CLI tests.
|
||||||
|
|
||||||
|
## v1.1.0
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- MS Word formats: Fixed skill coloring/level bug.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Make the `TO` keyword optional. If no `TO` keyword is specified (for the `build` and `convert` commands), HMR will assume the last file passed in is the desired output file. So these are equivalent:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
hackmyresume BUILD resume.json TO out/resume.all
|
||||||
|
hackmyresume BUILD resume.json out/resume.all
|
||||||
|
```
|
||||||
|
|
||||||
|
`TO` only needs to be included if you have multipled output files:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
hackmyresume BUILD resume.json TO out1.doc out2.html out3.tex
|
||||||
|
```
|
||||||
|
|
||||||
|
## v1.0.1
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Correctly generate MS Word hyperlinks from Markdown source data.
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
- Initial public 1.0 release.
|
||||||
|
|
||||||
|
[i45]: https://github.com/hacksalot/HackMyResume/issues/45
|
||||||
|
[i65]: https://github.com/hacksalot/HackMyResume/issues/65
|
||||||
|
[i84]: https://github.com/hacksalot/HackMyResume/issues/84
|
||||||
|
[i92]: https://github.com/hacksalot/HackMyResume/issues/92
|
||||||
|
[i101]: https://github.com/hacksalot/HackMyResume/issues/101
|
||||||
|
[i111]: https://github.com/hacksalot/HackMyResume/issues/111
|
||||||
|
[fresca]: https://github.com/fluentdesk/FRESCA
|
||||||
|
[themes]: https://github.com/fluentdesk/fresh-themes
|
228
FAQ.md
Normal file
228
FAQ.md
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
Frequently Asked Questions (FAQ)
|
||||||
|
================================
|
||||||
|
|
||||||
|
## How do I get started with HackMyResume?
|
||||||
|
|
||||||
|
1. Install with NPM: `[sudo] npm install hackmyresume -g`.
|
||||||
|
|
||||||
|
2. Create a new resume with: `hackmyresume NEW <resume-name>.json`.
|
||||||
|
|
||||||
|
3. Test with `hackmyresume BUILD <resume-name>.json`. Look in the `out/` folder.
|
||||||
|
|
||||||
|
4. Play around with different themes with the `-t` or `--theme` parameter.
|
||||||
|
You can use any [FRESH](https://github.com/fluentdesk/fresh-themes) or
|
||||||
|
[JSON Resume](https://jsonresume.org/themes) theme. The latter have to be
|
||||||
|
installed first.
|
||||||
|
|
||||||
|
## What is FRESH?
|
||||||
|
|
||||||
|
FRESH is the **F**luent **R**esume and **E**mployment **S**ystem for **H**umans.
|
||||||
|
It's an open-source, user-first workflow, schema, and set of practices for
|
||||||
|
technical candidates and recruiters.
|
||||||
|
|
||||||
|
## What is FRESCA?
|
||||||
|
|
||||||
|
The **F**RESH **R**esume and **E**mployment **SC**hem**A**—an open-source,
|
||||||
|
JSON-driven schema for resumes, CVs, and other employment artifacts. FRESCA is
|
||||||
|
the recommended schema/format for FRESH, with optional support for JSON Resume.
|
||||||
|
|
||||||
|
## What is JSON Resume?
|
||||||
|
|
||||||
|
An [open resume standard](http://jsonresume.org/themes/) sponsored by Hired.com.
|
||||||
|
Like FRESCA, JSON Resume is JSON-driven and open-source. Unlike FRESCA, JSON
|
||||||
|
Resume targets a worldwide audience where FRESCA is optimized for technical
|
||||||
|
candidates.
|
||||||
|
|
||||||
|
## Should I use the FRESH or JSON Resume format/schema for my resume?
|
||||||
|
|
||||||
|
Both! The workflow we like to use:
|
||||||
|
|
||||||
|
1. Create a resume in FRESH format for tooling and analysis.
|
||||||
|
2. Convert it to JSON Resume format for additional themes/tools.
|
||||||
|
3. Maintain both versions.
|
||||||
|
|
||||||
|
Both formats are open-source and both formats are JSON-driven. FRESH was
|
||||||
|
designed as a universal container format and superset of existing formats, where
|
||||||
|
the JSON Resume format is intended for a generic audience.
|
||||||
|
|
||||||
|
## How do I use a FRESH theme?
|
||||||
|
|
||||||
|
Several FRESH themes come preinstalled with HackMyResume; others can be
|
||||||
|
installed from NPM and GitHub.
|
||||||
|
|
||||||
|
### To use a preinstalled FRESH theme:
|
||||||
|
|
||||||
|
1. Pass the theme name into HackMyResume via the `--theme` or `-t` parameter:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume build resume.json --theme compact
|
||||||
|
```
|
||||||
|
|
||||||
|
### To use an external FRESH theme:
|
||||||
|
|
||||||
|
1. Install the theme locally. The easiest way to do that is with NPM.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install fresh-theme-underscore
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Pass the theme folder into HackMyResume:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json --theme node_modules/fresh-theme-underscore
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Check your output folder. It's best to view HTML formats over a local web
|
||||||
|
server connection.
|
||||||
|
|
||||||
|
## How do I use a JSON Resume theme?
|
||||||
|
|
||||||
|
JSON Resume (JRS) themes can be installed from NPM and GitHub and passed into
|
||||||
|
HackMyResume via the `--theme` or `-t` parameter.
|
||||||
|
|
||||||
|
1. Install the theme locally. The easiest way to do that is with NPM.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install jsonresume-theme-classy
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Pass the theme folder path into HackMyResume:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json --theme node_modules/jsonresume-theme-classy
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Check your output folder. It's best to view HTML formats over a local web
|
||||||
|
server connection.
|
||||||
|
|
||||||
|
## Should I keep my resume in version control?
|
||||||
|
|
||||||
|
Absolutely! As text-based, JSON-driven documents, both FRESH and JSON Resume are
|
||||||
|
ideal candidates for version control. Future versions of HackMyResume will have
|
||||||
|
this functionality built in.
|
||||||
|
|
||||||
|
## Can I change the default section titles ("Employment", "Skills", etc.)?
|
||||||
|
|
||||||
|
If you're using a FRESH theme, yes. First, create a HackMyResume options file
|
||||||
|
mapping resume sections to your preferred section title:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// myoptions.json
|
||||||
|
{
|
||||||
|
"sectionTitles": {
|
||||||
|
"employment": "empleo",
|
||||||
|
"skills": "habilidades",
|
||||||
|
"education": "educación"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, pass the options file into the `-o` or `--opts` parameter:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json -o myoptions.json
|
||||||
|
```
|
||||||
|
|
||||||
|
This ability is currently only supported for FRESH resume themes.
|
||||||
|
|
||||||
|
## How does resume merging work?
|
||||||
|
|
||||||
|
Resume merging is a way of storing your resume in separate files that
|
||||||
|
HackMyResume will merge into a single "master" resume file prior to generating
|
||||||
|
specific output formats like HTML or PDF. It's a way of producing flexible,
|
||||||
|
configurable, targeted resumes with minimal duplication.
|
||||||
|
|
||||||
|
For example, a software developer who moonlights as a game programmer might
|
||||||
|
create three FRESH or JRS resumes at different levels of specificity:
|
||||||
|
|
||||||
|
- **generic.json**: A generic technical resume, suitable for all audiences.
|
||||||
|
- **game-developer.json**: Overrides and amendments for game developer
|
||||||
|
positions.
|
||||||
|
- **blizzard.json**: Overrides and amendments specific to a hypothetical
|
||||||
|
position at Blizzard.
|
||||||
|
|
||||||
|
If you run `hackmyresume BUILD generic.json TO out/resume.all`, HMR will
|
||||||
|
generate all available output formats for the `generic.json` as usual. But if
|
||||||
|
you instead run...
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD generic.json game-developer.json TO out/resume.all
|
||||||
|
```
|
||||||
|
|
||||||
|
...HackMyResume will notice that multiple source resumes were specified and
|
||||||
|
merge `game-developer.json` onto `generic.json` before generating, yielding a
|
||||||
|
resume that's more suitable for game-developer-related positions.
|
||||||
|
|
||||||
|
You can take this a step further. Let's say you want to do a targeted resume
|
||||||
|
submission to a game developer position at Blizzard, and `blizzard.json`
|
||||||
|
contains the edits and revisions you'd like to show up in the targeted resume.
|
||||||
|
In that case, merge again! Feed all three resumes to HackMyResume, in order
|
||||||
|
from most generic to most specific, and HMR will merge them all prior to
|
||||||
|
generating the final output format(s) for your resume.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Merge blizzard.json onto game-developer.json onto generic.json, then build
|
||||||
|
hackmyresume BUILD generic.json game-developer.json blizzard.json TO out/resume.all
|
||||||
|
```
|
||||||
|
|
||||||
|
There's no limit to the number of resumes you can merge this way.
|
||||||
|
|
||||||
|
You can also divide your resume into files containing different sections:
|
||||||
|
|
||||||
|
- **resume-a.json**: Contains `info`, `employment`, and `summary` sections.
|
||||||
|
- **resume-b.json**: Contains all other sections except `references`.
|
||||||
|
- **references.json**: Contains the private `references` section.
|
||||||
|
|
||||||
|
Under that scenario, `hackmyresume BUILD resume-a.json resume-b.json` would
|
||||||
|
|
||||||
|
|
||||||
|
## The HackMyResume terminal color scheme is giving me a headache. Can I disable it?
|
||||||
|
|
||||||
|
Yes. Use the `--no-color` option to disable terminal colors:
|
||||||
|
|
||||||
|
`hackmyresume <somecommand> <someoptions> --no-color`
|
||||||
|
|
||||||
|
## What's the difference between a FRESH theme and a JSON Resume theme?
|
||||||
|
|
||||||
|
FRESH themes are multiformat (HTML, Word, PDF, etc.) and required to support
|
||||||
|
Markdown formatting, configurable section titles, and various other features.
|
||||||
|
|
||||||
|
JSON Resume themes are typically HTML-driven, but capable of expansion to other
|
||||||
|
formats through tools. JSON Resume themes don't support Markdown natively, but
|
||||||
|
HMR does its best to apply your Markdown, when present, to any JSON Resume
|
||||||
|
themes it encounters.
|
||||||
|
|
||||||
|
## Do I have to have a FRESH resume to use a FRESH theme or a JSON Resume to use a JSON Resume theme?
|
||||||
|
|
||||||
|
No. You can mix and match FRESH and JRS-format themes freely. HackMyResume will
|
||||||
|
perform the necessary conversions on the fly.
|
||||||
|
|
||||||
|
## Can I build my own custom FRESH theme?
|
||||||
|
|
||||||
|
Yes. The easiest way is to copy an existing FRESH theme, like `modern` or
|
||||||
|
`compact`, and make your changes there. You can test your theme with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume build resume.json --theme path/to/my/theme/folder
|
||||||
|
```
|
||||||
|
|
||||||
|
## Can I build my own custom JSON Resume theme?
|
||||||
|
|
||||||
|
Yes. The easiest way is to copy an existing JSON Rsume theme and make your
|
||||||
|
changes there. You can test your theme with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume build resume.json --theme path/to/my/theme/folder
|
||||||
|
```
|
||||||
|
|
||||||
|
## Can I build my own tools / services / apps / websites around FRESH / FRESCA?
|
||||||
|
|
||||||
|
Yes! FRESH/FRESCA formats are 100% open source, permissively licensed under MIT,
|
||||||
|
and 100% free from company-specific, tool-specific, or commercially oriented
|
||||||
|
lock-in or cruft. These are clean formats designed for users and builders.
|
||||||
|
|
||||||
|
## Can I build my own tools / services / apps / websites around JSON Resume?
|
||||||
|
|
||||||
|
Yes! HackMyResume is not affiliated with JSON Resume, but like FRESH/FRESCA,
|
||||||
|
JSON Resume is open-source, permissively licensed, and free of proprietary
|
||||||
|
lock-in. See the JSON Resume website for details.
|
15
Gruntfile.js
15
Gruntfile.js
@ -17,6 +17,16 @@ module.exports = function (grunt) {
|
|||||||
all: { src: ['test/*.js'] }
|
all: { src: ['test/*.js'] }
|
||||||
},
|
},
|
||||||
|
|
||||||
|
jsdoc : {
|
||||||
|
dist : {
|
||||||
|
src: ['src/**/*.js'],
|
||||||
|
options: {
|
||||||
|
private: true,
|
||||||
|
destination: 'doc'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
clean: ['test/sandbox'],
|
clean: ['test/sandbox'],
|
||||||
|
|
||||||
yuidoc: {
|
yuidoc: {
|
||||||
@ -47,13 +57,14 @@ module.exports = function (grunt) {
|
|||||||
|
|
||||||
grunt.loadNpmTasks('grunt-simple-mocha');
|
grunt.loadNpmTasks('grunt-simple-mocha');
|
||||||
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
||||||
|
grunt.loadNpmTasks('grunt-jsdoc');
|
||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||||
|
|
||||||
grunt.registerTask('test', 'Test the HackMyResume library.',
|
grunt.registerTask('test', 'Test the HackMyResume library.',
|
||||||
function( config ) { grunt.task.run(['clean','jshint','simplemocha:all']); });
|
function( config ) { grunt.task.run(['clean','jshint','simplemocha:all']); });
|
||||||
grunt.registerTask('document', 'Generate HackMyResume library documentation.',
|
grunt.registerTask('document', 'Generate HackMyResume library documentation.',
|
||||||
function( config ) { grunt.task.run( ['yuidoc'] ); });
|
function( config ) { grunt.task.run( ['jsdoc'] ); });
|
||||||
grunt.registerTask('default', [ 'test', 'yuidoc' ]);
|
grunt.registerTask('default', [ 'test', 'jsdoc' ]);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
The MIT License
|
The MIT License
|
||||||
===============
|
===============
|
||||||
|
|
||||||
Copyright (c) 2015 James M. Devlin (https://github.com/hacksalot)
|
Copyright (c) 2016 hacksalot (https://github.com/hacksalot)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
300
README.md
300
README.md
@ -1,14 +1,16 @@
|
|||||||
HackMyResume
|
HackMyResume
|
||||||
============
|
============
|
||||||
|
|
||||||
[![Build status][travis-image]][travis-url]
|
[![Latest release][img-release]][latest-release]
|
||||||
|
[![Build status (MASTER)][img-master]][travis-url-master]
|
||||||
|
[![Build status (DEV)][img-dev]][travis-url-dev]
|
||||||
|
|
||||||
*Create polished résumés and CVs in multiple formats from your command line or
|
*Create polished résumés and CVs in multiple formats from your command line or
|
||||||
shell. Author in clean Markdown and JSON, export to Word, HTML, PDF, LaTeX,
|
shell. Author in clean Markdown and JSON, export to Word, HTML, PDF, LaTeX,
|
||||||
plain text, and other arbitrary formats. Fight the power, save trees. Compatible
|
plain text, and other arbitrary formats. Fight the power, save trees. Compatible
|
||||||
with [FRESH][fresca] and [JRS][6] resumes.*
|
with [FRESH][fresca] and [JRS][6] resumes.*
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
HackMyResume is a dev-friendly, local-only Swiss Army knife for resumes and CVs.
|
HackMyResume is a dev-friendly, local-only Swiss Army knife for resumes and CVs.
|
||||||
Use it to:
|
Use it to:
|
||||||
@ -16,34 +18,54 @@ Use it to:
|
|||||||
1. **Generate** HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML,
|
1. **Generate** HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML,
|
||||||
YAML, print, smoke signal, carrier pigeon, and other arbitrary-format resumes
|
YAML, print, smoke signal, carrier pigeon, and other arbitrary-format resumes
|
||||||
and CVs, from a single source of truth—without violating DRY.
|
and CVs, from a single source of truth—without violating DRY.
|
||||||
2. **Convert** resumes between [FRESH][fresca] and [JSON Resume][6] formats.
|
2. **Analyze** your resume for keyword density, gaps/overlaps, and other
|
||||||
3. **Validate** resumes against either format.
|
metrics.
|
||||||
|
3. **Convert** resumes between [FRESH][fresca] and [JSON Resume][6] formats.
|
||||||
|
4. **Validate** resumes against either format.
|
||||||
|
|
||||||
HackMyResume is built with Node.js and runs on recent versions of OS X, Linux,
|
HackMyResume is built with Node.js and runs on recent versions of OS X, Linux,
|
||||||
or Windows.
|
or Windows. View the [FAQ](FAQ.md).
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- OS X, Linux, and Windows.
|
- OS X, Linux, and Windows.
|
||||||
|
- Choose from dozens of FRESH or JSON Resume themes.
|
||||||
|
- Private, local-only resume authoring and analysis.
|
||||||
|
- Analyze your resume for keywords, gaps, and other metrics.
|
||||||
- Store your resume data as a durable, versionable JSON or YAML document.
|
- Store your resume data as a durable, versionable JSON or YAML document.
|
||||||
- Generate polished resumes in multiple formats without violating [DRY][dry].
|
- Generate polished resumes in multiple formats without violating [DRY][dry].
|
||||||
- Output to HTML, Markdown, LaTeX, PDF, MS Word, JSON, YAML, plain text, or XML.
|
- Output to HTML, Markdown, LaTeX, PDF, MS Word, JSON, YAML, plain text, or XML.
|
||||||
- Validate resumes against the FRESH or JSON Resume schema.
|
- Validate resumes against the FRESH or JSON Resume schema.
|
||||||
- Support for multiple input and output resumes.
|
- Support for multiple input and output resumes.
|
||||||
|
- Convert between FRESH and JSON Resume resumes.
|
||||||
- Use from your command line or [desktop][7].
|
- Use from your command line or [desktop][7].
|
||||||
- Free and open-source through the MIT license.
|
- Free and open-source through the MIT license.
|
||||||
- Updated daily.
|
- Updated daily / weekly. Contributions are [welcome](CONTRIBUTING.md).
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Install HackMyResume with NPM:
|
Install the latest stable version of HackMyResume with NPM:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[sudo] npm install hackmyresume -g
|
[sudo] npm install hackmyresume -g
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: for PDF generation you'll need to install a copy of [wkhtmltopdf][3] for
|
Alternately, install the latest bleeding-edge version (updated daily):
|
||||||
your platform.
|
|
||||||
|
```bash
|
||||||
|
[sudo] npm install hacksalot/hackmyresume#dev -g
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installing PDF Support (optional)
|
||||||
|
|
||||||
|
HackMyResume tries not to impose a specific PDF engine requirement on
|
||||||
|
the user, but will instead work with whatever PDF engines you have installed.
|
||||||
|
|
||||||
|
Currently, HackMyResume's PDF generation requires either [Phantom.js][2] or
|
||||||
|
[wkhtmltopdf][3] to be installed on your system and the `phantomjs` and/or
|
||||||
|
`wkhtmltopdf` binaries to be accessible on your PATH. This is an optional
|
||||||
|
requirement for users who care about PDF formats. If you don't care about PDF
|
||||||
|
formats, skip this step.
|
||||||
|
|
||||||
## Installing Themes
|
## Installing Themes
|
||||||
|
|
||||||
@ -78,14 +100,14 @@ package.json or other NPM/Node infrastructure.
|
|||||||
|
|
||||||
To use HackMyResume you'll need to create a valid resume in either
|
To use HackMyResume you'll need to create a valid resume in either
|
||||||
[FRESH][fresca] or [JSON Resume][6] format. Then you can start using the command
|
[FRESH][fresca] or [JSON Resume][6] format. Then you can start using the command
|
||||||
line tool. There are four basic commands you should be aware of:
|
line tool. There are five basic commands you should be aware of:
|
||||||
|
|
||||||
- **build** generates resumes in HTML, Word, Markdown, PDF, and other formats.
|
- **build** generates resumes in HTML, Word, Markdown, PDF, and other formats.
|
||||||
Use it when you need to submit, upload, print, or email resumes in specific
|
Use it when you need to submit, upload, print, or email resumes in specific
|
||||||
formats.
|
formats.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# hackmyresume BUILD <INPUTS> TO <OUTPUTS> [-t THEME]
|
# hackmyresume BUILD <INPUTS...> TO <OUTPUTS...> [-t THEME]
|
||||||
hackmyresume BUILD resume.json TO out/resume.all
|
hackmyresume BUILD resume.json TO out/resume.all
|
||||||
hackmyresume BUILD r1.json r2.json TO out/rez.html out/rez.md foo/rez.all
|
hackmyresume BUILD r1.json r2.json TO out/rez.html out/rez.md foo/rez.all
|
||||||
```
|
```
|
||||||
@ -93,19 +115,26 @@ formats.
|
|||||||
- **new** creates a new resume in FRESH or JSON Resume format.
|
- **new** creates a new resume in FRESH or JSON Resume format.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# hackmyresume NEW <OUTPUTS> [-f <FORMAT>]
|
# hackmyresume NEW <OUTPUTS...> [-f <FORMAT>]
|
||||||
hackmyresume NEW resume.json
|
hackmyresume NEW resume.json
|
||||||
hackmyresume NEW resume.json -f fresh
|
hackmyresume NEW resume.json -f fresh
|
||||||
hackmyresume NEW r1.json r2.json -f jrs
|
hackmyresume NEW r1.json r2.json -f jrs
|
||||||
```
|
```
|
||||||
|
|
||||||
- **convert** converts your source resume between FRESH and JSON Resume
|
- **analyze** inspects your resume for keywords, duration, and other metrics.
|
||||||
formats.
|
|
||||||
Use it to convert between the two formats to take advantage of tools and
|
|
||||||
services.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# hackmyresume CONVERT <INPUTS> TO <OUTPUTS>
|
# hackmyresume ANALYZE <INPUTS...>
|
||||||
|
hackmyresume ANALYZE resume.json
|
||||||
|
hackmyresume ANALYZE r1.json r2.json
|
||||||
|
```
|
||||||
|
|
||||||
|
- **convert** converts your source resume between FRESH and JSON Resume
|
||||||
|
formats. Use it to convert between the two formats to take advantage of tools
|
||||||
|
and services.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# hackmyresume CONVERT <INPUTS...> TO <OUTPUTS...>
|
||||||
hackmyresume CONVERT resume.json TO resume-jrs.json
|
hackmyresume CONVERT resume.json TO resume-jrs.json
|
||||||
hackmyresume CONVERT 1.json 2.json 3.json TO out/1.json out/2.json out/3.json
|
hackmyresume CONVERT 1.json 2.json 3.json TO out/1.json out/2.json out/3.json
|
||||||
```
|
```
|
||||||
@ -114,11 +143,22 @@ services.
|
|||||||
Resume schema. Use it to make sure your resume data is sufficient and complete.
|
Resume schema. Use it to make sure your resume data is sufficient and complete.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# hackmyresume VALIDATE <INPUTS>
|
# hackmyresume VALIDATE <INPUTS...>
|
||||||
hackmyresume VALIDATE resume.json
|
hackmyresume VALIDATE resume.json
|
||||||
hackmyresume VALIDATE r1.json r2.json r3.json
|
hackmyresume VALIDATE r1.json r2.json r3.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- **peek** echoes your resume or any field, property, or object path on your
|
||||||
|
resume to standard output.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# hackmyresume PEEK <INPUTS...> [OBJECT-PATH]
|
||||||
|
hackmyresume PEEK rez.json # Echo the whole resume
|
||||||
|
hackmyresume PEEK rez.json info.brief # Echo the "info.brief" field
|
||||||
|
hackmyresume PEEK rez.json employment.history[1] # Echo the 1st job
|
||||||
|
hackmyresume PEEK rez.json rez2.json info.brief # Compare value
|
||||||
|
```
|
||||||
|
|
||||||
## Supported Output Formats
|
## Supported Output Formats
|
||||||
|
|
||||||
HackMyResume supports these output formats:
|
HackMyResume supports these output formats:
|
||||||
@ -140,7 +180,7 @@ image | .png, .bmp | Forthcoming.
|
|||||||
## Use
|
## Use
|
||||||
|
|
||||||
Assuming you've got a JSON-formatted resume handy, generating resumes in
|
Assuming you've got a JSON-formatted resume handy, generating resumes in
|
||||||
different formats and combinations easy. Just run:
|
different formats and combinations is easy. Just run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
hackmyresume BUILD <INPUTS> <OUTPUTS> [-t theme].
|
hackmyresume BUILD <INPUTS> <OUTPUTS> [-t theme].
|
||||||
@ -170,7 +210,7 @@ hackmyresume BUILD in1.json in2.json TO out.html out.doc out.pdf
|
|||||||
You should see something to the effect of:
|
You should see something to the effect of:
|
||||||
|
|
||||||
```
|
```
|
||||||
*** HackMyResume v0.9.0 ***
|
*** HackMyResume v1.4.0 ***
|
||||||
Reading JSON resume: foo/resume.json
|
Reading JSON resume: foo/resume.json
|
||||||
Applying MODERN Theme (7 formats)
|
Applying MODERN Theme (7 formats)
|
||||||
Generating HTML resume: out/resume.html
|
Generating HTML resume: out/resume.html
|
||||||
@ -186,17 +226,36 @@ Generating YAML resume: out/resume.yml
|
|||||||
|
|
||||||
### Applying a theme
|
### Applying a theme
|
||||||
|
|
||||||
You can specify a predefined or custom theme via the optional `-t` parameter.
|
HackMyResume can work with any FRESH or JSON Resume theme (the latter must be
|
||||||
For a predefined theme, include the theme name. For a custom theme, include the
|
installed first). To specify a theme when generating your resume, use the `-t`
|
||||||
path to the custom theme's folder.
|
or `--theme` parameter:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json TO out/rez.all -t [theme]
|
||||||
|
```
|
||||||
|
|
||||||
|
The `[theme]` parameter can be the name of a predefined theme OR the path to any
|
||||||
|
FRESH or JSON Resume theme folder:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
hackmyresume BUILD resume.json TO out/rez.all -t modern
|
hackmyresume BUILD resume.json TO out/rez.all -t modern
|
||||||
hackmyresume BUILD resume.json TO OUT.rez.all -t ~/foo/bar/my-custom-theme/
|
hackmyresume BUILD resume.json TO OUT.rez.all -t ../some-folder/my-custom-theme/
|
||||||
|
hackmyresume BUILD resume.json TO OUT.rez.all -t node_modules/jsonresume-theme-classy
|
||||||
```
|
```
|
||||||
|
|
||||||
As of v1.0.0, available predefined themes are `positive`, `modern`, `compact`,
|
FRESH themes are currently pre-installed with HackMyResume. JSON Resume themes
|
||||||
`minimist`, and `hello-world`.
|
can be installed prior to use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install a JSON Resume theme into a local node_modules subfolder:
|
||||||
|
npm install jsonresume-theme-[name]
|
||||||
|
# Use it with HackMyResume
|
||||||
|
hackmyresume build resume.json -t node_modules/jsonresume-theme-[name]
|
||||||
|
```
|
||||||
|
|
||||||
|
As of v1.6.0, available predefined FRESH themes are `positive`, `modern`,
|
||||||
|
`compact`, `minimist`, and `hello-world`. For a list of JSON Resume themes,
|
||||||
|
check the [NPM Registry](https://www.npmjs.com/search?q=jsonresume-theme).
|
||||||
|
|
||||||
### Merging resumes
|
### Merging resumes
|
||||||
|
|
||||||
@ -249,6 +308,134 @@ hackmyresume BUILD me.json TO out/resume.all
|
|||||||
`out/resume.doc`, `out/resume.html`, `out/resume.txt`, `out/resume.pdf`, and
|
`out/resume.doc`, `out/resume.html`, `out/resume.txt`, `out/resume.pdf`, and
|
||||||
`out/resume.json`.
|
`out/resume.json`.
|
||||||
|
|
||||||
|
### Building PDFs
|
||||||
|
|
||||||
|
*Users who don't care about PDFs can turn off PDF generation across all themes
|
||||||
|
and formats with the `--pdf none` switch.*
|
||||||
|
|
||||||
|
HackMyResume takes a unique approach to PDF generation. Instead of enforcing
|
||||||
|
a specific PDF engine on users, HackMyResume will attempt to work with whatever
|
||||||
|
PDF engine you have installed through the engine's command-line interface (CLI).
|
||||||
|
Currently that means one or both of...
|
||||||
|
|
||||||
|
- [wkhtmltopdf][3]
|
||||||
|
- [Phantom.js][3]
|
||||||
|
|
||||||
|
..with support for other engines planned in the future. But for now, **one or
|
||||||
|
both of these engines must be installed and accessible on your PATH in order to
|
||||||
|
generate PDF resumes with HackMyResume**. That means you should be able to
|
||||||
|
invoke either of these tools directly from your shell or terminal without error:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wkhtmltopdf input.html output.pdf
|
||||||
|
phantomjs script.js input.html output.pdf
|
||||||
|
```
|
||||||
|
|
||||||
|
Assuming you've installed one or both of these engines on your system, you can
|
||||||
|
tell HackMyResume which flavor of PDF generation to use via the `--pdf` option
|
||||||
|
(`-p` for short):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json TO out.all --pdf phantom
|
||||||
|
hackmyresume BUILD resume.json TO out.all --pdf wkhtmltopdf
|
||||||
|
hackmyresume BUILD resume.json TO out.all --pdf none
|
||||||
|
```
|
||||||
|
|
||||||
|
### Analyzing
|
||||||
|
|
||||||
|
HackMyResume can analyze your resume for keywords, employment gaps, and other
|
||||||
|
metrics. Run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume ANALYZE <my-resume>.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Depending on the HackMyResume version, you should see output similar to:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
*** HackMyResume v1.6.0 ***
|
||||||
|
Reading resume: resume.json
|
||||||
|
Analyzing FRESH resume: resume.json
|
||||||
|
|
||||||
|
SECTIONS (10):
|
||||||
|
|
||||||
|
employment: 12
|
||||||
|
education: 2
|
||||||
|
service: 1
|
||||||
|
skills: 8
|
||||||
|
writing: 1
|
||||||
|
recognition: 0
|
||||||
|
social: 4
|
||||||
|
interests: 2
|
||||||
|
references: 1
|
||||||
|
languages: 2
|
||||||
|
|
||||||
|
COVERAGE (61.1%):
|
||||||
|
|
||||||
|
Total Days: 6034
|
||||||
|
Employed: 3688
|
||||||
|
Gaps: 8 [31, 1065, 273, 153, 671, 61, 61, 31]
|
||||||
|
Overlaps: 1 [243]
|
||||||
|
|
||||||
|
KEYWORDS (61):
|
||||||
|
|
||||||
|
Node.js: 6 mentions
|
||||||
|
JavaScript: 9 mentions
|
||||||
|
SQL Server: 3 mentions
|
||||||
|
Visual Studio: 6 mentions
|
||||||
|
Web API: 1 mentions
|
||||||
|
N-tier / 3-tier: 1 mentions
|
||||||
|
HTML 5: 1 mentions
|
||||||
|
JavaScript: 6 mentions
|
||||||
|
CSS: 2 mentions
|
||||||
|
Sass / LESS / SCSS: 1 mentions
|
||||||
|
LAMP: 3 mentions
|
||||||
|
WISC: 1 mentions
|
||||||
|
HTTP: 21 mentions
|
||||||
|
JSON: 1 mentions
|
||||||
|
XML: 2 mentions
|
||||||
|
REST: 1 mentions
|
||||||
|
WebSockets: 2 mentions
|
||||||
|
Backbone.js: 3 mentions
|
||||||
|
Angular.js: 1 mentions
|
||||||
|
Node.js: 4 mentions
|
||||||
|
NPM: 1 mentions
|
||||||
|
Bower: 1 mentions
|
||||||
|
Grunt: 2 mentions
|
||||||
|
Gulp: 1 mentions
|
||||||
|
jQuery: 2 mentions
|
||||||
|
Bootstrap: 3 mentions
|
||||||
|
Underscore.js: 1 mentions
|
||||||
|
PhantomJS: 1 mentions
|
||||||
|
CoffeeScript: 1 mentions
|
||||||
|
Python: 11 mentions
|
||||||
|
Perl: 4 mentions
|
||||||
|
PHP: 7 mentions
|
||||||
|
MySQL: 12 mentions
|
||||||
|
PostgreSQL: 4 mentions
|
||||||
|
NoSQL: 2 mentions
|
||||||
|
Apache: 2 mentions
|
||||||
|
AWS: 2 mentions
|
||||||
|
EC2: 2 mentions
|
||||||
|
RDS: 3 mentions
|
||||||
|
S3: 1 mentions
|
||||||
|
Azure: 1 mentions
|
||||||
|
Rackspace: 1 mentions
|
||||||
|
C++: 23 mentions
|
||||||
|
C++ 11: 1 mentions
|
||||||
|
Boost: 1 mentions
|
||||||
|
Xcode: 2 mentions
|
||||||
|
gcc: 1 mentions
|
||||||
|
OO&AD: 1 mentions
|
||||||
|
.NET: 20 mentions
|
||||||
|
Unity 5: 2 mentions
|
||||||
|
Mono: 3 mentions
|
||||||
|
MonoDevelop: 1 mentions
|
||||||
|
Xamarin: 1 mentions
|
||||||
|
TOTAL: 180 mentions
|
||||||
|
```
|
||||||
|
|
||||||
### Validating
|
### Validating
|
||||||
|
|
||||||
HackMyResume can also validate your resumes against either the [FRESH /
|
HackMyResume can also validate your resumes against either the [FRESH /
|
||||||
@ -263,7 +450,7 @@ hackmyresume VALIDATE resumeA.json resumeB.json
|
|||||||
HackMyResume will validate each specified resume in turn:
|
HackMyResume will validate each specified resume in turn:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
*** HackMyResume v0.9.0 ***
|
*** HackMyResume v1.6.0 ***
|
||||||
Validating JSON resume: resumeA.json (INVALID)
|
Validating JSON resume: resumeA.json (INVALID)
|
||||||
Validating JSON resume: resumeB.json (VALID)
|
Validating JSON resume: resumeB.json (VALID)
|
||||||
```
|
```
|
||||||
@ -282,14 +469,49 @@ where <INPUTS> is one or more resumes in FRESH or JSON Resume format, and
|
|||||||
autodetect the format (FRESH or JRS) of each input resume and convert it to the
|
autodetect the format (FRESH or JRS) of each input resume and convert it to the
|
||||||
other format (JRS or FRESH).
|
other format (JRS or FRESH).
|
||||||
|
|
||||||
|
### File-based Options
|
||||||
|
|
||||||
|
You can pass options into HackMyResume via an external options or ".hackmyrc"
|
||||||
|
file with the `--options` or `-o` switch:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json -o path/to/options.json
|
||||||
|
```
|
||||||
|
|
||||||
|
The options file can contain any documented HackMyResume option, including
|
||||||
|
`theme`, `silent`, `debug`, `pdf`, `css`, and other settings.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
// Set the default theme to "compact"
|
||||||
|
"theme": "compact",
|
||||||
|
// Change the "employment" section title text to "Work"
|
||||||
|
"sectionTitles": {
|
||||||
|
"employment": "Work"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If a particular option is specified both on the command line and in an external
|
||||||
|
options file, the explicit command-line option takes precedence.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# path/to/options.json specifes the POSITIVE theme
|
||||||
|
# -t parameter specifies the COMPACT theme
|
||||||
|
# The -t parameter wins.
|
||||||
|
hackmyresume BUILD resume.json -o path/to/options.json -t compact
|
||||||
|
> Reading resume: resume.json
|
||||||
|
> Applying COMPACT theme (7 formats)
|
||||||
|
```
|
||||||
|
|
||||||
### Prettifying
|
### Prettifying
|
||||||
|
|
||||||
HackMyResume applies [js-beautify][10]-style HTML prettification by default to
|
HackMyResume applies [js-beautify][10]-style HTML prettification by default to
|
||||||
HTML-formatted resumes. To disable prettification, the `--nopretty` or `-n` flag
|
HTML-formatted resumes. To disable prettification, the `--no-prettify` or `-n`
|
||||||
can be used:
|
flag can be used:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
hackmyresume BUILD resume.json out.all --nopretty
|
hackmyresume BUILD resume.json out.all --no-prettify
|
||||||
```
|
```
|
||||||
|
|
||||||
### Silent Mode
|
### Silent Mode
|
||||||
@ -301,6 +523,16 @@ hackmyresume BUILD resume.json -o someFile.all -s
|
|||||||
hackmyresume BUILD resume.json -o someFile.all --silent
|
hackmyresume BUILD resume.json -o someFile.all --silent
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Debug Mode
|
||||||
|
|
||||||
|
Use `-d` or `--debug` to force HMR to emit a call stack when errors occur. In
|
||||||
|
the future, this option will emit detailed error logging.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hackmyresume BUILD resume.json -d
|
||||||
|
hackmyresume ANALYZE resume.json --debug
|
||||||
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
HackMyResume is a community-driven free and open source project under the MIT
|
HackMyResume is a community-driven free and open source project under the MIT
|
||||||
@ -324,8 +556,12 @@ MIT. Go crazy. See [LICENSE.md][1] for details.
|
|||||||
[fresh]: https://github.com/fluentdesk/FRESH
|
[fresh]: https://github.com/fluentdesk/FRESH
|
||||||
[fresca]: https://github.com/fluentdesk/FRESCA
|
[fresca]: https://github.com/fluentdesk/FRESCA
|
||||||
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
||||||
[travis-image]: https://img.shields.io/travis/palomajs/paloma.svg?style=flat-square
|
[img-release]: https://img.shields.io/github/release/hacksalot/HackMyResume.svg?label=version
|
||||||
[travis-url]: https://travis-ci.org/hacksalot/HackMyResume
|
[img-master]: https://img.shields.io/travis/hacksalot/HackMyResume/master.svg
|
||||||
|
[img-dev]: https://img.shields.io/travis/hacksalot/HackMyResume/dev.svg?label=dev
|
||||||
|
[travis-url-master]: https://travis-ci.org/hacksalot/HackMyResume?branch=master
|
||||||
|
[travis-url-dev]: https://travis-ci.org/hacksalot/HackMyResume?branch=dev
|
||||||
|
[latest-release]: https://github.com/hacksalot/HackMyResume/releases/latest
|
||||||
[contribute]: CONTRIBUTING.md
|
[contribute]: CONTRIBUTING.md
|
||||||
[fresh-themes]: https://github.com/fluentdesk/fresh-themes
|
[fresh-themes]: https://github.com/fluentdesk/fresh-themes
|
||||||
[jrst]: https://www.npmjs.com/search?q=jsonresume-theme
|
[jrst]: https://www.npmjs.com/search?q=jsonresume-theme
|
||||||
|
BIN
assets/hackmyresume.cli.1.6.0.png
Normal file
BIN
assets/hackmyresume.cli.1.6.0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Binary file not shown.
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 83 KiB |
33
package.json
33
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hackmyresume",
|
"name": "hackmyresume",
|
||||||
"version": "1.3.0",
|
"version": "1.6.0",
|
||||||
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
|
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -30,8 +30,11 @@
|
|||||||
],
|
],
|
||||||
"author": "hacksalot <hacksalot@indevious.com> (https://github.com/hacksalot)",
|
"author": "hacksalot <hacksalot@indevious.com> (https://github.com/hacksalot)",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Edmund Jorgensen (https://github.com/tomheon)",
|
"aruberto (https://github.com/aruberto)",
|
||||||
"Ya Zhuang (https://github.com/zhuangya)",
|
"jjanusch (https://github.com/driftdev)",
|
||||||
|
"robertmain (https://github.com/robertmain)",
|
||||||
|
"tomheon (https://github.com/tomheon)",
|
||||||
|
"zhuangya (https://github.com/zhuangya)",
|
||||||
"hacksalot <hacksalot@indevious.com> (https://github.com/hacksalot)"
|
"hacksalot <hacksalot@indevious.com> (https://github.com/hacksalot)"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -39,16 +42,20 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/hacksalot/HackMyResume/issues"
|
"url": "https://github.com/hacksalot/HackMyResume/issues"
|
||||||
},
|
},
|
||||||
"main": "src/hackmycmd.js",
|
"main": "src/hackmyapi.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"hackmyresume": "src/index.js"
|
"hackmyresume": "src/index.js"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/hacksalot/HackMyResume",
|
"homepage": "https://github.com/hacksalot/HackMyResume",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.1.2",
|
"chalk": "^1.1.1",
|
||||||
|
"commander": "^2.9.0",
|
||||||
"copy": "^0.1.3",
|
"copy": "^0.1.3",
|
||||||
"fresca": "~0.2.2",
|
"extend": "^3.0.0",
|
||||||
"fresh-themes": "~0.9.3-beta",
|
"fresca": "~0.6.0",
|
||||||
|
"fresh-jrs-converter": "^0.2.0",
|
||||||
|
"fresh-resume-starter": "^0.2.2",
|
||||||
|
"fresh-themes": "~0.13.0-beta",
|
||||||
"fs-extra": "^0.24.0",
|
"fs-extra": "^0.24.0",
|
||||||
"handlebars": "^4.0.5",
|
"handlebars": "^4.0.5",
|
||||||
"html": "0.0.10",
|
"html": "0.0.10",
|
||||||
@ -57,30 +64,34 @@
|
|||||||
"jst": "0.0.13",
|
"jst": "0.0.13",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
"marked": "^0.3.5",
|
"marked": "^0.3.5",
|
||||||
"minimist": "^1.2.0",
|
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"moment": "^2.10.6",
|
"moment": "^2.10.6",
|
||||||
"parse-filepath": "^0.6.3",
|
"parse-filepath": "^0.6.3",
|
||||||
"path-exists": "^2.1.0",
|
"path-exists": "^2.1.0",
|
||||||
|
"printf": "^0.2.3",
|
||||||
"recursive-readdir-sync": "^1.0.6",
|
"recursive-readdir-sync": "^1.0.6",
|
||||||
"simple-html-tokenizer": "^0.2.0",
|
"simple-html-tokenizer": "^0.2.0",
|
||||||
|
"slash": "^1.0.0",
|
||||||
|
"string-padding": "^1.0.2",
|
||||||
|
"string.prototype.endswith": "^0.2.0",
|
||||||
"string.prototype.startswith": "^0.2.0",
|
"string.prototype.startswith": "^0.2.0",
|
||||||
|
"traverse": "^0.6.6",
|
||||||
"underscore": "^1.8.3",
|
"underscore": "^1.8.3",
|
||||||
"webshot": "^0.16.0",
|
"webshot": "^0.16.0",
|
||||||
"wkhtmltopdf": "^0.1.5",
|
"word-wrap": "^1.1.0",
|
||||||
"xml-escape": "^1.0.0",
|
"xml-escape": "^1.0.0",
|
||||||
"yamljs": "^0.2.4"
|
"yamljs": "^0.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "*",
|
"chai": "*",
|
||||||
|
"fresh-test-resumes": "^0.6.0",
|
||||||
"grunt": "*",
|
"grunt": "*",
|
||||||
"grunt-cli": "^0.1.13",
|
"grunt-cli": "^0.1.13",
|
||||||
"grunt-contrib-clean": "^0.7.0",
|
"grunt-contrib-clean": "^0.7.0",
|
||||||
"grunt-contrib-jshint": "^0.11.3",
|
"grunt-contrib-jshint": "^0.11.3",
|
||||||
"grunt-contrib-yuidoc": "^0.10.0",
|
"grunt-contrib-yuidoc": "^0.10.0",
|
||||||
|
"grunt-jsdoc": "^1.1.0",
|
||||||
"grunt-simple-mocha": "*",
|
"grunt-simple-mocha": "*",
|
||||||
"jane-q-fullstacker": "fluentdesk/jane-q-fullstacker",
|
|
||||||
"johnny-trouble-resume": "fluentdesk/johnny-trouble-resume",
|
|
||||||
"jsonresume-theme-boilerplate": "^0.1.2",
|
"jsonresume-theme-boilerplate": "^0.1.2",
|
||||||
"jsonresume-theme-classy": "^1.0.9",
|
"jsonresume-theme-classy": "^1.0.9",
|
||||||
"jsonresume-theme-modern": "0.0.18",
|
"jsonresume-theme-modern": "0.0.18",
|
||||||
|
30
src/cli/analyze.hbs
Normal file
30
src/cli/analyze.hbs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
{{style "SECTIONS (" "bold"}}{{style totals.numSections "white" }}{{style ")" "bold"}}
|
||||||
|
|
||||||
|
employment: {{v totals.totals.employment "-" 2 "bold" }}
|
||||||
|
projects: {{v totals.totals.projects "-" 2 "bold" }}
|
||||||
|
education: {{v totals.totals.education "-" 2 "bold" }}
|
||||||
|
service: {{v totals.totals.service "-" 2 "bold" }}
|
||||||
|
skills: {{v totals.totals.skills "-" 2 "bold" }}
|
||||||
|
writing: {{v totals.totals.writing "-" 2 "bold" }}
|
||||||
|
speaking: {{v totals.totals.speaking "-" 2 "bold" }}
|
||||||
|
reading: {{v totals.totals.reading "-" 2 "bold" }}
|
||||||
|
social: {{v totals.totals.social "-" 2 "bold" }}
|
||||||
|
references: {{v totals.totals.references "-" 2 "bold" }}
|
||||||
|
testimonials: {{v totals.totals.testimonials "-" 2 "bold" }}
|
||||||
|
languages: {{v totals.totals.languages "-" 2 "bold" }}
|
||||||
|
interests: {{v totals.totals.interests "-" 2 "bold" }}
|
||||||
|
|
||||||
|
{{style "COVERAGE (" "bold"}}{{style coverage.pct "white"}}{{style ")" "bold"}}
|
||||||
|
|
||||||
|
Total Days: {{v coverage.duration.total "-" 5 "bold" }}
|
||||||
|
Employed: {{v coverage.duration.work "-" 5 "bold" }}
|
||||||
|
Gaps: {{v coverage.gaps.length "-" 5 "bold" }} [{{#if coverage.gaps.length }}{{#each coverage.gaps }}{{#unless @first}} {{/unless}}{{gapLength duration }}{{/each}}{{/if}}]
|
||||||
|
Overlaps: {{v coverage.overlaps.length "-" 5 "bold" }} [{{#if coverage.overlaps.length }}{{#each coverage.overlaps }}{{#unless @first}} {{/unless}}{{gapLength duration }}{{/each}}{{/if}}]
|
||||||
|
|
||||||
|
{{style "KEYWORDS (" "bold"}}{{style keywords.length "white" }}{{style ")" "bold"}}
|
||||||
|
|
||||||
|
{{#each keywords }}{{{pad name 18}}}: {{v count "-" 5 "bold"}} mention{{#isPlural count}}s{{/isPlural}}
|
||||||
|
{{/each}}
|
||||||
|
-------------------------------
|
||||||
|
{{v keywords.length "0" 9 "bold"}} {{style "KEYWORDS" "bold"}} {{v keywords.totalKeywords "0" 5 "bold"}} {{style "mentions" "bold"}}
|
280
src/cli/error.js
Normal file
280
src/cli/error.js
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
/**
|
||||||
|
Error-handling routines for HackMyResume.
|
||||||
|
@module cli/error
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var HMSTATUS = require('../core/status-codes')
|
||||||
|
, PKG = require('../../package.json')
|
||||||
|
, FS = require('fs')
|
||||||
|
, FCMD = require('../hackmyapi')
|
||||||
|
, PATH = require('path')
|
||||||
|
, WRAP = require('word-wrap')
|
||||||
|
, M2C = require('../utils/md2chalk.js')
|
||||||
|
, chalk = require('chalk')
|
||||||
|
, extend = require('extend')
|
||||||
|
, YAML = require('yamljs')
|
||||||
|
, printf = require('printf')
|
||||||
|
, SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||||
|
require('string.prototype.startswith');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Error handler for HackMyResume. All errors are handled here.
|
||||||
|
@class ErrorHandler
|
||||||
|
*/
|
||||||
|
var ErrorHandler = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init: function( debug, assert, silent ) {
|
||||||
|
this.debug = debug;
|
||||||
|
this.assert = assert;
|
||||||
|
this.silent = silent;
|
||||||
|
this.msgs = require('./msg.js').errors;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
err: function( ex, shouldExit ) {
|
||||||
|
|
||||||
|
// Short-circuit logging output if --silent is on
|
||||||
|
var o = this.silent ? function() { } : _defaultLog;
|
||||||
|
|
||||||
|
// Special case; can probably be removed.
|
||||||
|
if( ex.pass ) throw ex;
|
||||||
|
|
||||||
|
// Load error messages
|
||||||
|
this.msgs = this.msgs || require('./msg.js').errors;
|
||||||
|
|
||||||
|
// Handle packaged HMR exceptions
|
||||||
|
if( ex.fluenterror ) {
|
||||||
|
|
||||||
|
// Output the error message
|
||||||
|
var objError = assembleError.call( this, ex );
|
||||||
|
o( this[ 'format_' + objError.etype ]( objError.msg ));
|
||||||
|
|
||||||
|
// Output the stack (sometimes)
|
||||||
|
if( objError.withStack ) {
|
||||||
|
var stack = ex.stack || (ex.inner && ex.inner.stack);
|
||||||
|
stack && o( chalk.gray( stack ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quit if necessary
|
||||||
|
if( ex.quit || objError.quit ) {
|
||||||
|
this.debug && o(
|
||||||
|
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
||||||
|
if( this.assert ) { ex.pass = true; throw ex; }
|
||||||
|
process.exit( ex.fluenterror );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle raw exceptions
|
||||||
|
else {
|
||||||
|
o( ex );
|
||||||
|
var stackTrace = ex.stack || (ex.inner && ex.inner.stack);
|
||||||
|
if( stackTrace && this.debug )
|
||||||
|
o( M2C(ex.stack || ex.inner.stack, 'gray') );
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
format_error: function( msg ) {
|
||||||
|
msg = msg || '';
|
||||||
|
return chalk.red.bold(
|
||||||
|
msg.toUpperCase().startsWith('ERROR:') ? msg : 'Error: ' + msg );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
format_warning: function( brief, msg ) {
|
||||||
|
return chalk.yellow(brief) + chalk.yellow(msg || '');
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
format_custom: function( msg ) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function _defaultLog() {
|
||||||
|
console.log.apply( console.log, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function assembleError( ex ) {
|
||||||
|
|
||||||
|
var msg = '', withStack = false, quit = false, etype = 'warning';
|
||||||
|
if( this.debug ) withStack = true;
|
||||||
|
|
||||||
|
switch( ex.fluenterror ) {
|
||||||
|
|
||||||
|
case HMSTATUS.themeNotFound:
|
||||||
|
msg = printf( M2C( this.msgs.themeNotFound.msg, 'yellow' ), ex.data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.copyCSS:
|
||||||
|
msg = M2C( this.msgs.copyCSS.msg, 'red' );
|
||||||
|
quit = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.resumeNotFound:
|
||||||
|
msg = M2C( this.msgs.resumeNotFound.msg, 'yellow' );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.missingCommand:
|
||||||
|
msg = M2C( this.msgs.missingCommand.msg + " (", 'yellow');
|
||||||
|
msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
||||||
|
return (idx === ar.length - 1 ? chalk.yellow('or ') : '') +
|
||||||
|
chalk.yellow.bold(v.toUpperCase());
|
||||||
|
}).join( chalk.yellow(', ')) + chalk.yellow(").\n\n");
|
||||||
|
|
||||||
|
msg += chalk.gray(FS.readFileSync(
|
||||||
|
PATH.resolve(__dirname, '../cli/use.txt'), 'utf8' ));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.invalidCommand:
|
||||||
|
msg = printf( M2C( this.msgs.invalidCommand.msg, 'yellow'), ex.attempted );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.resumeNotFoundAlt:
|
||||||
|
msg = M2C( this.msgs.resumeNotFoundAlt.msg, 'yellow' );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.inputOutputParity:
|
||||||
|
msg = M2C( this.msgs.inputOutputParity.msg );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.createNameMissing:
|
||||||
|
msg = M2C( this.msgs.createNameMissing.msg );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.pdfGeneration:
|
||||||
|
msg = M2C( this.msgs.pdfGeneration.msg, 'bold' );
|
||||||
|
if( ex.inner ) msg += chalk.red('\n' + ex.inner);
|
||||||
|
withStack = true; quit = false; etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.invalid:
|
||||||
|
msg = M2C( this.msgs.invalid.msg, 'red' );
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.generateError:
|
||||||
|
msg = (ex.inner && ex.inner.toString()) || ex;
|
||||||
|
quit = false;
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.fileSaveError:
|
||||||
|
msg = printf( M2C( this.msgs.fileSaveError.msg ), (ex.inner || ex).toString() );
|
||||||
|
etype = 'error';
|
||||||
|
quit = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.invalidFormat:
|
||||||
|
ex.data.forEach(function(d){
|
||||||
|
msg += printf( M2C( this.msgs.invalidFormat.msg, 'bold' ),
|
||||||
|
ex.theme.name.toUpperCase(), d.format.toUpperCase());
|
||||||
|
}, this);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.missingParam:
|
||||||
|
msg = printf( M2C( this.msgs.missingParam.msg ), ex.expected, ex.helper );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.invalidHelperUse:
|
||||||
|
msg = printf( M2C( this.msgs.invalidHelperUse.msg ), ex.helper );
|
||||||
|
if( ex.error ) {
|
||||||
|
msg += '\n--> ' + assembleError.call( this, extend( true, {}, ex, {fluenterror: ex.error} )).msg;
|
||||||
|
//msg += printf( '\n--> ' + M2C( this.msgs.invalidParamCount.msg ), ex.expected );
|
||||||
|
}
|
||||||
|
quit = false;
|
||||||
|
etype = 'warning';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.notOnPath:
|
||||||
|
msg = printf( M2C(this.msgs.notOnPath.msg, 'bold'), ex.engine);
|
||||||
|
quit = false;
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.readError:
|
||||||
|
if( !ex.quiet )
|
||||||
|
console.error(printf( M2C(this.msgs.readError.msg, 'red'), ex.file));
|
||||||
|
msg = ex.inner.toString();
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.mixedMerge:
|
||||||
|
msg = M2C( this.msgs.mixedMerge.msg );
|
||||||
|
quit = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.invokeTemplate:
|
||||||
|
msg = M2C( this.msgs.invokeTemplate.msg, 'red' );
|
||||||
|
msg += M2C( '\n' + WRAP(ex.inner.toString(), { width: 60, indent: ' ' }), 'gray' );
|
||||||
|
etype = 'custom';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.compileTemplate:
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.themeLoad:
|
||||||
|
msg = M2C( printf( this.msgs.themeLoad.msg, ex.attempted.toUpperCase() ), 'red');
|
||||||
|
if( ex.inner && ex.inner.fluenterror ) {
|
||||||
|
msg += M2C('\nError: ', 'red') + assembleError.call( this, ex.inner ).msg;
|
||||||
|
}
|
||||||
|
quit = true;
|
||||||
|
etype = 'custom';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HMSTATUS.parseError:
|
||||||
|
if( SyntaxErrorEx.is( ex.inner )) {
|
||||||
|
console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) );
|
||||||
|
var se = new SyntaxErrorEx( ex, ex.raw );
|
||||||
|
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||||
|
se.line, se.col);
|
||||||
|
}
|
||||||
|
else if( ex.inner && ex.inner.line !== undefined && ex.inner.col !== undefined ) {
|
||||||
|
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||||
|
ex.inner.line, ex.inner.col);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = ex;
|
||||||
|
}
|
||||||
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
msg: msg, // The error message to display
|
||||||
|
withStack: withStack, // Whether to include the stack
|
||||||
|
quit: quit,
|
||||||
|
etype: etype
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
331
src/cli/main.js
Normal file
331
src/cli/main.js
Normal file
@ -0,0 +1,331 @@
|
|||||||
|
/**
|
||||||
|
Definition of the `main` function.
|
||||||
|
@module cli/main
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var HMR = require( '../hackmyapi')
|
||||||
|
, PKG = require('../../package.json')
|
||||||
|
, FS = require('fs')
|
||||||
|
, EXTEND = require('extend')
|
||||||
|
, chalk = require('chalk')
|
||||||
|
, PATH = require('path')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, HME = require('../core/event-codes')
|
||||||
|
, safeLoadJSON = require('../utils/safe-json-loader')
|
||||||
|
, StringUtils = require('../utils/string.js')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, OUTPUT = require('./out')
|
||||||
|
, PAD = require('string-padding')
|
||||||
|
, Command = require('commander').Command;
|
||||||
|
|
||||||
|
var _opts = { };
|
||||||
|
var _title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***');
|
||||||
|
var _out = new OUTPUT( _opts );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
A callable implementation of the HackMyResume CLI. Encapsulates the command
|
||||||
|
line interface as a single method accepting a parameter array.
|
||||||
|
@alias module:cli/main.main
|
||||||
|
@param rawArgs {Array} An array of command-line parameters. Will either be
|
||||||
|
process.argv (in production) or custom parameters (in test).
|
||||||
|
*/
|
||||||
|
var main = module.exports = function( rawArgs ) {
|
||||||
|
|
||||||
|
var initInfo = initialize( rawArgs );
|
||||||
|
var args = initInfo.args;
|
||||||
|
|
||||||
|
// Create the top-level (application) command...
|
||||||
|
var program = new Command('hackmyresume')
|
||||||
|
.version(PKG.version)
|
||||||
|
.description(chalk.yellow.bold('*** HackMyResume ***'))
|
||||||
|
.option('-s --silent', 'Run in silent mode')
|
||||||
|
.option('--no-color', 'Disable colors')
|
||||||
|
.option('--color', 'Enable colors')
|
||||||
|
.option('-d --debug', 'Enable diagnostics', false)
|
||||||
|
.option('-a --assert', 'Treat warnings as errors', false)
|
||||||
|
.option('-v --version', 'Show the version')
|
||||||
|
.allowUnknownOption();
|
||||||
|
program.jsonArgs = initInfo.options;
|
||||||
|
|
||||||
|
// Create the NEW command
|
||||||
|
program
|
||||||
|
.command('new')
|
||||||
|
.arguments('<sources...>')
|
||||||
|
.option('-f --format <fmt>', 'FRESH or JRS format', 'FRESH')
|
||||||
|
.alias('create')
|
||||||
|
.description('Create resume(s) in FRESH or JSON RESUME format.')
|
||||||
|
.action(function( sources ) {
|
||||||
|
execute.call( this, sources, [], this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the VALIDATE command
|
||||||
|
program
|
||||||
|
.command('validate')
|
||||||
|
.arguments('<sources...>')
|
||||||
|
.description('Validate a resume in FRESH or JSON RESUME format.')
|
||||||
|
.action(function(sources) {
|
||||||
|
execute.call( this, sources, [], this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the CONVERT command
|
||||||
|
program
|
||||||
|
.command('convert')
|
||||||
|
.description('Convert a resume to/from FRESH or JSON RESUME format.')
|
||||||
|
.action(function() {
|
||||||
|
var x = splitSrcDest.call( this );
|
||||||
|
execute.call( this, x.src, x.dst, this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the ANALYZE command
|
||||||
|
program
|
||||||
|
.command('analyze')
|
||||||
|
.arguments('<sources...>')
|
||||||
|
.description('Analyze one or more resumes.')
|
||||||
|
.action(function( sources ) {
|
||||||
|
execute.call( this, sources, [], this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the PEEK command
|
||||||
|
program
|
||||||
|
.command('peek')
|
||||||
|
.arguments('<sources...>')
|
||||||
|
.description('Peek at a resume field or section')
|
||||||
|
.action(function( sources, sectionOrField ) {
|
||||||
|
var dst = (sources && sources.length > 1) ? [sources.pop()] : [];
|
||||||
|
execute.call( this, sources, dst, this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the BUILD command
|
||||||
|
program
|
||||||
|
.command('build')
|
||||||
|
.alias('generate')
|
||||||
|
.option('-t --theme <theme>', 'Theme name or path')
|
||||||
|
.option('-n --no-prettify', 'Disable HTML prettification', true)
|
||||||
|
.option('-c --css <option>', 'CSS linking / embedding')
|
||||||
|
.option('-p --pdf <engine>', 'PDF generation engine')
|
||||||
|
.option('--no-sort', 'Sort resume sections by date', false)
|
||||||
|
.option('--tips', 'Display theme tips and warnings.', false)
|
||||||
|
.description('Generate resume to multiple formats')
|
||||||
|
.action(function( sources, targets, options ) {
|
||||||
|
var x = splitSrcDest.call( this );
|
||||||
|
execute.call( this, x.src, x.dst, this.opts(), logMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
program.parse( args );
|
||||||
|
|
||||||
|
if (!program.args.length) { throw { fluenterror: 4 }; }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Massage command-line args and setup Commander.js. */
|
||||||
|
function initialize( ar ) {
|
||||||
|
|
||||||
|
var o = initOptions( ar );
|
||||||
|
|
||||||
|
o.silent || logMsg( _title );
|
||||||
|
|
||||||
|
// Emit debug prelude if --debug was specified
|
||||||
|
if( o.debug ) {
|
||||||
|
_out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.'));
|
||||||
|
_out.log('');
|
||||||
|
_out.log(chalk.cyan(PAD(' Platform:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.platform === 'win32' ? 'windows' : process.platform ));
|
||||||
|
_out.log(chalk.cyan(PAD(' Node.js:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.version ));
|
||||||
|
_out.log(chalk.cyan(PAD(' HackMyResume:',25, null, PAD.RIGHT)) + chalk.cyan.bold('v' + PKG.version ));
|
||||||
|
_out.log(chalk.cyan(PAD(' FRESCA:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies.fresca ));
|
||||||
|
_out.log(chalk.cyan(PAD(' fresh-themes:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-themes'] ));
|
||||||
|
_out.log(chalk.cyan(PAD(' fresh-jrs-converter:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-jrs-converter'] ));
|
||||||
|
_out.log('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle invalid verbs here (a bit easier here than in commander.js)...
|
||||||
|
if( o.verb && !HMR.verbs[ o.verb ] && !HMR.alias[ o.verb ] ) {
|
||||||
|
throw { fluenterror: HMSTATUS.invalidCommand, quit: true,
|
||||||
|
attempted: o.orgVerb };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override the .missingArgument behavior
|
||||||
|
Command.prototype.missingArgument = function(name) {
|
||||||
|
if( this.name() !== 'new' ) {
|
||||||
|
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Override the .helpInformation behavior
|
||||||
|
Command.prototype.helpInformation = function() {
|
||||||
|
var manPage = FS.readFileSync(
|
||||||
|
PATH.join(__dirname, 'use.txt'), 'utf8' );
|
||||||
|
return chalk.green.bold(manPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
args: o.args,
|
||||||
|
options: o.json
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Init options prior to setting up command infrastructure. */
|
||||||
|
function initOptions( ar ) {
|
||||||
|
var oVerb, verb = '', args = ar.slice(), cleanArgs = args.slice(2), oJSON;
|
||||||
|
if( cleanArgs.length ) {
|
||||||
|
|
||||||
|
// Support case-insensitive sub-commands (build, generate, validate, etc)
|
||||||
|
var vidx = _.findIndex( cleanArgs, function(v){ return v[0] !== '-'; });
|
||||||
|
if( vidx !== -1 ) {
|
||||||
|
oVerb = cleanArgs[ vidx ];
|
||||||
|
verb = args[ vidx + 2 ] = oVerb.trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove --options --opts -o and process separately
|
||||||
|
var optsIdx = _.findIndex( cleanArgs, function(v){
|
||||||
|
return v === '-o' || v === '--options' || v === '--opts';
|
||||||
|
});
|
||||||
|
if(optsIdx !== -1) {
|
||||||
|
var optStr = cleanArgs[ optsIdx + 1];
|
||||||
|
args.splice( optsIdx + 2, 2 );
|
||||||
|
if( optStr && (optStr = optStr.trim()) ) {
|
||||||
|
//var myJSON = JSON.parse(optStr);
|
||||||
|
if( optStr[0] === '{')
|
||||||
|
oJSON = eval('(' + optStr + ')'); // jshint ignore:line
|
||||||
|
else {
|
||||||
|
var inf = safeLoadJSON( optStr );
|
||||||
|
if( !inf.ex )
|
||||||
|
oJSON = inf.json;
|
||||||
|
// TODO: Error handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grab the --debug flag
|
||||||
|
var isDebug = _.some( args, function(v) {
|
||||||
|
return v === '-d' || v === '--debug';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Grab the --silent flag
|
||||||
|
var isSilent = _.some( args, function(v) {
|
||||||
|
return v === '-s' || v === '--silent';
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
debug: isDebug,
|
||||||
|
silent: isSilent,
|
||||||
|
orgVerb: oVerb,
|
||||||
|
verb: verb,
|
||||||
|
json: oJSON,
|
||||||
|
args: args
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Invoke a HackMyResume verb. */
|
||||||
|
function execute( src, dst, opts, log ) {
|
||||||
|
|
||||||
|
loadOptions.call( this, opts, this.parent.jsonArgs );
|
||||||
|
var hand = require( './error' );
|
||||||
|
hand.init( _opts.debug, _opts.assert, _opts.silent );
|
||||||
|
var v = new HMR.verbs[ this.name() ]();
|
||||||
|
_opts.errHandler = v;
|
||||||
|
_out.init( _opts );
|
||||||
|
v.on( 'hmr:status', function() { _out.do.apply( _out, arguments ); });
|
||||||
|
v.on( 'hmr:error', function() {
|
||||||
|
hand.err.apply( hand, arguments );
|
||||||
|
});
|
||||||
|
v.invoke.call( v, src, dst, _opts, log );
|
||||||
|
if( v.errorCode )
|
||||||
|
process.exit(v.errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize HackMyResume options.
|
||||||
|
TODO: Options loading is a little hacky, for two reasons:
|
||||||
|
- Commander.js idiosyncracies
|
||||||
|
- Need to accept JSON inputs from the command line.
|
||||||
|
*/
|
||||||
|
function loadOptions( o, cmdO ) {
|
||||||
|
|
||||||
|
// o and this.opts() seem to be the same (command-specific options)
|
||||||
|
|
||||||
|
// Load the specified options file (if any) and apply options
|
||||||
|
if( cmdO )
|
||||||
|
o = EXTEND(true, o, cmdO);
|
||||||
|
|
||||||
|
// Merge in command-line options
|
||||||
|
o = EXTEND( true, o, this.opts() );
|
||||||
|
|
||||||
|
// Kludge parent-level options until piping issue is resolved
|
||||||
|
if( this.parent.silent !== undefined && this.parent.silent !== null)
|
||||||
|
o.silent = this.parent.silent;
|
||||||
|
if( this.parent.debug !== undefined && this.parent.debug !== null)
|
||||||
|
o.debug = this.parent.debug;
|
||||||
|
if( this.parent.assert !== undefined && this.parent.assert !== null)
|
||||||
|
o.assert = this.parent.assert;
|
||||||
|
|
||||||
|
if( o.debug ) {
|
||||||
|
logMsg(chalk.cyan('OPTIONS:') + '\n');
|
||||||
|
_.each(o, function(val, key) {
|
||||||
|
logMsg(chalk.cyan(' %s') + chalk.cyan.bold(' %s'),
|
||||||
|
PAD(key,22,null,PAD.RIGHT), val);
|
||||||
|
});
|
||||||
|
logMsg('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
EXTEND(true, _opts, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Split multiple command-line filenames by the 'TO' keyword */
|
||||||
|
function splitSrcDest() {
|
||||||
|
|
||||||
|
var params = this.parent.args.filter(function(j) { return String.is(j); });
|
||||||
|
if( params.length === 0 )
|
||||||
|
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||||
|
|
||||||
|
// Find the TO keyword, if any
|
||||||
|
var splitAt = _.findIndex( params, function(p) {
|
||||||
|
return p.toLowerCase() === 'to';
|
||||||
|
});
|
||||||
|
|
||||||
|
// TO can't be the last keyword
|
||||||
|
if( splitAt === params.length - 1 && splitAt !== -1 ) {
|
||||||
|
logMsg(chalk.yellow('Please ') +
|
||||||
|
chalk.yellow.bold('specify an output file') +
|
||||||
|
chalk.yellow(' for this operation or ') +
|
||||||
|
chalk.yellow.bold('omit the TO keyword') +
|
||||||
|
chalk.yellow('.') );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
src: params.slice(0, splitAt === -1 ? undefined : splitAt ),
|
||||||
|
dst: splitAt === -1 ? [] : params.slice( splitAt + 1 )
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Simple logging placeholder. */
|
||||||
|
function logMsg() {
|
||||||
|
_opts.silent || console.log.apply( console.log, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
18
src/cli/msg.js
Normal file
18
src/cli/msg.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
Message-handling routines for HackMyResume.
|
||||||
|
@module msg.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var PATH = require('path');
|
||||||
|
var YAML = require('yamljs');
|
||||||
|
|
||||||
|
var cache = module.exports = function() {
|
||||||
|
return cache ? cache : YAML.load( PATH.join(__dirname, 'msg.yml') );
|
||||||
|
}();
|
||||||
|
|
||||||
|
}());
|
98
src/cli/msg.yml
Normal file
98
src/cli/msg.yml
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
events:
|
||||||
|
begin:
|
||||||
|
msg: Invoking **%s** command.
|
||||||
|
beforeCreate:
|
||||||
|
msg: Creating new **%s** resume: **%s**
|
||||||
|
afterRead:
|
||||||
|
msg: Reading **%s** resume: **%s**
|
||||||
|
beforeTheme:
|
||||||
|
msg: Verifying **%s** theme.
|
||||||
|
afterTheme:
|
||||||
|
msg: Verifying outputs: ???
|
||||||
|
beforeMerge:
|
||||||
|
msg:
|
||||||
|
- "Merging **%s**"
|
||||||
|
- " onto **%s**"
|
||||||
|
applyTheme:
|
||||||
|
msg: Applying **%s** theme (**%s** format%s)
|
||||||
|
afterBuild:
|
||||||
|
msg:
|
||||||
|
- "The **%s** theme says:"
|
||||||
|
- |
|
||||||
|
"For best results view JSON Resume themes over a
|
||||||
|
local or remote HTTP connection. For example:
|
||||||
|
|
||||||
|
npm install http-server -g
|
||||||
|
http-server <resume-folder>
|
||||||
|
|
||||||
|
For more information, see the README."
|
||||||
|
afterGenerate:
|
||||||
|
msg:
|
||||||
|
- " (with %s)"
|
||||||
|
- "Skipping %s resume: %s"
|
||||||
|
- "Generating **%s** resume: **%s**"
|
||||||
|
beforeAnalyze:
|
||||||
|
msg: "Analyzing **%s** resume: **%s**"
|
||||||
|
beforeConvert:
|
||||||
|
msg: "Converting **%s** (**%s**) to **%s** (**%s**)"
|
||||||
|
afterValidate:
|
||||||
|
msg:
|
||||||
|
- "Validating **%s** against the **%s** schema: "
|
||||||
|
- "VALID!"
|
||||||
|
- "INVALID"
|
||||||
|
- "BROKEN"
|
||||||
|
beforePeek:
|
||||||
|
msg:
|
||||||
|
- Peeking at **%s** in **%s**
|
||||||
|
- Peeking at **%s**
|
||||||
|
afterPeek:
|
||||||
|
msg: "The specified key **%s** was not found in **%s**."
|
||||||
|
afterInlineConvert:
|
||||||
|
msg: Converting **%s** to **%s** format.
|
||||||
|
errors:
|
||||||
|
themeNotFound:
|
||||||
|
msg: >
|
||||||
|
**Couldn't find the '%s' theme.** Please specify the name of a preinstalled
|
||||||
|
FRESH theme or the path to a locally installed FRESH or JSON Resume theme.
|
||||||
|
copyCSS:
|
||||||
|
msg: Couldn't copy CSS file to destination folder.
|
||||||
|
resumeNotFound:
|
||||||
|
msg: Please **feed me a resume** in FRESH or JSON Resume format.
|
||||||
|
missingCommand:
|
||||||
|
msg: Please **give me a command**
|
||||||
|
invalidCommand:
|
||||||
|
msg: Invalid command: '%s'
|
||||||
|
resumeNotFoundAlt:
|
||||||
|
msg: Please **feed me a resume** in either FRESH or JSON Resume format.
|
||||||
|
inputOutputParity:
|
||||||
|
msg: Please **specify an output file name** for every input file you wish to convert.
|
||||||
|
createNameMissing:
|
||||||
|
msg: Please **specify the filename** of the resume to create.
|
||||||
|
pdfGeneration:
|
||||||
|
msg: PDF generation failed. Make sure wkhtmltopdf is installed and accessible from your path.
|
||||||
|
invalid:
|
||||||
|
msg: Validation failed and the --assert option was specified.
|
||||||
|
invalidFormat:
|
||||||
|
msg: The **%s** theme doesn't support the **%s** format.
|
||||||
|
notOnPath:
|
||||||
|
msg: %s wasn't found on your system path or is inaccessible. PDF not generated.
|
||||||
|
readError:
|
||||||
|
msg: Reading **???** resume: **%s**
|
||||||
|
parseError:
|
||||||
|
msg: Invalid or corrupt JSON on line %s column %s.
|
||||||
|
invalidHelperUse:
|
||||||
|
msg: "**Warning**: Incorrect use of the **%s** theme helper."
|
||||||
|
fileSaveError:
|
||||||
|
msg: An error occurred while writing %s to disk: %s.
|
||||||
|
mixedMerge:
|
||||||
|
msg: "**Warning:** merging mixed resume types. Errors may occur."
|
||||||
|
invokeTemplate:
|
||||||
|
msg: "An error occurred during template invocation."
|
||||||
|
compileTemplate:
|
||||||
|
msg: "An error occurred during template compilation."
|
||||||
|
themeLoad:
|
||||||
|
msg: "Applying **%s** theme (? formats)"
|
||||||
|
invalidParamCount:
|
||||||
|
msg: "Invalid number of parameters. Expected: **%s**."
|
||||||
|
missingParam:
|
||||||
|
msg: The '**%s**' parameter was needed but not supplied.
|
229
src/cli/out.js
Normal file
229
src/cli/out.js
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
/**
|
||||||
|
Output routines for HackMyResume.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module out.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var chalk = require('chalk')
|
||||||
|
, HME = require('../core/event-codes')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, Class = require('../utils/class.js')
|
||||||
|
, M2C = require('../utils/md2chalk.js')
|
||||||
|
, PATH = require('path')
|
||||||
|
, LO = require('lodash')
|
||||||
|
, FS = require('fs')
|
||||||
|
, EXTEND = require('extend')
|
||||||
|
, HANDLEBARS = require('handlebars')
|
||||||
|
, YAML = require('yamljs')
|
||||||
|
, printf = require('printf')
|
||||||
|
, pad = require('string-padding')
|
||||||
|
, dbgStyle = 'cyan';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
A stateful output module. All HMR console output handled here.
|
||||||
|
*/
|
||||||
|
var OutputHandler = module.exports = Class.extend({
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init: function( opts ) {
|
||||||
|
this.opts = EXTEND( true, this.opts || { }, opts );
|
||||||
|
this.msgs = YAML.load(PATH.join( __dirname, 'msg.yml' )).events;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log: function( msg ) {
|
||||||
|
msg = msg || '';
|
||||||
|
var printf = require('printf');
|
||||||
|
var finished = printf.apply( printf, arguments );
|
||||||
|
this.opts.silent || console.log( finished );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
do: function( evt ) {
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
function L() {
|
||||||
|
that.log.apply( that, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( evt.sub ) {
|
||||||
|
|
||||||
|
case HME.begin:
|
||||||
|
this.opts.debug &&
|
||||||
|
L( M2C( this.msgs.begin.msg, dbgStyle), evt.cmd.toUpperCase() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.error:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeCreate:
|
||||||
|
L( M2C( this.msgs.beforeCreate.msg, 'green' ), evt.fmt, evt.file );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeRead:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterRead:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeTheme:
|
||||||
|
this.opts.debug &&
|
||||||
|
L( M2C( this.msgs.beforeTheme.msg, dbgStyle), evt.theme.toUpperCase() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterParse:
|
||||||
|
L(
|
||||||
|
M2C( this.msgs.afterRead.msg, 'gray', 'white.dim'), evt.fmt.toUpperCase(), evt.file
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterTheme:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeMerge:
|
||||||
|
var msg = '';
|
||||||
|
evt.f.reverse().forEach( function( a, idx ) {
|
||||||
|
msg += printf(
|
||||||
|
((idx === 0) ?
|
||||||
|
this.msgs.beforeMerge.msg[0] :
|
||||||
|
this.msgs.beforeMerge.msg[1] ), a.file
|
||||||
|
);
|
||||||
|
}, this);
|
||||||
|
L( M2C(msg, evt.mixed ? 'yellow' : 'gray', 'white.dim') );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterMerge:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.applyTheme:
|
||||||
|
this.theme = evt.theme;
|
||||||
|
var numFormats = Object.keys( evt.theme.formats ).length;
|
||||||
|
L( M2C(this.msgs.applyTheme.msg, evt.status === 'error' ? 'red' : 'gray', evt.status === 'error' ? 'bold' : 'white.dim'),
|
||||||
|
evt.theme.name.toUpperCase(),
|
||||||
|
numFormats, ( numFormats === 1 ? '' : 's') );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.end:
|
||||||
|
if( evt.cmd === 'build' ) {
|
||||||
|
var themeName = this.theme.name.toUpperCase();
|
||||||
|
if( this.opts.tips && (this.theme.message || this.theme.render) ) {
|
||||||
|
var WRAP = require('word-wrap');
|
||||||
|
if( this.theme.message ) {
|
||||||
|
L( M2C( this.msgs.afterBuild.msg[0], 'cyan' ), themeName );
|
||||||
|
L( M2C( this.theme.message, 'white' ));
|
||||||
|
}
|
||||||
|
else if ( this.theme.render ) {
|
||||||
|
L( M2C( this.msgs.afterBuild.msg[0], 'cyan'), themeName);
|
||||||
|
L( M2C( this.msgs.afterBuild.msg[1], 'white'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterGenerate:
|
||||||
|
var suffix = '';
|
||||||
|
if( evt.fmt === 'pdf' ) {
|
||||||
|
if( this.opts.pdf ) {
|
||||||
|
if( this.opts.pdf !== 'none' ) {
|
||||||
|
suffix = printf( M2C( this.msgs.afterGenerate.msg[0], evt.error ? 'red' : 'green' ), this.opts.pdf );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
L( M2C( this.msgs.afterGenerate.msg[1], 'gray' ),
|
||||||
|
evt.fmt.toUpperCase(), evt.file );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
L( M2C( this.msgs.afterGenerate.msg[2] + suffix, evt.error ? 'red' : 'green' ),
|
||||||
|
pad(evt.fmt.toUpperCase(),4,null,pad.RIGHT),
|
||||||
|
PATH.relative(process.cwd(), evt.file ));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeAnalyze:
|
||||||
|
L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterAnalyze:
|
||||||
|
var info = evt.info;
|
||||||
|
var rawTpl = FS.readFileSync( PATH.join( __dirname, 'analyze.hbs' ), 'utf8');
|
||||||
|
HANDLEBARS.registerHelper( require('../helpers/console-helpers') );
|
||||||
|
var template = HANDLEBARS.compile(rawTpl, { strict: false, assumeObjects: false });
|
||||||
|
var tot = 0;
|
||||||
|
info.keywords.forEach(function(g) { tot += g.count; });
|
||||||
|
info.keywords.totalKeywords = tot;
|
||||||
|
var output = template( info );
|
||||||
|
this.log( chalk.cyan(output) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforeConvert:
|
||||||
|
L( M2C( this.msgs.beforeConvert.msg, 'green' ),
|
||||||
|
evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterInlineConvert:
|
||||||
|
L( M2C( this.msgs.afterInlineConvert.msg, 'gray', 'white.dim' ),
|
||||||
|
evt.file, evt.fmt );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterValidate:
|
||||||
|
var style = evt.isValid ? 'green' : 'yellow';
|
||||||
|
L(
|
||||||
|
M2C( this.msgs.afterValidate.msg[0], 'white' ) +
|
||||||
|
chalk[style].bold( evt.isValid ?
|
||||||
|
this.msgs.afterValidate.msg[1] :
|
||||||
|
this.msgs.afterValidate.msg[2] ),
|
||||||
|
evt.file, evt.fmt
|
||||||
|
);
|
||||||
|
|
||||||
|
if( evt.errors ) {
|
||||||
|
_.each(evt.errors, function(err,idx) {
|
||||||
|
L( chalk.yellow.bold('--> ') +
|
||||||
|
chalk.yellow(err.field.replace('data.','resume.').toUpperCase() + ' ' +
|
||||||
|
err.message) );
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.beforePeek:
|
||||||
|
// if( evt.target )
|
||||||
|
// L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
|
||||||
|
// else
|
||||||
|
// L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HME.afterPeek:
|
||||||
|
var sty = evt.error ? 'red' : ( evt.target !== undefined ? 'green' : 'yellow' );
|
||||||
|
if( evt.requested )
|
||||||
|
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file);
|
||||||
|
else
|
||||||
|
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file);
|
||||||
|
|
||||||
|
if( evt.target !== undefined )
|
||||||
|
console.dir( evt.target, { depth: null, colors: true } );
|
||||||
|
else if( !evt.error )
|
||||||
|
L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
51
src/cli/use.txt
Normal file
51
src/cli/use.txt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
Usage:
|
||||||
|
|
||||||
|
hackmyresume <command> <sources> [TO <targets>] [<options>]
|
||||||
|
|
||||||
|
Available commands:
|
||||||
|
|
||||||
|
BUILD Build your resume to the destination format(s).
|
||||||
|
ANALYZE Analyze your resume for keywords, gaps, and metrics.
|
||||||
|
VALIDATE Validate your resume for errors and typos.
|
||||||
|
CONVERT Convert your resume between FRESH and JSON Resume.
|
||||||
|
NEW Create a new resume in FRESH or JSON Resume format.
|
||||||
|
PEEK View a specific field or element on your resume.
|
||||||
|
|
||||||
|
Available options:
|
||||||
|
|
||||||
|
--theme -t Path to a FRESH or JSON Resume theme.
|
||||||
|
--pdf -p Specify the PDF engine to use (wkhtmltopdf or phantom).
|
||||||
|
--options -o Load options from an external JSON file.
|
||||||
|
--format -f The format (FRESH or JSON Resume) to use.
|
||||||
|
--debug -d Emit extended debugging info.
|
||||||
|
--assert -a Treat resume validation warnings as errors.
|
||||||
|
--no-colors Disable terminal colors.
|
||||||
|
--tips Display theme messages and tips.
|
||||||
|
--help -h Display help documentation.
|
||||||
|
--version -v Display the current version.
|
||||||
|
|
||||||
|
Not all options are supported for all commands. For example, the
|
||||||
|
--theme option is only supported for the BUILD command.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
hackmyresume BUILD resume.json TO out/resume.all --theme modern
|
||||||
|
hackmyresume ANALYZE resume.json
|
||||||
|
hackmyresume NEW my-new-resume.json --format JRS
|
||||||
|
hackmyresume CONVERT resume-fresh.json TO resume-jrs.json
|
||||||
|
hackmyresume VALIDATE resume.json
|
||||||
|
hackmyresume PEEK resume.json employment[2].summary
|
||||||
|
|
||||||
|
Tips:
|
||||||
|
|
||||||
|
- You can specify multiple sources and/or targets for all commands.
|
||||||
|
- You can use any FRESH or JSON Resume theme with HackMyResume.
|
||||||
|
- Specify a file extension of .all to generate your resume to all
|
||||||
|
available formats supported by the theme. (BUILD command.)
|
||||||
|
- The --theme parameter can specify either the name of a preinstalled
|
||||||
|
theme, or the path to a local FRESH or JSON Resume theme.
|
||||||
|
- Visit https://www.npmjs.com/search?q=jsonresume-theme for a full
|
||||||
|
listing of all available JSON Resume themes.
|
||||||
|
- Visit https://github.com/fluentdesk/fresh-themes for a complete
|
||||||
|
listing of all available FRESH themes.
|
||||||
|
- Report bugs to https://githut.com/hacksalot/HackMyResume/issues.
|
@ -1,396 +0,0 @@
|
|||||||
/**
|
|
||||||
FRESH to JSON Resume conversion routiens.
|
|
||||||
@license MIT. See LICENSE.md for details.
|
|
||||||
@module convert.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
var _ = require('underscore');
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert between FRESH and JRS resume/CV formats.
|
|
||||||
@class FRESHConverter
|
|
||||||
*/
|
|
||||||
var FRESHConverter = module.exports = {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert from JSON Resume format to FRESH.
|
|
||||||
@method toFresh
|
|
||||||
@todo Refactor
|
|
||||||
*/
|
|
||||||
toFRESH: function( src, foreign ) {
|
|
||||||
|
|
||||||
foreign = (foreign === undefined || foreign === null) ? true : foreign;
|
|
||||||
|
|
||||||
return {
|
|
||||||
|
|
||||||
name: src.basics.name,
|
|
||||||
|
|
||||||
imp: src.basics.imp,
|
|
||||||
|
|
||||||
info: {
|
|
||||||
label: src.basics.label,
|
|
||||||
class: src.basics.class, // <--> round-trip
|
|
||||||
image: src.basics.picture,
|
|
||||||
brief: src.basics.summary
|
|
||||||
},
|
|
||||||
|
|
||||||
contact: {
|
|
||||||
email: src.basics.email,
|
|
||||||
phone: src.basics.phone,
|
|
||||||
website: src.basics.website,
|
|
||||||
other: src.basics.other // <--> round-trip
|
|
||||||
},
|
|
||||||
|
|
||||||
meta: meta( true, src.meta ),
|
|
||||||
|
|
||||||
location: {
|
|
||||||
city: src.basics.location.city,
|
|
||||||
region: src.basics.location.region,
|
|
||||||
country: src.basics.location.countryCode,
|
|
||||||
code: src.basics.location.postalCode,
|
|
||||||
address: src.basics.location.address
|
|
||||||
},
|
|
||||||
|
|
||||||
employment: employment( src.work, true ),
|
|
||||||
education: education( src.education, true),
|
|
||||||
service: service( src.volunteer, true),
|
|
||||||
skills: skillsToFRESH( src.skills ),
|
|
||||||
writing: writing( src.publications, true),
|
|
||||||
recognition: recognition( src.awards, true, foreign ),
|
|
||||||
social: social( src.basics.profiles, true ),
|
|
||||||
interests: src.interests,
|
|
||||||
testimonials: references( src.references, true ),
|
|
||||||
languages: src.languages,
|
|
||||||
disposition: src.disposition // <--> round-trip
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert from FRESH format to JSON Resume.
|
|
||||||
@param foreign True if non-JSON-Resume properties should be included in
|
|
||||||
the result, false if those properties should be excluded.
|
|
||||||
@todo Refactor
|
|
||||||
*/
|
|
||||||
toJRS: function( src, foreign ) {
|
|
||||||
|
|
||||||
foreign = (foreign === undefined || foreign === null) ? false : foreign;
|
|
||||||
|
|
||||||
return {
|
|
||||||
|
|
||||||
basics: {
|
|
||||||
name: src.name,
|
|
||||||
label: src.info.label,
|
|
||||||
class: foreign ? src.info.class : undefined,
|
|
||||||
summary: src.info.brief,
|
|
||||||
website: src.contact.website,
|
|
||||||
phone: src.contact.phone,
|
|
||||||
email: src.contact.email,
|
|
||||||
picture: src.info.image,
|
|
||||||
location: {
|
|
||||||
address: src.location.address,
|
|
||||||
postalCode: src.location.code,
|
|
||||||
city: src.location.city,
|
|
||||||
countryCode: src.location.country,
|
|
||||||
region: src.location.region
|
|
||||||
},
|
|
||||||
profiles: social( src.social, false ),
|
|
||||||
imp: src.imp
|
|
||||||
},
|
|
||||||
|
|
||||||
work: employment( src.employment, false ),
|
|
||||||
education: education( src.education, false ),
|
|
||||||
skills: skillsToJRS( src.skills, false ),
|
|
||||||
volunteer: service( src.service, false ),
|
|
||||||
awards: recognition( src.recognition, false, foreign ),
|
|
||||||
publications: writing( src.writing, false ),
|
|
||||||
interests: src.interests,
|
|
||||||
references: references( src.testimonials, false ),
|
|
||||||
samples: foreign ? src.samples : undefined,
|
|
||||||
disposition: foreign ? src.disposition : undefined,
|
|
||||||
languages: src.languages
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
toSTRING: function( src ) {
|
|
||||||
function replacerJRS( key,value ) { // Exclude these keys from stringification
|
|
||||||
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
|
||||||
'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result',
|
|
||||||
'isModified', 'htmlPreview', 'display_progress_bar'],
|
|
||||||
function( val ) { return key.trim() === val; }
|
|
||||||
) ? undefined : value;
|
|
||||||
}
|
|
||||||
function replacerFRESH( key,value ) { // Exclude these keys from stringification
|
|
||||||
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
|
||||||
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
|
|
||||||
function( val ) { return key.trim() === val; }
|
|
||||||
) ? undefined : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return JSON.stringify( src, src.basics ? replacerJRS : replacerFRESH, 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function meta( direction, obj ) {
|
|
||||||
//if( !obj ) return obj; // preserve null and undefined
|
|
||||||
if( direction ) {
|
|
||||||
obj = obj || { };
|
|
||||||
obj.format = obj.format || "FRESH@0.1.0";
|
|
||||||
obj.version = obj.version || "0.1.0";
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function employment( obj, direction ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( !direction ) {
|
|
||||||
return obj && obj.history ?
|
|
||||||
obj.history.map(function(emp){
|
|
||||||
return {
|
|
||||||
company: emp.employer,
|
|
||||||
website: emp.url,
|
|
||||||
position: emp.position,
|
|
||||||
startDate: emp.start,
|
|
||||||
endDate: emp.end,
|
|
||||||
summary: emp.summary,
|
|
||||||
highlights: emp.highlights
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return {
|
|
||||||
history: obj && obj.length ?
|
|
||||||
obj.map( function( job ) {
|
|
||||||
return {
|
|
||||||
position: job.position,
|
|
||||||
employer: job.company,
|
|
||||||
summary: job.summary,
|
|
||||||
current: (!job.endDate || !job.endDate.trim() || job.endDate.trim().toLowerCase() === 'current') || undefined,
|
|
||||||
start: job.startDate,
|
|
||||||
end: job.endDate,
|
|
||||||
url: job.website,
|
|
||||||
keywords: [],
|
|
||||||
highlights: job.highlights
|
|
||||||
};
|
|
||||||
}) : undefined
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function education( obj, direction ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return obj && obj.length ? {
|
|
||||||
level: "",
|
|
||||||
history: obj.map(function(edu){
|
|
||||||
return {
|
|
||||||
institution: edu.institution,
|
|
||||||
start: edu.startDate,
|
|
||||||
end: edu.endDate,
|
|
||||||
grade: edu.gpa,
|
|
||||||
curriculum: edu.courses,
|
|
||||||
url: edu.website || edu.url || undefined,
|
|
||||||
summary: edu.summary || "",
|
|
||||||
area: edu.area,
|
|
||||||
studyType: edu.studyType
|
|
||||||
};
|
|
||||||
})
|
|
||||||
} : undefined;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj && obj.history ?
|
|
||||||
obj.history.map(function(edu){
|
|
||||||
return {
|
|
||||||
institution: edu.institution,
|
|
||||||
gpa: edu.grade,
|
|
||||||
courses: edu.curriculum,
|
|
||||||
startDate: edu.start,
|
|
||||||
endDate: edu.end,
|
|
||||||
area: edu.area,
|
|
||||||
studyType: edu.studyType
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function service( obj, direction, foreign ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return {
|
|
||||||
history: obj && obj.length ? obj.map(function(vol) {
|
|
||||||
return {
|
|
||||||
type: 'volunteer',
|
|
||||||
position: vol.position,
|
|
||||||
organization: vol.organization,
|
|
||||||
start: vol.startDate,
|
|
||||||
end: vol.endDate,
|
|
||||||
url: vol.website,
|
|
||||||
summary: vol.summary,
|
|
||||||
highlights: vol.highlights
|
|
||||||
};
|
|
||||||
}) : undefined
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj && obj.history ?
|
|
||||||
obj.history.map(function(srv){
|
|
||||||
return {
|
|
||||||
flavor: foreign ? srv.flavor : undefined,
|
|
||||||
organization: srv.organization,
|
|
||||||
position: srv.position,
|
|
||||||
startDate: srv.start,
|
|
||||||
endDate: srv.end,
|
|
||||||
website: srv.url,
|
|
||||||
summary: srv.summary,
|
|
||||||
highlights: srv.highlights
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function social( obj, direction ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return obj.map(function(pro){
|
|
||||||
return {
|
|
||||||
label: pro.network,
|
|
||||||
network: pro.network,
|
|
||||||
url: pro.url,
|
|
||||||
user: pro.username
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj.map( function( soc ) {
|
|
||||||
return {
|
|
||||||
network: soc.network,
|
|
||||||
username: soc.user,
|
|
||||||
url: soc.url
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function recognition( obj, direction, foreign ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return obj && obj.length ? obj.map(
|
|
||||||
function(awd){
|
|
||||||
return {
|
|
||||||
flavor: foreign ? awd.flavor : undefined,
|
|
||||||
url: foreign ? awd.url: undefined,
|
|
||||||
title: awd.title,
|
|
||||||
date: awd.date,
|
|
||||||
from: awd.awarder,
|
|
||||||
summary: awd.summary
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj && obj.length ? obj.map(function(awd){
|
|
||||||
return {
|
|
||||||
flavor: foreign ? awd.flavor : undefined,
|
|
||||||
url: foreign ? awd.url: undefined,
|
|
||||||
title: awd.title,
|
|
||||||
date: awd.date,
|
|
||||||
awarder: awd.from,
|
|
||||||
summary: awd.summary
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function references( obj, direction ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return obj && obj.length && obj.map(function(ref){
|
|
||||||
return {
|
|
||||||
name: ref.name,
|
|
||||||
flavor: 'professional',
|
|
||||||
quote: ref.reference,
|
|
||||||
private: false
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj && obj.length && obj.map(function(ref){
|
|
||||||
return {
|
|
||||||
name: ref.name,
|
|
||||||
reference: ref.quote
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function writing( obj, direction ) {
|
|
||||||
if( !obj ) return obj;
|
|
||||||
if( direction ) {
|
|
||||||
return obj.map(function( pub ) {
|
|
||||||
return {
|
|
||||||
title: pub.name,
|
|
||||||
flavor: undefined,
|
|
||||||
publisher: pub.publisher,
|
|
||||||
url: pub.website,
|
|
||||||
date: pub.releaseDate,
|
|
||||||
summary: pub.summary
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return obj && obj.length ? obj.map(function(pub){
|
|
||||||
return {
|
|
||||||
name: pub.title,
|
|
||||||
publisher: pub.publisher && pub.publisher.name ? pub.publisher.name : pub.publisher,
|
|
||||||
releaseDate: pub.date,
|
|
||||||
website: pub.url,
|
|
||||||
summary: pub.summary
|
|
||||||
};
|
|
||||||
}) : undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function skillsToFRESH( skills ) {
|
|
||||||
|
|
||||||
return {
|
|
||||||
sets: skills.map(function(set) {
|
|
||||||
return {
|
|
||||||
name: set.name,
|
|
||||||
level: set.level,
|
|
||||||
skills: set.keywords
|
|
||||||
};
|
|
||||||
})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function skillsToJRS( skills ) {
|
|
||||||
var ret = [];
|
|
||||||
if( skills.sets && skills.sets.length ) {
|
|
||||||
ret = skills.sets.map(function(set){
|
|
||||||
return {
|
|
||||||
name: set.name,
|
|
||||||
level: set.level,
|
|
||||||
keywords: set.skills
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if( skills.list ) {
|
|
||||||
ret = skills.list.map(function(sk){
|
|
||||||
return {
|
|
||||||
name: sk.name,
|
|
||||||
level: sk.level,
|
|
||||||
keywords: sk.keywords
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
@ -1,20 +1,20 @@
|
|||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
var FLUENT = require('../hackmyapi');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Supported resume formats.
|
Supported resume formats.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{ name: 'html', ext: 'html', gen: new FLUENT.HtmlGenerator() },
|
|
||||||
{ name: 'txt', ext: 'txt', gen: new FLUENT.TextGenerator() },
|
{ name: 'html', ext: 'html', gen: new (require('../generators/html-generator'))() },
|
||||||
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new FLUENT.WordGenerator() },
|
{ name: 'txt', ext: 'txt', gen: new (require('../generators/text-generator'))() },
|
||||||
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new FLUENT.HtmlPdfGenerator() },
|
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new (require('../generators/word-generator'))() },
|
||||||
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new FLUENT.HtmlPngGenerator() },
|
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new (require('../generators/html-pdf-cli-generator'))() },
|
||||||
{ name: 'md', ext: 'md', fmt: 'txt', gen: new FLUENT.MarkdownGenerator() },
|
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new (require('../generators/html-png-generator'))() },
|
||||||
{ name: 'json', ext: 'json', gen: new FLUENT.JsonGenerator() },
|
{ name: 'md', ext: 'md', fmt: 'txt', gen: new (require('../generators/markdown-generator'))() },
|
||||||
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new FLUENT.JsonYamlGenerator() },
|
{ name: 'json', ext: 'json', gen: new (require('../generators/json-generator'))() },
|
||||||
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new FLUENT.LaTeXGenerator() }
|
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new (require('../generators/json-yaml-generator'))() },
|
||||||
|
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new (require('../generators/latex-generator'))() }
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,184 +0,0 @@
|
|||||||
{
|
|
||||||
|
|
||||||
"name": "",
|
|
||||||
|
|
||||||
"meta": {
|
|
||||||
"format": "FRESH@0.1.0",
|
|
||||||
"version": "0.1.0"
|
|
||||||
},
|
|
||||||
|
|
||||||
"info": {
|
|
||||||
"label": "",
|
|
||||||
"characterClass": "",
|
|
||||||
"brief": "",
|
|
||||||
"image": ""
|
|
||||||
},
|
|
||||||
|
|
||||||
"contact": {
|
|
||||||
"website": "",
|
|
||||||
"phone": "",
|
|
||||||
"email": "",
|
|
||||||
"other": []
|
|
||||||
},
|
|
||||||
|
|
||||||
"location": {
|
|
||||||
"address": "",
|
|
||||||
"city": "",
|
|
||||||
"region": "",
|
|
||||||
"code": "",
|
|
||||||
"country": ""
|
|
||||||
},
|
|
||||||
|
|
||||||
"social": [
|
|
||||||
{
|
|
||||||
"label": "",
|
|
||||||
"network": "",
|
|
||||||
"user": "",
|
|
||||||
"url": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"employment": {
|
|
||||||
"summary": "",
|
|
||||||
"history": [
|
|
||||||
{
|
|
||||||
"employer": "",
|
|
||||||
"url": "",
|
|
||||||
"position": "",
|
|
||||||
"summary": "",
|
|
||||||
"start": "",
|
|
||||||
"end": "",
|
|
||||||
"keywords": [],
|
|
||||||
"highlights": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
"education": {
|
|
||||||
"summary": "",
|
|
||||||
"level": "",
|
|
||||||
"degree": "",
|
|
||||||
"history": [
|
|
||||||
{
|
|
||||||
"institution": "",
|
|
||||||
"url": "",
|
|
||||||
"start": "",
|
|
||||||
"end": "",
|
|
||||||
"grade": "",
|
|
||||||
"summary": "",
|
|
||||||
"curriculum": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
"service": {
|
|
||||||
"summary": "",
|
|
||||||
"history": [
|
|
||||||
{
|
|
||||||
"flavor": "",
|
|
||||||
"position": "",
|
|
||||||
"organization": "",
|
|
||||||
"url": "",
|
|
||||||
"start": "",
|
|
||||||
"end": "",
|
|
||||||
"summary": "",
|
|
||||||
"highlights": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
"skills": {
|
|
||||||
|
|
||||||
"sets": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"level": "",
|
|
||||||
"skills": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"list": [ ]
|
|
||||||
},
|
|
||||||
|
|
||||||
"samples": [
|
|
||||||
{
|
|
||||||
"title": "",
|
|
||||||
"summary": "",
|
|
||||||
"url": "",
|
|
||||||
"date": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"writing": [
|
|
||||||
{
|
|
||||||
"title": "",
|
|
||||||
"flavor": "",
|
|
||||||
"date": "",
|
|
||||||
"publisher": {
|
|
||||||
"name": "",
|
|
||||||
"url": ""
|
|
||||||
},
|
|
||||||
"url": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"reading": [
|
|
||||||
{
|
|
||||||
"title": "",
|
|
||||||
"flavor": "",
|
|
||||||
"url": "",
|
|
||||||
"author": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"recognition": [
|
|
||||||
{
|
|
||||||
"flavor": "",
|
|
||||||
"from": "",
|
|
||||||
"title": "",
|
|
||||||
"event": "",
|
|
||||||
"date": "",
|
|
||||||
"summary": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"references": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"flavor": "",
|
|
||||||
"private": true,
|
|
||||||
"contact": [
|
|
||||||
{
|
|
||||||
"label": "",
|
|
||||||
"flavor": "",
|
|
||||||
"value": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"testimonials": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"flavor": "",
|
|
||||||
"quote": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"languages": [
|
|
||||||
{
|
|
||||||
"language": "",
|
|
||||||
"level": "",
|
|
||||||
"years": 0
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"interests": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"summary": "",
|
|
||||||
"keywords": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
/**
|
|
||||||
@module error-handler.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
var HACKMYSTATUS = require('./status-codes')
|
|
||||||
, PKG = require('../../package.json')
|
|
||||||
, FS = require('fs')
|
|
||||||
, FCMD = require('../hackmycmd')
|
|
||||||
, PATH = require('path')
|
|
||||||
, title = ('\n*** HackMyResume v' + PKG.version + ' ***').bold.white;
|
|
||||||
|
|
||||||
var ErrorHandler = module.exports = {
|
|
||||||
|
|
||||||
|
|
||||||
err: function( ex, shouldExit ) {
|
|
||||||
var msg = '', exitCode;
|
|
||||||
|
|
||||||
if( ex.fluenterror ){
|
|
||||||
switch( ex.fluenterror ) { // TODO: Remove magic numbers
|
|
||||||
|
|
||||||
case HACKMYSTATUS.themeNotFound:
|
|
||||||
msg = "The specified theme couldn't be found: " + ex.data;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.copyCSS:
|
|
||||||
msg = "Couldn't copy CSS file to destination folder";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.resumeNotFound:
|
|
||||||
msg = 'Please '.guide + 'feed me a resume'.guide.bold +
|
|
||||||
' in FRESH or JSON Resume format.'.guide;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.missingCommand:
|
|
||||||
msg = title + "\nPlease ".guide + "give me a command".guide.bold +
|
|
||||||
" (".guide;
|
|
||||||
|
|
||||||
msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
|
||||||
return (idx === ar.length - 1 ? 'or '.guide : '') +
|
|
||||||
v.toUpperCase().guide;
|
|
||||||
}).join(', '.guide) + ").\n\n".guide;
|
|
||||||
|
|
||||||
msg += FS.readFileSync(
|
|
||||||
PATH.resolve(__dirname, '../use.txt'), 'utf8' ).info.bold;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.invalidCommand:
|
|
||||||
msg = 'Please '.guide + 'specify the output resume file'.guide.bold +
|
|
||||||
' that should be created.'.guide;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.resumeNotFoundAlt:
|
|
||||||
msg = 'Please '.guide + 'feed me a resume'.guide.bold +
|
|
||||||
' in either FRESH or JSON Resume format.'.guide;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.inputOutputParity:
|
|
||||||
msg = 'Please '.guide + 'specify an output file name'.guide.bold +
|
|
||||||
' for every input file you wish to convert.'.guide;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.createNameMissing:
|
|
||||||
msg = 'Please '.guide + 'specify the filename of the resume'.guide.bold +
|
|
||||||
' to create.'.guide;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HACKMYSTATUS.wkhtmltopdf:
|
|
||||||
msg = 'ERROR: PDF generation failed. '.red.bold + ('Make sure wkhtmltopdf is ' +
|
|
||||||
'installed and accessible from your path.').red;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
exitCode = ex.fluenterror;
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = ex.toString();
|
|
||||||
exitCode = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
var idx = msg.indexOf('Error: ');
|
|
||||||
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
|
|
||||||
if( !ex.fluenterror || ex.fluenterror < 3 ) { // TODO: magic #s
|
|
||||||
console.log( ('ERROR: ' + trimmed.toString()).red.bold );
|
|
||||||
console.log( ex.stack.gray);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log( trimmed.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( shouldExit )
|
|
||||||
process.exit( exitCode );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}());
|
|
46
src/core/event-codes.js
Normal file
46
src/core/event-codes.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
Event code definitions.
|
||||||
|
@module event-codes.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
var val = 0;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
error: -1,
|
||||||
|
success: 0,
|
||||||
|
begin: 1,
|
||||||
|
end: 2,
|
||||||
|
beforeRead: 3,
|
||||||
|
afterRead: 4,
|
||||||
|
beforeCreate: 5,
|
||||||
|
afterCreate: 6,
|
||||||
|
beforeTheme: 7,
|
||||||
|
afterTheme: 8,
|
||||||
|
beforeMerge: 9,
|
||||||
|
afterMerge: 10,
|
||||||
|
beforeGenerate: 11,
|
||||||
|
afterGenerate: 12,
|
||||||
|
beforeAnalyze: 13,
|
||||||
|
afterAnalyze: 14,
|
||||||
|
beforeConvert: 15,
|
||||||
|
afterConvert: 16,
|
||||||
|
verifyOutputs: 17,
|
||||||
|
beforeParse: 18,
|
||||||
|
afterParse: 19,
|
||||||
|
beforePeek: 20,
|
||||||
|
afterPeek: 21,
|
||||||
|
beforeInlineConvert: 22,
|
||||||
|
afterInlineConvert: 23,
|
||||||
|
beforeValidate: 24,
|
||||||
|
afterValidate: 25
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -1,9 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
The HackMyResume date representation.
|
The HackMyResume date representation.
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
@license MIT. See LICENSE.md for details.
|
||||||
@module fluent-date.js
|
@module core/fluent-date
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,7 +28,10 @@ function FluentDate( dt ) {
|
|||||||
this.rep = this.fmt( dt );
|
this.rep = this.fmt( dt );
|
||||||
}
|
}
|
||||||
|
|
||||||
FluentDate/*.prototype*/.fmt = function( dt ) {
|
FluentDate/*.prototype*/.fmt = function( dt, throws ) {
|
||||||
|
|
||||||
|
throws = (throws === undefined || throws === null) || throws;
|
||||||
|
|
||||||
if( (typeof dt === 'string' || dt instanceof String) ) {
|
if( (typeof dt === 'string' || dt instanceof String) ) {
|
||||||
dt = dt.toLowerCase().trim();
|
dt = dt.toLowerCase().trim();
|
||||||
if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now"
|
if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now"
|
||||||
@ -63,7 +68,9 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
|
|||||||
var mt = moment( dt );
|
var mt = moment( dt );
|
||||||
if(mt.isValid())
|
if(mt.isValid())
|
||||||
return mt;
|
return mt;
|
||||||
|
if( throws )
|
||||||
throw 'Invalid date format encountered.';
|
throw 'Invalid date format encountered.';
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -72,7 +79,9 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
|
|||||||
}
|
}
|
||||||
else if( dt.isValid && dt.isValid() )
|
else if( dt.isValid && dt.isValid() )
|
||||||
return dt;
|
return dt;
|
||||||
|
if( throws )
|
||||||
throw 'Unknown date object encountered.';
|
throw 'Unknown date object encountered.';
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,3 +91,5 @@ moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;});
|
|||||||
abbr.sept = 9;
|
abbr.sept = 9;
|
||||||
|
|
||||||
module.exports = FluentDate;
|
module.exports = FluentDate;
|
||||||
|
|
||||||
|
}());
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
Definition of the FRESHResume class.
|
Definition of the FRESHResume class.
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
@license MIT. See LICENSE.md for details.
|
||||||
@module fresh-resume.js
|
@module core/fresh-resume
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FS = require('fs')
|
var FS = require('fs')
|
||||||
, extend = require('../utils/extend')
|
, extend = require('extend')
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
, _ = require('underscore')
|
, _ = require('underscore')
|
||||||
, __ = require('lodash')
|
, __ = require('lodash')
|
||||||
@ -15,45 +19,113 @@ Definition of the FRESHResume class.
|
|||||||
, moment = require('moment')
|
, moment = require('moment')
|
||||||
, XML = require('xml-escape')
|
, XML = require('xml-escape')
|
||||||
, MD = require('marked')
|
, MD = require('marked')
|
||||||
, CONVERTER = require('./convert')
|
, CONVERTER = require('fresh-jrs-converter')
|
||||||
, JRSResume = require('./jrs-resume');
|
, JRSResume = require('./jrs-resume');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A FRESH-style resume in JSON or YAML.
|
A FRESH resume or CV. FRESH resumes are backed by JSON, and each FreshResume
|
||||||
@class FreshResume
|
object is an instantiation of that JSON decorated with utility methods.
|
||||||
|
@constructor
|
||||||
*/
|
*/
|
||||||
function FreshResume() {
|
function FreshResume() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open and parse the specified FRESH resume sheet. Merge the JSON object model
|
Initialize the FreshResume from file.
|
||||||
onto this Sheet instance with extend() and convert sheet dates to a safe &
|
|
||||||
consistent format. Then sort each section by startDate descending.
|
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.open = function( file, title ) {
|
FreshResume.prototype.open = function( file, opts ) {
|
||||||
this.imp = { fileName: file };
|
var raw = FS.readFileSync( file, 'utf8' );
|
||||||
this.imp.raw = FS.readFileSync( file, 'utf8' );
|
var ret = this.parse( raw, opts );
|
||||||
return this.parse( this.imp.raw, title );
|
this.imp.file = file;
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the the FreshResume from JSON string data.
|
||||||
|
*/
|
||||||
|
FreshResume.prototype.parse = function( stringData, opts ) {
|
||||||
|
return this.parseJSON( JSON.parse( stringData ), opts );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the FreshResume from JSON.
|
||||||
|
Open and parse the specified FRESH resume. Merge the JSON object model onto
|
||||||
|
this Sheet instance with extend() and convert sheet dates to a safe &
|
||||||
|
consistent format. Then sort each section by startDate descending.
|
||||||
|
@param rep {Object} The raw JSON representation.
|
||||||
|
@param opts {Object} Resume loading and parsing options.
|
||||||
|
{
|
||||||
|
date: Perform safe date conversion.
|
||||||
|
sort: Sort resume items by date.
|
||||||
|
compute: Prepare computed resume totals.
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
FreshResume.prototype.parseJSON = function( rep, opts ) {
|
||||||
|
|
||||||
|
// Ignore any element with the 'ignore: true' designator.
|
||||||
|
var that = this, traverse = require('traverse'), ignoreList = [];
|
||||||
|
var scrubbed = traverse( rep ).map( function( x ) {
|
||||||
|
if( !this.isLeaf && this.node.ignore ) {
|
||||||
|
if ( this.node.ignore === true || this.node.ignore === 'true' ) {
|
||||||
|
ignoreList.push( this.node );
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Now apply the resume representation onto this object
|
||||||
|
extend( true, this, scrubbed );
|
||||||
|
|
||||||
|
// If the resume already has a .imp object, then we are being called from
|
||||||
|
// the .dupe method, and there's no need to do any post processing
|
||||||
|
if( !this.imp ) {
|
||||||
|
// Set up metadata TODO: Clean up metadata on the object model.
|
||||||
|
opts = opts || { };
|
||||||
|
if( opts.imp === undefined || opts.imp ) {
|
||||||
|
this.imp = this.imp || { };
|
||||||
|
this.imp.title = (opts.title || this.imp.title) || this.name;
|
||||||
|
}
|
||||||
|
// Parse dates, sort dates, and calculate computed values
|
||||||
|
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
||||||
|
(opts.sort === undefined || opts.sort) && this.sort();
|
||||||
|
(opts.compute === undefined || opts.compute) && (this.computed = {
|
||||||
|
numYears: this.duration(),
|
||||||
|
keywords: this.keywords()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk (for environments that have disk access).
|
Save the sheet to disk (for environments that have disk access).
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.save = function( filename ) {
|
FreshResume.prototype.save = function( filename ) {
|
||||||
this.imp.fileName = filename || this.imp.fileName;
|
this.imp.file = filename || this.imp.file;
|
||||||
FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' );
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.saveAs = function( filename, format ) {
|
FreshResume.prototype.saveAs = function( filename, format ) {
|
||||||
|
|
||||||
if( format !== 'JRS' ) {
|
if( format !== 'JRS' ) {
|
||||||
this.imp.fileName = filename || this.imp.fileName;
|
this.imp.file = filename || this.imp.file;
|
||||||
FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var newRep = CONVERTER.toJRS( this );
|
var newRep = CONVERTER.toJRS( this );
|
||||||
@ -62,15 +134,27 @@ Definition of the FRESHResume class.
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Duplicate this FreshResume instance.
|
||||||
|
This method first extend()s this object onto an empty, creating a deep copy,
|
||||||
|
and then passes the result into a new FreshResume instance via .parseJSON.
|
||||||
|
We do it this way to create a true clone of the object without re-running any
|
||||||
|
of the associated processing.
|
||||||
|
*/
|
||||||
FreshResume.prototype.dupe = function() {
|
FreshResume.prototype.dupe = function() {
|
||||||
|
var jso = extend( true, { }, this );
|
||||||
var rnew = new FreshResume();
|
var rnew = new FreshResume();
|
||||||
rnew.parse( this.stringify(), { } );
|
rnew.parseJSON( jso, { } );
|
||||||
return rnew;
|
return rnew;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert the supplied object to a JSON string, sanitizing meta-properties along
|
Convert the supplied FreshResume to a JSON string, sanitizing meta-properties
|
||||||
the way.
|
along the way.
|
||||||
*/
|
*/
|
||||||
FreshResume.stringify = function( obj ) {
|
FreshResume.stringify = function( obj ) {
|
||||||
function replacer( key,value ) { // Exclude these keys from stringification
|
function replacer( key,value ) { // Exclude these keys from stringification
|
||||||
@ -82,51 +166,31 @@ Definition of the FRESHResume class.
|
|||||||
return JSON.stringify( obj, replacer, 2 );
|
return JSON.stringify( obj, replacer, 2 );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert this object to a JSON string, sanitizing meta-properties along the
|
||||||
|
way.
|
||||||
|
*/
|
||||||
|
FreshResume.prototype.stringify = function() {
|
||||||
|
return FreshResume.stringify( this );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a copy of this resume in which all string fields have been run through
|
Create a copy of this resume in which all string fields have been run through
|
||||||
a transformation function (such as a Markdown filter or XML encoder).
|
a transformation function (such as a Markdown filter or XML encoder).
|
||||||
|
TODO: Move this out of FRESHResume.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.transformStrings = function( filters, transformer ) {
|
FreshResume.prototype.transformStrings = function( filt, transformer ) {
|
||||||
|
|
||||||
var that = this;
|
|
||||||
var ret = this.dupe();
|
var ret = this.dupe();
|
||||||
|
var trx = require('../utils/string-transformer');
|
||||||
// TODO: refactor recursion
|
return trx( ret, filt, transformer );
|
||||||
function transformStringsInObject( obj ) {
|
|
||||||
|
|
||||||
if( !obj ) return;
|
|
||||||
if( moment.isMoment( obj ) ) return;
|
|
||||||
|
|
||||||
if( _.isArray( obj ) ) {
|
|
||||||
obj.forEach( function(elem, idx, ar) {
|
|
||||||
if( typeof elem === 'string' || elem instanceof String )
|
|
||||||
ar[idx] = transformer( null, elem );
|
|
||||||
else if (_.isObject(elem))
|
|
||||||
transformStringsInObject( elem );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (_.isObject( obj )) {
|
|
||||||
Object.keys( obj ).forEach(function(k) {
|
|
||||||
var sub = obj[k];
|
|
||||||
if( typeof sub === 'string' || sub instanceof String ) {
|
|
||||||
if( filters.length && _.contains(filters, k) )
|
|
||||||
return;
|
|
||||||
obj[k] = transformer( k, sub );
|
|
||||||
}
|
|
||||||
else if (_.isObject( sub ))
|
|
||||||
transformStringsInObject( sub );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys( ret ).forEach(function(member){
|
|
||||||
transformStringsInObject( ret[ member ] );
|
|
||||||
});
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a copy of this resume in which all fields have been interpreted as
|
Create a copy of this resume in which all fields have been interpreted as
|
||||||
Markdown.
|
Markdown.
|
||||||
@ -147,132 +211,64 @@ Definition of the FRESHResume class.
|
|||||||
return this.transformStrings( ['skills','url','start','end','date'], trx );
|
return this.transformStrings( ['skills','url','start','end','date'], trx );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a copy of this resume in which all fields have been interpreted as
|
Create a copy of this resume in which all fields have been interpreted as
|
||||||
Markdown.
|
Markdown.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.xmlify = function() {
|
FreshResume.prototype.xmlify = function() {
|
||||||
|
|
||||||
function trx(key, val) {
|
function trx(key, val) {
|
||||||
return XML(val);
|
return XML(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.transformStrings( [], trx );
|
return this.transformStrings( [], trx );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
Create a copy of this resume in which all fields have been interpreted as
|
|
||||||
Markdown.
|
|
||||||
*/
|
|
||||||
FreshResume.prototype.markdownify2 = function() {
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
var ret = this.dupe();
|
|
||||||
|
|
||||||
function MDIN(txt){
|
|
||||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: refactor recursion
|
|
||||||
function markdownifyStringsInObject( obj, inline ) {
|
|
||||||
|
|
||||||
if( !obj ) return;
|
|
||||||
|
|
||||||
inline = inline === undefined || inline;
|
|
||||||
|
|
||||||
if( Object.prototype.toString.call( obj ) === '[object Array]' ) {
|
|
||||||
obj.forEach(function(elem, idx, ar){
|
|
||||||
if( typeof elem === 'string' || elem instanceof String )
|
|
||||||
ar[idx] = inline ? MDIN(elem) : MD( elem );
|
|
||||||
else
|
|
||||||
markdownifyStringsInObject( elem );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (typeof obj === 'object') {
|
|
||||||
Object.keys( obj ).forEach(function(key) {
|
|
||||||
var sub = obj[key];
|
|
||||||
if( typeof sub === 'string' || sub instanceof String ) {
|
|
||||||
if( _.contains(['skills','url','start','end','date'], key) )
|
|
||||||
return;
|
|
||||||
if( key === 'summary' )
|
|
||||||
obj[key] = MD( obj[key] );
|
|
||||||
else
|
|
||||||
obj[key] = inline ? MDIN( obj[key] ) : MD( obj[key] );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
markdownifyStringsInObject( sub );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys( ret ).forEach(function(member){
|
|
||||||
markdownifyStringsInObject( ret[ member ] );
|
|
||||||
});
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert this object to a JSON string, sanitizing meta-properties along the
|
Return the resume format.
|
||||||
way. Don't override .toString().
|
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.stringify = function() {
|
FreshResume.prototype.format = function() {
|
||||||
return FreshResume.stringify( this );
|
return 'FRESH';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize the FreshResume from JSON data.
|
Return internal metadata. Create if it doesn't exist.
|
||||||
Open and parse the specified FRESH resume. Merge the JSON object model onto
|
|
||||||
this Sheet instance with extend() and convert sheet dates to a safe &
|
|
||||||
consistent format. Then sort each section by startDate descending.
|
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.parseJSON = function( rep, opts ) {
|
FreshResume.prototype.i = function() {
|
||||||
// Convert JSON Resume to FRESH if necessary
|
this.imp = (this.imp || { });
|
||||||
if( rep.basics ) {
|
return this.imp;
|
||||||
rep = CONVERTER.toFRESH( rep );
|
|
||||||
rep.imp = rep.imp || { };
|
|
||||||
rep.imp.orgFormat = 'JRS';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now apply the resume representation onto this object
|
|
||||||
extend( true, this, rep );
|
|
||||||
|
|
||||||
// Set up metadata
|
|
||||||
opts = opts || { };
|
|
||||||
if( opts.imp === undefined || opts.imp ) {
|
|
||||||
this.imp = this.imp || { };
|
|
||||||
this.imp.title = (opts.title || this.imp.title) || this.name;
|
|
||||||
}
|
|
||||||
// Parse dates, sort dates, and calculate computed values
|
|
||||||
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
|
||||||
(opts.sort === undefined || opts.sort) && this.sort();
|
|
||||||
(opts.compute === undefined || opts.compute) && (this.computed = {
|
|
||||||
numYears: this.duration(),
|
|
||||||
keywords: this.keywords()
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
Initialize the the FreshResume from string data.
|
|
||||||
*/
|
|
||||||
FreshResume.prototype.parse = function( stringData, opts ) {
|
|
||||||
return this.parseJSON( JSON.parse( stringData ), opts );
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return a unique list of all keywords across all skills.
|
Return a unique list of all keywords across all skills.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.keywords = function() {
|
FreshResume.prototype.keywords = function() {
|
||||||
var flatSkills = [];
|
var flatSkills = [];
|
||||||
this.skills && this.skills.length &&
|
if( this.skills ) {
|
||||||
(flatSkills = this.skills.map(function(sk) { return sk.name; }));
|
if( this.skills.sets ) {
|
||||||
|
flatSkills = this.skills.sets.map(function(sk) { return sk.skills; })
|
||||||
|
.reduce(function(a,b) { return a.concat(b); });
|
||||||
|
}
|
||||||
|
else if( this.skills.list ) {
|
||||||
|
flatSkills = flatSkills.concat( this.skills.list.map(function(sk) {
|
||||||
|
return sk.name;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
flatSkills = _.uniq( flatSkills );
|
||||||
|
}
|
||||||
return flatSkills;
|
return flatSkills;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reset the sheet to an empty state.
|
Reset the sheet to an empty state. TODO: refactor/review
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.clear = function( clearMeta ) {
|
FreshResume.prototype.clear = function( clearMeta ) {
|
||||||
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
||||||
@ -289,6 +285,8 @@ Definition of the FRESHResume class.
|
|||||||
delete this.social;
|
delete this.social;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get a safe count of the number of things in a section.
|
Get a safe count of the number of things in a section.
|
||||||
*/
|
*/
|
||||||
@ -299,14 +297,17 @@ Definition of the FRESHResume class.
|
|||||||
return obj.length || 0;
|
return obj.length || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the default (empty) sheet.
|
Get the default (starter) sheet.
|
||||||
*/
|
*/
|
||||||
FreshResume.default = function() {
|
FreshResume.default = function() {
|
||||||
return new FreshResume().open(
|
return new FreshResume().parseJSON( require('fresh-resume-starter') );
|
||||||
PATH.join( __dirname, 'empty-fresh.json'), 'Empty' );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add work experience to the sheet.
|
Add work experience to the sheet.
|
||||||
*/
|
*/
|
||||||
@ -327,6 +328,8 @@ Definition of the FRESHResume class.
|
|||||||
return newObject;
|
return newObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the sheet includes a specific social profile (eg, GitHub).
|
Determine if the sheet includes a specific social profile (eg, GitHub).
|
||||||
*/
|
*/
|
||||||
@ -337,6 +340,8 @@ Definition of the FRESHResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the specified network profile.
|
Return the specified network profile.
|
||||||
*/
|
*/
|
||||||
@ -347,6 +352,8 @@ Definition of the FRESHResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return an array of profiles for the specified network, for when the user
|
Return an array of profiles for the specified network, for when the user
|
||||||
has multiple eg. GitHub accounts.
|
has multiple eg. GitHub accounts.
|
||||||
@ -358,6 +365,8 @@ Definition of the FRESHResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the sheet includes a specific skill.
|
Determine if the sheet includes a specific skill.
|
||||||
*/
|
*/
|
||||||
@ -370,13 +379,15 @@ Definition of the FRESHResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Validate the sheet against the FRESH Resume schema.
|
Validate the sheet against the FRESH Resume schema.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.isValid = function( info ) {
|
FreshResume.prototype.isValid = function( info ) {
|
||||||
var schemaObj = require('fresca');
|
var schemaObj = require('fresca');
|
||||||
var validator = require('is-my-json-valid');
|
var validator = require('is-my-json-valid');
|
||||||
var validate = validator( schemaObj, { // Note [1]
|
var validate = validator( schemaObj, { // See Note [1].
|
||||||
formats: { date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/ }
|
formats: { date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/ }
|
||||||
});
|
});
|
||||||
var ret = validate( this );
|
var ret = validate( this );
|
||||||
@ -387,6 +398,8 @@ Definition of the FRESHResume class.
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
||||||
by start date descending, perhaps via a call to Sheet.sort().
|
by start date descending, perhaps via a call to Sheet.sort().
|
||||||
@ -395,31 +408,48 @@ Definition of the FRESHResume class.
|
|||||||
*latest end date of all jobs in the work history*. This last condition is for
|
*latest end date of all jobs in the work history*. This last condition is for
|
||||||
sheets that have overlapping jobs.
|
sheets that have overlapping jobs.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.duration = function() {
|
FreshResume.prototype.duration = function(unit) {
|
||||||
|
unit = unit || 'years';
|
||||||
var empHist = __.get(this, 'employment.history');
|
var empHist = __.get(this, 'employment.history');
|
||||||
if( empHist && empHist.length ) {
|
if( empHist && empHist.length ) {
|
||||||
var firstJob = _.last( this.employment.history );
|
var firstJob = _.last( empHist );
|
||||||
var careerStart = firstJob.start ? firstJob.safe.start : '';
|
var careerStart = firstJob.start ? firstJob.safe.start : '';
|
||||||
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
||||||
!careerStart.trim())
|
!careerStart.trim())
|
||||||
return 0;
|
return 0;
|
||||||
var careerLast = _.max( this.employment.history, function( w ) {
|
var careerLast = _.max( empHist, function( w ) {
|
||||||
return( w.safe && w.safe.end ) ? w.safe.end.unix() : moment().unix();
|
return( w.safe && w.safe.end ) ? w.safe.end.unix() : moment().unix();
|
||||||
});
|
});
|
||||||
return careerLast.safe.end.diff( careerStart, 'years' );
|
return careerLast.safe.end.diff( careerStart, unit );
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sort dated things on the sheet by start date descending. Assumes that dates
|
Sort dated things on the sheet by start date descending. Assumes that dates
|
||||||
on the sheet have been processed with _parseDates().
|
on the sheet have been processed with _parseDates().
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.sort = function( ) {
|
FreshResume.prototype.sort = function( ) {
|
||||||
|
|
||||||
__.get(this, 'employment.history') && this.employment.history.sort( byDateDesc );
|
function byDateDesc(a,b) {
|
||||||
__.get(this, 'education.history') && this.education.history.sort( byDateDesc );
|
return( a.safe.start.isBefore(b.safe.start) ) ? 1
|
||||||
__.get(this, 'service.history') && this.service.history.sort( byDateDesc );
|
: ( a.safe.start.isAfter(b.safe.start) && -1 ) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortSection( key ) {
|
||||||
|
var ar = __.get(this, key);
|
||||||
|
if( ar && ar.length ) {
|
||||||
|
var datedThings = obj.filter( function(o) { return o.start; } );
|
||||||
|
datedThings.sort( byDateDesc );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sortSection( 'employment.history' );
|
||||||
|
sortSection( 'education.history' );
|
||||||
|
sortSection( 'service.history' );
|
||||||
|
sortSection( 'projects' );
|
||||||
|
|
||||||
// this.awards && this.awards.sort( function(a, b) {
|
// this.awards && this.awards.sort( function(a, b) {
|
||||||
// return( a.safeDate.isBefore(b.safeDate) ) ? 1
|
// return( a.safeDate.isBefore(b.safeDate) ) ? 1
|
||||||
@ -429,14 +459,10 @@ Definition of the FRESHResume class.
|
|||||||
return( a.safe.date.isBefore(b.safe.date) ) ? 1
|
return( a.safe.date.isBefore(b.safe.date) ) ? 1
|
||||||
: ( a.safe.date.isAfter(b.safe.date) && -1 ) || 0;
|
: ( a.safe.date.isAfter(b.safe.date) && -1 ) || 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
function byDateDesc(a,b) {
|
|
||||||
return( a.safe.start.isBefore(b.safe.start) ) ? 1
|
|
||||||
: ( a.safe.start.isAfter(b.safe.start) && -1 ) || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert human-friendly dates into formal Moment.js dates for all collections.
|
Convert human-friendly dates into formal Moment.js dates for all collections.
|
||||||
We don't want to lose the raw textual date as entered by the user, so we store
|
We don't want to lose the raw textual date as entered by the user, so we store
|
||||||
@ -482,11 +508,15 @@ Definition of the FRESHResume class.
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Export the Sheet function/ctor.
|
Export the Sheet function/ctor.
|
||||||
*/
|
*/
|
||||||
module.exports = FreshResume;
|
module.exports = FreshResume;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// Note 1: Adjust default date validation to allow YYYY and YYYY-MM formats
|
// Note 1: Adjust default date validation to allow YYYY and YYYY-MM formats
|
||||||
|
@ -9,14 +9,15 @@ Definition of the FRESHTheme class.
|
|||||||
|
|
||||||
|
|
||||||
var FS = require('fs')
|
var FS = require('fs')
|
||||||
, extend = require('../utils/extend')
|
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
, _ = require('underscore')
|
, _ = require('underscore')
|
||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, parsePath = require('parse-filepath')
|
, parsePath = require('parse-filepath')
|
||||||
, pathExists = require('path-exists').sync
|
, pathExists = require('path-exists').sync
|
||||||
, EXTEND = require('../utils/extend')
|
, EXTEND = require('extend')
|
||||||
|
, HMSTATUS = require('./status-codes')
|
||||||
, moment = require('moment')
|
, moment = require('moment')
|
||||||
|
, loadSafeJson = require('../utils/safe-json-loader')
|
||||||
, READFILES = require('recursive-readdir-sync');
|
, READFILES = require('recursive-readdir-sync');
|
||||||
|
|
||||||
|
|
||||||
@ -46,21 +47,39 @@ Definition of the FRESHTheme class.
|
|||||||
var formatsHash = { };
|
var formatsHash = { };
|
||||||
|
|
||||||
// Load the theme
|
// Load the theme
|
||||||
var themeFile = PATH.join( themeFolder, pathInfo.basename + '.json' );
|
var themeFile = PATH.join( themeFolder, 'theme.json' );
|
||||||
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
var themeInfo = loadSafeJson( themeFile );
|
||||||
|
if( themeInfo.ex ) throw {
|
||||||
|
fluenterror: themeInfo.ex.operation === 'parse' ?
|
||||||
|
HMSTATUS.parseError : HMSTATUS.readError,
|
||||||
|
inner: themeInfo.ex.inner
|
||||||
|
};
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
// Move properties from the theme JSON file to the theme object
|
// Move properties from the theme JSON file to the theme object
|
||||||
EXTEND( true, this, themeInfo );
|
EXTEND( true, this, themeInfo.json );
|
||||||
|
|
||||||
|
// Check for an "inherits" entry in the theme JSON.
|
||||||
|
if( this.inherits ) {
|
||||||
|
var cached = { };
|
||||||
|
_.each( this.inherits, function(th, key) {
|
||||||
|
var themesFolder = require.resolve('fresh-themes');
|
||||||
|
var d = parsePath( themeFolder ).dirname;
|
||||||
|
var themePath = PATH.join(d, th);
|
||||||
|
cached[ th ] = cached[th] || new FRESHTheme().open( themePath );
|
||||||
|
formatsHash[ key ] = cached[ th ].getFormat( key );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Check for an explicit "formats" entry in the theme JSON. If it has one,
|
// Check for an explicit "formats" entry in the theme JSON. If it has one,
|
||||||
// then this theme declares its files explicitly.
|
// then this theme declares its files explicitly.
|
||||||
if( !!this.formats ) {
|
if( !!this.formats ) {
|
||||||
formatsHash = loadExplicit.call( this );
|
formatsHash = loadExplicit.call( this, formatsHash );
|
||||||
this.explicit = true;
|
this.explicit = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
formatsHash = loadImplicit.call( this );
|
formatsHash = loadImplicit.call( this, formatsHash );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
@ -95,10 +114,9 @@ Definition of the FRESHTheme class.
|
|||||||
Load the theme implicitly, by scanning the theme folder for
|
Load the theme implicitly, by scanning the theme folder for
|
||||||
files. TODO: Refactor duplicated code with loadExplicit.
|
files. TODO: Refactor duplicated code with loadExplicit.
|
||||||
*/
|
*/
|
||||||
function loadImplicit() {
|
function loadImplicit(formatsHash) {
|
||||||
|
|
||||||
// Set up a hash of formats supported by this theme.
|
// Set up a hash of formats supported by this theme.
|
||||||
var formatsHash = { };
|
|
||||||
var that = this;
|
var that = this;
|
||||||
var major = false;
|
var major = false;
|
||||||
|
|
||||||
@ -170,20 +188,26 @@ Definition of the FRESHTheme class.
|
|||||||
return fmt && (fmt.ext === 'css');
|
return fmt && (fmt.ext === 'css');
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// For each CSS file, get its corresponding HTML file
|
// For each CSS file, get its corresponding HTML file. It's possible that
|
||||||
|
// a theme can have a CSS file but *no* HTML file, as when a theme author
|
||||||
|
// creates a pure CSS override of an existing theme.
|
||||||
.forEach(function( cssf ) {
|
.forEach(function( cssf ) {
|
||||||
|
|
||||||
var idx = _.findIndex(fmts, function( fmt ) {
|
var idx = _.findIndex(fmts, function( fmt ) {
|
||||||
return fmt && fmt.pre === cssf.pre && fmt.ext === 'html';
|
return fmt && fmt.pre === cssf.pre && fmt.ext === 'html';
|
||||||
});
|
});
|
||||||
cssf.action = null;
|
cssf.major = false;
|
||||||
|
if( idx > -1) {
|
||||||
fmts[ idx ].css = cssf.data;
|
fmts[ idx ].css = cssf.data;
|
||||||
fmts[ idx ].cssPath = cssf.path;
|
fmts[ idx ].cssPath = cssf.path;
|
||||||
});
|
}
|
||||||
|
else {
|
||||||
// Remove CSS files from the formats array
|
if( that.inherits ) {
|
||||||
fmts = fmts.filter( function( fmt) {
|
// Found a CSS file without an HTML file in a theme that inherits
|
||||||
return fmt && (fmt.ext !== 'css');
|
// from another theme. This is the override CSS file.
|
||||||
|
that.overrides = { file: cssf.path, data: cssf.data };
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return formatsHash;
|
return formatsHash;
|
||||||
@ -195,10 +219,9 @@ Definition of the FRESHTheme class.
|
|||||||
Load the theme explicitly, by following the 'formats' hash
|
Load the theme explicitly, by following the 'formats' hash
|
||||||
in the theme's JSON settings file.
|
in the theme's JSON settings file.
|
||||||
*/
|
*/
|
||||||
function loadExplicit() {
|
function loadExplicit(formatsHash) {
|
||||||
|
|
||||||
// Housekeeping
|
// Housekeeping
|
||||||
var formatsHash = { };
|
|
||||||
var tplFolder = PATH.join( this.folder, 'src' );
|
var tplFolder = PATH.join( this.folder, 'src' );
|
||||||
var act = null;
|
var act = null;
|
||||||
var that = this;
|
var that = this;
|
||||||
|
@ -1,65 +1,132 @@
|
|||||||
/**
|
/**
|
||||||
Definition of the JRSResume class.
|
Definition of the JRSResume class.
|
||||||
@license MIT. See LICENSE.md for details.
|
@license MIT. See LICENSE.md for details.
|
||||||
@module jrs-resume.js
|
@module core/jrs-resume
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FS = require('fs')
|
var FS = require('fs')
|
||||||
, extend = require('../utils/extend')
|
, extend = require('extend')
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
, _ = require('underscore')
|
, _ = require('underscore')
|
||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, MD = require('marked')
|
, MD = require('marked')
|
||||||
, CONVERTER = require('./convert')
|
, CONVERTER = require('fresh-jrs-converter')
|
||||||
, moment = require('moment');
|
, moment = require('moment');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The JRSResume class represent a specific JSON character sheet. When Sheet.open
|
A JRS resume or CV. JRS resumes are backed by JSON, and each JRSResume object
|
||||||
is called, we merge the loaded JSON sheet properties onto the Sheet instance
|
is an instantiation of that JSON decorated with utility methods.
|
||||||
via extend(), so a full-grown sheet object will have all of the methods here,
|
|
||||||
plus a complement of JSON properties from the backing JSON file. That allows
|
|
||||||
us to treat Sheet objects interchangeably with the loaded JSON model.
|
|
||||||
@class JRSResume
|
@class JRSResume
|
||||||
*/
|
*/
|
||||||
function JRSResume() {
|
function JRSResume() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open and parse the specified JSON resume sheet. Merge the JSON object model
|
Initialize the JSResume from file.
|
||||||
onto this Sheet instance with extend() and convert sheet dates to a safe &
|
|
||||||
consistent format. Then sort each section by startDate descending.
|
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.open = function( file, title ) {
|
JRSResume.prototype.open = function( file, title ) {
|
||||||
//this.imp = { fileName: file }; <-- schema violation, tuck it into .basics instead
|
//this.imp = { fileName: file }; <-- schema violation, tuck it into .basics
|
||||||
this.basics = {
|
this.basics = {
|
||||||
imp: {
|
imp: {
|
||||||
fileName: file,
|
file: file,
|
||||||
raw: FS.readFileSync( file, 'utf8' )
|
raw: FS.readFileSync( file, 'utf8' )
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return this.parse( this.basics.imp.raw, title );
|
return this.parse( this.basics.imp.raw, title );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the the JSResume from string.
|
||||||
|
*/
|
||||||
|
JRSResume.prototype.parse = function( stringData, opts ) {
|
||||||
|
opts = opts || { };
|
||||||
|
var rep = JSON.parse( stringData );
|
||||||
|
return this.parseJSON( rep, opts );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the JRSResume object from JSON.
|
||||||
|
Open and parse the specified JRS resume. Merge the JSON object model onto
|
||||||
|
this Sheet instance with extend() and convert sheet dates to a safe &
|
||||||
|
consistent format. Then sort each section by startDate descending.
|
||||||
|
@param rep {Object} The raw JSON representation.
|
||||||
|
@param opts {Object} Resume loading and parsing options.
|
||||||
|
{
|
||||||
|
date: Perform safe date conversion.
|
||||||
|
sort: Sort resume items by date.
|
||||||
|
compute: Prepare computed resume totals.
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
JRSResume.prototype.parseJSON = function( rep, opts ) {
|
||||||
|
opts = opts || { };
|
||||||
|
|
||||||
|
// Ignore any element with the 'ignore: true' designator.
|
||||||
|
var that = this, traverse = require('traverse'), ignoreList = [];
|
||||||
|
var scrubbed = traverse( rep ).map( function( x ) {
|
||||||
|
if( !this.isLeaf && this.node.ignore ) {
|
||||||
|
if ( this.node.ignore === true || this.node.ignore === 'true' ) {
|
||||||
|
ignoreList.push( this.node );
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Extend resume properties onto ourself.
|
||||||
|
extend( true, this, scrubbed );
|
||||||
|
|
||||||
|
// Set up metadata
|
||||||
|
if( opts.imp === undefined || opts.imp ) {
|
||||||
|
this.basics.imp = this.basics.imp || { };
|
||||||
|
this.basics.imp.title =
|
||||||
|
(opts.title || this.basics.imp.title) || this.basics.name;
|
||||||
|
this.basics.imp.orgFormat = 'JRS';
|
||||||
|
}
|
||||||
|
// Parse dates, sort dates, and calculate computed values
|
||||||
|
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
||||||
|
(opts.sort === undefined || opts.sort) && this.sort();
|
||||||
|
(opts.compute === undefined || opts.compute) && (this.basics.computed = {
|
||||||
|
numYears: this.duration(),
|
||||||
|
keywords: this.keywords()
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk (for environments that have disk access).
|
Save the sheet to disk (for environments that have disk access).
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.save = function( filename ) {
|
JRSResume.prototype.save = function( filename ) {
|
||||||
this.basics.imp.fileName = filename || this.basics.imp.fileName;
|
this.basics.imp.file = filename || this.basics.imp.file;
|
||||||
FS.writeFileSync( this.basics.imp.fileName, this.stringify( this ), 'utf8' );
|
FS.writeFileSync(this.basics.imp.file, this.stringify( this ), 'utf8');
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk in a specific format, either FRESH or JRS.
|
Save the sheet to disk in a specific format, either FRESH or JRS.
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.saveAs = function( filename, format ) {
|
JRSResume.prototype.saveAs = function( filename, format ) {
|
||||||
|
|
||||||
if( format === 'JRS' ) {
|
if( format === 'JRS' ) {
|
||||||
this.basics.imp.fileName = filename || this.imp.fileName;
|
this.basics.imp.file = filename || this.basics.imp.file;
|
||||||
FS.writeFileSync( this.basics.imp.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.basics.imp.file, this.stringify(), 'utf8' );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var newRep = CONVERTER.toFRESH( this );
|
var newRep = CONVERTER.toFRESH( this );
|
||||||
@ -70,6 +137,17 @@ Definition of the JRSResume class.
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return the resume format.
|
||||||
|
*/
|
||||||
|
JRSResume.prototype.format = function() {
|
||||||
|
return 'JRS';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert this object to a JSON string, sanitizing meta-properties along the
|
Convert this object to a JSON string, sanitizing meta-properties along the
|
||||||
way. Don't override .toString().
|
way. Don't override .toString().
|
||||||
@ -85,43 +163,13 @@ Definition of the JRSResume class.
|
|||||||
return JSON.stringify( obj, replacer, 2 );
|
return JSON.stringify( obj, replacer, 2 );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JRSResume.prototype.stringify = function() {
|
JRSResume.prototype.stringify = function() {
|
||||||
return JRSResume.stringify( this );
|
return JRSResume.stringify( this );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
Initialize the JRS Resume from string data.
|
|
||||||
Open and parse the specified JSON resume sheet. Merge the JSON object model
|
|
||||||
onto this Sheet instance with extend() and convert sheet dates to a safe &
|
|
||||||
consistent format. Then sort each section by startDate descending.
|
|
||||||
*/
|
|
||||||
JRSResume.prototype.parse = function( stringData, opts ) {
|
|
||||||
opts = opts || { };
|
|
||||||
var rep = JSON.parse( stringData );
|
|
||||||
return this.parseJSON( rep, opts );
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Initialize the JRSRume from JSON data.
|
|
||||||
*/
|
|
||||||
JRSResume.prototype.parseJSON = function( rep, opts ) {
|
|
||||||
opts = opts || { };
|
|
||||||
extend( true, this, rep );
|
|
||||||
// Set up metadata
|
|
||||||
if( opts.imp === undefined || opts.imp ) {
|
|
||||||
this.basics.imp = this.basics.imp || { };
|
|
||||||
this.basics.imp.title = (opts.title || this.basics.imp.title) || this.basics.name;
|
|
||||||
this.basics.imp.orgFormat = 'JRS';
|
|
||||||
}
|
|
||||||
// Parse dates, sort dates, and calculate computed values
|
|
||||||
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
|
||||||
(opts.sort === undefined || opts.sort) && this.sort();
|
|
||||||
(opts.compute === undefined || opts.compute) && (this.basics.computed = {
|
|
||||||
numYears: this.duration(),
|
|
||||||
keywords: this.keywords()
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return a unique list of all keywords across all skills.
|
Return a unique list of all keywords across all skills.
|
||||||
@ -136,6 +184,21 @@ Definition of the JRSResume class.
|
|||||||
return flatSkills;
|
return flatSkills;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return internal metadata. Create if it doesn't exist.
|
||||||
|
JSON Resume v0.0.0 doesn't allow additional properties at the root level,
|
||||||
|
so tuck this into the .basic sub-object.
|
||||||
|
*/
|
||||||
|
JRSResume.prototype.i = function() {
|
||||||
|
this.basics = this.basics || { };
|
||||||
|
this.basics.imp = this.basics.imp || { };
|
||||||
|
return this.basics.imp;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reset the sheet to an empty state.
|
Reset the sheet to an empty state.
|
||||||
*/
|
*/
|
||||||
@ -153,13 +216,19 @@ Definition of the JRSResume class.
|
|||||||
delete this.basics.profiles;
|
delete this.basics.profiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the default (empty) sheet.
|
Get the default (empty) sheet.
|
||||||
*/
|
*/
|
||||||
JRSResume.default = function() {
|
JRSResume.default = function() {
|
||||||
return new JRSResume().open( PATH.join( __dirname, 'empty-jrs.json'), 'Empty' );
|
return new JRSResume().open(
|
||||||
|
PATH.join( __dirname, 'empty-jrs.json'), 'Empty'
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add work experience to the sheet.
|
Add work experience to the sheet.
|
||||||
*/
|
*/
|
||||||
@ -171,6 +240,8 @@ Definition of the JRSResume class.
|
|||||||
return newObject;
|
return newObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the sheet includes a specific social profile (eg, GitHub).
|
Determine if the sheet includes a specific social profile (eg, GitHub).
|
||||||
*/
|
*/
|
||||||
@ -181,6 +252,8 @@ Definition of the JRSResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the sheet includes a specific skill.
|
Determine if the sheet includes a specific skill.
|
||||||
*/
|
*/
|
||||||
@ -193,6 +266,8 @@ Definition of the JRSResume class.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Validate the sheet against the JSON Resume schema.
|
Validate the sheet against the JSON Resume schema.
|
||||||
*/
|
*/
|
||||||
@ -211,6 +286,8 @@ Definition of the JRSResume class.
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
||||||
by start date descending, perhaps via a call to Sheet.sort().
|
by start date descending, perhaps via a call to Sheet.sort().
|
||||||
@ -219,7 +296,8 @@ Definition of the JRSResume class.
|
|||||||
*latest end date of all jobs in the work history*. This last condition is for
|
*latest end date of all jobs in the work history*. This last condition is for
|
||||||
sheets that have overlapping jobs.
|
sheets that have overlapping jobs.
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.duration = function() {
|
JRSResume.prototype.duration = function( unit ) {
|
||||||
|
unit = unit || 'years';
|
||||||
if( this.work && this.work.length ) {
|
if( this.work && this.work.length ) {
|
||||||
var careerStart = this.work[ this.work.length - 1].safeStartDate;
|
var careerStart = this.work[ this.work.length - 1].safeStartDate;
|
||||||
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
||||||
@ -228,11 +306,13 @@ Definition of the JRSResume class.
|
|||||||
var careerLast = _.max( this.work, function( w ) {
|
var careerLast = _.max( this.work, function( w ) {
|
||||||
return w.safeEndDate.unix();
|
return w.safeEndDate.unix();
|
||||||
}).safeEndDate;
|
}).safeEndDate;
|
||||||
return careerLast.diff( careerStart, 'years' );
|
return careerLast.diff( careerStart, unit );
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sort dated things on the sheet by start date descending. Assumes that dates
|
Sort dated things on the sheet by start date descending. Assumes that dates
|
||||||
on the sheet have been processed with _parseDates().
|
on the sheet have been processed with _parseDates().
|
||||||
@ -259,12 +339,16 @@ Definition of the JRSResume class.
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JRSResume.prototype.dupe = function() {
|
JRSResume.prototype.dupe = function() {
|
||||||
var rnew = new JRSResume();
|
var rnew = new JRSResume();
|
||||||
rnew.parse( this.stringify(), { } );
|
rnew.parse( this.stringify(), { } );
|
||||||
return rnew;
|
return rnew;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a copy of this resume in which all fields have been interpreted as
|
Create a copy of this resume in which all fields have been interpreted as
|
||||||
Markdown.
|
Markdown.
|
||||||
@ -302,7 +386,9 @@ Definition of the JRSResume class.
|
|||||||
Object.keys( obj ).forEach(function(key) {
|
Object.keys( obj ).forEach(function(key) {
|
||||||
var sub = obj[key];
|
var sub = obj[key];
|
||||||
if( typeof sub === 'string' || sub instanceof String ) {
|
if( typeof sub === 'string' || sub instanceof String ) {
|
||||||
if( _.contains(['skills','url','website','startDate','endDate','releaseDate','date','phone','email','address','postalCode','city','country','region'], key) )
|
if( _.contains(['skills','url','website','startDate','endDate',
|
||||||
|
'releaseDate','date','phone','email','address','postalCode',
|
||||||
|
'city','country','region'], key) )
|
||||||
return;
|
return;
|
||||||
if( key === 'summary' )
|
if( key === 'summary' )
|
||||||
obj[key] = HD( obj[key] );
|
obj[key] = HD( obj[key] );
|
||||||
@ -323,6 +409,8 @@ Definition of the JRSResume class.
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert human-friendly dates into formal Moment.js dates for all collections.
|
Convert human-friendly dates into formal Moment.js dates for all collections.
|
||||||
We don't want to lose the raw textual date as entered by the user, so we store
|
We don't want to lose the raw textual date as entered by the user, so we store
|
||||||
@ -354,9 +442,13 @@ Definition of the JRSResume class.
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Export the JRSResume function/ctor.
|
Export the JRSResume function/ctor.
|
||||||
*/
|
*/
|
||||||
module.exports = JRSResume;
|
module.exports = JRSResume;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -16,8 +16,7 @@ Definition of the JRSTheme class.
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The JRSTheme class is a representation of a JSON Resume
|
The JRSTheme class is a representation of a JSON Resume theme asset.
|
||||||
theme asset. See also: FRESHTheme.
|
|
||||||
@class JRSTheme
|
@class JRSTheme
|
||||||
*/
|
*/
|
||||||
function JRSTheme() {
|
function JRSTheme() {
|
||||||
@ -41,16 +40,40 @@ Definition of the JRSTheme class.
|
|||||||
// Open and parse the theme's package.json file.
|
// Open and parse the theme's package.json file.
|
||||||
var pkgJsonPath = PATH.join( thFolder, 'package.json' );
|
var pkgJsonPath = PATH.join( thFolder, 'package.json' );
|
||||||
if( pathExists( pkgJsonPath )) {
|
if( pathExists( pkgJsonPath )) {
|
||||||
|
|
||||||
var thApi = require( thFolder )
|
var thApi = require( thFolder )
|
||||||
, thPkg = require( pkgJsonPath );
|
, thPkg = require( pkgJsonPath );
|
||||||
|
|
||||||
this.name = thPkg.name;
|
this.name = thPkg.name;
|
||||||
this.render = (thApi && thApi.render) || undefined;
|
this.render = (thApi && thApi.render) || undefined;
|
||||||
|
this.engine = 'jrs';
|
||||||
|
|
||||||
|
// Create theme formats (HTML and PDF). Just add the bare minimum mix of
|
||||||
|
// properties necessary to allow JSON Resume themes to share a rendering
|
||||||
|
// path with FRESH themes.
|
||||||
this.formats = {
|
this.formats = {
|
||||||
html: { title:'html', outFormat:'html', ext:'html' }
|
html: { outFormat: 'html', files: [
|
||||||
|
{
|
||||||
|
action: 'transform',
|
||||||
|
render: this.render,
|
||||||
|
major: true,
|
||||||
|
ext: 'html',
|
||||||
|
css: null
|
||||||
|
}
|
||||||
|
]},
|
||||||
|
pdf: { outFormat: 'pdf', files: [
|
||||||
|
{
|
||||||
|
action: 'transform',
|
||||||
|
render: this.render,
|
||||||
|
major: true,
|
||||||
|
ext: 'pdf',
|
||||||
|
css: null
|
||||||
|
}
|
||||||
|
]}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw { fluenterror: 10 };
|
throw { fluenterror: HACKMYSTATUS.missingPackageJSON };
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -10,9 +10,14 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var FS = require('fs'),
|
||||||
|
HACKMYSTATUS = require('./status-codes'),
|
||||||
|
HME = require('./event-codes'),
|
||||||
|
ResumeConverter = require('fresh-jrs-converter'),
|
||||||
|
chalk = require('chalk'),
|
||||||
|
SyntaxErrorEx = require('../utils/syntax-error-ex'),
|
||||||
|
_ = require('underscore');
|
||||||
require('string.prototype.startswith');
|
require('string.prototype.startswith');
|
||||||
var FS = require('fs');
|
|
||||||
var ResumeConverter = require('./convert');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -26,14 +31,24 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Load one or more resumes from disk.
|
Load one or more resumes from disk.
|
||||||
|
|
||||||
|
@param {Object} opts An options object with settings for the factory as well
|
||||||
|
as passthrough settings for FRESHResume or JRSResume. Structure:
|
||||||
|
|
||||||
|
{
|
||||||
|
format: 'FRESH', // Format to open as. ('FRESH', 'JRS', null)
|
||||||
|
objectify: true, // FRESH/JRSResume or raw JSON?
|
||||||
|
inner: { // Passthru options for FRESH/JRSResume
|
||||||
|
sort: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
load: function ( sources, log, toFormat, objectify ) {
|
load: function ( sources, opts, emitter ) {
|
||||||
// Loop over all inputs, parsing each to JSON and then to a FRESHResume
|
|
||||||
// or JRSResume object.
|
|
||||||
var that = this;
|
|
||||||
return sources.map( function( src ) {
|
return sources.map( function( src ) {
|
||||||
return that.loadOne( src, log, toFormat, objectify );
|
return this.loadOne( src, opts, emitter );
|
||||||
});
|
}, this);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -42,17 +57,20 @@ Definition of the ResumeFactory class.
|
|||||||
/**
|
/**
|
||||||
Load a single resume from disk.
|
Load a single resume from disk.
|
||||||
*/
|
*/
|
||||||
loadOne: function( src, log, toFormat, objectify ) {
|
loadOne: function( src, opts, emitter ) {
|
||||||
|
|
||||||
|
var toFormat = opts.format; // Can be null
|
||||||
|
var objectify = opts.objectify;
|
||||||
|
|
||||||
// Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
|
// Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
|
||||||
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
||||||
|
|
||||||
// Load and parse the resume JSON
|
// Load and parse the resume JSON
|
||||||
var info = _parse( src, log, toFormat );
|
var info = _parse( src, opts, emitter );
|
||||||
if( info.error ) return info;
|
if( info.fluenterror ) return info;
|
||||||
var json = info.json;
|
|
||||||
|
|
||||||
// Determine the resume format: FRESH or JRS
|
// Determine the resume format: FRESH or JRS
|
||||||
|
var json = info.json;
|
||||||
var orgFormat = ( json.meta && json.meta.format &&
|
var orgFormat = ( json.meta && json.meta.format &&
|
||||||
json.meta.format.startsWith('FRESH@') ) ?
|
json.meta.format.startsWith('FRESH@') ) ?
|
||||||
'fresh' : 'jrs';
|
'fresh' : 'jrs';
|
||||||
@ -67,7 +85,8 @@ Definition of the ResumeFactory class.
|
|||||||
var rez;
|
var rez;
|
||||||
if( objectify ) {
|
if( objectify ) {
|
||||||
var ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
var ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
||||||
rez = new ResumeClass().parseJSON( json );
|
rez = new ResumeClass().parseJSON( json, opts.inner );
|
||||||
|
rez.i().file = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -80,26 +99,38 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function _parse( fileName, log, toFormat ) {
|
function _parse( fileName, opts, eve ) {
|
||||||
|
|
||||||
var rawData;
|
var rawData;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// TODO: Core should not log
|
// Read the file
|
||||||
log( 'Reading '.info + /*orgFormat.toUpperCase().infoBold +*/
|
eve && eve.stat( HME.beforeRead, { file: fileName });
|
||||||
'resume: '.info + fileName.cyan.bold );
|
|
||||||
|
|
||||||
rawData = FS.readFileSync( fileName, 'utf8' );
|
rawData = FS.readFileSync( fileName, 'utf8' );
|
||||||
return {
|
eve && eve.stat( HME.afterRead, { file: fileName, data: rawData });
|
||||||
json: JSON.parse( rawData )
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Parse the file
|
||||||
|
eve && eve.stat( HME.beforeParse, { data: rawData });
|
||||||
|
var ret = { json: JSON.parse( rawData ) };
|
||||||
|
var orgFormat = ( ret.json.meta && ret.json.meta.format &&
|
||||||
|
ret.json.meta.format.startsWith('FRESH@') ) ?
|
||||||
|
'fresh' : 'jrs';
|
||||||
|
eve && eve.stat( HME.afterParse, { file: fileName, data: ret.json, fmt: orgFormat } );
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
catch(ex) {
|
catch( e ) {
|
||||||
return {
|
// Can be ENOENT, EACCES, SyntaxError, etc.
|
||||||
error: ex,
|
var ex = {
|
||||||
raw: rawData
|
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
|
||||||
|
inner: e, raw: rawData, file: fileName, shouldExit: false
|
||||||
};
|
};
|
||||||
|
opts.quit && (ex.quit = true);
|
||||||
|
eve && eve.err( ex.fluenterror, ex );
|
||||||
|
if( opts.throw ) throw ex;
|
||||||
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
@module spawn-watch.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
// Catch various out-of-band child process errors such as ENOENT for PDFs
|
|
||||||
// http://stackoverflow.com/q/27688804
|
|
||||||
var SpawnWatcher = module.exports = function() {
|
|
||||||
var childProcess = require("child_process");
|
|
||||||
var oldSpawn = childProcess.spawn;
|
|
||||||
childProcess.spawn = function() {
|
|
||||||
return oldSpawn.apply(this, arguments)
|
|
||||||
.on('error', function(err) {
|
|
||||||
require('./error-handler').err( err, false );
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}();
|
|
||||||
|
|
||||||
//SpawnWatcher();
|
|
||||||
|
|
||||||
}());
|
|
@ -16,8 +16,22 @@ Status codes for HackMyResume.
|
|||||||
resumeNotFoundAlt: 6,
|
resumeNotFoundAlt: 6,
|
||||||
inputOutputParity: 7,
|
inputOutputParity: 7,
|
||||||
createNameMissing: 8,
|
createNameMissing: 8,
|
||||||
wkhtmltopdf: 9,
|
pdfgeneration: 9,
|
||||||
missingPackageJSON: 10
|
missingPackageJSON: 10,
|
||||||
|
invalid: 11,
|
||||||
|
invalidFormat: 12,
|
||||||
|
notOnPath: 13,
|
||||||
|
readError: 14,
|
||||||
|
parseError: 15,
|
||||||
|
fileSaveError: 16,
|
||||||
|
generateError: 17,
|
||||||
|
invalidHelperUse: 18,
|
||||||
|
mixedMerge: 19,
|
||||||
|
invokeTemplate: 20,
|
||||||
|
compileTemplate: 21,
|
||||||
|
themeLoad: 22,
|
||||||
|
invalidParamCount: 23,
|
||||||
|
missingParam: 24
|
||||||
};
|
};
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -1,182 +0,0 @@
|
|||||||
/**
|
|
||||||
Generic template helper definitions for HackMyResume / FluentCV.
|
|
||||||
@license MIT. See LICENSE.md for details.
|
|
||||||
@module generic-helpers.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
var MD = require('marked')
|
|
||||||
, H2W = require('../utils/html-to-wpml')
|
|
||||||
, XML = require('xml-escape')
|
|
||||||
, moment = require('moment')
|
|
||||||
, _ = require('underscore');
|
|
||||||
|
|
||||||
/**
|
|
||||||
Generic template helper function definitions.
|
|
||||||
@class GenericHelpers
|
|
||||||
*/
|
|
||||||
var GenericHelpers = module.exports = {
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert the input date to a specified format through Moment.js.
|
|
||||||
@method formatDate
|
|
||||||
*/
|
|
||||||
formatDate: function(datetime, format) {
|
|
||||||
return moment ? moment( datetime ).format( format ) : datetime;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert inline Markdown to inline WordProcessingML.
|
|
||||||
@method wpml
|
|
||||||
*/
|
|
||||||
wpml: function( txt, inline ) {
|
|
||||||
if(!txt) return '';
|
|
||||||
inline = (inline && !inline.hash) || false;
|
|
||||||
txt = XML(txt.trim());
|
|
||||||
txt = inline ?
|
|
||||||
MD(txt).replace(/^\s*<p>|<\/p>\s*$/gi, '') :
|
|
||||||
MD(txt);
|
|
||||||
txt = H2W( txt );
|
|
||||||
console.log(txt);
|
|
||||||
return txt;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Emit a conditional link.
|
|
||||||
@method link
|
|
||||||
*/
|
|
||||||
link: function( text, url ) {
|
|
||||||
return url && url.trim() ?
|
|
||||||
('<a href="' + url + '">' + text + '</a>') : text;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Return the last word of the specified text.
|
|
||||||
@method lastWord
|
|
||||||
*/
|
|
||||||
lastWord: function( txt ) {
|
|
||||||
return txt && txt.trim() ? _.last( txt.split(' ') ) : '';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert a skill level to an RGB color triplet.
|
|
||||||
@method skillColor
|
|
||||||
@param lvl Input skill level. Skill level can be expressed as a string
|
|
||||||
("beginner", "intermediate", etc.), as an integer (1,5,etc), as a string
|
|
||||||
integer ("1", "5", etc.), or as an RRGGBB color triplet ('#C00000',
|
|
||||||
'#FFFFAA').
|
|
||||||
*/
|
|
||||||
skillColor: function( lvl ) {
|
|
||||||
var idx = skillLevelToIndex( lvl );
|
|
||||||
var skillColors = (this.theme && this.theme.palette &&
|
|
||||||
this.theme.palette.skillLevels) ||
|
|
||||||
[ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ];
|
|
||||||
return skillColors[idx];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Return an appropriate height.
|
|
||||||
@method lastWord
|
|
||||||
*/
|
|
||||||
skillHeight: function( lvl ) {
|
|
||||||
var idx = skillLevelToIndex( lvl );
|
|
||||||
return ['38.25', '30', '16', '8', '0'][idx];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Return all but the last word of the input text.
|
|
||||||
@method initialWords
|
|
||||||
*/
|
|
||||||
initialWords: function( txt ) {
|
|
||||||
return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : '';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Trim the protocol (http or https) from a URL/
|
|
||||||
@method trimURL
|
|
||||||
*/
|
|
||||||
trimURL: function( url ) {
|
|
||||||
return url && url.trim() ? url.trim().replace(/^https?:\/\//i, '') : '';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Convert text to lowercase.
|
|
||||||
@method toLower
|
|
||||||
*/
|
|
||||||
toLower: function( txt ) {
|
|
||||||
return txt && txt.trim() ? txt.toLowerCase() : '';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Return true if either value is truthy.
|
|
||||||
@method either
|
|
||||||
*/
|
|
||||||
either: function( lhs, rhs, options ) {
|
|
||||||
if (lhs || rhs) return options.fn(this);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Conditional stylesheet link. Either display the link or embed the stylesheet
|
|
||||||
via <style></style> tag.
|
|
||||||
*/
|
|
||||||
styleSheet: function( file, options ) {
|
|
||||||
return ( this.opts.css === 'link') ?
|
|
||||||
'<link href="' + file + '" rel="stylesheet" type="text/css">' :
|
|
||||||
'<style>' + this.cssInfo.data + '</style>';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Perform a generic comparison.
|
|
||||||
See: http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates
|
|
||||||
@method compare
|
|
||||||
*/
|
|
||||||
compare: function(lvalue, rvalue, options) {
|
|
||||||
if (arguments.length < 3)
|
|
||||||
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
|
|
||||||
var operator = options.hash.operator || "==";
|
|
||||||
var operators = {
|
|
||||||
'==': function(l,r) { return l == r; },
|
|
||||||
'===': function(l,r) { return l === r; },
|
|
||||||
'!=': function(l,r) { return l != r; },
|
|
||||||
'<': function(l,r) { return l < r; },
|
|
||||||
'>': function(l,r) { return l > r; },
|
|
||||||
'<=': function(l,r) { return l <= r; },
|
|
||||||
'>=': function(l,r) { return l >= r; },
|
|
||||||
'typeof': function(l,r) { return typeof l == r; }
|
|
||||||
};
|
|
||||||
if (!operators[operator])
|
|
||||||
throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
|
|
||||||
var result = operators[operator](lvalue,rvalue);
|
|
||||||
return result ? options.fn(this) : options.inverse(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function skillLevelToIndex( lvl ) {
|
|
||||||
var idx = 0;
|
|
||||||
if( String.is( lvl ) ) {
|
|
||||||
lvl = lvl.trim().toLowerCase();
|
|
||||||
var intVal = parseInt( lvl );
|
|
||||||
if( isNaN( intVal ) ) {
|
|
||||||
switch( lvl ) {
|
|
||||||
case 'beginner': idx = 1; break;
|
|
||||||
case 'intermediate': idx = 2; break;
|
|
||||||
case 'advanced': idx = 3; break;
|
|
||||||
case 'master': idx = 4; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
idx = Math.min( intVal / 2, 4 );
|
|
||||||
idx = Math.max( 0, idx );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
idx = Math.min( lvl / 2, 4 );
|
|
||||||
idx = Math.max( 0, idx );
|
|
||||||
}
|
|
||||||
return idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
}());
|
|
@ -1,56 +0,0 @@
|
|||||||
/**
|
|
||||||
Definition of the HandlebarsGenerator class.
|
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
|
||||||
@module handlebars-generator.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var _ = require('underscore')
|
|
||||||
, HANDLEBARS = require('handlebars')
|
|
||||||
, FS = require('fs')
|
|
||||||
, registerHelpers = require('./handlebars-helpers');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Perform template-based resume generation using Handlebars.js.
|
|
||||||
@class HandlebarsGenerator
|
|
||||||
*/
|
|
||||||
var HandlebarsGenerator = module.exports = {
|
|
||||||
|
|
||||||
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
|
||||||
|
|
||||||
// Pre-compile any partials present in the theme.
|
|
||||||
_.each( theme.partials, function( el ) {
|
|
||||||
var tplData = FS.readFileSync( el.path, 'utf8' );
|
|
||||||
var compiledTemplate = HANDLEBARS.compile( tplData );
|
|
||||||
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
|
||||||
});
|
|
||||||
|
|
||||||
// Register necessary helpers.
|
|
||||||
registerHelpers( theme );
|
|
||||||
|
|
||||||
// Compile and run the Handlebars template.
|
|
||||||
var template = HANDLEBARS.compile(jst);
|
|
||||||
|
|
||||||
var encData = json;
|
|
||||||
( format === 'html' || format === 'pdf' ) && (encData = json.markdownify());
|
|
||||||
( format === 'doc' ) && (encData = json.xmlify());
|
|
||||||
|
|
||||||
return template({
|
|
||||||
r: encData,
|
|
||||||
RAW: json,
|
|
||||||
filt: opts.filters,
|
|
||||||
cssInfo: cssInfo,
|
|
||||||
opts: opts,
|
|
||||||
headFragment: opts.headFragment || ''
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}());
|
|
@ -1,82 +0,0 @@
|
|||||||
/**
|
|
||||||
Definition of the HtmlPdfGenerator class.
|
|
||||||
@module html-pdf-generator.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
var TemplateGenerator = require('./template-generator')
|
|
||||||
, FS = require('fs-extra')
|
|
||||||
, HTML = require( 'html' );
|
|
||||||
|
|
||||||
/**
|
|
||||||
An HTML-based PDF resume generator for HackMyResume.
|
|
||||||
*/
|
|
||||||
var HtmlPdfGenerator = module.exports = TemplateGenerator.extend({
|
|
||||||
|
|
||||||
init: function() {
|
|
||||||
this._super( 'pdf', 'html' );
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
Generate the binary PDF.
|
|
||||||
*/
|
|
||||||
onBeforeSave: function( info ) {
|
|
||||||
pdf.call( this, info.mk, info.outputFile );
|
|
||||||
return null; // halt further processing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
Generate a PDF from HTML.
|
|
||||||
*/
|
|
||||||
function pdf( markup, fOut ) {
|
|
||||||
|
|
||||||
pdf_wkhtmltopdf.call( this, markup, fOut );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Generate a PDF from HTML using wkhtmltopdf.
|
|
||||||
*/
|
|
||||||
function pdf_wkhtmltopdf( markup, fOut ) {
|
|
||||||
var wk;
|
|
||||||
try {
|
|
||||||
wk = require('wkhtmltopdf');
|
|
||||||
wk( markup, { pageSize: 'letter' } )
|
|
||||||
.pipe( FS.createWriteStream( fOut ) );
|
|
||||||
}
|
|
||||||
catch(ex) {
|
|
||||||
// { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }
|
|
||||||
// { [Error: ENOENT] }
|
|
||||||
throw { fluenterror: this.codes.wkhtmltopdf };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// function pdf_phantom() {
|
|
||||||
// pdfCount++;
|
|
||||||
// require('phantom').create( function( ph ) {
|
|
||||||
// ph.createPage( function( page ) {
|
|
||||||
// page.setContent( markup );
|
|
||||||
// page.set('paperSize', {
|
|
||||||
// format: 'A4',
|
|
||||||
// orientation: 'portrait',
|
|
||||||
// margin: '1cm'
|
|
||||||
// });
|
|
||||||
// page.set("viewportSize", {
|
|
||||||
// width: 1024, // TODO: option-ify
|
|
||||||
// height: 768 // TODO: Use "A" sizes
|
|
||||||
// });
|
|
||||||
// page.set('onLoadFinished', function(success) {
|
|
||||||
// page.render( fOut );
|
|
||||||
// pdfCount++;
|
|
||||||
// ph.exit();
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// { dnodeOpts: { weak: false } } );
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
}());
|
|
@ -1,316 +0,0 @@
|
|||||||
/**
|
|
||||||
Definition of the TemplateGenerator class.
|
|
||||||
@license MIT. See LICENSE.md for details.
|
|
||||||
@module template-generator.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FS = require( 'fs-extra' )
|
|
||||||
, _ = require( 'underscore' )
|
|
||||||
, MD = require( 'marked' )
|
|
||||||
, XML = require( 'xml-escape' )
|
|
||||||
, PATH = require('path')
|
|
||||||
, parsePath = require('parse-filepath')
|
|
||||||
, MKDIRP = require('mkdirp')
|
|
||||||
, BaseGenerator = require( './base-generator' )
|
|
||||||
, EXTEND = require('../utils/extend')
|
|
||||||
, FRESHTheme = require('../core/fresh-theme')
|
|
||||||
, JRSTheme = require('../core/jrs-theme');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Default options.
|
|
||||||
var _defaultOpts = {
|
|
||||||
engine: 'underscore',
|
|
||||||
keepBreaks: true,
|
|
||||||
freezeBreaks: false,
|
|
||||||
nSym: '&newl;', // newline entity
|
|
||||||
rSym: '&retn;', // return entity
|
|
||||||
template: {
|
|
||||||
interpolate: /\{\{(.+?)\}\}/g,
|
|
||||||
escape: /\{\{\=(.+?)\}\}/g,
|
|
||||||
evaluate: /\{\%(.+?)\%\}/g,
|
|
||||||
comment: /\{\#(.+?)\#\}/g
|
|
||||||
},
|
|
||||||
filters: {
|
|
||||||
out: function( txt ) { return txt; },
|
|
||||||
raw: function( txt ) { return txt; },
|
|
||||||
xml: function( txt ) { return XML(txt); },
|
|
||||||
md: function( txt ) { return MD( txt || '' ); },
|
|
||||||
mdin: function( txt ) {
|
|
||||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
|
||||||
},
|
|
||||||
lower: function( txt ) { return txt.toLowerCase(); },
|
|
||||||
link: function( name, url ) { return url ?
|
|
||||||
'<a href="' + url + '">' + name + '</a>' : name; }
|
|
||||||
},
|
|
||||||
prettify: { // ← See https://github.com/beautify-web/js-beautify#options
|
|
||||||
indent_size: 2,
|
|
||||||
unformatted: ['em','strong','a'],
|
|
||||||
max_char: 80, // ← See lib/html.js in above-linked repo
|
|
||||||
//wrap_line_length: 120, <-- Don't use this
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
TemplateGenerator performs resume generation via local Handlebar or Underscore
|
|
||||||
style template expansion and is appropriate for text-based formats like HTML,
|
|
||||||
plain text, and XML versions of Microsoft Word, Excel, and OpenOffice.
|
|
||||||
@class TemplateGenerator
|
|
||||||
*/
|
|
||||||
var TemplateGenerator = module.exports = BaseGenerator.extend({
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init: function( outputFormat, templateFormat, cssFile ){
|
|
||||||
this._super( outputFormat );
|
|
||||||
this.tplFormat = templateFormat || outputFormat;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
String-based template generation method.
|
|
||||||
@method invoke
|
|
||||||
@param rez A FreshResume object.
|
|
||||||
@param opts Generator options.
|
|
||||||
@returns An array of objects representing the generated output files. Each
|
|
||||||
object has this format:
|
|
||||||
|
|
||||||
{
|
|
||||||
files: [ { info: { }, data: [ ] }, { ... } ],
|
|
||||||
themeInfo: { }
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
invoke: function( rez, opts ) {
|
|
||||||
|
|
||||||
// Carry over options
|
|
||||||
this.opts = EXTEND( true, { }, _defaultOpts, opts );
|
|
||||||
|
|
||||||
// Load the theme
|
|
||||||
var themeInfo = themeFromMoniker.call( this );
|
|
||||||
var theme = themeInfo.theme;
|
|
||||||
var tFolder = themeInfo.folder;
|
|
||||||
var tplFolder = PATH.join( tFolder, 'src' );
|
|
||||||
var curFmt = theme.getFormat( this.format );
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
// "Generate": process individual files within the theme
|
|
||||||
return {
|
|
||||||
files: curFmt.files.map( function( tplInfo ) {
|
|
||||||
return {
|
|
||||||
info: tplInfo,
|
|
||||||
data: tplInfo.action === 'transform' ?
|
|
||||||
transform.call( that, rez, tplInfo, theme ) : undefined
|
|
||||||
};
|
|
||||||
}).filter(function(item){ return item !== null; }),
|
|
||||||
themeInfo: themeInfo
|
|
||||||
};
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
File-based template generation method.
|
|
||||||
@method generate
|
|
||||||
@param rez A FreshResume object.
|
|
||||||
@param f Full path to the output resume file to generate.
|
|
||||||
@param opts Generator options.
|
|
||||||
*/
|
|
||||||
generate: function( rez, f, opts ) {
|
|
||||||
|
|
||||||
// Call the generation method
|
|
||||||
var genInfo = this.invoke( rez, opts );
|
|
||||||
|
|
||||||
// Carry over options
|
|
||||||
this.opts = EXTEND( true, { }, _defaultOpts, opts );
|
|
||||||
|
|
||||||
// Load the theme
|
|
||||||
var themeInfo = genInfo.themeInfo;
|
|
||||||
var theme = themeInfo.theme;
|
|
||||||
var tFolder = themeInfo.folder;
|
|
||||||
var tplFolder = PATH.join( tFolder, 'src' );
|
|
||||||
var outFolder = parsePath(f).dirname;
|
|
||||||
var curFmt = theme.getFormat( this.format );
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
// "Generate": process individual files within the theme
|
|
||||||
genInfo.files.forEach(function( file ){
|
|
||||||
|
|
||||||
var thisFilePath;
|
|
||||||
|
|
||||||
if( file.info.action === 'transform' ) {
|
|
||||||
thisFilePath = PATH.join( outFolder, file.info.orgPath );
|
|
||||||
try {
|
|
||||||
if( that.onBeforeSave ) {
|
|
||||||
file.data = that.onBeforeSave({
|
|
||||||
theme: theme,
|
|
||||||
outputFile: (file.info.major ? f : thisFilePath),
|
|
||||||
mk: file.data
|
|
||||||
});
|
|
||||||
if( !file.data ) return; // PDF etc
|
|
||||||
}
|
|
||||||
var fileName = file.info.major ? f : thisFilePath;
|
|
||||||
MKDIRP.sync( PATH.dirname( fileName ) );
|
|
||||||
FS.writeFileSync( fileName, file.data,
|
|
||||||
{ encoding: 'utf8', flags: 'w' } );
|
|
||||||
that.onAfterSave && that.onAfterSave(
|
|
||||||
{ outputFile: fileName, mk: file.data } );
|
|
||||||
}
|
|
||||||
catch(ex) {
|
|
||||||
require('../core/error-handler').err(ex, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( file.info.action === null/* && theme.explicit*/ ) {
|
|
||||||
thisFilePath = PATH.join( outFolder, file.info.orgPath );
|
|
||||||
try {
|
|
||||||
MKDIRP.sync( PATH.dirname(thisFilePath) );
|
|
||||||
FS.copySync( file.info.path, thisFilePath );
|
|
||||||
}
|
|
||||||
catch(ex) {
|
|
||||||
console.log(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Some themes require a symlink structure. If so, create it.
|
|
||||||
if( curFmt.symLinks ) {
|
|
||||||
Object.keys( curFmt.symLinks ).forEach( function(loc) {
|
|
||||||
var absLoc = PATH.join(outFolder, loc);
|
|
||||||
var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]);
|
|
||||||
// 'file', 'dir', or 'junction' (Windows only)
|
|
||||||
var type = parsePath( absLoc ).extname ? 'file' : 'junction';
|
|
||||||
FS.symlinkSync( absTarg, absLoc, type);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return genInfo;
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Perform a single resume JSON-to-DEST resume transformation.
|
|
||||||
@param json A FRESH or JRS resume object.
|
|
||||||
@param jst The stringified template data
|
|
||||||
@param format The format name, such as "html" or "latex"
|
|
||||||
@param cssInfo Needs to be refactored.
|
|
||||||
@param opts Options and passthrough data.
|
|
||||||
*/
|
|
||||||
single: function( json, jst, format, cssInfo, opts, theme ) {
|
|
||||||
this.opts.freezeBreaks && ( jst = freeze(jst) );
|
|
||||||
|
|
||||||
var eng = require( '../eng/' + theme.engine + '-generator' );
|
|
||||||
var result = eng.generate( json, jst, format, cssInfo, opts, theme );
|
|
||||||
|
|
||||||
this.opts.freezeBreaks && ( result = unfreeze(result) );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Export the TemplateGenerator function/ctor.
|
|
||||||
*/
|
|
||||||
module.exports = TemplateGenerator;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Given a theme title, load the corresponding theme.
|
|
||||||
*/
|
|
||||||
function themeFromMoniker() {
|
|
||||||
|
|
||||||
// Verify the specified theme name/path
|
|
||||||
var tFolder = PATH.join(
|
|
||||||
parsePath( require.resolve('fresh-themes') ).dirname,
|
|
||||||
this.opts.theme
|
|
||||||
);
|
|
||||||
|
|
||||||
var t;
|
|
||||||
if( this.opts.theme.startsWith('jsonresume-theme-') ) {
|
|
||||||
console.log('LOADING JSON RESUME');
|
|
||||||
t = new JRSTheme().open( tFolder );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var exists = require('path-exists').sync;
|
|
||||||
if( !exists( tFolder ) ) {
|
|
||||||
tFolder = PATH.resolve( this.opts.theme );
|
|
||||||
if( !exists( tFolder ) ) {
|
|
||||||
throw { fluenterror: this.codes.themeNotFound, data: this.opts.theme};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t = this.opts.themeObj || new FRESHTheme().open( tFolder );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the theme and format
|
|
||||||
return {
|
|
||||||
theme: t,
|
|
||||||
folder: tFolder
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function transform( rez, tplInfo, theme ) {
|
|
||||||
try {
|
|
||||||
var cssInfo = {
|
|
||||||
file: tplInfo.css ? tplInfo.cssPath : null,
|
|
||||||
data: tplInfo.css || null
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.single( rez, tplInfo.data, this.format, cssInfo, this.opts,
|
|
||||||
theme );
|
|
||||||
}
|
|
||||||
catch(ex) {
|
|
||||||
console.log(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Freeze newlines for protection against errant JST parsers.
|
|
||||||
*/
|
|
||||||
function freeze( markup ) {
|
|
||||||
return markup
|
|
||||||
.replace( _reg.regN, _defaultOpts.nSym )
|
|
||||||
.replace( _reg.regR, _defaultOpts.rSym );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Unfreeze newlines when the coast is clear.
|
|
||||||
*/
|
|
||||||
function unfreeze( markup ) {
|
|
||||||
return markup
|
|
||||||
.replace( _reg.regSymR, '\r' )
|
|
||||||
.replace( _reg.regSymN, '\n' );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Regexes for linebreak preservation.
|
|
||||||
*/
|
|
||||||
var _reg = {
|
|
||||||
regN: new RegExp( '\n', 'g' ),
|
|
||||||
regR: new RegExp( '\r', 'g' ),
|
|
||||||
regSymN: new RegExp( _defaultOpts.nSym, 'g' ),
|
|
||||||
regSymR: new RegExp( _defaultOpts.rSym, 'g' )
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
@ -10,6 +10,7 @@ Definition of the HTMLGenerator class.
|
|||||||
, FS = require('fs-extra')
|
, FS = require('fs-extra')
|
||||||
, HTML = require( 'html' )
|
, HTML = require( 'html' )
|
||||||
, PATH = require('path');
|
, PATH = require('path');
|
||||||
|
require('string.prototype.endswith');
|
||||||
|
|
||||||
var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ Definition of the HTMLGenerator class.
|
|||||||
the HTML resume prior to saving.
|
the HTML resume prior to saving.
|
||||||
*/
|
*/
|
||||||
onBeforeSave: function( info ) {
|
onBeforeSave: function( info ) {
|
||||||
|
if( info.outputFile.endsWith('.css') )
|
||||||
|
return info.mk;
|
||||||
return this.opts.prettify ?
|
return this.opts.prettify ?
|
||||||
HTML.prettyPrint( info.mk, this.opts.prettify ) : info.mk;
|
HTML.prettyPrint( info.mk, this.opts.prettify ) : info.mk;
|
||||||
}
|
}
|
113
src/generators/html-pdf-cli-generator.js
Normal file
113
src/generators/html-pdf-cli-generator.js
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
Definition of the HtmlPdfCLIGenerator class.
|
||||||
|
@module html-pdf-generator.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var TemplateGenerator = require('./template-generator')
|
||||||
|
, FS = require('fs-extra')
|
||||||
|
, HTML = require( 'html' )
|
||||||
|
, PATH = require('path')
|
||||||
|
, SPAWN = require('../utils/safe-spawn')
|
||||||
|
, SLASH = require('slash');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
An HTML-driven PDF resume generator for HackMyResume. Talks to Phantom,
|
||||||
|
wkhtmltopdf, and other PDF engines over a CLI (command-line interface).
|
||||||
|
If an engine isn't installed for a particular platform, error out gracefully.
|
||||||
|
*/
|
||||||
|
var HtmlPdfCLIGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super( 'pdf', 'html' );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generate the binary PDF.
|
||||||
|
*/
|
||||||
|
onBeforeSave: function( info ) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
var safe_eng = info.opts.pdf || 'wkhtmltopdf';
|
||||||
|
if( safe_eng !== 'none' )
|
||||||
|
engines[ safe_eng ].call( this, info.mk, info.outputFile );
|
||||||
|
return null; // halt further processing
|
||||||
|
}
|
||||||
|
catch(ex) {
|
||||||
|
// { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... }
|
||||||
|
// { [Error: ENOENT] }
|
||||||
|
throw ( ex.inner && ex.inner.code === 'ENOENT' ) ?
|
||||||
|
{ fluenterror: this.codes.notOnPath, inner: ex.inner, engine: ex.cmd,
|
||||||
|
stack: ex.inner && ex.inner.stack } :
|
||||||
|
{ fluenterror: this.codes.pdfGeneration, inner: ex, stack: ex.stack };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Move each engine to a separate module
|
||||||
|
var engines = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generate a PDF from HTML using wkhtmltopdf's CLI interface.
|
||||||
|
Spawns a child process with `wkhtmltopdf <source> <target>`. wkhtmltopdf
|
||||||
|
must be installed and path-accessible.
|
||||||
|
TODO: If HTML generation has run, reuse that output
|
||||||
|
TODO: Local web server to ease wkhtmltopdf rendering
|
||||||
|
*/
|
||||||
|
wkhtmltopdf: function(markup, fOut) {
|
||||||
|
|
||||||
|
// Save the markup to a temporary file
|
||||||
|
var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||||
|
FS.writeFileSync( tempFile, markup, 'utf8' );
|
||||||
|
var info = SPAWN( 'wkhtmltopdf', [ tempFile, fOut ] );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generate a PDF from HTML using Phantom's CLI interface.
|
||||||
|
Spawns a child process with `phantomjs <script> <source> <target>`. Phantom
|
||||||
|
must be installed and path-accessible.
|
||||||
|
TODO: If HTML generation has run, reuse that output
|
||||||
|
TODO: Local web server to ease Phantom rendering
|
||||||
|
*/
|
||||||
|
phantom: function( markup, fOut ) {
|
||||||
|
|
||||||
|
// Save the markup to a temporary file
|
||||||
|
var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||||
|
FS.writeFileSync( tempFile, markup, 'utf8' );
|
||||||
|
var scriptPath = SLASH( PATH.relative( process.cwd(),
|
||||||
|
PATH.resolve( __dirname, '../utils/rasterize.js' ) ) );
|
||||||
|
var sourcePath = SLASH( PATH.relative( process.cwd(), tempFile) );
|
||||||
|
var destPath = SLASH( PATH.relative( process.cwd(), fOut) );
|
||||||
|
var info = SPAWN('phantomjs', [ scriptPath, sourcePath, destPath ]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -4,25 +4,37 @@ Definition of the HtmlPngGenerator class.
|
|||||||
@module html-png-generator.js
|
@module html-png-generator.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var TemplateGenerator = require('./template-generator')
|
var TemplateGenerator = require('./template-generator')
|
||||||
, FS = require('fs-extra')
|
, FS = require('fs-extra')
|
||||||
, HTML = require( 'html' );
|
, HTML = require( 'html' );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An HTML-based PNG resume generator for HackMyResume.
|
An HTML-based PNG resume generator for HackMyResume.
|
||||||
*/
|
*/
|
||||||
var HtmlPngGenerator = module.exports = TemplateGenerator.extend({
|
var HtmlPngGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super( 'png', 'html' );
|
this._super( 'png', 'html' );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
invoke: function( rez, themeMarkup, cssInfo, opts ) {
|
invoke: function( rez, themeMarkup, cssInfo, opts ) {
|
||||||
//return YAML.stringify( JSON.parse( rez.stringify() ), Infinity, 2 );
|
// TODO: Not currently called or callable.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generate: function( rez, f, opts ) {
|
generate: function( rez, f, opts ) {
|
||||||
var htmlResults = opts.targets.filter(function(t){
|
var htmlResults = opts.targets.filter(function(t){
|
||||||
return t.fmt.outFormat === 'html';
|
return t.fmt.outFormat === 'html';
|
||||||
@ -33,15 +45,22 @@ Definition of the HtmlPngGenerator class.
|
|||||||
png( htmlFile[0].data, f );
|
png( htmlFile[0].data, f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Generate a PNG from HTML.
|
Generate a PNG from HTML.
|
||||||
*/
|
*/
|
||||||
function png( markup, fOut ) {
|
function png( markup, fOut ) {
|
||||||
|
// TODO: Which Webshot syntax?
|
||||||
// require('webshot')( markup , { encoding: 'binary', siteType: 'html' } )
|
// require('webshot')( markup , { encoding: 'binary', siteType: 'html' } )
|
||||||
// .pipe( FS.createWriteStream( fOut ) );
|
// .pipe( FS.createWriteStream( fOut ) );
|
||||||
require('webshot')( markup , fOut, { siteType: 'html' }, function(err) { } );
|
require('webshot')( markup , fOut, { siteType: 'html' }, function(err) { } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
244
src/generators/template-generator.js
Normal file
244
src/generators/template-generator.js
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
/**
|
||||||
|
Definition of the TemplateGenerator class. TODO: Refactor
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module template-generator.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var FS = require( 'fs-extra' )
|
||||||
|
, _ = require( 'underscore' )
|
||||||
|
, MD = require( 'marked' )
|
||||||
|
, XML = require( 'xml-escape' )
|
||||||
|
, PATH = require('path')
|
||||||
|
, parsePath = require('parse-filepath')
|
||||||
|
, MKDIRP = require('mkdirp')
|
||||||
|
, BaseGenerator = require( './base-generator' )
|
||||||
|
, EXTEND = require('extend')
|
||||||
|
, FRESHTheme = require('../core/fresh-theme')
|
||||||
|
, JRSTheme = require('../core/jrs-theme');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
TemplateGenerator performs resume generation via local Handlebar or Underscore
|
||||||
|
style template expansion and is appropriate for text-based formats like HTML,
|
||||||
|
plain text, and XML versions of Microsoft Word, Excel, and OpenOffice.
|
||||||
|
@class TemplateGenerator
|
||||||
|
*/
|
||||||
|
var TemplateGenerator = module.exports = BaseGenerator.extend({
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Constructor. Set the output format and template format for this
|
||||||
|
generator. Will usually be called by a derived generator such as
|
||||||
|
HTMLGenerator or MarkdownGenerator. */
|
||||||
|
|
||||||
|
init: function( outputFormat, templateFormat, cssFile ){
|
||||||
|
this._super( outputFormat );
|
||||||
|
this.tplFormat = templateFormat || outputFormat;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Generate a resume using string-based inputs and outputs without touching
|
||||||
|
the filesystem.
|
||||||
|
@method invoke
|
||||||
|
@param rez A FreshResume object.
|
||||||
|
@param opts Generator options.
|
||||||
|
@returns {Array} An array of objects representing the generated output
|
||||||
|
files. */
|
||||||
|
|
||||||
|
invoke: function( rez, opts ) {
|
||||||
|
|
||||||
|
opts = opts ?
|
||||||
|
(this.opts = EXTEND( true, { }, _defaultOpts, opts )) :
|
||||||
|
this.opts;
|
||||||
|
|
||||||
|
// Sort such that CSS files are processed before others
|
||||||
|
var curFmt = opts.themeObj.getFormat( this.format );
|
||||||
|
curFmt.files = _.sortBy( curFmt.files, function(fi) {
|
||||||
|
return fi.ext !== 'css';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run the transformation!
|
||||||
|
var results = curFmt.files.map( function( tplInfo, idx ) {
|
||||||
|
var trx = this.single( rez, tplInfo.data, this.format, opts, opts.themeObj, curFmt );
|
||||||
|
if( tplInfo.ext === 'css' ) { curFmt.files[idx].data = trx; }
|
||||||
|
else if( tplInfo.ext === 'html' ) {
|
||||||
|
//tplInfo.css contains the CSS data loaded by theme
|
||||||
|
//tplInfo.cssPath contains the absolute path to the source CSS File
|
||||||
|
}
|
||||||
|
return { info: tplInfo, data: trx };
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
return {
|
||||||
|
files: results
|
||||||
|
};
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Generate a resume using file-based inputs and outputs. Requires access
|
||||||
|
to the local filesystem.
|
||||||
|
@method generate
|
||||||
|
@param rez A FreshResume object.
|
||||||
|
@param f Full path to the output resume file to generate.
|
||||||
|
@param opts Generator options. */
|
||||||
|
|
||||||
|
generate: function( rez, f, opts ) {
|
||||||
|
|
||||||
|
// Prepare
|
||||||
|
this.opts = EXTEND( true, { }, _defaultOpts, opts );
|
||||||
|
|
||||||
|
// Call the string-based generation method to perform the generation.
|
||||||
|
var genInfo = this.invoke( rez, null );
|
||||||
|
|
||||||
|
var outFolder = parsePath( f ).dirname;
|
||||||
|
var curFmt = opts.themeObj.getFormat( this.format );
|
||||||
|
|
||||||
|
// Process individual files within this format. For example, the HTML
|
||||||
|
// output format for a theme may have multiple HTML files, CSS files,
|
||||||
|
// etc. Process them here.
|
||||||
|
genInfo.files.forEach(function( file ){
|
||||||
|
|
||||||
|
// Pre-processing
|
||||||
|
file.info.orgPath = file.info.orgPath || ''; // <-- For JRS themes
|
||||||
|
var thisFilePath = PATH.join( outFolder, file.info.orgPath );
|
||||||
|
if( this.onBeforeSave ) {
|
||||||
|
file.data = this.onBeforeSave({
|
||||||
|
theme: opts.themeObj,
|
||||||
|
outputFile: (file.info.major ? f : thisFilePath),
|
||||||
|
mk: file.data,
|
||||||
|
opts: this.opts
|
||||||
|
});
|
||||||
|
if( !file.data ) return; // PDF etc
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the file
|
||||||
|
var fileName = file.info.major ? f : thisFilePath;
|
||||||
|
MKDIRP.sync( PATH.dirname( fileName ) );
|
||||||
|
FS.writeFileSync( fileName, file.data,
|
||||||
|
{ encoding: 'utf8', flags: 'w' } );
|
||||||
|
|
||||||
|
// Post-processing
|
||||||
|
this.onAfterSave && this.onAfterSave(
|
||||||
|
{ outputFile: fileName, mk: file.data, opts: this.opts } );
|
||||||
|
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Some themes require a symlink structure. If so, create it.
|
||||||
|
if( curFmt.symLinks ) {
|
||||||
|
Object.keys( curFmt.symLinks ).forEach( function(loc) {
|
||||||
|
var absLoc = PATH.join(outFolder, loc);
|
||||||
|
var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]);
|
||||||
|
// 'file', 'dir', or 'junction' (Windows only)
|
||||||
|
var type = parsePath( absLoc ).extname ? 'file' : 'junction';
|
||||||
|
FS.symlinkSync( absTarg, absLoc, type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return genInfo;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Perform a single resume resume transformation using string-based inputs
|
||||||
|
and outputs without touching the local file system.
|
||||||
|
@param json A FRESH or JRS resume object.
|
||||||
|
@param jst The stringified template data
|
||||||
|
@param format The format name, such as "html" or "latex"
|
||||||
|
@param cssInfo Needs to be refactored.
|
||||||
|
@param opts Options and passthrough data. */
|
||||||
|
|
||||||
|
single: function( json, jst, format, opts, theme, curFmt ) {
|
||||||
|
this.opts.freezeBreaks && ( jst = freeze(jst) );
|
||||||
|
|
||||||
|
var eng = require( '../renderers/' + theme.engine + '-generator' );
|
||||||
|
var result = eng.generate( json, jst, format, curFmt, opts, theme );
|
||||||
|
|
||||||
|
this.opts.freezeBreaks && ( result = unfreeze(result) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Export the TemplateGenerator function/ctor. */
|
||||||
|
module.exports = TemplateGenerator;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Freeze newlines for protection against errant JST parsers. */
|
||||||
|
function freeze( markup ) {
|
||||||
|
return markup
|
||||||
|
.replace( _reg.regN, _defaultOpts.nSym )
|
||||||
|
.replace( _reg.regR, _defaultOpts.rSym );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Unfreeze newlines when the coast is clear. */
|
||||||
|
function unfreeze( markup ) {
|
||||||
|
return markup
|
||||||
|
.replace( _reg.regSymR, '\r' )
|
||||||
|
.replace( _reg.regSymN, '\n' );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Default template generator options. */
|
||||||
|
var _defaultOpts = {
|
||||||
|
engine: 'underscore',
|
||||||
|
keepBreaks: true,
|
||||||
|
freezeBreaks: false,
|
||||||
|
nSym: '&newl;', // newline entity
|
||||||
|
rSym: '&retn;', // return entity
|
||||||
|
template: {
|
||||||
|
interpolate: /\{\{(.+?)\}\}/g,
|
||||||
|
escape: /\{\{\=(.+?)\}\}/g,
|
||||||
|
evaluate: /\{\%(.+?)\%\}/g,
|
||||||
|
comment: /\{\#(.+?)\#\}/g
|
||||||
|
},
|
||||||
|
filters: {
|
||||||
|
out: function( txt ) { return txt; },
|
||||||
|
raw: function( txt ) { return txt; },
|
||||||
|
xml: function( txt ) { return XML(txt); },
|
||||||
|
md: function( txt ) { return MD( txt || '' ); },
|
||||||
|
mdin: function( txt ) {
|
||||||
|
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||||
|
},
|
||||||
|
lower: function( txt ) { return txt.toLowerCase(); },
|
||||||
|
link: function( name, url ) { return url ?
|
||||||
|
'<a href="' + url + '">' + name + '</a>' : name; }
|
||||||
|
},
|
||||||
|
prettify: { // ← See https://github.com/beautify-web/js-beautify#options
|
||||||
|
indent_size: 2,
|
||||||
|
unformatted: ['em','strong','a'],
|
||||||
|
max_char: 80, // ← See lib/html.js in above-linked repo
|
||||||
|
//wrap_line_length: 120, <-- Don't use this
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Regexes for linebreak preservation. */
|
||||||
|
var _reg = {
|
||||||
|
regN: new RegExp( '\n', 'g' ),
|
||||||
|
regR: new RegExp( '\r', 'g' ),
|
||||||
|
regSymN: new RegExp( _defaultOpts.nSym, 'g' ),
|
||||||
|
regSymR: new RegExp( _defaultOpts.rSym, 'g' )
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -1,24 +1,51 @@
|
|||||||
/**
|
/**
|
||||||
External API surface for HackMyResume.
|
External API surface for HackMyResume.
|
||||||
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
|
@license MIT. See LICENSE.md for details.
|
||||||
@module hackmyapi.js
|
@module hackmyapi.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
The formal HackMyResume API.
|
||||||
|
*/
|
||||||
|
var HackMyAPI = module.exports = {
|
||||||
|
verbs: {
|
||||||
|
build: require('./verbs/build'),
|
||||||
|
analyze: require('./verbs/analyze'),
|
||||||
|
validate: require('./verbs/validate'),
|
||||||
|
convert: require('./verbs/convert'),
|
||||||
|
new: require('./verbs/create'),
|
||||||
|
peek: require('./verbs/peek')
|
||||||
|
},
|
||||||
|
alias: {
|
||||||
|
generate: require('./verbs/build'),
|
||||||
|
create: require('./verbs/create')
|
||||||
|
},
|
||||||
|
options: require('./core/default-options'),
|
||||||
|
formats: require('./core/default-formats'),
|
||||||
Sheet: require('./core/fresh-resume'),
|
Sheet: require('./core/fresh-resume'),
|
||||||
FRESHResume: require('./core/fresh-resume'),
|
FRESHResume: require('./core/fresh-resume'),
|
||||||
JRSResume: require('./core/jrs-resume'),
|
JRSResume: require('./core/jrs-resume'),
|
||||||
FRESHTheme: require('./core/fresh-theme'),
|
FRESHTheme: require('./core/fresh-theme'),
|
||||||
JRSTheme: require('./core/jrs-theme'),
|
JRSTheme: require('./core/jrs-theme'),
|
||||||
FluentDate: require('./core/fluent-date'),
|
FluentDate: require('./core/fluent-date'),
|
||||||
HtmlGenerator: require('./gen/html-generator'),
|
HtmlGenerator: require('./generators/html-generator'),
|
||||||
TextGenerator: require('./gen/text-generator'),
|
TextGenerator: require('./generators/text-generator'),
|
||||||
HtmlPdfGenerator: require('./gen/html-pdf-generator'),
|
HtmlPdfCliGenerator: require('./generators/html-pdf-cli-generator'),
|
||||||
WordGenerator: require('./gen/word-generator'),
|
WordGenerator: require('./generators/word-generator'),
|
||||||
MarkdownGenerator: require('./gen/markdown-generator'),
|
MarkdownGenerator: require('./generators/markdown-generator'),
|
||||||
JsonGenerator: require('./gen/json-generator'),
|
JsonGenerator: require('./generators/json-generator'),
|
||||||
YamlGenerator: require('./gen/yaml-generator'),
|
YamlGenerator: require('./generators/yaml-generator'),
|
||||||
JsonYamlGenerator: require('./gen/json-yaml-generator'),
|
JsonYamlGenerator: require('./generators/json-yaml-generator'),
|
||||||
LaTeXGenerator: require('./gen/latex-generator'),
|
LaTeXGenerator: require('./generators/latex-generator'),
|
||||||
HtmlPngGenerator: require('./gen/html-png-generator')
|
HtmlPngGenerator: require('./generators/html-png-generator')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
Internal resume generation logic for HackMyResume.
|
|
||||||
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
|
|
||||||
@module hackmycmd.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
module.exports = function () {
|
|
||||||
|
|
||||||
var unused = require('./utils/string')
|
|
||||||
, PATH = require('path')
|
|
||||||
, FS = require('fs');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Display help documentation.
|
|
||||||
*/
|
|
||||||
function help() {
|
|
||||||
var manPage = FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' );
|
|
||||||
console.log( manPage.useful.bold );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Internal module interface. Used by FCV Desktop and HMR.
|
|
||||||
*/
|
|
||||||
var v = {
|
|
||||||
build: require('./verbs/generate'),
|
|
||||||
validate: require('./verbs/validate'),
|
|
||||||
convert: require('./verbs/convert'),
|
|
||||||
new: require('./verbs/create'),
|
|
||||||
help: help
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
verbs: v,
|
|
||||||
alias: {
|
|
||||||
generate: v.build,
|
|
||||||
create: v.build
|
|
||||||
},
|
|
||||||
lib: require('./hackmyapi'),
|
|
||||||
options: require('./core/default-options'),
|
|
||||||
formats: require('./core/default-formats')
|
|
||||||
};
|
|
||||||
|
|
||||||
}();
|
|
||||||
|
|
||||||
}());
|
|
||||||
|
|
||||||
// [1]: JSON.parse throws SyntaxError on invalid JSON. See:
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
|
|
67
src/helpers/console-helpers.js
Normal file
67
src/helpers/console-helpers.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
Generic template helper definitions for command-line output.
|
||||||
|
@module console-helpers.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var PAD = require('string-padding')
|
||||||
|
, LO = require('lodash')
|
||||||
|
, CHALK = require('chalk')
|
||||||
|
, _ = require('underscore');
|
||||||
|
require('../utils/string');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var consoleFormatHelpers = module.exports = {
|
||||||
|
|
||||||
|
v: function( val, defaultVal, padding, style ) {
|
||||||
|
retVal = ( val === null || val === undefined ) ? defaultVal : val;
|
||||||
|
var spaces = 0;
|
||||||
|
if( String.is(padding) ) {
|
||||||
|
spaces = parseInt( padding, 10 );
|
||||||
|
if( isNaN(spaces) ) spaces = 0;
|
||||||
|
}
|
||||||
|
else if( _.isNumber(padding) ) {
|
||||||
|
spaces = padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( spaces !== 0 )
|
||||||
|
retVal = PAD( retVal, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
|
||||||
|
|
||||||
|
if( style && String.is( style )) {
|
||||||
|
retVal = LO.get( CHALK, style )( retVal );
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
},
|
||||||
|
|
||||||
|
gapLength: function(val) {
|
||||||
|
if( val < 35 )
|
||||||
|
return CHALK.green.bold(val);
|
||||||
|
else if( val < 95 )
|
||||||
|
return CHALK.yellow.bold(val);
|
||||||
|
else
|
||||||
|
return CHALK.red.bold(val);
|
||||||
|
},
|
||||||
|
|
||||||
|
style: function( val, style ) {
|
||||||
|
return LO.get( CHALK, style )( val );
|
||||||
|
},
|
||||||
|
|
||||||
|
isPlural: function( val, options ) {
|
||||||
|
if( val > 1 )
|
||||||
|
return options.fn(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
pad: function( val, spaces ) {
|
||||||
|
return PAD(val, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
609
src/helpers/generic-helpers.js
Normal file
609
src/helpers/generic-helpers.js
Normal file
@ -0,0 +1,609 @@
|
|||||||
|
/**
|
||||||
|
Generic template helper definitions for HackMyResume / FluentCV.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module helpers/generic-helpers
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var MD = require('marked')
|
||||||
|
, H2W = require('../utils/html-to-wpml')
|
||||||
|
, XML = require('xml-escape')
|
||||||
|
, FluentDate = require('../core/fluent-date')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, moment = require('moment')
|
||||||
|
, FS = require('fs')
|
||||||
|
, LO = require('lodash')
|
||||||
|
, PATH = require('path')
|
||||||
|
, printf = require('printf')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, unused = require('../utils/string');
|
||||||
|
|
||||||
|
/** Generic template helper function definitions. */
|
||||||
|
var GenericHelpers = module.exports = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert the input date to a specified format through Moment.js.
|
||||||
|
If date is invalid, will return the time provided by the user,
|
||||||
|
or default to the fallback param or 'Present' if that is set to true
|
||||||
|
@method formatDate
|
||||||
|
*/
|
||||||
|
formatDate: function(datetime, format, fallback) {
|
||||||
|
if (moment) {
|
||||||
|
var momentDate = moment( datetime );
|
||||||
|
if (momentDate.isValid()) return momentDate.format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
return datetime || (typeof fallback == 'string' ? fallback : (fallback === true ? 'Present' : null));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Given a resume sub-object with a start/end date, format a representation of
|
||||||
|
the date range.
|
||||||
|
@method dateRange
|
||||||
|
*/
|
||||||
|
dateRange: function( obj, fmt, sep, fallback, options ) {
|
||||||
|
if( !obj ) return '';
|
||||||
|
return _fromTo( obj.start, obj.end, fmt, sep, fallback, options );
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Format a from/to date range for display.
|
||||||
|
@method toFrom
|
||||||
|
*/
|
||||||
|
fromTo: function() {
|
||||||
|
return _fromTo.apply( this, arguments );
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return a named color value as an RRGGBB string.
|
||||||
|
@method toFrom
|
||||||
|
*/
|
||||||
|
color: function( colorName, colorDefault ) {
|
||||||
|
// Key must be specified
|
||||||
|
if( !( colorName && colorName.trim()) ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontList', error: HMSTATUS.missingParam, expected: 'name'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( !GenericHelpers.theme.colors ) return colorDefault;
|
||||||
|
var ret = GenericHelpers.theme.colors[ colorName ];
|
||||||
|
if( !(ret && ret.trim()) )
|
||||||
|
return colorDefault;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return true if the section is present on the resume and has at least one
|
||||||
|
element.
|
||||||
|
@method section
|
||||||
|
*/
|
||||||
|
section: function( title, options ) {
|
||||||
|
title = title.trim().toLowerCase();
|
||||||
|
var obj = LO.get( this.r, title );
|
||||||
|
if( _.isArray( obj ) ) {
|
||||||
|
return obj.length ? options.fn(this) : undefined;
|
||||||
|
}
|
||||||
|
else if( _.isObject( obj )) {
|
||||||
|
return ( (obj.history && obj.history.length) ||
|
||||||
|
( obj.sets && obj.sets.length ) ) ?
|
||||||
|
options.fn(this) : undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Emit the size of the specified named font.
|
||||||
|
@param key {String} A named style from the "fonts" section of the theme's
|
||||||
|
theme.json file. For example: 'default' or 'heading1'.
|
||||||
|
*/
|
||||||
|
fontSize: function( key, defSize, units ){
|
||||||
|
|
||||||
|
var ret = ''
|
||||||
|
, hasDef = defSize && ( String.is( defSize ) || _.isNumber( defSize ));
|
||||||
|
|
||||||
|
// Key must be specified
|
||||||
|
if( !( key && key.trim()) ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontSize', error: HMSTATUS.missingParam, expected: 'key'
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ( GenericHelpers.theme.fonts ) {
|
||||||
|
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||||
|
if( !fontSpec ) {
|
||||||
|
// Check for an "all" format
|
||||||
|
if( GenericHelpers.theme.fonts.all )
|
||||||
|
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||||
|
}
|
||||||
|
if( fontSpec ) {
|
||||||
|
// fontSpec can be a string, an array, or an object
|
||||||
|
if( String.is( fontSpec )) {
|
||||||
|
// No font size was specified, only a font family.
|
||||||
|
}
|
||||||
|
else if( _.isArray( fontSpec )) {
|
||||||
|
// An array of fonts were specified. Each one could be a string
|
||||||
|
// or an object
|
||||||
|
if( !String.is( fontSpec[0] )) {
|
||||||
|
ret = fontSpec[0].size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// A font description object.
|
||||||
|
ret = fontSpec.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We weren't able to lookup the specified key. Default to defFont.
|
||||||
|
if( !ret ) {
|
||||||
|
if( hasDef )
|
||||||
|
ret = defSize;
|
||||||
|
else {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontSize', error: HMSTATUS.missingParam,
|
||||||
|
expected: 'defSize'});
|
||||||
|
ret = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Emit the font face (such as 'Helvetica' or 'Calibri') associated with the
|
||||||
|
provided key.
|
||||||
|
@param key {String} A named style from the "fonts" section of the theme's
|
||||||
|
theme.json file. For example: 'default' or 'heading1'.
|
||||||
|
@param defFont {String} The font to use if the specified key isn't present.
|
||||||
|
Can be any valid font-face name such as 'Helvetica Neue' or 'Calibri'.
|
||||||
|
*/
|
||||||
|
fontFace: function( key, defFont ) {
|
||||||
|
|
||||||
|
var ret = ''
|
||||||
|
, hasDef = defFont && String.is( defFont );
|
||||||
|
|
||||||
|
// Key must be specified
|
||||||
|
if( !( key && key.trim()) ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'key'
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the theme has a "fonts" section, lookup the font face.
|
||||||
|
else if( GenericHelpers.theme.fonts ) {
|
||||||
|
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||||
|
if( !fontSpec ) {
|
||||||
|
// Check for an "all" format
|
||||||
|
if( GenericHelpers.theme.fonts.all )
|
||||||
|
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||||
|
}
|
||||||
|
if( fontSpec ) {
|
||||||
|
// fontSpec can be a string, an array, or an object
|
||||||
|
if( String.is( fontSpec )) {
|
||||||
|
ret = fontSpec;
|
||||||
|
}
|
||||||
|
else if( _.isArray( fontSpec )) {
|
||||||
|
// An array of fonts were specified. Each one could be a string
|
||||||
|
// or an object
|
||||||
|
ret = String.is( fontSpec[0] ) ? fontSpec[0] : fontSpec[0].name;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// A font description object.
|
||||||
|
ret = fontSpec.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We weren't able to lookup the specified key. Default to defFont.
|
||||||
|
if( !(ret && ret.trim()) ) {
|
||||||
|
ret = defFont;
|
||||||
|
if( !hasDef ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontFace', error: HMSTATUS.missingParam,
|
||||||
|
expected: 'defFont'});
|
||||||
|
ret = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Emit a comma-delimited list of font names suitable associated with the
|
||||||
|
provided key.
|
||||||
|
@param key {String} A named style from the "fonts" section of the theme's
|
||||||
|
theme.json file. For example: 'default' or 'heading1'.
|
||||||
|
@param defFontList {Array} The font list to use if the specified key isn't
|
||||||
|
present. Can be an array of valid font-face name such as 'Helvetica Neue'
|
||||||
|
or 'Calibri'.
|
||||||
|
@param sep {String} The default separator to use in the rendered output.
|
||||||
|
Defaults to ", " (comma with a space).
|
||||||
|
*/
|
||||||
|
fontList: function( key, defFontList, sep ) {
|
||||||
|
|
||||||
|
var ret = ''
|
||||||
|
, hasDef = defFontList && String.is( defFontList );
|
||||||
|
|
||||||
|
// Key must be specified
|
||||||
|
if( !( key && key.trim()) ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontList', error: HMSTATUS.missingParam, expected: 'key'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the theme has a "fonts" section, lookup the font list.
|
||||||
|
else if( GenericHelpers.theme.fonts ) {
|
||||||
|
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||||
|
if( !fontSpec ) {
|
||||||
|
if( GenericHelpers.theme.fonts.all )
|
||||||
|
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( fontSpec ) {
|
||||||
|
// fontSpec can be a string, an array, or an object
|
||||||
|
if( String.is( fontSpec )) {
|
||||||
|
ret = fontSpec;
|
||||||
|
}
|
||||||
|
else if( _.isArray( fontSpec )) {
|
||||||
|
// An array of fonts were specified. Each one could be a string
|
||||||
|
// or an object
|
||||||
|
fontSpec = fontSpec.map( function( ff ) {
|
||||||
|
return "'" + (String.is( ff ) ? ff : ff.name) + "'";
|
||||||
|
});
|
||||||
|
ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// A font description object.
|
||||||
|
ret = fontSpec.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The key wasn't found in the "fonts" section. Default to defFont.
|
||||||
|
if( !(ret && ret.trim()) ) {
|
||||||
|
if( !hasDef ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
|
helper: 'fontList', error: HMSTATUS.missingParam,
|
||||||
|
expected: 'defFontList'});
|
||||||
|
ret = '';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = defFontList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Capitalize the first letter of the word.
|
||||||
|
@method section
|
||||||
|
*/
|
||||||
|
camelCase: function(val) {
|
||||||
|
val = (val && val.trim()) || '';
|
||||||
|
return val ? (val.charAt(0).toUpperCase() + val.slice(1)) : val;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return true if the context has the property or subpropery.
|
||||||
|
@method has
|
||||||
|
*/
|
||||||
|
has: function( title, options ) {
|
||||||
|
title = title && title.trim().toLowerCase();
|
||||||
|
if( LO.get( this.r, title ) ) {
|
||||||
|
return options.fn(this);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generic template helper function to display a user-overridable section
|
||||||
|
title for a FRESH resume theme. Use this in lieue of hard-coding section
|
||||||
|
titles.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
{{sectionTitle "sectionName"}}
|
||||||
|
{{sectionTitle "sectionName" "sectionTitle"}}
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
{{sectionTitle "Education"}}
|
||||||
|
{{sectionTitle "Employment" "Project History"}}
|
||||||
|
|
||||||
|
@param sect_name The name of the section being title. Must be one of the
|
||||||
|
top-level FRESH resume sections ("info", "education", "employment", etc.).
|
||||||
|
@param sect_title The theme-specified section title. May be replaced by the
|
||||||
|
user.
|
||||||
|
@method sectionTitle
|
||||||
|
*/
|
||||||
|
sectionTitle: function( sname, stitle ) {
|
||||||
|
|
||||||
|
// If not provided by the user, stitle should default to sname. ps.
|
||||||
|
// Handlebars silently passes in the options object to the last param,
|
||||||
|
// where in Underscore stitle will be null/undefined, so we check both.
|
||||||
|
stitle = (stitle && String.is(stitle) && stitle) || sname;
|
||||||
|
|
||||||
|
// If there's a section title override, use it.
|
||||||
|
return ( this.opts.stitles &&
|
||||||
|
this.opts.stitles[ sname.toLowerCase().trim() ] ) ||
|
||||||
|
stitle;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert inline Markdown to inline WordProcessingML.
|
||||||
|
@method wpml
|
||||||
|
*/
|
||||||
|
wpml: function( txt, inline ) {
|
||||||
|
if(!txt) return '';
|
||||||
|
inline = (inline && !inline.hash) || false;
|
||||||
|
txt = XML(txt.trim());
|
||||||
|
txt = inline ?
|
||||||
|
MD(txt).replace(/^\s*<p>|<\/p>\s*$/gi, '') :
|
||||||
|
MD(txt);
|
||||||
|
txt = H2W( txt );
|
||||||
|
return txt;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Emit a conditional link.
|
||||||
|
@method link
|
||||||
|
*/
|
||||||
|
link: function( text, url ) {
|
||||||
|
return url && url.trim() ?
|
||||||
|
('<a href="' + url + '">' + text + '</a>') : text;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return the last word of the specified text.
|
||||||
|
@method lastWord
|
||||||
|
*/
|
||||||
|
lastWord: function( txt ) {
|
||||||
|
return txt && txt.trim() ? _.last( txt.split(' ') ) : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert a skill level to an RGB color triplet. TODO: refactor
|
||||||
|
@method skillColor
|
||||||
|
@param lvl Input skill level. Skill level can be expressed as a string
|
||||||
|
("beginner", "intermediate", etc.), as an integer (1,5,etc), as a string
|
||||||
|
integer ("1", "5", etc.), or as an RRGGBB color triplet ('#C00000',
|
||||||
|
'#FFFFAA').
|
||||||
|
*/
|
||||||
|
skillColor: function( lvl ) {
|
||||||
|
var idx = skillLevelToIndex( lvl );
|
||||||
|
var skillColors = (this.theme && this.theme.palette &&
|
||||||
|
this.theme.palette.skillLevels) ||
|
||||||
|
[ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ];
|
||||||
|
return skillColors[idx];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return an appropriate height. TODO: refactor
|
||||||
|
@method lastWord
|
||||||
|
*/
|
||||||
|
skillHeight: function( lvl ) {
|
||||||
|
var idx = skillLevelToIndex( lvl );
|
||||||
|
return ['38.25', '30', '16', '8', '0'][idx];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return all but the last word of the input text.
|
||||||
|
@method initialWords
|
||||||
|
*/
|
||||||
|
initialWords: function( txt ) {
|
||||||
|
return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Trim the protocol (http or https) from a URL/
|
||||||
|
@method trimURL
|
||||||
|
*/
|
||||||
|
trimURL: function( url ) {
|
||||||
|
return url && url.trim() ? url.trim().replace(/^https?:\/\//i, '') : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert text to lowercase.
|
||||||
|
@method toLower
|
||||||
|
*/
|
||||||
|
toLower: function( txt ) {
|
||||||
|
return txt && txt.trim() ? txt.toLowerCase() : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert text to lowercase.
|
||||||
|
@method toLower
|
||||||
|
*/
|
||||||
|
toUpper: function( txt ) {
|
||||||
|
return txt && txt.trim() ? txt.toUpperCase() : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return true if either value is truthy.
|
||||||
|
@method either
|
||||||
|
*/
|
||||||
|
either: function( lhs, rhs, options ) {
|
||||||
|
if (lhs || rhs) return options.fn(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Conditional stylesheet link. Creates a link to the specified stylesheet with
|
||||||
|
<link> or embeds the styles inline with <style></style>, depending on the
|
||||||
|
theme author's and user's preferences.
|
||||||
|
@param url {String} The path to the CSS file.
|
||||||
|
@param linkage {String} The default link method. Can be either `embed` or
|
||||||
|
`link`. If omitted, defaults to `embed`. Can be overridden by the `--css`
|
||||||
|
command-line switch.
|
||||||
|
*/
|
||||||
|
|
||||||
|
styleSheet: function( url, linkage ) {
|
||||||
|
|
||||||
|
// Establish the linkage style
|
||||||
|
linkage = this.opts.css || linkage || 'embed';
|
||||||
|
|
||||||
|
// Create the <link> or <style> tag
|
||||||
|
var ret = '';
|
||||||
|
if( linkage === 'link' ) {
|
||||||
|
ret = printf('<link href="%s" rel="stylesheet" type="text/css">', url);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var rawCss = FS.readFileSync(
|
||||||
|
PATH.join( this.opts.themeObj.folder, '/src/', url ), 'utf8' );
|
||||||
|
var renderedCss = this.engine.generateSimple( this, rawCss );
|
||||||
|
ret = printf('<style>%s</style>', renderedCss );
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the currently-executing template is inherited, append styles
|
||||||
|
if( this.opts.themeObj.inherits &&
|
||||||
|
this.opts.themeObj.inherits.html &&
|
||||||
|
this.format === 'html' ) {
|
||||||
|
ret += (linkage === 'link') ?
|
||||||
|
'<link href="' + this.opts.themeObj.overrides.path +
|
||||||
|
'" rel="stylesheet" type="text/css">' :
|
||||||
|
'<style>' + this.opts.themeObj.overrides.data + '</style>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: It would be nice to use Handlebar.SafeString here, but these
|
||||||
|
// are supposed to be generic helpers. Provide an equivalent, or expose
|
||||||
|
// it when Handlebars is the chosen engine, which is most of the time.
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Perform a generic comparison.
|
||||||
|
See: http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates
|
||||||
|
@method compare
|
||||||
|
*/
|
||||||
|
compare: function(lvalue, rvalue, options) {
|
||||||
|
if (arguments.length < 3)
|
||||||
|
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
|
||||||
|
var operator = options.hash.operator || "==";
|
||||||
|
var operators = {
|
||||||
|
'==': function(l,r) { return l == r; },
|
||||||
|
'===': function(l,r) { return l === r; },
|
||||||
|
'!=': function(l,r) { return l != r; },
|
||||||
|
'<': function(l,r) { return l < r; },
|
||||||
|
'>': function(l,r) { return l > r; },
|
||||||
|
'<=': function(l,r) { return l <= r; },
|
||||||
|
'>=': function(l,r) { return l >= r; },
|
||||||
|
'typeof': function(l,r) { return typeof l == r; }
|
||||||
|
};
|
||||||
|
if (!operators[operator])
|
||||||
|
throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
|
||||||
|
var result = operators[operator](lvalue,rvalue);
|
||||||
|
return result ? options.fn(this) : options.inverse(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Report an error to the outside world without throwing an exception. Currently
|
||||||
|
relies on kludging the running verb into. opts.
|
||||||
|
*/
|
||||||
|
function _reportError( code, params ) {
|
||||||
|
GenericHelpers.opts.errHandler.err( code, params );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Format a from/to date range for display.
|
||||||
|
*/
|
||||||
|
function _fromTo( dateA, dateB, fmt, sep, fallback ) {
|
||||||
|
|
||||||
|
// Prevent accidental use of safe.start, safe.end, safe.date
|
||||||
|
// The dateRange helper is for raw dates only
|
||||||
|
if( moment.isMoment( dateA ) || moment.isMoment( dateB ) ) {
|
||||||
|
_reportError( HMSTATUS.invalidHelperUse, { helper: 'dateRange' } );
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var dateFrom, dateTo, dateTemp;
|
||||||
|
|
||||||
|
// Check for 'current', 'present', 'now', '', null, and undefined
|
||||||
|
dateA = dateA || '';
|
||||||
|
dateB = dateB || '';
|
||||||
|
var dateATrim = dateA.trim().toLowerCase();
|
||||||
|
var dateBTrim = dateB.trim().toLowerCase();
|
||||||
|
var reserved = ['current','present','now', ''];
|
||||||
|
|
||||||
|
fmt = (fmt && String.is(fmt) && fmt) || 'YYYY-MM';
|
||||||
|
sep = (sep && String.is(sep) && sep) || ' — ';
|
||||||
|
|
||||||
|
if( _.contains( reserved, dateATrim )) {
|
||||||
|
dateFrom = fallback || '???';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dateTemp = FluentDate.fmt( dateA );
|
||||||
|
dateFrom = dateTemp.format( fmt );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( _.contains( reserved, dateBTrim )) {
|
||||||
|
dateTo = fallback || 'Current';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dateTemp = FluentDate.fmt( dateB );
|
||||||
|
dateTo = dateTemp.format( fmt );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( dateFrom && dateTo ) {
|
||||||
|
return dateFrom + sep + dateTo;
|
||||||
|
}
|
||||||
|
else if( dateFrom || dateTo ) {
|
||||||
|
return dateFrom || dateTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function skillLevelToIndex( lvl ) {
|
||||||
|
var idx = 0;
|
||||||
|
if( String.is( lvl ) ) {
|
||||||
|
lvl = lvl.trim().toLowerCase();
|
||||||
|
var intVal = parseInt( lvl );
|
||||||
|
if( isNaN( intVal ) ) {
|
||||||
|
switch( lvl ) {
|
||||||
|
case 'beginner': idx = 1; break;
|
||||||
|
case 'intermediate': idx = 2; break;
|
||||||
|
case 'advanced': idx = 3; break;
|
||||||
|
case 'master': idx = 4; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
idx = Math.min( intVal / 2, 4 );
|
||||||
|
idx = Math.max( 0, idx );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
idx = Math.min( lvl / 2, 4 );
|
||||||
|
idx = Math.max( 0, idx );
|
||||||
|
}
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
// Note [1] --------------------------------------------------------------------
|
||||||
|
// Make sure it's precisely a string or array since some template engines jam
|
||||||
|
// their options/context object into the last parameter and we are allowing the
|
||||||
|
// defFont parameter to be omitted in certain cases. This is a little kludgy,
|
||||||
|
// but works fine for this case. If we start doing this regularly, we should
|
||||||
|
// rebind these parameters.
|
||||||
|
|
||||||
|
// Note [2]: -------------------------------------------------------------------
|
||||||
|
// If execution reaches here, some sort of cosmic ray or sunspot has landed on
|
||||||
|
// HackMyResume, or a theme author is deliberately messing with us by doing
|
||||||
|
// something like:
|
||||||
|
//
|
||||||
|
// "fonts": {
|
||||||
|
// "default": "",
|
||||||
|
// "heading1": null
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Rather than sort it out, we'll just fall back to defFont.
|
@ -15,9 +15,10 @@ Template helper definitions for Handlebars.
|
|||||||
Register useful Handlebars helpers.
|
Register useful Handlebars helpers.
|
||||||
@method registerHelpers
|
@method registerHelpers
|
||||||
*/
|
*/
|
||||||
module.exports = function( theme ) {
|
module.exports = function( theme, opts ) {
|
||||||
|
|
||||||
helpers.theme = theme;
|
helpers.theme = theme;
|
||||||
|
helpers.opts = opts;
|
||||||
HANDLEBARS.registerHelper( helpers );
|
HANDLEBARS.registerHelper( helpers );
|
||||||
|
|
||||||
};
|
};
|
34
src/helpers/underscore-helpers.js
Normal file
34
src/helpers/underscore-helpers.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
Template helper definitions for Underscore.
|
||||||
|
@license MIT. Copyright (c) 2016 hacksalot (https://github.com/hacksalot)
|
||||||
|
@module handlebars-helpers.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var HANDLEBARS = require('handlebars')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, helpers = require('./generic-helpers');
|
||||||
|
|
||||||
|
/**
|
||||||
|
Register useful Underscore helpers.
|
||||||
|
@method registerHelpers
|
||||||
|
*/
|
||||||
|
module.exports = function( theme, opts, cssInfo, ctx, eng ) {
|
||||||
|
|
||||||
|
helpers.theme = theme;
|
||||||
|
helpers.opts = opts;
|
||||||
|
helpers.cssInfo = cssInfo;
|
||||||
|
helpers.engine = eng;
|
||||||
|
ctx.h = helpers;
|
||||||
|
|
||||||
|
_.each( helpers, function( hVal, hKey ) {
|
||||||
|
if( _.isFunction( hVal )) {
|
||||||
|
_.bind( hVal, ctx );
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
89
src/index.js
89
src/index.js
@ -1,97 +1,22 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Command-line interface (CLI) for HackMyResume.
|
Command-line interface (CLI) for HackMyResume.
|
||||||
@license MIT. Copyright (c) 2015 hacksalot (https://github.com/hacksalot)
|
@license MIT. See LICENSE.md for details.
|
||||||
@module index.js
|
@module index.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var SPAWNW = require('./core/spawn-watch')
|
|
||||||
, ARGS = require( 'minimist' )
|
|
||||||
, FCMD = require( './hackmycmd')
|
|
||||||
, PKG = require('../package.json')
|
|
||||||
, COLORS = require('colors')
|
|
||||||
, FS = require('fs')
|
|
||||||
, PATH = require('path')
|
|
||||||
, HACKMYSTATUS = require('./core/status-codes')
|
|
||||||
, opts = { }
|
|
||||||
, title = ('\n*** HackMyResume v' + PKG.version + ' ***').bold.white
|
|
||||||
, _ = require('underscore');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
main();
|
|
||||||
|
require('./cli/main')( process.argv );
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( ex ) {
|
catch( ex ) {
|
||||||
require('./core/error-handler').err( ex, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
require('./cli/error').err( ex, true );
|
||||||
|
|
||||||
function main() {
|
|
||||||
|
|
||||||
// Colorize
|
|
||||||
COLORS.setTheme({
|
|
||||||
title: ['white','bold'],
|
|
||||||
info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
|
||||||
infoBold: ['white','dim'],
|
|
||||||
warn: 'yellow',
|
|
||||||
error: 'red',
|
|
||||||
guide: 'yellow',
|
|
||||||
status: 'gray',//['white','dim'],
|
|
||||||
useful: 'green',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Setup
|
|
||||||
if( process.argv.length <= 2 ) { throw { fluenterror: 4 }; }
|
|
||||||
var a = ARGS( process.argv.slice(2) );
|
|
||||||
opts = getOpts( a );
|
|
||||||
logMsg( title );
|
|
||||||
|
|
||||||
// Get the action to be performed
|
|
||||||
var params = a._.map( function(p){ return p.toLowerCase().trim(); });
|
|
||||||
var verb = params[0];
|
|
||||||
if( !FCMD.verbs[ verb ] && !FCMD.alias[ verb ] ) {
|
|
||||||
logMsg('Invalid command: "'.warn + verb.warn.bold + '"'.warn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the TO keyword, if any
|
|
||||||
var splitAt = _.indexOf( params, 'to' );
|
|
||||||
if( splitAt === a._.length - 1 ) {
|
|
||||||
// 'TO' cannot be the last argument
|
|
||||||
logMsg('Please '.warn + 'specify an output file'.warn.bold +
|
|
||||||
' for this operation or '.warn + 'omit the TO keyword'.warn.bold +
|
|
||||||
'.'.warn );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Massage inputs and outputs
|
|
||||||
var src = a._.slice(1, splitAt === -1 ? undefined : splitAt );
|
|
||||||
var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 );
|
|
||||||
( splitAt === -1 ) && (src.length > 1) && (verb !== 'validate') && dst.push( src.pop() ); // Allow omitting TO keyword
|
|
||||||
|
|
||||||
// Invoke the action
|
|
||||||
(FCMD.verbs[verb] || FCMD.alias[verb]).apply(null, [src, dst, opts, logMsg]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function logMsg( msg ) {
|
|
||||||
opts.silent || console.log( msg );
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOpts( args ) {
|
|
||||||
var noPretty = args.nopretty || args.n;
|
|
||||||
noPretty = noPretty && (noPretty === true || noPretty === 'true');
|
|
||||||
return {
|
|
||||||
theme: args.t || 'modern',
|
|
||||||
format: args.f || 'FRESH',
|
|
||||||
prettify: !noPretty,
|
|
||||||
silent: args.s || args.silent,
|
|
||||||
css: args.css || 'embed'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
166
src/inspectors/gap-inspector.js
Normal file
166
src/inspectors/gap-inspector.js
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/**
|
||||||
|
Employment gap analysis for HackMyResume.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module inspectors/gap-inspector
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
var FluentDate = require('../core/fluent-date');
|
||||||
|
var moment = require('moment');
|
||||||
|
var LO = require('lodash');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Identify gaps in the candidate's employment history.
|
||||||
|
*/
|
||||||
|
var gapInspector = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
moniker: 'gap-inspector',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Run the Gap Analyzer on a resume.
|
||||||
|
@method run
|
||||||
|
@return {Array} An array of object representing gaps in the candidate's
|
||||||
|
employment history. Each object provides the start, end, and duration of the
|
||||||
|
gap:
|
||||||
|
{ <-- gap
|
||||||
|
start: // A Moment.js date
|
||||||
|
end: // A Moment.js date
|
||||||
|
duration: // Gap length
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
run: function( rez ) {
|
||||||
|
|
||||||
|
// This is what we'll return
|
||||||
|
var coverage = {
|
||||||
|
gaps: [],
|
||||||
|
overlaps: [],
|
||||||
|
duration: {
|
||||||
|
total: 0,
|
||||||
|
work: 0,
|
||||||
|
gaps: 0
|
||||||
|
},
|
||||||
|
pct: '0%'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Missing employment section? Bye bye.
|
||||||
|
var hist = LO.get( rez, 'employment.history' );
|
||||||
|
if( !hist || !hist.length ) { return coverage; }
|
||||||
|
|
||||||
|
// Convert the candidate's employment history to an array of dates,
|
||||||
|
// where each element in the array is a start date or an end date of a
|
||||||
|
// job -- it doesn't matter which.
|
||||||
|
var new_e = hist.map( function( job ){
|
||||||
|
var obj = _.pick( job, ['start', 'end'] );
|
||||||
|
if( obj && (obj.start || obj.end)) {
|
||||||
|
obj = _.pairs( obj );
|
||||||
|
obj[0][1] = FluentDate.fmt( obj[0][1] );
|
||||||
|
if( obj.length > 1 )
|
||||||
|
obj[1][1] = FluentDate.fmt( obj[1][1] );
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Flatten the array, remove empties, and sort
|
||||||
|
new_e = _.filter( _.flatten( new_e, true ), function(v) {
|
||||||
|
return ( v && v.length && v[0] && v[0].length );
|
||||||
|
});
|
||||||
|
if( !new_e || !new_e.length ) return coverage;
|
||||||
|
new_e = _.sortBy( new_e, function( elem ) { return elem[1].unix(); });
|
||||||
|
|
||||||
|
// Iterate over elements in the array. Each time a start date is found,
|
||||||
|
// increment a reference count. Each time an end date is found, decrement
|
||||||
|
// the reference count. When the reference count reaches 0, we have a gap.
|
||||||
|
// When the reference count is > 0, the candidate is employed. When the
|
||||||
|
// reference count reaches 2, the candidate is overlapped.
|
||||||
|
|
||||||
|
var num_gaps = 0, ref_count = 0, total_gap_days = 0, gap_start;
|
||||||
|
|
||||||
|
new_e.forEach( function(point) {
|
||||||
|
|
||||||
|
var inc = point[0] === 'start' ? 1 : -1;
|
||||||
|
ref_count += inc;
|
||||||
|
|
||||||
|
// If the ref count just reached 0, start a new GAP
|
||||||
|
if( ref_count === 0 ) {
|
||||||
|
coverage.gaps.push( { start: point[1], end: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the ref count reached 1 by rising, end the last GAP
|
||||||
|
else if( ref_count === 1 && inc === 1 ) {
|
||||||
|
var lastGap = _.last( coverage.gaps );
|
||||||
|
if( lastGap ) {
|
||||||
|
lastGap.end = point[1];
|
||||||
|
lastGap.duration = lastGap.end.diff( lastGap.start, 'days' );
|
||||||
|
total_gap_days += lastGap.duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the ref count reaches 2 by rising, start a new OVERLAP
|
||||||
|
else if( ref_count === 2 && inc === 1 ) {
|
||||||
|
coverage.overlaps.push( { start: point[1], end: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the ref count reaches 1 by falling, end the last OVERLAP
|
||||||
|
else if( ref_count === 1 && inc === -1 ) {
|
||||||
|
var lastOver = _.last( coverage.overlaps );
|
||||||
|
if( lastOver ) {
|
||||||
|
lastOver.end = point[1];
|
||||||
|
lastOver.duration = lastOver.end.diff( lastOver.start, 'days' );
|
||||||
|
if( lastOver.duration === 0 ) {
|
||||||
|
coverage.overlaps.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// It's possible that the last gap/overlap didn't have an explicit .end
|
||||||
|
// date.If so, set the end date to the present date and compute the
|
||||||
|
// duration normally.
|
||||||
|
if( coverage.overlaps.length ) {
|
||||||
|
var o = _.last( coverage.overlaps );
|
||||||
|
if( o && !o.end ) {
|
||||||
|
o.end = moment();
|
||||||
|
o.duration = o.end.diff( o.start, 'days' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( coverage.gaps.length ) {
|
||||||
|
var g = _.last( coverage.gaps );
|
||||||
|
if( g && !g.end ) {
|
||||||
|
g.end = moment();
|
||||||
|
g.duration = g.end.diff( g.start, 'days' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Package data for return to the client
|
||||||
|
var tdur = rez.duration('days');
|
||||||
|
var dur = {
|
||||||
|
total: tdur,
|
||||||
|
work: tdur - total_gap_days,
|
||||||
|
gaps: total_gap_days
|
||||||
|
};
|
||||||
|
coverage.pct = ( dur.total > 0 && dur.work > 0 ) ?
|
||||||
|
((((dur.total - dur.gaps) / dur.total) * 100)).toFixed(1) + '%' :
|
||||||
|
'???';
|
||||||
|
coverage.duration = dur;
|
||||||
|
return coverage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
98
src/inspectors/keyword-inspector.js
Normal file
98
src/inspectors/keyword-inspector.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
Keyword analysis for HackMyResume.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module keyword-inspector.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
var FluentDate = require('../core/fluent-date');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Analyze the resume's use of keywords.
|
||||||
|
TODO: BUG: Keyword search regex is inaccurate, especially for one or two
|
||||||
|
letter keywords like "C" or "CLI".
|
||||||
|
@class keywordInspector
|
||||||
|
*/
|
||||||
|
var keywordInspector = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
A unique name for this inspector.
|
||||||
|
*/
|
||||||
|
moniker: 'keyword-inspector',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Run the Keyword Inspector on a resume.
|
||||||
|
@method run
|
||||||
|
@return An collection of statistical keyword data.
|
||||||
|
*/
|
||||||
|
run: function( rez ) {
|
||||||
|
|
||||||
|
// "Quote" or safely escape a keyword so it can be used as a regex. For
|
||||||
|
// example, if the keyword is "C++", yield "C\+\+".
|
||||||
|
// http://stackoverflow.com/a/2593661/4942583
|
||||||
|
function regex_quote(str) {
|
||||||
|
return (str + '').replace(/[.?*+^$[\]\\(){}|-]/ig, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a searchable plain-text digest of the resume
|
||||||
|
// TODO: BUG: Don't search within keywords for other keywords. Job A
|
||||||
|
// declares the "foo" keyword. Job B declares the "foo & bar" keyword. Job
|
||||||
|
// B's mention of "foobar" should not count as a mention of "foo".
|
||||||
|
// To achieve this, remove keywords from the search digest and treat them
|
||||||
|
// separately.
|
||||||
|
var searchable = '';
|
||||||
|
rez.transformStrings( ['imp', 'computed', 'safe'], function trxString( key, val ) {
|
||||||
|
searchable += ' ' + val;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assemble a regex skeleton we can use to test for keywords with a bit
|
||||||
|
// more
|
||||||
|
var prefix = '(?:' + ['^', '\\s+', '[\\.,]+'].join('|') + ')';
|
||||||
|
var suffix = '(?:' + ['$', '\\s+', '[\\.,]+'].join('|') + ')';
|
||||||
|
|
||||||
|
return rez.keywords().map(function(kw) {
|
||||||
|
|
||||||
|
// 1. Using word boundary or other regex class is inaccurate
|
||||||
|
//
|
||||||
|
// var regex = new RegExp( '\\b' + regex_quote( kw )/* + '\\b'*/, 'ig');
|
||||||
|
//
|
||||||
|
// 2. Searching for the raw keyword is inaccurate ("C" will match any
|
||||||
|
// word containing a 'c'!).
|
||||||
|
//
|
||||||
|
// var regex = new RegExp( regex_quote( kw ), 'ig');
|
||||||
|
//
|
||||||
|
// 3. Instead, use a custom regex with special delimeters.
|
||||||
|
|
||||||
|
var regex_str = prefix + regex_quote( kw ) + suffix;
|
||||||
|
var regex = new RegExp( regex_str, 'ig');
|
||||||
|
var myArray, count = 0;
|
||||||
|
while ((myArray = regex.exec( searchable )) !== null) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name: kw,
|
||||||
|
count: count
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
63
src/inspectors/totals-inspector.js
Normal file
63
src/inspectors/totals-inspector.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
Section analysis for HackMyResume.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module totals-inspector.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
var FluentDate = require('../core/fluent-date');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Retrieve sectional overview and summary information.
|
||||||
|
@class totalsInspector
|
||||||
|
*/
|
||||||
|
var totalsInspector = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
moniker: 'totals-inspector',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Run the Totals Inspector on a resume.
|
||||||
|
@method run
|
||||||
|
@return An object containing summary information for each section on the
|
||||||
|
resume.
|
||||||
|
*/
|
||||||
|
run: function( rez ) {
|
||||||
|
|
||||||
|
var sectionTotals = { };
|
||||||
|
_.each( rez, function(val, key){
|
||||||
|
if( _.isArray( val ) && !_.isString(val) ) {
|
||||||
|
sectionTotals[ key ] = val.length;
|
||||||
|
}
|
||||||
|
else if( val.history && _.isArray( val.history ) ) {
|
||||||
|
sectionTotals[ key ] = val.history.length;
|
||||||
|
}
|
||||||
|
else if( val.sets && _.isArray( val.sets ) ) {
|
||||||
|
sectionTotals[ key ] = val.sets.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
totals: sectionTotals,
|
||||||
|
numSections: Object.keys( sectionTotals ).length
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
119
src/renderers/handlebars-generator.js
Normal file
119
src/renderers/handlebars-generator.js
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
Definition of the HandlebarsGenerator class.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module renderers/handlebars-generator
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore')
|
||||||
|
, HANDLEBARS = require('handlebars')
|
||||||
|
, FS = require('fs')
|
||||||
|
, registerHelpers = require('../helpers/handlebars-helpers')
|
||||||
|
, PATH = require('path')
|
||||||
|
, parsePath = require('parse-filepath')
|
||||||
|
, READFILES = require('recursive-readdir-sync')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, SLASH = require('slash');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Perform template-based resume generation using Handlebars.js.
|
||||||
|
@class HandlebarsGenerator
|
||||||
|
*/
|
||||||
|
var HandlebarsGenerator = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
generateSimple: function( data, tpl ) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Compile and run the Handlebars template.
|
||||||
|
var template = HANDLEBARS.compile( tpl, { strict: false, assumeObjects: false } );
|
||||||
|
return template( data );
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
throw {
|
||||||
|
fluenterror: template ?
|
||||||
|
HMSTATUS.invokeTemplate : HMSTATUS.compileTemplate,
|
||||||
|
inner: ex
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
generate: function( json, jst, format, curFmt, opts, theme ) {
|
||||||
|
|
||||||
|
// Set up partials and helpers
|
||||||
|
registerPartials( format, theme );
|
||||||
|
registerHelpers( theme, opts );
|
||||||
|
|
||||||
|
// Preprocess text
|
||||||
|
var encData = json;
|
||||||
|
( format === 'html' || format === 'pdf' ) && (encData = json.markdownify());
|
||||||
|
( format === 'doc' ) && (encData = json.xmlify());
|
||||||
|
|
||||||
|
// Set up the context
|
||||||
|
var ctx = {
|
||||||
|
r: encData,
|
||||||
|
RAW: json,
|
||||||
|
filt: opts.filters,
|
||||||
|
format: format,
|
||||||
|
opts: opts,
|
||||||
|
engine: this,
|
||||||
|
results: curFmt.files,
|
||||||
|
headFragment: opts.headFragment || ''
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render the template
|
||||||
|
return this.generateSimple( ctx, jst );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function registerPartials(format, theme) {
|
||||||
|
if( _.contains( ['html','doc','md','txt'], format )) {
|
||||||
|
|
||||||
|
// Locate the global partials folder
|
||||||
|
var partialsFolder = PATH.join(
|
||||||
|
parsePath( require.resolve('fresh-themes') ).dirname,
|
||||||
|
'/partials/',
|
||||||
|
format
|
||||||
|
);
|
||||||
|
|
||||||
|
// Register global partials in the /partials/[format] folder
|
||||||
|
// TODO: Only do this once per HMR invocation.
|
||||||
|
_.each( READFILES( partialsFolder, function(error){ }), function( el ) {
|
||||||
|
var pathInfo = parsePath( el );
|
||||||
|
var name = SLASH( PATH.relative( partialsFolder, el )
|
||||||
|
.replace(/\.(?:html|xml|hbs|md|txt)$/i, '') );
|
||||||
|
var tplData = FS.readFileSync( el, 'utf8' );
|
||||||
|
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||||
|
HANDLEBARS.registerPartial( name, compiledTemplate );
|
||||||
|
theme.partialsInitialized = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register theme-specific partials
|
||||||
|
_.each( theme.partials, function( el ) {
|
||||||
|
var tplData = FS.readFileSync( el.path, 'utf8' );
|
||||||
|
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||||
|
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
65
src/renderers/jrs-generator.js
Normal file
65
src/renderers/jrs-generator.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
Definition of the JRSGenerator class.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module jrs-generator.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore')
|
||||||
|
, HANDLEBARS = require('handlebars')
|
||||||
|
, FS = require('fs')
|
||||||
|
, registerHelpers = require('../helpers/handlebars-helpers')
|
||||||
|
, PATH = require('path')
|
||||||
|
, parsePath = require('parse-filepath')
|
||||||
|
, READFILES = require('recursive-readdir-sync')
|
||||||
|
, SLASH = require('slash')
|
||||||
|
, MD = require('marked');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Perform template-based resume generation for JSON Resume themes.
|
||||||
|
@class JRSGenerator
|
||||||
|
*/
|
||||||
|
var JRSGenerator = module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
|
|
||||||
|
// Disable JRS theme chatter (console.log, console.error, etc.)
|
||||||
|
var off = ['log', 'error', 'dir'], org = off.map(function(c){
|
||||||
|
var ret = console[c]; console[c] = function(){}; return ret;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Freeze and render
|
||||||
|
var rezHtml = theme.render( json.harden() );
|
||||||
|
|
||||||
|
// Turn logging back on
|
||||||
|
off.forEach(function(c, idx){ console[c] = org[idx]; });
|
||||||
|
|
||||||
|
// Unfreeze and apply Markdown
|
||||||
|
rezHtml = rezHtml.replace( /@@@@~.*?~@@@@/gm, function(val){
|
||||||
|
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
|
||||||
|
});
|
||||||
|
|
||||||
|
return rezHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function MDIN(txt) { // TODO: Move this
|
||||||
|
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -8,7 +8,9 @@ Definition of the UnderscoreGenerator class.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore')
|
||||||
|
, registerHelpers = require('../helpers/underscore-helpers')
|
||||||
|
, HMSTATUS = require('../core/status-codes');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +19,23 @@ Definition of the UnderscoreGenerator class.
|
|||||||
*/
|
*/
|
||||||
var UnderscoreGenerator = module.exports = {
|
var UnderscoreGenerator = module.exports = {
|
||||||
|
|
||||||
|
generateSimple: function( data, tpl ) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Compile and run the Handlebars template.
|
||||||
|
var template = _.template( tpl );
|
||||||
|
return template( data );
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
throw {
|
||||||
|
fluenterror: template ?
|
||||||
|
HMSTATUS.invokeTemplate : HMSTATUS.compileTemplate,
|
||||||
|
inner: ex
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
|
|
||||||
// Tweak underscore's default template delimeters
|
// Tweak underscore's default template delimeters
|
||||||
@ -31,23 +50,20 @@ Definition of the UnderscoreGenerator class.
|
|||||||
// Strip {# comments #}
|
// Strip {# comments #}
|
||||||
jst = jst.replace( delims.comment, '');
|
jst = jst.replace( delims.comment, '');
|
||||||
|
|
||||||
var helpers = require('./generic-helpers');
|
var ctx = {
|
||||||
helpers.opts = opts;
|
|
||||||
helpers.cssInfo = cssInfo;
|
|
||||||
|
|
||||||
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
|
||||||
var compiled = _.template(jst);
|
|
||||||
var ret = compiled({
|
|
||||||
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
|
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
|
||||||
filt: opts.filters,
|
filt: opts.filters,
|
||||||
XML: require('xml-escape'),
|
XML: require('xml-escape'),
|
||||||
RAW: json,
|
RAW: json,
|
||||||
cssInfo: cssInfo,
|
cssInfo: cssInfo,
|
||||||
|
//engine: this,
|
||||||
headFragment: opts.headFragment || '',
|
headFragment: opts.headFragment || '',
|
||||||
opts: opts,
|
opts: opts
|
||||||
h: helpers
|
};
|
||||||
});
|
|
||||||
return ret;
|
registerHelpers( theme, opts, cssInfo, ctx, this );
|
||||||
|
|
||||||
|
return this.generateSimple( ctx, jst );
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
25
src/use.txt
25
src/use.txt
@ -1,25 +0,0 @@
|
|||||||
Usage:
|
|
||||||
|
|
||||||
hackmyresume <COMMAND> <SOURCES> [TO <TARGETS>] [-t <THEME>] [-f <FORMAT>]
|
|
||||||
|
|
||||||
<COMMAND> should be BUILD, NEW, CONVERT, VALIDATE, or HELP. <SOURCES> should
|
|
||||||
be the path to one or more FRESH or JSON Resume format resumes. <TARGETS>
|
|
||||||
should be the name of the destination resume to be created, if any. The
|
|
||||||
<THEME> parameter should be the name of a predefined theme (for example:
|
|
||||||
COMPACT, MINIMIST, MODERN, or HELLO-WORLD) or the relative path to a custom
|
|
||||||
theme. <FORMAT> should be either FRESH (for a FRESH-format resume) or JRS
|
|
||||||
(for a JSON Resume-format resume).
|
|
||||||
|
|
||||||
hackmyresume BUILD resume.json TO out/resume.all
|
|
||||||
hackmyresume NEW resume.json
|
|
||||||
hackmyresume CONVERT resume.json TO resume-jrs.json
|
|
||||||
hackmyresume VALIDATE resume.json
|
|
||||||
|
|
||||||
Both SOURCES and TARGETS can accept multiple files:
|
|
||||||
|
|
||||||
hackmyresume BUILD r1.json r2.json TO out/resume.all out2/resume.html
|
|
||||||
hackmyresume NEW r1.json r2.json r3.json
|
|
||||||
hackmyresume VALIDATE resume.json resume2.json resume3.json
|
|
||||||
|
|
||||||
See https://github.com/hacksalot/hackmyresume/blob/master/README.md for more
|
|
||||||
information.
|
|
@ -1,79 +0,0 @@
|
|||||||
/**
|
|
||||||
Definition of the `extend` method.
|
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
|
||||||
@module extend.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
function _extend() {
|
|
||||||
|
|
||||||
function isPlainObject( obj ) {
|
|
||||||
if ((typeof obj !== "object") || obj.nodeType ||
|
|
||||||
(obj !== null && obj === obj.window)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (obj.constructor &&
|
|
||||||
!hasOwnProperty.call( obj.constructor.prototype, "isPrototypeOf" )) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var options
|
|
||||||
, name
|
|
||||||
, src
|
|
||||||
, copy
|
|
||||||
, copyIsArray
|
|
||||||
, clone
|
|
||||||
, target = arguments[0] || {}
|
|
||||||
, i = 1
|
|
||||||
, length = arguments.length
|
|
||||||
, deep = false;
|
|
||||||
|
|
||||||
// Handle a deep copy situation
|
|
||||||
if (typeof target === "boolean") {
|
|
||||||
deep = target;
|
|
||||||
// Skip the boolean and the target
|
|
||||||
target = arguments[i] || {};
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle case when target is a string or something (possible in deep copy)
|
|
||||||
//if (typeof target !== "object" && !jQuery.isFunction(target))
|
|
||||||
if (typeof target !== "object" && typeof target !== "function")
|
|
||||||
target = {};
|
|
||||||
|
|
||||||
for (; i < length; i++) {
|
|
||||||
// Only deal with non-null/undefined values
|
|
||||||
if ((options = arguments[i]) !== null) {
|
|
||||||
// Extend the base object
|
|
||||||
for (name in options) {
|
|
||||||
src = target[name];
|
|
||||||
copy = options[name];
|
|
||||||
|
|
||||||
// Prevent never-ending loop
|
|
||||||
if (target === copy) continue;
|
|
||||||
|
|
||||||
// Recurse if we're merging plain objects or arrays
|
|
||||||
if (deep && copy && (isPlainObject(copy) ||
|
|
||||||
(copyIsArray = (copy.constructor === Array)))) {
|
|
||||||
if (copyIsArray) {
|
|
||||||
copyIsArray = false;
|
|
||||||
clone = src && (src.constructor === Array) ? src : [];
|
|
||||||
} else {
|
|
||||||
clone = src && isPlainObject(src) ? src : {};
|
|
||||||
}
|
|
||||||
// Never move original objects, clone them
|
|
||||||
target[name] = _extend(deep, clone, copy);
|
|
||||||
// Don't bring in undefined values
|
|
||||||
} else if (copy !== undefined) {
|
|
||||||
target[name] = copy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the modified object
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = _extend;
|
|
12
src/utils/file-contains.js
Normal file
12
src/utils/file-contains.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
Definition of the SyntaxErrorEx class.
|
||||||
|
@module file-contains.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
module.exports = function( file, needle ) {
|
||||||
|
return require('fs').readFileSync(file,'utf-8').indexOf( needle ) > -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
19
src/utils/md2chalk.js
Normal file
19
src/utils/md2chalk.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
Inline Markdown-to-Chalk conversion routines.
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
@module md2chalk.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
var MD = require('marked');
|
||||||
|
var CHALK = require('chalk');
|
||||||
|
var LO = require('lodash');
|
||||||
|
|
||||||
|
module.exports = function( v, style, boldStyle ) {
|
||||||
|
boldStyle = boldStyle || 'bold';
|
||||||
|
var temp = v.replace(/\*\*(.*?)\*\*/g, LO.get( CHALK, boldStyle )('$1'));
|
||||||
|
return style ? LO.get( CHALK, style )(temp) : temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
56
src/utils/rasterize.js
Normal file
56
src/utils/rasterize.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Exemplar script for generating documents with Phantom.js.
|
||||||
|
// https://raw.githubusercontent.com/ariya/phantomjs/master/examples/rasterize.js
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
var page = require('webpage').create(),
|
||||||
|
system = require('system'),
|
||||||
|
address, output, size;
|
||||||
|
|
||||||
|
if (system.args.length < 3 || system.args.length > 5) {
|
||||||
|
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
|
||||||
|
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
||||||
|
console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px');
|
||||||
|
console.log(' "800px*600px" window, clipped to 800x600');
|
||||||
|
phantom.exit(1);
|
||||||
|
} else {
|
||||||
|
address = system.args[1];
|
||||||
|
output = system.args[2];
|
||||||
|
page.viewportSize = { width: 600, height: 600 };
|
||||||
|
if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
|
||||||
|
size = system.args[3].split('*');
|
||||||
|
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
|
||||||
|
: { format: system.args[3], orientation: 'portrait', margin: '1cm' };
|
||||||
|
} else if (system.args.length > 3 && system.args[3].substr(-2) === "px") {
|
||||||
|
size = system.args[3].split('*');
|
||||||
|
if (size.length === 2) {
|
||||||
|
pageWidth = parseInt(size[0], 10);
|
||||||
|
pageHeight = parseInt(size[1], 10);
|
||||||
|
page.viewportSize = { width: pageWidth, height: pageHeight };
|
||||||
|
page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };
|
||||||
|
} else {
|
||||||
|
console.log("size:", system.args[3]);
|
||||||
|
pageWidth = parseInt(system.args[3], 10);
|
||||||
|
pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any
|
||||||
|
console.log ("pageHeight:",pageHeight);
|
||||||
|
page.viewportSize = { width: pageWidth, height: pageHeight };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (system.args.length > 4) {
|
||||||
|
page.zoomFactor = system.args[4];
|
||||||
|
}
|
||||||
|
page.open(address, function (status) {
|
||||||
|
if (status !== 'success') {
|
||||||
|
console.log('Unable to load the address!');
|
||||||
|
phantom.exit(1);
|
||||||
|
} else {
|
||||||
|
window.setTimeout(function () {
|
||||||
|
page.render(output);
|
||||||
|
phantom.exit();
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}());
|
46
src/utils/safe-json-loader.js
Normal file
46
src/utils/safe-json-loader.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
Definition of the SafeJsonLoader class.
|
||||||
|
@module syntax-error-ex.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var FS = require('fs')
|
||||||
|
, SyntaxErrorEx = require('./syntax-error-ex');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function loadSafeJson( file ) {
|
||||||
|
|
||||||
|
var ret = { };
|
||||||
|
try {
|
||||||
|
|
||||||
|
ret.raw = FS.readFileSync( file, 'utf8' );
|
||||||
|
ret.json = JSON.parse( ret.raw );
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
|
||||||
|
// If we get here, either FS.readFileSync or JSON.parse failed.
|
||||||
|
// We'll return HMSTATUS.readError or HMSTATUS.parseError.
|
||||||
|
var retRaw = ret.raw && ret.raw.trim();
|
||||||
|
|
||||||
|
ret.ex = {
|
||||||
|
operation: retRaw ? 'parse' : 'read',
|
||||||
|
inner: SyntaxErrorEx.is( ex ) ? (new SyntaxErrorEx( ex, retRaw )) : ex,
|
||||||
|
file: file
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
45
src/utils/safe-spawn.js
Normal file
45
src/utils/safe-spawn.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
Safe spawn utility for HackMyResume / FluentCV.
|
||||||
|
@module safe-spawn.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function( cmd, args, isSync ) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
var spawn = require('child_process')[ isSync? 'spawnSync' : 'spawn'];
|
||||||
|
var info = spawn( cmd, args );
|
||||||
|
|
||||||
|
if( !isSync ) {
|
||||||
|
info.on('error', function(err) {
|
||||||
|
throw {
|
||||||
|
cmd: 'wkhtmltopdf',
|
||||||
|
inner: err
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( info.error ) {
|
||||||
|
throw {
|
||||||
|
cmd: 'wkhtmltopdf',
|
||||||
|
inner: info.error
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
65
src/utils/string-transformer.js
Normal file
65
src/utils/string-transformer.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
Object string transformation.
|
||||||
|
@module string-transformer.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
|
var moment = require('moment');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a copy of this object in which all string fields have been run through
|
||||||
|
a transformation function (such as a Markdown filter or XML encoder).
|
||||||
|
*/
|
||||||
|
module.exports = function( ret, filt, transformer ) {
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
// TODO: refactor recursion
|
||||||
|
function transformStringsInObject( obj, filters ) {
|
||||||
|
|
||||||
|
if( !obj ) return;
|
||||||
|
if( moment.isMoment( obj ) ) return;
|
||||||
|
|
||||||
|
if( _.isArray( obj ) ) {
|
||||||
|
obj.forEach( function(elem, idx, ar) {
|
||||||
|
if( typeof elem === 'string' || elem instanceof String )
|
||||||
|
ar[idx] = transformer( null, elem );
|
||||||
|
else if (_.isObject(elem))
|
||||||
|
transformStringsInObject( elem, filters );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (_.isObject( obj )) {
|
||||||
|
Object.keys( obj ).forEach(function(k) {
|
||||||
|
if( filters.length && _.contains(filters, k) )
|
||||||
|
return;
|
||||||
|
var sub = obj[k];
|
||||||
|
if( typeof sub === 'string' || sub instanceof String ) {
|
||||||
|
obj[k] = transformer( k, sub );
|
||||||
|
}
|
||||||
|
else if (_.isObject( sub ))
|
||||||
|
transformStringsInObject( sub, filters );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys( ret ).forEach(function(member){
|
||||||
|
if( !filt || !filt.length || !_.contains(filt, member) )
|
||||||
|
transformStringsInObject( ret[ member ], filt || [] );
|
||||||
|
});
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -1,6 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
Definition of the SyntaxErrorEx class.
|
Definition of the SyntaxErrorEx class.
|
||||||
@module syntax-error-ex.js
|
@module syntax-error-ex.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@ -10,31 +11,25 @@ Definition of the SyntaxErrorEx class.
|
|||||||
Represents a SyntaxError exception with line and column info.
|
Represents a SyntaxError exception with line and column info.
|
||||||
Collect syntax error information from the provided exception object. The
|
Collect syntax error information from the provided exception object. The
|
||||||
JavaScript `SyntaxError` exception isn't interpreted uniformly across environ-
|
JavaScript `SyntaxError` exception isn't interpreted uniformly across environ-
|
||||||
ments, so we first check for a .lineNumber and .columnNumber and, if that's
|
ments, so we reparse on error to grab the line and column.
|
||||||
not present, fall back to the JSONLint library, which provides that info.
|
|
||||||
See: http://stackoverflow.com/q/13323356
|
See: http://stackoverflow.com/q/13323356
|
||||||
@class SyntaxErrorEx
|
@class SyntaxErrorEx
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function SyntaxErrorEx( ex, rawData ) {
|
function SyntaxErrorEx( ex, rawData ) {
|
||||||
|
|
||||||
var lineNum = null, colNum = null;
|
var lineNum = null, colNum = null;
|
||||||
if( ex.lineNumber !== undefined && ex.lineNumber !== null ) {
|
|
||||||
lineNum = ex.lineNumber;
|
|
||||||
}
|
|
||||||
if( ex.columnNumber !== undefined && ex.columnNumber !== null ) {
|
|
||||||
colNum = ex.columnNumber;
|
|
||||||
}
|
|
||||||
if( lineNum === null || colNum === null ) {
|
|
||||||
var JSONLint = require('json-lint');
|
var JSONLint = require('json-lint');
|
||||||
var lint = JSONLint( rawData, { comments: false } );
|
var lint = JSONLint( rawData, { comments: false } );
|
||||||
if( lineNum === null ) lineNum = (lint.error ? lint.line : '???');
|
this.line = (lint.error ? lint.line : '???');
|
||||||
if( colNum === null ) colNum = (lint.error ? lint.character : '???');
|
this.col = (lint.error ? lint.character : '???');
|
||||||
}
|
|
||||||
this.line = lineNum;
|
|
||||||
this.col = colNum;
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SyntaxErrorEx.is = function( ex ) {
|
||||||
|
return ex instanceof SyntaxError;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = SyntaxErrorEx;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
94
src/verbs/analyze.js
Normal file
94
src/verbs/analyze.js
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
Implementation of the 'analyze' verb for HackMyResume.
|
||||||
|
@module verbs/analyze
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var MKDIRP = require('mkdirp')
|
||||||
|
, PATH = require('path')
|
||||||
|
, HMEVENT = require('../core/event-codes')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, ResumeFactory = require('../core/resume-factory')
|
||||||
|
, Verb = require('../verbs/verb')
|
||||||
|
, chalk = require('chalk');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var AnalyzeVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super('analyze');
|
||||||
|
},
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'analyze' });
|
||||||
|
analyze.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.end );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Run the 'analyze' command.
|
||||||
|
*/
|
||||||
|
function analyze( sources, dst, opts ) {
|
||||||
|
if( !sources || !sources.length )
|
||||||
|
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||||
|
|
||||||
|
var nlzrs = _loadInspectors();
|
||||||
|
|
||||||
|
_.each(sources, function(src) {
|
||||||
|
var result = ResumeFactory.loadOne( src, {
|
||||||
|
format: 'FRESH', objectify: true
|
||||||
|
}, this);
|
||||||
|
if( result.fluenterror )
|
||||||
|
this.setError( result.fluenterror, result );
|
||||||
|
else
|
||||||
|
_analyze.call(this, result, nlzrs, opts );
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Analyze a single resume.
|
||||||
|
*/
|
||||||
|
function _analyze( resumeObject, nlzrs, opts ) {
|
||||||
|
var rez = resumeObject.rez;
|
||||||
|
var safeFormat =
|
||||||
|
(rez.meta && rez.meta.format && rez.meta.format.startsWith('FRESH')) ?
|
||||||
|
'FRESH' : 'JRS';
|
||||||
|
|
||||||
|
this.stat( HMEVENT.beforeAnalyze, { fmt: safeFormat, file: resumeObject.file });
|
||||||
|
var info = _.mapObject( nlzrs, function(val, key) {
|
||||||
|
return val.run( resumeObject.rez );
|
||||||
|
});
|
||||||
|
this.stat( HMEVENT.afterAnalyze, { info: info } );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load inspectors.
|
||||||
|
*/
|
||||||
|
function _loadInspectors() {
|
||||||
|
return {
|
||||||
|
totals: require('../inspectors/totals-inspector'),
|
||||||
|
coverage: require('../inspectors/gap-inspector'),
|
||||||
|
keywords: require('../inspectors/keyword-inspector')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
385
src/verbs/build.js
Normal file
385
src/verbs/build.js
Normal file
@ -0,0 +1,385 @@
|
|||||||
|
/**
|
||||||
|
Implementation of the 'build' verb for HackMyResume.
|
||||||
|
@module verbs/build
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var _ = require('underscore')
|
||||||
|
, PATH = require('path')
|
||||||
|
, FS = require('fs')
|
||||||
|
, MD = require('marked')
|
||||||
|
, MKDIRP = require('mkdirp')
|
||||||
|
, extend = require('extend')
|
||||||
|
, parsePath = require('parse-filepath')
|
||||||
|
, RConverter = require('fresh-jrs-converter')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, HMEVENT = require('../core/event-codes')
|
||||||
|
, RTYPES = { FRESH: require('../core/fresh-resume'),
|
||||||
|
JRS: require('../core/jrs-resume') }
|
||||||
|
, _opts = require('../core/default-options')
|
||||||
|
, FRESHTheme = require('../core/fresh-theme')
|
||||||
|
, JRSTheme = require('../core/jrs-theme')
|
||||||
|
, ResumeFactory = require('../core/resume-factory')
|
||||||
|
, _fmts = require('../core/default-formats')
|
||||||
|
, Verb = require('../verbs/verb');
|
||||||
|
|
||||||
|
var _err, _log, _rezObj;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** An invokable resume generation command. */
|
||||||
|
var BuildVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
/** Create a new build verb. */
|
||||||
|
init: function() {
|
||||||
|
this._super('build');
|
||||||
|
},
|
||||||
|
|
||||||
|
/** Invoke the Build command. */
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'build' } );
|
||||||
|
var ret = build.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.end );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
||||||
|
theme file, generate 0..N resumes in the desired formats.
|
||||||
|
@param src Path to the source JSON resume file: "rez/resume.json".
|
||||||
|
@param dst An array of paths to the target resume file(s).
|
||||||
|
@param theme Friendly name of the resume theme. Defaults to "modern".
|
||||||
|
@param logger Optional logging override.
|
||||||
|
*/
|
||||||
|
function build( src, dst, opts ) {
|
||||||
|
|
||||||
|
if( !src || !src.length ) {
|
||||||
|
this.err( HMSTATUS.resumeNotFound, { quit: true } );
|
||||||
|
}
|
||||||
|
|
||||||
|
prep( src, dst, opts );
|
||||||
|
|
||||||
|
// Load input resumes as JSON...
|
||||||
|
var sheetObjects = ResumeFactory.load(src, {
|
||||||
|
format: null, objectify: false, quit: true, inner: { sort: _opts.sort }
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Explicit check for any resume loading errors...
|
||||||
|
if( !sheetObjects ||
|
||||||
|
_.some( sheetObjects, function(so) { return so.fluenterror; } ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sheets = sheetObjects.map(function(r) { return r.json; });
|
||||||
|
|
||||||
|
// Load the theme...
|
||||||
|
var theme;
|
||||||
|
this.stat( HMEVENT.beforeTheme, { theme: _opts.theme });
|
||||||
|
try {
|
||||||
|
var tFolder = verifyTheme.call( this, _opts.theme );
|
||||||
|
theme = _opts.themeObj = loadTheme( tFolder );
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
var newEx = {
|
||||||
|
fluenterror: HMSTATUS.themeLoad,
|
||||||
|
inner: ex,
|
||||||
|
attempted: _opts.theme
|
||||||
|
};
|
||||||
|
this.err( HMSTATUS.themeLoad, newEx );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this.stat( HMEVENT.afterTheme, { theme: theme });
|
||||||
|
|
||||||
|
// Check for invalid outputs...
|
||||||
|
var inv = verifyOutputs.call( this, dst, theme );
|
||||||
|
if( inv && inv.length ) {
|
||||||
|
this.err( HMSTATUS.invalidFormat, { data: inv, theme: theme } );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge input resumes, yielding a single source resume.
|
||||||
|
var rez;
|
||||||
|
if( sheets.length > 1 ) {
|
||||||
|
var isFRESH = !sheets[0].basics;
|
||||||
|
var mixed = _.any( sheets, function(s) { return isFRESH ? s.basics : !s.basics; });
|
||||||
|
this.stat( HMEVENT.beforeMerge, { f: _.clone(sheetObjects), mixed: mixed });
|
||||||
|
if( mixed ) {
|
||||||
|
this.err( HMSTATUS.mixedMerge );
|
||||||
|
}
|
||||||
|
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
||||||
|
return extend( true, b, a );
|
||||||
|
});
|
||||||
|
this.stat( HMEVENT.afterMerge, { r: rez } );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rez = sheets[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the merged source resume to the theme's format, if necessary
|
||||||
|
var orgFormat = rez.basics ? 'JRS' : 'FRESH';
|
||||||
|
var toFormat = theme.render ? 'JRS' : 'FRESH';
|
||||||
|
if( toFormat !== orgFormat ) {
|
||||||
|
this.stat( HMEVENT.beforeInlineConvert );
|
||||||
|
rez = RConverter[ 'to' + toFormat ]( rez );
|
||||||
|
this.stat( HMEVENT.afterInlineConvert, { file: sheetObjects[0].file, fmt: toFormat });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add freebie formats to the theme
|
||||||
|
addFreebieFormats( theme );
|
||||||
|
this.stat( HMEVENT.applyTheme, { r: rez, theme: theme });
|
||||||
|
|
||||||
|
// Load the resume into a FRESHResume or JRSResume object
|
||||||
|
_rezObj = new (RTYPES[ toFormat ])().parseJSON( rez );
|
||||||
|
|
||||||
|
// Expand output resumes...
|
||||||
|
var targets = expand( dst, theme );
|
||||||
|
|
||||||
|
// Run the transformation!
|
||||||
|
_.each(targets, function(t) {
|
||||||
|
t.final = single.call( this, t, theme, targets );
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Don't send the client back empty-handed
|
||||||
|
return { sheet: _rezObj, targets: targets, processed: targets };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Prepare for a BUILD run.
|
||||||
|
*/
|
||||||
|
function prep( src, dst, opts ) {
|
||||||
|
|
||||||
|
// Cherry-pick options //_opts = extend( true, _opts, opts );
|
||||||
|
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim()) || 'modern';
|
||||||
|
_opts.prettify = opts.prettify === true;
|
||||||
|
_opts.css = opts.css;
|
||||||
|
_opts.pdf = opts.pdf;
|
||||||
|
_opts.wrap = opts.wrap || 60;
|
||||||
|
_opts.stitles = opts.sectionTitles;
|
||||||
|
_opts.tips = opts.tips;
|
||||||
|
_opts.errHandler = opts.errHandler;
|
||||||
|
_opts.noTips = opts.noTips;
|
||||||
|
_opts.debug = opts.debug;
|
||||||
|
_opts.sort = opts.sort;
|
||||||
|
|
||||||
|
// If two or more files are passed to the GENERATE command and the TO
|
||||||
|
// keyword is omitted, the last file specifies the output file.
|
||||||
|
( src.length > 1 && ( !dst || !dst.length ) ) && dst.push( src.pop() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generate a single target resume such as "out/rez.html" or "out/rez.doc".
|
||||||
|
TODO: Refactor.
|
||||||
|
@param targInfo Information for the target resume.
|
||||||
|
@param theme A FRESHTheme or JRSTheme object.
|
||||||
|
*/
|
||||||
|
function single( targInfo, theme, finished ) {
|
||||||
|
|
||||||
|
var ret, ex, f = targInfo.file;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if( !targInfo.fmt ) { return; }
|
||||||
|
var fType = targInfo.fmt.outFormat
|
||||||
|
, fName = PATH.basename(f, '.' + fType)
|
||||||
|
, theFormat;
|
||||||
|
|
||||||
|
this.stat( HMEVENT.beforeGenerate, {
|
||||||
|
fmt: targInfo.fmt.outFormat,
|
||||||
|
file: PATH.relative(process.cwd(), f)
|
||||||
|
});
|
||||||
|
|
||||||
|
// If targInfo.fmt.files exists, this format is backed by a document.
|
||||||
|
// Fluent/FRESH themes are handled here.
|
||||||
|
if( targInfo.fmt.files && targInfo.fmt.files.length ) {
|
||||||
|
theFormat = _fmts.filter(
|
||||||
|
function(fmt) { return fmt.name === targInfo.fmt.outFormat; })[0];
|
||||||
|
MKDIRP.sync( PATH.dirname( f ) ); // Ensure dest folder exists;
|
||||||
|
_opts.targets = finished;
|
||||||
|
ret = theFormat.gen.generate( _rezObj, f, _opts );
|
||||||
|
}
|
||||||
|
//Otherwise this is an ad-hoc format (JSON, YML, or PNG) that every theme
|
||||||
|
// gets "for free".
|
||||||
|
else {
|
||||||
|
theFormat = _fmts.filter( function(fmt) {
|
||||||
|
return fmt.name === targInfo.fmt.outFormat;
|
||||||
|
})[0];
|
||||||
|
var outFolder = PATH.dirname( f );
|
||||||
|
MKDIRP.sync( outFolder ); // Ensure dest folder exists;
|
||||||
|
ret = theFormat.gen.generate( _rezObj, f, _opts );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( e ) {
|
||||||
|
// Catch any errors caused by generating this file and don't let them
|
||||||
|
// propagate -- typically we want to continue processing other formats
|
||||||
|
// even if this format failed.
|
||||||
|
ex = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.stat( HMEVENT.afterGenerate, {
|
||||||
|
fmt: targInfo.fmt.outFormat,
|
||||||
|
file: PATH.relative( process.cwd(), f ),
|
||||||
|
error: ex
|
||||||
|
});
|
||||||
|
|
||||||
|
if( ex ) {
|
||||||
|
if( ex.fluenterror )
|
||||||
|
this.err( ex.fluenterror, ex );
|
||||||
|
else
|
||||||
|
this.err( HMSTATUS.generateError, { inner: ex } );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ensure that user-specified outputs/targets are valid.
|
||||||
|
*/
|
||||||
|
function verifyOutputs( targets, theme ) {
|
||||||
|
|
||||||
|
this.stat(HMEVENT.verifyOutputs, { targets: targets, theme: theme });
|
||||||
|
|
||||||
|
return _.reject(
|
||||||
|
targets.map( function( t ) {
|
||||||
|
var pathInfo = parsePath( t );
|
||||||
|
return {
|
||||||
|
format: pathInfo.extname.substr(1)
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
function(t) {
|
||||||
|
return t.format === 'all' || theme.hasFormat( t.format );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reinforce the chosen theme with "freebie" formats provided by HackMyResume.
|
||||||
|
A "freebie" format is an output format such as JSON, YML, or PNG that can be
|
||||||
|
generated directly from the resume model or from one of the theme's declared
|
||||||
|
output formats. For example, the PNG format can be generated for any theme
|
||||||
|
that declares an HTML format; the theme doesn't have to provide an explicit
|
||||||
|
PNG template.
|
||||||
|
@param theTheme A FRESHTheme or JRSTheme object.
|
||||||
|
*/
|
||||||
|
function addFreebieFormats( theTheme ) {
|
||||||
|
// Add freebie formats (JSON, YAML, PNG) every theme gets...
|
||||||
|
// Add HTML-driven PNG only if the theme has an HTML format.
|
||||||
|
theTheme.formats.json = theTheme.formats.json || {
|
||||||
|
freebie: true, title: 'json', outFormat: 'json', pre: 'json',
|
||||||
|
ext: 'json', path: null, data: null
|
||||||
|
};
|
||||||
|
theTheme.formats.yml = theTheme.formats.yml || {
|
||||||
|
freebie: true, title: 'yaml', outFormat: 'yml', pre: 'yml',
|
||||||
|
ext: 'yml', path: null, data: null
|
||||||
|
};
|
||||||
|
if( theTheme.formats.html && !theTheme.formats.png ) {
|
||||||
|
theTheme.formats.png = {
|
||||||
|
freebie: true, title: 'png', outFormat: 'png',
|
||||||
|
ext: 'yml', path: null, data: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Expand output files. For example, "foo.all" should be expanded to
|
||||||
|
["foo.html", "foo.doc", "foo.pdf", "etc"].
|
||||||
|
@param dst An array of output files as specified by the user.
|
||||||
|
@param theTheme A FRESHTheme or JRSTheme object.
|
||||||
|
*/
|
||||||
|
function expand( dst, theTheme ) {
|
||||||
|
|
||||||
|
// Set up the destination collection. It's either the array of files passed
|
||||||
|
// by the user or 'out/resume.all' if no targets were specified.
|
||||||
|
var destColl = (dst && dst.length && dst) ||
|
||||||
|
[PATH.normalize('out/resume.all')];
|
||||||
|
|
||||||
|
// Assemble an array of expanded target files... (can't use map() here)
|
||||||
|
var targets = [];
|
||||||
|
destColl.forEach( function(t) {
|
||||||
|
|
||||||
|
var to = PATH.resolve(t), pa = parsePath(to),fmat = pa.extname || '.all';
|
||||||
|
|
||||||
|
|
||||||
|
targets.push.apply(
|
||||||
|
targets, fmat === '.all' ?
|
||||||
|
Object.keys( theTheme.formats ).map( function( k ) {
|
||||||
|
var z = theTheme.formats[k];
|
||||||
|
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
||||||
|
}) :
|
||||||
|
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
||||||
|
|
||||||
|
// targets.push.apply(
|
||||||
|
// targets, fmat === '.all' ?
|
||||||
|
// Object.keys( explicitFormats ).map( function( k ) {
|
||||||
|
// var z = theTheme.formats[k];
|
||||||
|
// return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
||||||
|
// }) :
|
||||||
|
// [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Verify the specified theme name/path.
|
||||||
|
*/
|
||||||
|
function verifyTheme( themeNameOrPath ) {
|
||||||
|
var tFolder = PATH.join(
|
||||||
|
parsePath ( require.resolve('fresh-themes') ).dirname,
|
||||||
|
'/themes/',
|
||||||
|
themeNameOrPath
|
||||||
|
);
|
||||||
|
var exists = require('path-exists').sync;
|
||||||
|
if( !exists( tFolder ) ) {
|
||||||
|
tFolder = PATH.resolve( themeNameOrPath );
|
||||||
|
if( !exists( tFolder ) ) {
|
||||||
|
this.err( HMSTATUS.themeNotFound, { data: _opts.theme } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load the specified theme, which could be either a FRESH theme or a JSON Resume
|
||||||
|
theme.
|
||||||
|
*/
|
||||||
|
function loadTheme( tFolder ) {
|
||||||
|
|
||||||
|
// Create a FRESH or JRS theme object
|
||||||
|
var theTheme = _opts.theme.indexOf('jsonresume-theme-') > -1 ?
|
||||||
|
new JRSTheme().open(tFolder) : new FRESHTheme().open( tFolder );
|
||||||
|
|
||||||
|
// Cache the theme object
|
||||||
|
_opts.themeObj = theTheme;
|
||||||
|
|
||||||
|
return theTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -1,37 +1,89 @@
|
|||||||
/**
|
/**
|
||||||
Implementation of the 'convert' verb for HackMyResume.
|
Implementation of the 'convert' verb for HackMyResume.
|
||||||
@module convert.js
|
@module verbs/convert
|
||||||
@license MIT. See LICENSE.md for details.
|
@license MIT. See LICENSE.md for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
var ResumeFactory = require('../core/resume-factory');
|
|
||||||
|
|
||||||
|
var ResumeFactory = require('../core/resume-factory')
|
||||||
|
, chalk = require('chalk')
|
||||||
|
, Verb = require('../verbs/verb')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, HMEVENT = require('../core/event-codes');
|
||||||
|
|
||||||
|
|
||||||
|
var ConvertVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super('convert');
|
||||||
|
},
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'convert' });
|
||||||
|
convert.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.end );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert between FRESH and JRS formats.
|
Convert between FRESH and JRS formats.
|
||||||
*/
|
*/
|
||||||
module.exports = function convert( sources, dst, opts, logger ) {
|
function convert( srcs, dst, opts ) {
|
||||||
var _log = logger || console.log;
|
|
||||||
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
|
// Housekeeping
|
||||||
|
if( !srcs || !srcs.length ) { throw { fluenterror: 6, quit: true }; }
|
||||||
if( !dst || !dst.length ) {
|
if( !dst || !dst.length ) {
|
||||||
if( sources.length === 1 ) { throw { fluenterror: 5 }; }
|
if( srcs.length === 1 ) {
|
||||||
else if( sources.length === 2 ) { dst = [ sources[1] ]; sources = [ sources[0] ]; }
|
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||||
else { throw { fluenterror: 5 }; }
|
|
||||||
}
|
}
|
||||||
if( sources && dst && sources.length && dst.length && sources.length !== dst.length ) {
|
else if( srcs.length === 2 ) {
|
||||||
throw { fluenterror: 7 };
|
dst = dst || []; dst.push( srcs.pop() );
|
||||||
}
|
}
|
||||||
var sourceResumes = ResumeFactory.load( sources, _log, null, true );
|
else {
|
||||||
sourceResumes.forEach(function( src, idx ) {
|
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||||
var sheet = src.rez;
|
}
|
||||||
var sourceFormat = ((sheet.basics && sheet.basics.imp) || sheet.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH';
|
}
|
||||||
var targetFormat = sourceFormat === 'JRS' ? 'FRESH' : 'JRS';
|
if(srcs && dst && srcs.length && dst.length && srcs.length !== dst.length){
|
||||||
_log( 'Converting '.useful + src.file.useful.bold + (' (' +
|
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||||
sourceFormat + ') to ').useful + dst[0].useful.bold +
|
}
|
||||||
(' (' + targetFormat + ').').useful );
|
|
||||||
sheet.saveAs( dst[idx], targetFormat );
|
// Load source resumes
|
||||||
|
_.each(srcs, function( src, idx ) {
|
||||||
|
|
||||||
|
// Load the resume
|
||||||
|
var rinfo = ResumeFactory.loadOne( src, {
|
||||||
|
format: null, objectify: true, throw: false
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
// If a load error occurs, report it and move on to the next file (if any)
|
||||||
|
if( rinfo.fluenterror ) {
|
||||||
|
this.err( rinfo.fluenterror, rinfo );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var s = rinfo.rez
|
||||||
|
, srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ?
|
||||||
|
'JRS' : 'FRESH'
|
||||||
|
, targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
||||||
|
|
||||||
|
this.stat(HMEVENT.beforeConvert, { srcFile: rinfo.file, srcFmt: srcFmt, dstFile: dst[idx], dstFmt: targetFormat });
|
||||||
|
|
||||||
|
// Save it to the destination format
|
||||||
|
s.saveAs( dst[idx], targetFormat );
|
||||||
|
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -1,28 +1,60 @@
|
|||||||
/**
|
/**
|
||||||
Implementation of the 'create' verb for HackMyResume.
|
Implementation of the 'create' verb for HackMyResume.
|
||||||
@module create.js
|
@module verbs/create
|
||||||
@license MIT. See LICENSE.md for details.
|
@license MIT. See LICENSE.md for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
var FLUENT = require('../hackmyapi')
|
|
||||||
, MKDIRP = require('mkdirp')
|
|
||||||
, PATH = require('path');
|
var MKDIRP = require('mkdirp')
|
||||||
|
, PATH = require('path')
|
||||||
|
, chalk = require('chalk')
|
||||||
|
, Verb = require('../verbs/verb')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, HMEVENT = require('../core/event-codes');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var CreateVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super('new');
|
||||||
|
},
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'create' });
|
||||||
|
create.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'convert' });
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a new empty resume in either FRESH or JRS format.
|
Create a new empty resume in either FRESH or JRS format.
|
||||||
*/
|
*/
|
||||||
module.exports = function create( src, dst, opts, logger ) {
|
function create( src, dst, opts ) {
|
||||||
var _log = logger || console.log;
|
|
||||||
if( !src || !src.length ) throw { fluenterror: 8 };
|
if( !src || !src.length )
|
||||||
src.forEach( function( t ) {
|
throw { fluenterror: HMSTATUS.createNameMissing, quit: true };
|
||||||
var safeFormat = opts.format.toUpperCase();
|
|
||||||
_log('Creating new '.useful +safeFormat.useful.bold +
|
_.each( src, function( t ) {
|
||||||
' resume: '.useful + t.useful.bold);
|
var safeFmt = opts.format.toUpperCase();
|
||||||
|
this.stat( HMEVENT.beforeCreate, { fmt: safeFmt, file: t } );
|
||||||
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
|
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
|
||||||
FLUENT[ safeFormat + 'Resume' ].default().save( t );
|
var RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume' );
|
||||||
});
|
RezClass.default().save(t);
|
||||||
};
|
this.stat( HMEVENT.afterCreate, { fmt: safeFmt, file: t } );
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -1,287 +0,0 @@
|
|||||||
/**
|
|
||||||
Implementation of the 'generate' verb for HackMyResume.
|
|
||||||
@module generate.js
|
|
||||||
@license MIT. See LICENSE.md for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var PATH = require('path')
|
|
||||||
, FS = require('fs')
|
|
||||||
, MD = require('marked')
|
|
||||||
, MKDIRP = require('mkdirp')
|
|
||||||
, EXTEND = require('../utils/extend')
|
|
||||||
, parsePath = require('parse-filepath')
|
|
||||||
, _opts = require('../core/default-options')
|
|
||||||
, FluentTheme = require('../core/fresh-theme')
|
|
||||||
, JRSTheme = require('../core/jrs-theme')
|
|
||||||
, ResumeFactory = require('../core/resume-factory')
|
|
||||||
, _ = require('underscore')
|
|
||||||
, _fmts = require('../core/default-formats')
|
|
||||||
, extend = require('../utils/extend')
|
|
||||||
, _err, _log, rez;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Handle an exception.
|
|
||||||
*/
|
|
||||||
function error( ex ) {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
|
||||||
theme file, generate 0..N resumes in the desired formats.
|
|
||||||
@param src Path to the source JSON resume file: "rez/resume.json".
|
|
||||||
@param dst An array of paths to the target resume file(s).
|
|
||||||
@param theme Friendly name of the resume theme. Defaults to "modern".
|
|
||||||
@param logger Optional logging override.
|
|
||||||
*/
|
|
||||||
function build( src, dst, opts, logger, errHandler ) {
|
|
||||||
|
|
||||||
// Housekeeping...
|
|
||||||
_log = logger || console.log;
|
|
||||||
_err = errHandler || error;
|
|
||||||
//_opts = extend( true, _opts, opts );
|
|
||||||
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim())|| 'modern';
|
|
||||||
_opts.prettify = opts.prettify === true ? _opts.prettify : false;
|
|
||||||
_opts.css = opts.css;
|
|
||||||
|
|
||||||
// Load the theme...
|
|
||||||
var tFolder = verify_theme( _opts.theme );
|
|
||||||
var theme = load_theme( tFolder );
|
|
||||||
|
|
||||||
// Load input resumes...
|
|
||||||
if( !src || !src.length ) { throw { fluenterror: 3 }; }
|
|
||||||
var sheets = ResumeFactory.load(src, _log, theme.render ? 'JRS' : 'FRESH', true);
|
|
||||||
|
|
||||||
// Merge input resumes...
|
|
||||||
var msg = '';
|
|
||||||
var rezRep = _.reduceRight( sheets, function( a, b, idx ) {
|
|
||||||
msg += ((idx == sheets.length - 2) ?
|
|
||||||
'Merging '.gray + a.rez.imp.fileName : '') + ' onto '.gray + b.rez.fileName;
|
|
||||||
return extend( true, b.rez, a.rez );
|
|
||||||
});
|
|
||||||
rez = rezRep.rez;
|
|
||||||
msg && _log(msg);
|
|
||||||
|
|
||||||
// Expand output resumes...
|
|
||||||
var targets = expand( dst, theme );
|
|
||||||
|
|
||||||
// Run the transformation!
|
|
||||||
targets.forEach( function(t) {
|
|
||||||
t.final = single( t, theme, targets );
|
|
||||||
});
|
|
||||||
|
|
||||||
// Don't send the client back empty-handed
|
|
||||||
return { sheet: rez, targets: targets, processed: targets };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Generate a single target resume such as "out/rez.html" or "out/rez.doc".
|
|
||||||
@param targInfo Information for the target resume.
|
|
||||||
@param theme A FRESHTheme or JRSTheme object.
|
|
||||||
@returns
|
|
||||||
*/
|
|
||||||
function single( targInfo, theme, finished ) {
|
|
||||||
|
|
||||||
function MDIN(txt) { // TODO: Move this
|
|
||||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
var f = targInfo.file
|
|
||||||
, fType = targInfo.fmt.outFormat
|
|
||||||
, fName = PATH.basename(f, '.' + fType)
|
|
||||||
, theFormat;
|
|
||||||
|
|
||||||
_log( 'Generating '.useful +
|
|
||||||
targInfo.fmt.outFormat.toUpperCase().useful.bold +
|
|
||||||
' resume: '.useful + PATH.relative(process.cwd(), f ).useful.bold );
|
|
||||||
|
|
||||||
// If targInfo.fmt.files exists, this format is backed by a document.
|
|
||||||
// Fluent/FRESH themes are handled here.
|
|
||||||
if( targInfo.fmt.files && targInfo.fmt.files.length ) {
|
|
||||||
theFormat = _fmts.filter(
|
|
||||||
function(fmt) { return fmt.name === targInfo.fmt.outFormat; })[0];
|
|
||||||
MKDIRP.sync( PATH.dirname( f ) ); // Ensure dest folder exists;
|
|
||||||
_opts.targets = finished;
|
|
||||||
return theFormat.gen.generate( rez, f, _opts );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise this is either a) a JSON Resume theme or b) an ad-hoc format
|
|
||||||
// (JSON, YML, or PNG) that every theme gets "for free".
|
|
||||||
else {
|
|
||||||
|
|
||||||
theFormat = _fmts.filter( function(fmt) {
|
|
||||||
return fmt.name === targInfo.fmt.outFormat;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
var outFolder = PATH.dirname( f );
|
|
||||||
MKDIRP.sync( outFolder ); // Ensure dest folder exists;
|
|
||||||
|
|
||||||
// JSON Resume themes have a 'render' method that needs to be called
|
|
||||||
if( theme.render ) {
|
|
||||||
var COPY = require('copy');
|
|
||||||
var globs = [ /*'**',*/ '*.css', '*.js', '*.png', '*.jpg', '*.gif', '*.bmp' ];
|
|
||||||
COPY.sync( globs , outFolder, {
|
|
||||||
cwd: theme.folder, nodir: true,
|
|
||||||
ignore: ['node_modules/','node_modules/**']
|
|
||||||
// rewrite: function(p1, p2) {
|
|
||||||
// return PATH.join(p2, p1);
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prevent JSON Resume theme .js from chattering (TODO: redirect IO)
|
|
||||||
var consoleLog = console.log;
|
|
||||||
console.log = function() { };
|
|
||||||
|
|
||||||
// Call the theme's render method
|
|
||||||
var rezDupe = rez.harden();
|
|
||||||
var rezHtml = theme.render( rezDupe );
|
|
||||||
|
|
||||||
// Turn logging back on
|
|
||||||
console.log = consoleLog;
|
|
||||||
|
|
||||||
// Unharden
|
|
||||||
rezHtml = rezHtml.replace( /@@@@~.+?~@@@@/g, function(val){
|
|
||||||
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save the file
|
|
||||||
FS.writeFileSync( f, rezHtml );
|
|
||||||
|
|
||||||
// Return markup to the client
|
|
||||||
return rezHtml;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return theFormat.gen.generate( rez, f, _opts );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( ex ) {
|
|
||||||
_err( ex );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Expand output files. For example, "foo.all" should be expanded to
|
|
||||||
["foo.html", "foo.doc", "foo.pdf", "etc"].
|
|
||||||
@param dst An array of output files as specified by the user.
|
|
||||||
@param theTheme A FRESHTheme or JRSTheme object.
|
|
||||||
*/
|
|
||||||
function expand( dst, theTheme ) {
|
|
||||||
|
|
||||||
// Add freebie formats (JSON, YAML, PNG) every theme gets...
|
|
||||||
// Add HTML-driven PNG only if the theme has an HTML format.
|
|
||||||
theTheme.formats.json = theTheme.formats.json || {
|
|
||||||
freebie: true, title: 'json', outFormat: 'json', pre: 'json',
|
|
||||||
ext: 'json', path: null, data: null
|
|
||||||
};
|
|
||||||
theTheme.formats.yml = theTheme.formats.yml || {
|
|
||||||
freebie: true, title: 'yaml', outFormat: 'yml', pre: 'yml',
|
|
||||||
ext: 'yml', path: null, data: null
|
|
||||||
};
|
|
||||||
if( theTheme.formats.html && !theTheme.formats.png ) {
|
|
||||||
theTheme.formats.png = {
|
|
||||||
freebie: true, title: 'png', outFormat: 'png',
|
|
||||||
ext: 'yml', path: null, data: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the destination collection. It's either the array of files passed
|
|
||||||
// by the user or 'out/resume.all' if no targets were specified.
|
|
||||||
var destColl = (dst && dst.length && dst) ||
|
|
||||||
[PATH.normalize('out/resume.all')];
|
|
||||||
|
|
||||||
// Assemble an array of expanded target files... (can't use map() here)
|
|
||||||
var targets = [];
|
|
||||||
destColl.forEach( function(t) {
|
|
||||||
|
|
||||||
var to = PATH.resolve(t), pa = parsePath(to),fmat = pa.extname || '.all';
|
|
||||||
|
|
||||||
var explicitFormats = _.omit( theTheme.formats, function(val, key) {
|
|
||||||
return !val.freebie;
|
|
||||||
});
|
|
||||||
var implicitFormats = _.omit( theTheme.formats, function(val) {
|
|
||||||
return val.freebie;
|
|
||||||
});
|
|
||||||
|
|
||||||
targets.push.apply(
|
|
||||||
targets, fmat === '.all' ?
|
|
||||||
Object.keys( implicitFormats ).map( function( k ) {
|
|
||||||
var z = theTheme.formats[k];
|
|
||||||
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
|
||||||
}) :
|
|
||||||
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
|
||||||
|
|
||||||
targets.push.apply(
|
|
||||||
targets, fmat === '.all' ?
|
|
||||||
Object.keys( explicitFormats ).map( function( k ) {
|
|
||||||
var z = theTheme.formats[k];
|
|
||||||
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
|
||||||
}) :
|
|
||||||
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Verify the specified theme name/path.
|
|
||||||
*/
|
|
||||||
function verify_theme( themeNameOrPath ) {
|
|
||||||
var tFolder = PATH.resolve(
|
|
||||||
__dirname,
|
|
||||||
'../../node_modules/fresh-themes/themes',
|
|
||||||
themeNameOrPath
|
|
||||||
);
|
|
||||||
var exists = require('path-exists').sync;
|
|
||||||
if( !exists( tFolder ) ) {
|
|
||||||
tFolder = PATH.resolve( themeNameOrPath );
|
|
||||||
if( !exists( tFolder ) ) {
|
|
||||||
throw { fluenterror: 1, data: _opts.theme };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Load the specified theme.
|
|
||||||
*/
|
|
||||||
function load_theme( tFolder ) {
|
|
||||||
|
|
||||||
// Create a FRESH or JRS theme object
|
|
||||||
var theTheme = _opts.theme.indexOf('jsonresume-theme-') > -1 ?
|
|
||||||
new JRSTheme().open(tFolder) : new FluentTheme().open( tFolder );
|
|
||||||
|
|
||||||
// Cache the theme object
|
|
||||||
_opts.themeObj = theTheme;
|
|
||||||
|
|
||||||
// Output a message TODO: core should not log
|
|
||||||
var numFormats = Object.keys(theTheme.formats).length;
|
|
||||||
_log( 'Applying '.info + theTheme.name.toUpperCase().infoBold +
|
|
||||||
(' theme (' + numFormats + ' formats)').info);
|
|
||||||
return theTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = build;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
83
src/verbs/peek.js
Normal file
83
src/verbs/peek.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
Implementation of the 'peek' verb for HackMyResume.
|
||||||
|
@module verbs/peek
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var Verb = require('../verbs/verb')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, __ = require('lodash')
|
||||||
|
, safeLoadJSON = require('../utils/safe-json-loader')
|
||||||
|
, HMSTATUS = require('../core/status-codes')
|
||||||
|
, HMEVENT = require('../core/event-codes');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var PeekVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
this._super('peek');
|
||||||
|
},
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'peek' } );
|
||||||
|
peek.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.end );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Peek at a resume, resume section, or resume field.
|
||||||
|
*/
|
||||||
|
function peek( src, dst, opts ) {
|
||||||
|
|
||||||
|
if(!src || !src.length) throw {fluenterror: HMSTATUS.resumeNotFound};
|
||||||
|
|
||||||
|
var objPath = (dst && dst[0]) || '';
|
||||||
|
|
||||||
|
_.each( src, function( t ) {
|
||||||
|
|
||||||
|
// Fire the 'beforePeek' event 2nd, so we have error/warning/success
|
||||||
|
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
|
||||||
|
|
||||||
|
// Load the input file JSON 1st
|
||||||
|
var obj = safeLoadJSON( t );
|
||||||
|
|
||||||
|
// Fetch the requested object path (or the entire file)
|
||||||
|
var tgt;
|
||||||
|
if( !obj.ex )
|
||||||
|
tgt = objPath ? __.get( obj.json, objPath ) : obj.json;
|
||||||
|
|
||||||
|
// Fire the 'afterPeek' event with collected info
|
||||||
|
this.stat( HMEVENT.afterPeek, {
|
||||||
|
file: t,
|
||||||
|
requested: objPath,
|
||||||
|
target: tgt,
|
||||||
|
error: obj.ex
|
||||||
|
});
|
||||||
|
|
||||||
|
// safeLoadJSON can only return a READ error or a PARSE error
|
||||||
|
if( obj.ex ) {
|
||||||
|
var errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||||
|
if( errCode === HMSTATUS.readError )
|
||||||
|
obj.ex.quiet = true;
|
||||||
|
this.setError( errCode, obj.ex );
|
||||||
|
this.err( errCode, obj.ex );
|
||||||
|
}
|
||||||
|
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -1,24 +1,48 @@
|
|||||||
/**
|
/**
|
||||||
Implementation of the 'validate' verb for HackMyResume.
|
Implementation of the 'validate' verb for HackMyResume.
|
||||||
@module validate.js
|
@module verbs/validate
|
||||||
@license MIT. See LICENSE.md for details.
|
@license MIT. See LICENSE.md for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FS = require('fs');
|
var FS = require('fs');
|
||||||
var ResumeFactory = require('../core/resume-factory');
|
var ResumeFactory = require('../core/resume-factory');
|
||||||
var SyntaxErrorEx = require('../utils/syntax-error-ex');
|
var SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||||
|
var chalk = require('chalk');
|
||||||
|
var Verb = require('../verbs/verb');
|
||||||
|
var HMSTATUS = require('../core/status-codes');
|
||||||
|
var HMEVENT = require('../core/event-codes');
|
||||||
|
var _ = require('underscore');
|
||||||
|
|
||||||
module.exports =
|
|
||||||
|
|
||||||
/**
|
|
||||||
Validate 1 to N resumes in either FRESH or JSON Resume format.
|
/** An invokable resume validation command. */
|
||||||
*/
|
var ValidateVerb = module.exports = Verb.extend({
|
||||||
function validate( sources, unused, opts, logger ) {
|
|
||||||
var _log = logger || console.log;
|
init: function() {
|
||||||
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
|
this._super('validate');
|
||||||
var isValid = true;
|
},
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
this.stat( HMEVENT.begin, { cmd: 'validate' } );
|
||||||
|
validate.apply( this, arguments );
|
||||||
|
this.stat( HMEVENT.end );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Validate 1 to N resumes in FRESH or JSON Resume format. */
|
||||||
|
function validate( sources, unused, opts ) {
|
||||||
|
|
||||||
|
if( !sources || !sources.length )
|
||||||
|
throw { fluenterror: HMSTATUS.resumeNotFoundAlt, quit: true };
|
||||||
|
|
||||||
var validator = require('is-my-json-valid');
|
var validator = require('is-my-json-valid');
|
||||||
var schemas = {
|
var schemas = {
|
||||||
@ -26,33 +50,26 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
jars: require('../core/resume.json')
|
jars: require('../core/resume.json')
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load input resumes...
|
var resumes = ResumeFactory.load( sources, {
|
||||||
sources.forEach(function( src ) {
|
format: null,
|
||||||
|
objectify: false
|
||||||
|
}, this );
|
||||||
|
|
||||||
var result = ResumeFactory.loadOne( src, function(){}, null, false );
|
// Validate input resumes. Return a { file: <f>, isValid: <v>} object for
|
||||||
if( result.error ) {
|
// each resume (valid, invalid, or broken).
|
||||||
_log( 'Validating '.info + src.infoBold + ' against '.info + 'AUTO'.infoBold + ' schema:'.info + ' BROKEN'.red.bold );
|
return resumes.map( function( src ) {
|
||||||
|
|
||||||
var ex = result.error; // alias
|
var ret = { file: src, isValid: false };
|
||||||
if ( ex instanceof SyntaxError) {
|
|
||||||
var info = new SyntaxErrorEx( ex, result.raw );
|
// If there was an error reading the resume
|
||||||
_log( ('--> '.warn.bold + src.toUpperCase() + ' contains invalid JSON on line ' +
|
if( src.fluenterror ) {
|
||||||
info.line + ' column ' + info.col + '.').warn +
|
if( opts.assert ) throw src;
|
||||||
' Unable to validate.'.warn );
|
this.setError( src.fluenterror, src );
|
||||||
_log( (' INTERNAL: ' + ex).warn );
|
return ret;
|
||||||
}
|
|
||||||
else {
|
|
||||||
_log(('ERROR: ' + ex.toString()).warn.bold);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = result.json;
|
// Successfully read the resume. Now parse it as JSON.
|
||||||
var isValid = false;
|
var json = src.json, fmt = json.basics ? 'jrs' : 'fresh', errors = [];
|
||||||
var style = 'useful';
|
|
||||||
var errors = [];
|
|
||||||
var fmt = json.meta && (json.meta.format==='FRESH@0.1.0') ? 'fresh':'jars';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var validate = validator( schemas[ fmt ], { // Note [1]
|
var validate = validator( schemas[ fmt ], { // Note [1]
|
||||||
formats: {
|
formats: {
|
||||||
@ -60,28 +77,27 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
isValid = validate( json );
|
ret.isValid = validate( json );
|
||||||
if( !isValid ) {
|
if( !ret.isValid ) {
|
||||||
style = 'warn';
|
|
||||||
errors = validate.errors;
|
errors = validate.errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( exc ) {
|
catch( exc ) {
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
_log( 'Validating '.info + result.file.infoBold + ' against '.info +
|
this.stat( HMEVENT.afterValidate, { file: src.file, isValid: ret.isValid,
|
||||||
fmt.replace('jars','JSON Resume').toUpperCase().infoBold +
|
fmt: fmt.replace( 'jars', 'JSON Resume' ), errors: errors });
|
||||||
' schema: '.info + (isValid ? 'VALID!' : 'INVALID')[style].bold );
|
|
||||||
|
|
||||||
errors.forEach(function(err,idx) {
|
if( opts.assert && !ret.isValid ) {
|
||||||
_log( '--> '.bold.yellow +
|
throw { fluenterror: HMSTATUS.invalid, shouldExit: true };
|
||||||
(err.field.replace('data.','resume.').toUpperCase() + ' ' +
|
}
|
||||||
err.message).yellow );
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
return ret;
|
||||||
};
|
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
96
src/verbs/verb.js
Normal file
96
src/verbs/verb.js
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
Definition of the Verb class.
|
||||||
|
@module verbs/verb
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Use J. Resig's nifty class implementation
|
||||||
|
var Class = require( '../utils/class' )
|
||||||
|
, EVENTS = require('events');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
An instantiation of a HackMyResume command.
|
||||||
|
@class Verb
|
||||||
|
*/
|
||||||
|
var Verb = module.exports = Class.extend({
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructor. Automatically called at creation.
|
||||||
|
*/
|
||||||
|
init: function( moniker ) {
|
||||||
|
this.moniker = moniker;
|
||||||
|
this.emitter = new EVENTS.EventEmitter();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Forward subscriptions to the event emitter.
|
||||||
|
*/
|
||||||
|
on: function() {
|
||||||
|
this.emitter.on.apply( this.emitter, arguments );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Fire an arbitrary event, scoped to "hmr:".
|
||||||
|
*/
|
||||||
|
fire: function(evtName, payload) {
|
||||||
|
payload = payload || { };
|
||||||
|
payload.cmd = this.moniker;
|
||||||
|
this.emitter.emit( 'hmr:' + evtName, payload );
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handle an error condition.
|
||||||
|
*/
|
||||||
|
err: function( errorCode, payload, hot ) {
|
||||||
|
payload = payload || { };
|
||||||
|
payload.sub = payload.fluenterror = errorCode;
|
||||||
|
payload.throw = hot;
|
||||||
|
this.fire( 'error', payload );
|
||||||
|
if( hot ) throw payload;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Fire the 'hmr:status' error event.
|
||||||
|
*/
|
||||||
|
stat: function( subEvent, payload ) {
|
||||||
|
payload = payload || { };
|
||||||
|
payload.sub = subEvent;
|
||||||
|
this.fire('status', payload);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Associate error info with the invocation.
|
||||||
|
*/
|
||||||
|
setError: function( code, obj ) {
|
||||||
|
this.errorCode = code;
|
||||||
|
this.errorObj = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}());
|
4
test/hmr-options.json
Normal file
4
test/hmr-options.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"theme": "positive",
|
||||||
|
"debug": true
|
||||||
|
}
|
207
test/test-api.js
Normal file
207
test/test-api.js
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
/**
|
||||||
|
@module test-api.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
var chai = require('chai')
|
||||||
|
, expect = chai.expect
|
||||||
|
, should = chai.should()
|
||||||
|
, path = require('path')
|
||||||
|
, _ = require('underscore')
|
||||||
|
, FRESHResume = require('../src/core/fresh-resume')
|
||||||
|
, FCMD = require( '../src/hackmyapi')
|
||||||
|
, validator = require('is-my-json-valid')
|
||||||
|
, HMRMAIN = require('../src/cli/main')
|
||||||
|
, EXTEND = require('extend');
|
||||||
|
|
||||||
|
chai.config.includeStack = false;
|
||||||
|
|
||||||
|
var _sheet;
|
||||||
|
|
||||||
|
var opts = {
|
||||||
|
format: 'FRESH',
|
||||||
|
prettify: true,
|
||||||
|
silent: false,
|
||||||
|
assert: true // Causes validation errors to throw exceptions
|
||||||
|
};
|
||||||
|
|
||||||
|
var opts2 = {
|
||||||
|
format: 'JRS',
|
||||||
|
prettify: true,
|
||||||
|
silent: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var sb = 'test/sandbox/';
|
||||||
|
var ft = 'node_modules/fresh-test-resumes/src/fresh/';
|
||||||
|
|
||||||
|
var tests = [
|
||||||
|
|
||||||
|
[ 'new',
|
||||||
|
[sb + 'new-fresh-resume.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (FRESH format)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'new',
|
||||||
|
[sb + 'new-jrs-resume.json'],
|
||||||
|
[],
|
||||||
|
opts2,
|
||||||
|
' (JRS format)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'new',
|
||||||
|
[sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (multiple FRESH resumes)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'new',
|
||||||
|
[sb + 'new-jrs-1.json', sb + 'new-jrs-2.json', sb + 'new-jrs-3.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (multiple JRS resumes)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ '!new',
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
" (when a filename isn't specified)"
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
[ft + 'jane-fullstacker.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (jane-q-fullstacker|FRESH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
[ft + 'johnny-trouble.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (johnny-trouble|FRESH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
[sb + 'new-fresh-resume.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (new-fresh-resume|FRESH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
|
||||||
|
[],
|
||||||
|
opts2,
|
||||||
|
' (richard-hendriks.json|JRS)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
['test/resumes/jrs-0.0.0/jane-incomplete.json'],
|
||||||
|
[],
|
||||||
|
opts2,
|
||||||
|
' (jane-incomplete.json|JRS)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'validate',
|
||||||
|
[sb + 'new-1.json', sb + 'new-jrs-resume.json', sb + 'new-1.json',
|
||||||
|
sb + 'new-2.json', sb + 'new-3.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (5|BOTH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'analyze',
|
||||||
|
[ft + 'jane-fullstacker.json'],
|
||||||
|
[],
|
||||||
|
opts,
|
||||||
|
' (jane-q-fullstacker|FRESH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'analyze',
|
||||||
|
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
|
||||||
|
[],
|
||||||
|
opts2,
|
||||||
|
' (richard-hendriks|JRS)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'build',
|
||||||
|
[ ft + 'jane-fullstacker.json', ft + 'override/jane-fullstacker-override.fresh.json' ],
|
||||||
|
[ sb + 'merged/jane-fullstacker-gamedev.fresh.all'],
|
||||||
|
opts,
|
||||||
|
' (jane-q-fullstacker w/ override|FRESH)'
|
||||||
|
],
|
||||||
|
|
||||||
|
[ 'build',
|
||||||
|
[ ft + 'override/jane-partial-a.json', ft + 'override/jane-partial-b.json',
|
||||||
|
ft + 'override/jane-partial-c.json' ],
|
||||||
|
[ sb + 'merged/jane-abc.fresh.all'],
|
||||||
|
opts,
|
||||||
|
' (jane merge A + B + C|FRESH)',
|
||||||
|
function( r ) {
|
||||||
|
var expected = [
|
||||||
|
'name','meta','info', 'contact', 'location', 'projects', 'social',
|
||||||
|
'employment', 'education', 'affiliation', 'service', 'skills',
|
||||||
|
'samples', 'writing', 'reading', 'speaking', 'recognition',
|
||||||
|
'references', 'testimonials', 'languages', 'interests',
|
||||||
|
'extracurricular', 'governance'
|
||||||
|
];
|
||||||
|
return Object.keys( _.pick( r, expected ) ).length === expected.length;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
[ '!build',
|
||||||
|
[ ft + 'jane-fullstacker.json'],
|
||||||
|
[ sb + 'shouldnt-exist.pdf' ],
|
||||||
|
EXTEND(true, {}, opts, { theme: 'awesome' }),
|
||||||
|
' (jane-q-fullstacker + Awesome + PDF|FRESH)'
|
||||||
|
]
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('Testing API interface', function () {
|
||||||
|
|
||||||
|
function run( verb, src, dst, opts, msg, fnTest ) {
|
||||||
|
|
||||||
|
msg = msg || '.';
|
||||||
|
var shouldSucceed = true;
|
||||||
|
if( verb[0] === '!' ) {
|
||||||
|
verb = verb.substr(1);
|
||||||
|
shouldSucceed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () {
|
||||||
|
|
||||||
|
function runIt() {
|
||||||
|
try {
|
||||||
|
var v = new FCMD.verbs[verb]();
|
||||||
|
v.on('hmr:error', function(ex) { throw ex; });
|
||||||
|
var r = v.invoke( src, dst, opts );
|
||||||
|
if( fnTest )
|
||||||
|
if( !fnTest( r.sheet ) )
|
||||||
|
throw "Test: Unexpected API result.";
|
||||||
|
}
|
||||||
|
catch(ex) {
|
||||||
|
console.error(ex);
|
||||||
|
if( ex.stack || (ex.inner && ex.inner.stack))
|
||||||
|
console.error( ex.stack || ex.inner.stack );
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( shouldSucceed )
|
||||||
|
runIt.should.not.Throw();
|
||||||
|
else
|
||||||
|
runIt.should.Throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tests.forEach( function(a) {
|
||||||
|
run.apply( /* The players of */ null, a );
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
116
test/test-cli.js
116
test/test-cli.js
@ -1,76 +1,76 @@
|
|||||||
|
/**
|
||||||
|
CLI test routines for HackMyResume.
|
||||||
|
@module test-cli.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
, expect = chai.expect
|
|
||||||
, should = chai.should()
|
, should = chai.should()
|
||||||
, path = require('path')
|
, HMRMAIN = require('../src/cli/main')
|
||||||
, _ = require('underscore')
|
, CHALK = require('chalk')
|
||||||
, FRESHResume = require('../src/core/fresh-resume')
|
, FS = require('fs')
|
||||||
, FCMD = require( '../src/hackmycmd')
|
, PATH = require('path')
|
||||||
, validator = require('is-my-json-valid')
|
, PKG = require('../package.json')
|
||||||
, COLORS = require('colors');
|
, _ = require('underscore');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var gather = '';
|
||||||
|
var ConsoleLogOrg = console.log;
|
||||||
|
var ProcessExitOrg = process.exit;
|
||||||
|
var commandRetVal = 0;
|
||||||
|
|
||||||
chai.config.includeStack = false;
|
|
||||||
|
|
||||||
describe('Testing CLI interface', function () {
|
describe('Testing CLI interface', function () {
|
||||||
|
|
||||||
var _sheet;
|
// TODO: use sinon
|
||||||
|
// Replacement for process.exit()
|
||||||
|
function MyProcessExit( retVal ) {
|
||||||
|
commandRetVal = retVal;
|
||||||
|
}
|
||||||
|
|
||||||
function logMsg() {
|
// HackMyResume CLI stub. Handle a single HMR invocation.
|
||||||
|
function HackMyResumeStub( argsString ) {
|
||||||
|
|
||||||
|
var args = argsString.split(' ');
|
||||||
|
args.unshift( process.argv[1] );
|
||||||
|
args.unshift( process.argv[0] );
|
||||||
|
process.exit = MyProcessExit;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var HMRMAIN = require('../src/cli/main');
|
||||||
|
HMRMAIN( args );
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
require('../src/cli/error').err( ex, false );
|
||||||
|
//if(ex.stack || (ex.inner && ex.inner.stacl))
|
||||||
|
//console.log(ex.stack || ex.inner.stack);
|
||||||
|
}
|
||||||
|
process.exit = ProcessExitOrg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORS.setTheme({
|
// Run a test through the stub, gathering console.log output into "gather"
|
||||||
title: ['white','bold'],
|
// and testing against it.
|
||||||
info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
function run( args, expErr ) {
|
||||||
infoBold: ['white','dim'],
|
var title = args;
|
||||||
warn: 'yellow',
|
it( 'Testing: "' + title + '"\n\n', function() {
|
||||||
error: 'red',
|
commandRetVal = 0;
|
||||||
guide: 'yellow',
|
HackMyResumeStub( args );
|
||||||
status: 'gray',//['white','dim'],
|
commandRetVal.should.equal( parseInt(expErr, 10) );
|
||||||
useful: 'green',
|
|
||||||
});
|
|
||||||
|
|
||||||
var opts = {
|
|
||||||
//theme: 'compact',
|
|
||||||
format: 'FRESH',
|
|
||||||
prettify: true,
|
|
||||||
silent: true
|
|
||||||
};
|
|
||||||
|
|
||||||
var opts2 = {
|
|
||||||
format: 'JRS',
|
|
||||||
prettify: true,
|
|
||||||
silent: true
|
|
||||||
};
|
|
||||||
|
|
||||||
run( 'new', ['test/sandbox/new-fresh-resume.json'], [], opts, ' (FRESH format)' );
|
|
||||||
run( 'new', ['test/sandbox/new-jrs-resume.json'], [], opts2, ' (JRS format)' );
|
|
||||||
run( 'new', ['test/sandbox/new-1.json', 'test/sandbox/new-2.json', 'test/sandbox/new-3.json'], [], opts, ' (multiple FRESH resumes)' );
|
|
||||||
run( 'new', ['test/sandbox/new-jrs-1.json', 'test/sandbox/new-jrs-2.json', 'test/sandbox/new-jrs-3.json'], [], opts, ' (multiple JRS resumes)' );
|
|
||||||
run( 'new', ['test/sandbox/new-jrs-resume.json'], [], opts2, ' (JRS format)' );
|
|
||||||
fail( 'new', [], [], opts, " (when a filename isn't specified)" );
|
|
||||||
|
|
||||||
run( 'validate', ['node_modules/jane-q-fullstacker/resume/jane-resume.json'], [], opts, ' (FRESH format)' );
|
|
||||||
run( 'validate', ['test/sandbox/new-fresh-resume.json'], [], opts, ' (FRESH format)' );
|
|
||||||
|
|
||||||
function run( verb, src, dst, opts, msg ) {
|
|
||||||
msg = msg || '.';
|
|
||||||
it( 'The ' + verb.toUpperCase() + ' command should SUCCEED' + msg, function () {
|
|
||||||
function runIt() {
|
|
||||||
FCMD.verbs[verb]( src, dst, opts, opts.silent ? logMsg : null );
|
|
||||||
}
|
|
||||||
runIt.should.not.Throw();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fail( verb, src, dst, opts, msg ) {
|
var lines = FS.readFileSync( PATH.join( __dirname, './test-hmr.txt'), 'utf8').split('\n');
|
||||||
msg = msg || '.';
|
lines.forEach(function(l){
|
||||||
it( 'The ' + verb.toUpperCase() + ' command should FAIL' + msg, function () {
|
if( l && l.trim() ) {
|
||||||
function runIt() {
|
if(l[0] !== '#') {
|
||||||
FCMD.verbs[verb]( src, dst, opts, logMsg );
|
var lineInfo = l.split('|');
|
||||||
|
var errCode = lineInfo[0];
|
||||||
|
run( lineInfo.length > 1 ? lineInfo[1] : '', errCode );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
runIt.should.Throw();
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
var chai = require('chai')
|
|
||||||
, expect = chai.expect
|
|
||||||
, should = chai.should()
|
|
||||||
, path = require('path')
|
|
||||||
, _ = require('underscore')
|
|
||||||
, FRESHResume = require('../src/core/fresh-resume')
|
|
||||||
, CONVERTER = require('../src/core/convert')
|
|
||||||
, FS = require('fs')
|
|
||||||
, MKDIRP = require('mkdirp')
|
|
||||||
, _ = require('underscore');
|
|
||||||
|
|
||||||
chai.config.includeStack = false;
|
|
||||||
|
|
||||||
describe('FRESH/JRS converter', function () {
|
|
||||||
|
|
||||||
var _sheet;
|
|
||||||
|
|
||||||
it('should round-trip from JRS to FRESH to JRS without modifying or losing data', function () {
|
|
||||||
|
|
||||||
var fileA = path.join( __dirname, 'resumes/jrs-0.0.0/richard-hendriks.json' );
|
|
||||||
var fileB = path.join( __dirname, 'sandbox/richard-hendriks.json' );
|
|
||||||
|
|
||||||
_sheet = new FRESHResume().open( fileA );
|
|
||||||
MKDIRP.sync( path.parse(fileB).dir );
|
|
||||||
_sheet.saveAs( fileB, 'JRS' );
|
|
||||||
|
|
||||||
var rawA = FS.readFileSync( fileA, 'utf8' );
|
|
||||||
var rawB = FS.readFileSync( fileB, 'utf8' );
|
|
||||||
|
|
||||||
var objA = JSON.parse( rawA );
|
|
||||||
var objB = JSON.parse( rawB );
|
|
||||||
|
|
||||||
_.isEqual(objA, objB).should.equal(true);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
@ -58,5 +58,14 @@ function testResume(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sects = [ 'info', 'employment', 'service', 'skills', 'education', 'writing', 'recognition', 'references' ];
|
var sects = [ 'info', 'employment', 'service', 'skills', 'education', 'writing', 'recognition', 'references' ];
|
||||||
testResume({ title: 'jane-q-fullstacker', path: 'node_modules/jane-q-fullstacker/resume/jane-resume.json', duration: 7, sections: sects });
|
testResume({ title: 'jane-q-fullstacker', path: 'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json', duration: 7, sections: sects });
|
||||||
testResume({ title: 'johnny-trouble-resume', path: 'node_modules/johnny-trouble-resume/src/johnny-trouble.fresh.json', duration: 3, sections: sects });
|
testResume({ title: 'johnny-trouble-resume', path: 'node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json', duration: 4, sections: sects });
|
||||||
|
|
||||||
|
sects = [ 'info', 'contact', 'location' ];
|
||||||
|
testResume({ title: 'jane-q-fullstacker A', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-a.json', duration: 0, sections: sects });
|
||||||
|
|
||||||
|
sects = [ 'projects', 'social', 'employment', 'education', 'affiliation' ];
|
||||||
|
testResume({ title: 'jane-q-fullstacker B', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-b.json', duration: 7, sections: sects });
|
||||||
|
|
||||||
|
sects = [ 'service', 'skills', 'samples', 'writing', 'reading', 'speaking', 'recognition', 'references', 'testimonials', 'languages', 'interests', 'extracurricular', 'governance' ];
|
||||||
|
testResume({ title: 'jane-q-fullstacker C', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-c.json', duration: 0, sections: sects });
|
||||||
|
27
test/test-hmr.txt
Normal file
27
test/test-hmr.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
0|
|
||||||
|
0|--help
|
||||||
|
0|-h
|
||||||
|
0|--debug
|
||||||
|
0|-d
|
||||||
|
5|notacommand
|
||||||
|
3|build
|
||||||
|
14|build doesnt-exist.json
|
||||||
|
14|build doesnt-exist.json -t not-a-theme
|
||||||
|
14|build doesnt-exist.json -t node_modules/not-a-theme
|
||||||
|
8|new
|
||||||
|
0|new test/sandbox/cli-test/new-empty-resume.auto.json
|
||||||
|
0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs
|
||||||
|
0|new test/sandbox/cli-test/new-empty-resume.fresh.json -f fresh
|
||||||
|
3|analyze
|
||||||
|
14|analyze doesnt-exist.json
|
||||||
|
3|convert
|
||||||
|
7|convert doesnt-exist.json
|
||||||
|
3|validate
|
||||||
|
14|validate doesnt-exist.json
|
||||||
|
0|validate node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json
|
||||||
|
3|peek
|
||||||
|
14|peek doesnt-exist.json
|
||||||
|
14|peek doesnt-exist.json not.a.path
|
||||||
|
0|peek test/resumes/jrs-0.0.0/richard-hendriks.json work[0]
|
||||||
|
0|peek node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json employment.history[1]
|
||||||
|
0|peek node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json skills.sets
|
144
test/test-stdout.js
Normal file
144
test/test-stdout.js
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
Output test routines for HackMyResume.
|
||||||
|
@module test-stdout.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var chai = require('chai')
|
||||||
|
, expect = chai.expect
|
||||||
|
, HMRMAIN = require('../src/cli/main')
|
||||||
|
, CHALK = require('chalk')
|
||||||
|
, FS = require('fs')
|
||||||
|
, PATH = require('path')
|
||||||
|
, PKG = require('../package.json')
|
||||||
|
, _ = require('underscore');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var gather = '';
|
||||||
|
var ConsoleLogOrg = console.log;
|
||||||
|
var ProcessExitOrg = process.exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe('Testing Ouput interface', function () {
|
||||||
|
|
||||||
|
// TODO: use sinon
|
||||||
|
// Replacement for console.log
|
||||||
|
function MyConsoleLog( msg ) {
|
||||||
|
gather += Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
ConsoleLogOrg.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replacement for process.exit()
|
||||||
|
function MyProcessExit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// HackMyResume CLI stub. Handle a single HMR invocation.
|
||||||
|
function HackMyResumeStub( args ) {
|
||||||
|
|
||||||
|
console.log = MyConsoleLog;
|
||||||
|
process.exit = MyProcessExit;
|
||||||
|
CHALK.enabled = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
args.unshift( process.argv[1] );
|
||||||
|
args.unshift( process.argv[0] );
|
||||||
|
var HMRMAIN = require('../src/cli/main');
|
||||||
|
HMRMAIN( args );
|
||||||
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
require('../src/cli/error').err( ex, false );
|
||||||
|
}
|
||||||
|
CHALK.enabled = true;
|
||||||
|
process.exit = ProcessExitOrg;
|
||||||
|
console.log = ConsoleLogOrg;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run a test through the stub, gathering console.log output into "gather"
|
||||||
|
// and testing against it.
|
||||||
|
function run( title, args, tests ) {
|
||||||
|
it( title, function() {
|
||||||
|
|
||||||
|
gather = '';
|
||||||
|
HackMyResumeStub( args );
|
||||||
|
|
||||||
|
expect(
|
||||||
|
_.all( tests, function(t) {
|
||||||
|
return gather.indexOf(t) > -1;
|
||||||
|
})
|
||||||
|
).to.equal(true);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var title = '*** HackMyResume v' + PKG.version + ' ***';
|
||||||
|
var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.';
|
||||||
|
var manPage = FS.readFileSync( PATH.resolve( __dirname, '../src/cli/use.txt' ), 'utf8');
|
||||||
|
|
||||||
|
run('HMR should output a help string when no command is specified',
|
||||||
|
[], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, NEW, or PEEK).' ]);
|
||||||
|
|
||||||
|
run('BUILD should output a tip when no source is specified',
|
||||||
|
['build'], [ title, feedMe ]);
|
||||||
|
|
||||||
|
run('VALIDATE should output a tip when no source is specified',
|
||||||
|
['validate'], [ title, feedMe ]);
|
||||||
|
|
||||||
|
run('ANALYZE should output a tip when no source is specified',
|
||||||
|
['analyze'], [ title, feedMe ]);
|
||||||
|
|
||||||
|
run('BUILD should display an error on a broken resume',
|
||||||
|
['build',
|
||||||
|
'node_modules/fresh-test-resumes/src/fresh/johnny-trouble.broken.json',
|
||||||
|
'-t', 'modern'
|
||||||
|
], [ title, 'Error: Invalid or corrupt JSON on line' ]);
|
||||||
|
|
||||||
|
run('CONVERT should output a tip when no source is specified',
|
||||||
|
['convert'], [ title, feedMe ]);
|
||||||
|
|
||||||
|
run('NEW should output a tip when no source is specified',
|
||||||
|
['new'], [ title, 'Please specify the filename of the resume to create.' ]);
|
||||||
|
|
||||||
|
// This will cause the HELP doc to be emitted, followed by an "unknown option --help"
|
||||||
|
// error in the log, based on the way we're calling into HMR. As long as the test
|
||||||
|
// passes, any extraneous error messages can be ignored here.
|
||||||
|
run('HMR should output help doc with --help',
|
||||||
|
['--help'], [ manPage ]);
|
||||||
|
|
||||||
|
run('HMR should accept raw JSON via --options',
|
||||||
|
[
|
||||||
|
'build',
|
||||||
|
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
|
||||||
|
'to',
|
||||||
|
'test/sandbox/temp/janeq-1.all',
|
||||||
|
'-o',
|
||||||
|
"{ theme: 'compact', debug: true, pdf: 'wkhtmltopdf' }"],
|
||||||
|
[ 'Applying COMPACT theme (', '(with wkhtmltopdf)'] );
|
||||||
|
|
||||||
|
run('HMR should accept a JSON settings file via --options',
|
||||||
|
[
|
||||||
|
'build',
|
||||||
|
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
|
||||||
|
'to',
|
||||||
|
'test/sandbox/temp/janeq-2.all',
|
||||||
|
'--options',
|
||||||
|
"test/hmr-options.json"],
|
||||||
|
[ 'Applying POSITIVE theme'] );
|
||||||
|
|
||||||
|
run('Explicit command line options should override --options',
|
||||||
|
[
|
||||||
|
'build',
|
||||||
|
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
|
||||||
|
'to',
|
||||||
|
'test/sandbox/temp/janeq-3.all',
|
||||||
|
'--options',
|
||||||
|
"test/hmr-options.json",
|
||||||
|
"-t",
|
||||||
|
"modern"
|
||||||
|
],
|
||||||
|
[ 'Applying MODERN theme'] );
|
||||||
|
});
|
@ -1,16 +1,18 @@
|
|||||||
|
|
||||||
var SPAWNWATCHER = require('../src/core/spawn-watch')
|
var chai = require('chai')
|
||||||
, chai = require('chai')
|
|
||||||
, expect = chai.expect
|
, expect = chai.expect
|
||||||
, should = chai.should()
|
, should = chai.should()
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, _ = require('underscore')
|
, _ = require('underscore')
|
||||||
, FRESHResume = require('../src/core/fresh-resume')
|
, FRESHResume = require('../src/core/fresh-resume')
|
||||||
, FCMD = require( '../src/hackmycmd')
|
, HMR = require( '../src/hackmyapi')
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
, COLORS = require('colors');
|
, READFILES = require('recursive-readdir-sync')
|
||||||
|
, fileContains = require('../src/utils/file-contains')
|
||||||
|
, FS = require('fs')
|
||||||
|
, CHALK = require('chalk');
|
||||||
|
|
||||||
chai.config.includeStack = false;
|
chai.config.includeStack = true;
|
||||||
|
|
||||||
function genThemes( title, src, fmt ) {
|
function genThemes( title, src, fmt ) {
|
||||||
|
|
||||||
@ -18,17 +20,6 @@ function genThemes( title, src, fmt ) {
|
|||||||
|
|
||||||
var _sheet;
|
var _sheet;
|
||||||
|
|
||||||
COLORS.setTheme({
|
|
||||||
title: ['white','bold'],
|
|
||||||
info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
|
||||||
infoBold: ['white','dim'],
|
|
||||||
warn: 'yellow',
|
|
||||||
error: 'red',
|
|
||||||
guide: 'yellow',
|
|
||||||
status: 'gray',//['white','dim'],
|
|
||||||
useful: 'green',
|
|
||||||
});
|
|
||||||
|
|
||||||
function genTheme( fmt, src, themeName, themeLoc, testTitle ) {
|
function genTheme( fmt, src, themeName, themeLoc, testTitle ) {
|
||||||
themeLoc = themeLoc || themeName;
|
themeLoc = themeLoc || themeName;
|
||||||
testTitle = themeName.toUpperCase() + ' theme (' + fmt + ') should generate without throwing an exception';
|
testTitle = themeName.toUpperCase() + ' theme (' + fmt + ') should generate without throwing an exception';
|
||||||
@ -40,9 +31,19 @@ function genThemes( title, src, fmt ) {
|
|||||||
theme: themeLoc,
|
theme: themeLoc,
|
||||||
format: fmt,
|
format: fmt,
|
||||||
prettify: true,
|
prettify: true,
|
||||||
silent: true
|
silent: false,
|
||||||
|
css: 'embed',
|
||||||
|
debug: true
|
||||||
};
|
};
|
||||||
FCMD.verbs.build( src, dst, opts, function() {} );
|
try {
|
||||||
|
var v = new HMR.verbs.build();
|
||||||
|
v.invoke( src, dst, opts );
|
||||||
|
}
|
||||||
|
catch(ex) {
|
||||||
|
console.error( ex );
|
||||||
|
console.error( ex.stack );
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tryOpen.should.not.Throw();
|
tryOpen.should.not.Throw();
|
||||||
});
|
});
|
||||||
@ -51,7 +52,7 @@ function genThemes( title, src, fmt ) {
|
|||||||
genTheme(fmt, src, 'hello-world');
|
genTheme(fmt, src, 'hello-world');
|
||||||
genTheme(fmt, src, 'compact');
|
genTheme(fmt, src, 'compact');
|
||||||
genTheme(fmt, src, 'modern');
|
genTheme(fmt, src, 'modern');
|
||||||
genTheme(fmt, src, 'minimist');
|
genTheme(fmt, src, 'underscore');
|
||||||
genTheme(fmt, src, 'awesome');
|
genTheme(fmt, src, 'awesome');
|
||||||
genTheme(fmt, src, 'positive');
|
genTheme(fmt, src, 'positive');
|
||||||
genTheme(fmt, src, 'jsonresume-theme-boilerplate', 'node_modules/jsonresume-theme-boilerplate' );
|
genTheme(fmt, src, 'jsonresume-theme-boilerplate', 'node_modules/jsonresume-theme-boilerplate' );
|
||||||
@ -63,6 +64,23 @@ function genThemes( title, src, fmt ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
genThemes( 'jane-q-fullstacker', ['node_modules/jane-q-fullstacker/resume/jane-resume.json'], 'FRESH' );
|
function folderContains( needle, haystack ) {
|
||||||
genThemes( 'johnny-trouble', ['node_modules/johnny-trouble-resume/src/johnny-trouble.fresh.json'], 'FRESH' );
|
return _.some( READFILES( path.join(__dirname, haystack) ), function( absPath ) {
|
||||||
|
if( FS.lstatSync( absPath ).isFile() ) {
|
||||||
|
if( fileContains( absPath, needle ) ) {
|
||||||
|
console.error('Found invalid metadata in ' + absPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
genThemes( 'jane-q-fullstacker', ['node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json'], 'FRESH' );
|
||||||
|
genThemes( 'johnny-trouble', ['node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json'], 'FRESH' );
|
||||||
genThemes( 'richard-hendriks', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], 'JRS' );
|
genThemes( 'richard-hendriks', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], 'JRS' );
|
||||||
|
|
||||||
|
describe('Verifying generated theme files...', function() {
|
||||||
|
it('Generated files should not contain ICE.', function() {
|
||||||
|
expect( folderContains('@@@@', 'sandbox') ).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user