Skip to content

Commit

Permalink
Merge pull request #110 from marp-team/upgrade-dependencies
Browse files Browse the repository at this point in the history
Update dependent packages to the latest version
  • Loading branch information
yhatt committed Jun 24, 2019
2 parents 11f28c4 + 03d831c commit f447710
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 89 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]

### Added

- Support [`size` global directive](https://github.com/marp-team/marp-core/#size-global-directive) of the updated Marp Core ([#110](https://github.com/marp-team/marp-cli/pull/110))

### Changed

- Upgrade to [Marp Core v0.11.0](https://github.com/marp-team/marp-core/releases/tag/v0.11.0) ([#110](https://github.com/marp-team/marp-cli/pull/110))
- Upgrade dependent packages to the latest version ([#110](https://github.com/marp-team/marp-cli/pull/110))

## v0.10.2 - 2019-06-21

### Fixed
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@types/express": "^4.17.0",
"@types/jest": "^24.0.15",
"@types/jest-plugin-context": "^2.9.2",
"@types/node": "^12.0.8",
"@types/node": "^12.0.10",
"@types/pug": "^2.0.4",
"@types/puppeteer": "^1.12.4",
"@types/supertest": "^2.0.7",
Expand All @@ -82,6 +82,7 @@
"cheerio": "^1.0.0-rc.3",
"codecov": "^3.5.0",
"cssnano": "^4.1.10",
"image-size": "^0.7.4",
"jest": "^24.8.0",
"jest-junit": "^6.4.0",
"jest-plugin-context": "^2.9.0",
Expand All @@ -90,10 +91,10 @@
"postcss-url": "^8.0.0",
"prettier": "^1.18.2",
"pug": "^2.0.4",
"rollup": "^1.15.6",
"rollup": "^1.16.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.0.3",
"rollup-plugin-node-resolve": "^5.0.4",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-pug": "^1.1.1",
"rollup-plugin-terser": "^5.0.0",
Expand All @@ -110,16 +111,16 @@
"ts-jest": "24.0.2",
"ts-keycode-enum": "^1.0.6",
"tslib": "^1.10.0",
"tslint": "^5.17.0",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.5.2",
"zip-stream": "^2.0.1"
},
"dependencies": {
"@marp-team/marp-core": "^0.10.2",
"@marp-team/marp-core": "^0.11.0",
"@marp-team/marpit": "^1.2.0",
"carlo": "^0.9.45",
"carlo": "^0.9.46",
"chalk": "^2.4.2",
"chokidar": "^3.0.1",
"chrome-launcher": "^0.10.7",
Expand All @@ -128,7 +129,7 @@
"get-stdin": "^7.0.0",
"globby": "^9.2.0",
"import-from": "^3.0.0",
"is-wsl": "^2.0.0",
"is-wsl": "^2.1.0",
"mkdirp": "^0.5.1",
"os-locale": "^4.0.0",
"pkg-up": "^3.1.0",
Expand Down
32 changes: 11 additions & 21 deletions src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { URL } from 'url'
import { silence, warn } from './cli'
import { Engine } from './engine'
import metaPlugin from './engine/meta-plugin'
import infoPlugin, { engineInfo, EngineInfo } from './engine/info-plugin'
import { error } from './error'
import { File, FileType } from './file'
import templates, {
Expand Down Expand Up @@ -101,25 +102,12 @@ export class Converter {
renderer: tplOpts => {
const engine = this.generateEngine(tplOpts)
const ret = engine.render(`${markdown}${additionals}`)
const info = engine[engineInfo]

const { themeSet, lastGlobalDirectives } = <any>engine
const globalDirectives = lastGlobalDirectives || {}
const themeName: string | undefined =
globalDirectives.theme || (themeSet.default || {}).name

if (isFile) this.options.themeSet.observe(file!.absolutePath, themeName)

return {
...ret,
description: globalDirectives.marpCLIDescription,
image: globalDirectives.marpCLIImage,
title: globalDirectives.marpCLITitle,
url: globalDirectives.marpCLIURL,
size: {
height: engine.themeSet.getThemeProp(themeName!, 'heightPixel'),
width: engine.themeSet.getThemeProp(themeName!, 'widthPixel'),
},
}
if (isFile)
this.options.themeSet.observe(file!.absolutePath, info && info.theme)

return { ...ret, ...info! }
},
})
}
Expand Down Expand Up @@ -198,7 +186,9 @@ export class Converter {
})
}

private generateEngine(mergeOptions: MarpitOptions): Marpit {
private generateEngine(
mergeOptions: MarpitOptions
): Marpit & { [engineInfo]: EngineInfo | undefined } {
const { html, options } = this.options
const { prototype } = this.options.engine
const opts = { ...options, ...mergeOptions, html }
Expand All @@ -213,8 +203,8 @@ export class Converter {

if (html !== undefined) engine.markdown.set({ html })

// Plugins
engine.use(metaPlugin, engine)
// Marpit plugins
engine.use(metaPlugin).use(infoPlugin)

// Additional themes
this.options.themeSet.registerTo(engine)
Expand Down
36 changes: 36 additions & 0 deletions src/engine/info-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export interface EngineInfo {
theme: string | undefined
description: string | undefined
image: string | undefined
title: string | undefined
url: string | undefined
size: { height: number; width: number }
}

export const engineInfo = Symbol()

export default function infoPlugin(md: any) {
const { marpit } = md

md.core.ruler.push('marp_cli_info', state => {
if (state.inlineMode) return

const { themeSet, lastGlobalDirectives } = marpit
const globalDirectives = lastGlobalDirectives || {}
const theme = globalDirectives.theme || (themeSet.default || {}).name

const info: EngineInfo = {
theme,
description: globalDirectives.marpCLIDescription,
image: globalDirectives.marpCLIImage,
title: globalDirectives.marpCLITitle,
url: globalDirectives.marpCLIURL,
size: {
height: themeSet.getThemeProp(theme!, 'heightPixel'),
width: themeSet.getThemeProp(theme!, 'widthPixel'),
},
}

marpit[engineInfo] = info
})
}
2 changes: 1 addition & 1 deletion src/engine/meta-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Marpit } from '@marp-team/marpit'
import { URL } from 'url'
import { warn } from '../cli'

export default function metaPlugin(_, marpit: Marpit) {
export default function metaPlugin({ marpit }: { marpit: Marpit }) {
Object.assign(marpit.customDirectives.global, {
description: v => (typeof v === 'string' ? { marpCLIDescription: v } : {}),
image: v => (typeof v === 'string' ? { marpCLIImage: v } : {}),
Expand Down
2 changes: 1 addition & 1 deletion test/_configs/custom-engine/custom-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = class CustomEngine {
}

this.themeSet = { getThemeProp: jest.fn() }
this.use = jest.fn()
this.use = jest.fn(() => this)
}

render() {
Expand Down
2 changes: 2 additions & 0 deletions test/_files/2.mdown
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
## two

<!-- size: 4:3 -->
68 changes: 59 additions & 9 deletions test/converter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Marp from '@marp-team/marp-core'
import { MarpitOptions } from '@marp-team/marpit'
import fs from 'fs'
import imageSize from 'image-size'
import os from 'os'
import path from 'path'
import { URL } from 'url'
Expand Down Expand Up @@ -310,43 +311,92 @@ describe('Converter', () => {
})

context('when convert type is PNG', () => {
let converter: Converter
let write: jest.Mock

beforeEach(() => {
converter = instance({ output: 'a.png', type: ConvertType.png })
write = (<any>fs).__mockWriteFile()
})

it(
'converts markdown file into PNG',
async () => {
const write = (<any>fs).__mockWriteFile()
const converter = instance({ output: 'a.png', type: ConvertType.png })

await converter.convertFile(new File(onePath))
const png: Buffer = write.mock.calls[0][1]

expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('a.png')
expect(png.toString('ascii', 1, 4)).toBe('PNG')

const { width, height } = imageSize(png, undefined)
expect(width).toBe(1280)
expect(height).toBe(720)
},
puppeteerTimeoutMs
)

context('with 4:3 size global directive for Marp Core', () => {
const slide43Path = twoPath

it(
'converts into 4:3 PNG',
async () => {
await converter.convertFile(new File(slide43Path))
const png: Buffer = write.mock.calls[0][1]

const { width, height } = imageSize(png, undefined)
expect(width).toBe(960)
expect(height).toBe(720)
},
puppeteerTimeoutMs
)
})
})

context('when convert type is JPEG', () => {
let converter: Converter
let write: jest.Mock

beforeEach(() => {
converter = instance({ output: 'b.jpg', type: ConvertType.jpeg })
write = (<any>fs).__mockWriteFile()
})

it(
'converts markdown file into JPEG',
async () => {
const write = (<any>fs).__mockWriteFile()
const converter = instance({
output: 'b.jpg',
type: ConvertType.jpeg,
})

await converter.convertFile(new File(onePath))
const jpeg: Buffer = write.mock.calls[0][1]

expect(write).toHaveBeenCalled()
expect(write.mock.calls[0][0]).toBe('b.jpg')
expect(jpeg[0]).toBe(0xff)
expect(jpeg[1]).toBe(0xd8)

const { width, height } = imageSize(jpeg, undefined)
expect(width).toBe(1280)
expect(height).toBe(720)
},
puppeteerTimeoutMs
)

context('with 4:3 size global directive for Marp Core', () => {
const slide43Path = twoPath

it(
'converts into 4:3 JPEG',
async () => {
await converter.convertFile(new File(slide43Path))
const jpeg: Buffer = write.mock.calls[0][1]

const { width, height } = imageSize(jpeg, undefined)
expect(width).toBe(960)
expect(height).toBe(720)
},
puppeteerTimeoutMs
)
})
})
})

Expand Down
Loading

0 comments on commit f447710

Please sign in to comment.