feat(esm): migrate to ESM

- Build with microbundle
- Add build step to GitHub Actions workflow
This commit is contained in:
Rafael Bardini 2021-11-05 18:39:36 +01:00
parent 6029ac9a23
commit de801d2027
9 changed files with 8044 additions and 268 deletions

View File

@ -1,8 +1,10 @@
{
"env": {
"commonjs": true,
"es2017": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended"
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
}
}

View File

@ -3,7 +3,7 @@ on: push
jobs:
test-and-release:
name: Test and release
name: Test and build
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -23,5 +23,8 @@ jobs:
- name: Test
run: npm test
- name: Build
run: npm run build
- name: Coverage
uses: codecov/codecov-action@v1

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.DS_Store
.nyc_output
coverage
dist
node_modules
public
npm-debug.log

View File

@ -14,6 +14,7 @@ Inspired by [jsonresume-theme-flat](https://github.com/erming/jsonresume-theme-f
- 📐 CSS grid layout
- 🌗 Light and dark modes
- 🧩 Standalone CLI
- 📦 ESM and CommonJS builds
[View demo →](https://jsonresume-theme-even.netlify.app)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env node
const fs = require('fs')
const { render } = require('..')
import fs from 'fs'
import { render } from '../dist/index.modern.js'
const resume = JSON.parse(fs.readFileSync(process.stdin.fd, 'utf-8'))
const html = render(resume)

View File

@ -1,10 +1,13 @@
const fs = require('fs')
const path = require('path')
const { icons } = require('feather-icons')
const Handlebars = require('handlebars')
const micromark = require('micromark')
const striptags = require('striptags')
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { icons } from 'feather-icons'
import Handlebars from 'handlebars'
import micromark from 'micromark'
import striptags from 'striptags'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const extname = '.hbs'
const partialsDir = path.join(__dirname, 'partials')
@ -54,9 +57,9 @@ Handlebars.registerHelper('markdown', doc => micromark(doc))
Handlebars.registerHelper('stripTags', html => striptags(html))
exports.pdfRenderOptions = { mediaType: 'print' }
export const pdfRenderOptions = { mediaType: 'print' }
exports.render = resume => {
export const render = resume => {
const template = fs.readFileSync(path.join(__dirname, 'resume.hbs'), 'utf-8')
const css = fs.readFileSync(path.join(__dirname, 'style.css'), 'utf-8')

8242
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,22 +12,30 @@
},
"license": "MIT",
"author": "Rafael Bardini",
"type": "module",
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
},
"main": "./dist/index.cjs",
"unpkg": "./dist/index.umd.js",
"module": "./dist/index.module.js",
"source": "index.js",
"bin": {
"jsonresume-theme-even": "bin/cli.js"
},
"files": [
"bin",
"index.js",
"resume.hbs",
"partials/*.hbs",
"style.css"
"dist"
],
"scripts": {
"build": "microbundle build --target node",
"postbuild": "cp -r resume.hbs partials style.css dist",
"build:demo": "mkdir -p public && cat node_modules/resume-schema/sample.resume.json | ./bin/cli.js > public/index.html",
"format": "prettier --write .",
"lint": "eslint .",
"format": "prettier --ignore-path .gitignore .",
"lint": "eslint --ignore-path .gitignore .",
"prepare": "husky install",
"test": "tap --no-check-coverage"
"test": "c8 tap --node-arg=--experimental-json-modules --no-coverage"
},
"dependencies": {
"feather-icons": "^4.28.0",
@ -36,10 +44,12 @@
"striptags": "^3.2.0"
},
"devDependencies": {
"c8": "7.10.0",
"eslint": "7.32.0",
"html-validate": "6.1.0",
"husky": "7.0.2",
"lint-staged": "11.2.0",
"microbundle": "0.14.1",
"prettier": "2.4.1",
"resume-schema": "1.0.0",
"tap": "15.0.10"

View File

@ -1,8 +1,8 @@
const { test } = require('tap')
const { HtmlValidate } = require('html-validate')
import { test } from 'tap'
import { HtmlValidate } from 'html-validate'
const { render } = require('..')
const resume = require('resume-schema/sample.resume.json')
import { render } from '../index.js'
import resume from 'resume-schema/sample.resume.json'
// Overwrite empty sample resume values
resume.basics.image = 'image.jpg'