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

Rename bespoke option arguments using dot notation #122

Merged
merged 2 commits into from
Jul 4, 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

- Set up CI for Windows with Azure Pipelines ([#120](https://github.com/marp-team/marp-cli/pull/120))

### Changed

- Rename bespoke option arguments using dot notation ([#122](https://github.com/marp-team/marp-cli/pull/122))

### Deprecated

- Deprecate `--bespoke-osc` and `--bespoke-progress` argument options in favor of options using dot notation ([#122](https://github.com/marp-team/marp-cli/pull/122))

## v0.11.3 - 2019-06-30

### Fixed
Expand Down
69 changes: 32 additions & 37 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import { Theme, ThemeSet } from './theme'
import { TemplateOption } from './templates'

const lstat = promisify(fs.lstat)
const pick = <T>(...args: T[]): T | undefined => args.find(v => v !== undefined)

type Overwrite<T, U> = Omit<T, Extract<keyof T, keyof U>> & U

export type IMarpCLIArguments = IMarpCLIBaseArguments & IMarpCLIBespokeArguments

interface IMarpCLIBaseArguments {
interface IMarpCLIArguments {
_?: string[]
allowLocalFiles?: boolean
bespoke?: {
osc?: boolean
progress?: boolean
}
configFile?: string
description?: string
engine?: string
Expand All @@ -39,20 +42,21 @@ interface IMarpCLIBaseArguments {
title?: string
url?: string
watch?: boolean
}

interface IMarpCLIBespokeArguments {
// Deprecated bespoke arguments
bespokeOsc?: boolean
bespokeProgress?: boolean
}

// TODO: Remove deprecated bespoke arguments
type IMarpCLIDeprecatedBespokeArguments = 'bespokeOsc' | 'bespokeProgress'

export type IMarpCLIConfig = Overwrite<
Omit<IMarpCLIBaseArguments, 'configFile' | '_'>,
Omit<
IMarpCLIArguments,
'configFile' | '_' | IMarpCLIDeprecatedBespokeArguments
>,
{
bespoke?: {
osc?: boolean
progress?: boolean
}
engine?: ResolvableEngine | ResolvableEngine[]
html?: ConverterOption['html']
lang?: string
Expand Down Expand Up @@ -90,7 +94,7 @@ export class MarpCLIConfig {

async converterOption(): Promise<ConverterOption> {
const inputDir = await this.inputDir()
const server = this.pickDefined(this.args.server, this.conf.server) || false
const server = pick(this.args.server, this.conf.server) || false
const output = (() => {
if (server) return false
if (this.args.output !== undefined) return this.args.output
Expand All @@ -108,9 +112,14 @@ export class MarpCLIConfig {
const bespoke = this.conf.bespoke || {}

return {
osc: this.pickDefined(this.args.bespokeOsc, bespoke.osc),
progress: this.pickDefined(
this.args.bespokeProgress,
osc: pick(
this.args.bespoke && this.args.bespoke.osc,
this.args.bespokeOsc, // TODO: Remove deprecated argument
bespoke.osc
),
progress: pick(
this.args.bespoke && this.args.bespoke.progress,
this.args.bespokeProgress, // TODO: Remove deprecated argument
bespoke.progress
),
}
Expand Down Expand Up @@ -160,7 +169,7 @@ export class MarpCLIConfig {
})()

const preview = (() => {
const p = this.pickDefined(this.args.preview, this.conf.preview) || false
const p = pick(this.args.preview, this.conf.preview) || false

if (p && process.env.IS_DOCKER) {
warn(
Expand All @@ -182,34 +191,24 @@ export class MarpCLIConfig {
themeSet,
type,
allowLocalFiles:
this.pickDefined(
this.args.allowLocalFiles,
this.conf.allowLocalFiles
) || false,
pick(this.args.allowLocalFiles, this.conf.allowLocalFiles) || false,
engine: this.engine.klass,
globalDirectives: {
description: this.pickDefined(
this.args.description,
this.conf.description
),
image: this.pickDefined(this.args.ogImage, this.conf.ogImage),
description: pick(this.args.description, this.conf.description),
image: pick(this.args.ogImage, this.conf.ogImage),
theme: theme instanceof Theme ? theme.name : theme,
title: this.pickDefined(this.args.title, this.conf.title),
url: this.pickDefined(this.args.url, this.conf.url),
title: pick(this.args.title, this.conf.title),
url: pick(this.args.url, this.conf.url),
},
html: this.pickDefined(this.args.html, this.conf.html),
jpegQuality:
this.pickDefined(this.args.jpegQuality, this.conf.jpegQuality) || 85,
html: pick(this.args.html, this.conf.html),
jpegQuality: pick(this.args.jpegQuality, this.conf.jpegQuality) || 85,
lang: this.conf.lang || (await osLocale()).replace(/@/g, '-'),
options: this.conf.options || {},
readyScript: this.engine.browserScript
? `<script>${this.engine.browserScript}</script>`
: undefined,
watch:
this.pickDefined(this.args.watch, this.conf.watch) ||
preview ||
server ||
false,
pick(this.args.watch, this.conf.watch) || preview || server || false,
}
}

Expand Down Expand Up @@ -312,10 +311,6 @@ export class MarpCLIConfig {

return theme.name
}

private pickDefined<T>(...args: T[]): T | undefined {
return args.find(v => v !== undefined)
}
}

export default MarpCLIConfig.fromArguments
36 changes: 34 additions & 2 deletions src/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,50 @@ export default async function(argv: string[] = []): Promise<number> {
choices: Object.keys(templates),
type: 'string',
},
'bespoke-osc': {
'bespoke.osc': {
describe: '[Bespoke] Use on-screen controller',
defaultDescription: 'true',
group: OptionGroup.Template,
type: 'boolean',
},
'bespoke-progress': {
'bespoke-osc': {
coerce: v => {
cli.warn(
`${chalk.yellow(
'--bespoke-osc'
)} option is deprecated. Please use ${chalk.yellow(
'--bespoke.osc'
)} instead.`
)
return v
},
describe: '[DEPRECATED]',
group: OptionGroup.Template,
hidden: true,
type: 'boolean',
},
'bespoke.progress': {
describe: '[Bespoke] Use progress bar',
defaultDescription: 'false',
group: OptionGroup.Template,
type: 'boolean',
},
'bespoke-progress': {
coerce: v => {
cli.warn(
`${chalk.yellow(
'--bespoke-progress'
)} option is deprecated. Please use ${chalk.yellow(
'--bespoke.progress'
)} instead.`
)
return v
},
describe: '[DEPRECATED]',
group: OptionGroup.Template,
hidden: true,
type: 'boolean',
},
title: {
describe: 'Define title of the slide deck',
group: OptionGroup.Meta,
Expand Down