Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve version output when using user-installed Marp Core #105

Merged
merged 4 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Improve version output when using user-installed Marp Core ([#105](https://github.com/marp-team/marp-cli/pull/105))

## v0.10.1 - 2019-06-19

### Fixed
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ npm install -g @marp-team/marp-cli

### Standalone binary _(EXPERIMENTAL)_

Do you never want to install any dependent tools? we also provide executable binaries for Linux, macOS, and Windows. [:fast_forward: Download the latest standalone binary for your OS from release page.](https://github.com/marp-team/marp-cli/releases)
Do you never want to install any dependent tools? we also provide executable binaries for Linux, macOS, and Windows.

**[:fast_forward: Download the latest standalone binary for your OS from release page.](https://github.com/marp-team/marp-cli/releases)**

## Basic usage

Expand Down Expand Up @@ -326,10 +328,10 @@ By using `--version` (`-v`) option, you may confirm the version of engine that i

```console
$ marp --version
@marp-team/marp-cli v0.x.x (/w bundled @marp-team/marp-core v0.x.x)
@marp-team/marp-cli v0.x.x (w/ bundled @marp-team/marp-core v0.x.x)
```

Marp CLI prefers to use _an installed core by user_ than the bundled. If the current project has installed `@marp-team/marp-core` individually, it would show its version and the annotation "/w customized engine".
Marp CLI prefers to use _an installed core by user_ than the bundled. If the current project has installed `@marp-team/marp-core` individually, it would show its version and the annotation: `w/ user-installed @marp-team/marp-core vX.X.X` or `w/ customized engine`.

## Configuration file

Expand Down
14 changes: 9 additions & 5 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import { MarpCLIConfig } from './config'
import { name, version } from '../package.json'

export default async function outputVersion(config: MarpCLIConfig): Promise<0> {
let message = `${name} v${version} `
let engineVer = ''
const { engine } = config

if (engine.klass === Marp) {
message += `(/w bundled @marp-team/marp-core v${bundledCoreVer})`
engineVer = `bundled @marp-team/marp-core v${bundledCoreVer}`

if (engine.package && engine.package.version !== bundledCoreVer) {
engineVer = `user-installed @marp-team/marp-core v${engine.package.version}`
}
} else if (engine.package && engine.package.name && engine.package.version) {
message += `(/w customized engine in ${engine.package.name} v${engine.package.version})`
engineVer = `customized engine in ${engine.package.name} v${engine.package.version}`
} else {
message += `(/w customized engine)`
engineVer = `customized engine`
}

console.log(message)
console.log(`${name} v${version}${engineVer ? ` (w/ ${engineVer})` : ''}`)
return 0
}
31 changes: 29 additions & 2 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ describe('Marp CLI', () => {
for (const cmd of ['--version', '-v'])
context(`with ${cmd} option`, () => {
let log: jest.SpyInstance<void, any>
let findClassPath: jest.SpyInstance<ResolvedEngine['findClassPath']>
let findClassPath: jest.SpyInstance

beforeEach(() => {
log = jest.spyOn(console, 'log').mockImplementation()
findClassPath = jest
.spyOn(<any>ResolvedEngine.prototype, 'findClassPath')
.spyOn(ResolvedEngine.prototype as any, 'findClassPath')
.mockImplementation()
})

Expand All @@ -67,6 +67,33 @@ describe('Marp CLI', () => {
)
})

context(
'when resolved core has unexpected version against bundled',
() => {
const pkgJson = { name: '@marp-team/marp-core', version: '0.0.0' }
const pkgPath = '../node_modules/@marp-team/marp-core/package.json'

beforeEach(() => {
findClassPath.mockImplementation(() =>
assetFn('../node_modules/@marp-team/marp-core/lib/marp.js')
)

jest.doMock(pkgPath, () => pkgJson)
})

afterEach(() => jest.unmock(pkgPath))

it('outputs resolved version as user-installed core', async () => {
expect(await marpCli([cmd])).toBe(0)
expect(log).toBeCalledWith(
expect.stringContaining(
'user-installed @marp-team/marp-core v0.0.0'
)
)
})
}
)

context('with specified Marpit engine', () => {
const cmds = [cmd, '--engine', '@marp-team/marpit']

Expand Down