Skip to content

Commit

Permalink
feat: add html head options to CLI (#33)
Browse files Browse the repository at this point in the history
* feat: add html head options to CLI

* chore: update cleanup cli options

* chore: cleanup cli options before using it

* chore: remove breaking change
  • Loading branch information
userquin authored Jan 13, 2024
1 parent 1c889f5 commit e9b15d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/api/instructions-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ async function resolvePreset(
preset: BuiltInPreset | Preset,
faviconPreset?: HtmlLinkPreset,
): Promise<[preset: Preset, htmlLinkPreset: HtmlLinkPreset]> {
const htmlLinkPreset = faviconPreset ?? 'default'
if (typeof preset === 'object')
return [preset, faviconPreset ?? 'default']
return [preset, htmlLinkPreset]

switch (preset) {
case 'minimal':
return [await import('../presets/minimal.ts').then(m => m.minimalPreset), 'default']
return [await import('../presets/minimal.ts').then(m => m.minimalPreset), htmlLinkPreset]
case 'minimal-2023':
return [await import('../presets/minimal-2023.ts').then(m => m.minimal2023Preset), '2023']
return [await import('../presets/minimal-2023.ts').then(m => m.minimal2023Preset), faviconPreset ?? '2023']
default:
throw new Error(`Preset ${preset} not yet implemented`)
}
Expand Down
27 changes: 25 additions & 2 deletions src/cli-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { generateManifestIconsEntry } from './api/generate-manifest-icons-entry.

interface CliOptions extends Omit<UserConfig, 'preset' | 'images'> {
preset?: BuiltInPreset
headLinkOptions?: HeadLinkOptions
headLinkOptions?: Omit<HeadLinkOptions, 'resolveSvgName'>
override?: boolean
manifest?: boolean
}
Expand All @@ -29,6 +29,7 @@ export async function startCli(args: string[] = process.argv) {
.option('-p, --preset <preset-name>', 'Built-in preset name: minimal, android, windows, ios or all')
.option('-o, --override', 'Override assets? Defaults to true')
.option('-m, --manifest', 'Generate generate PWA web manifest icons entry? Defaults to true')
.option('--html [options]', 'Available options: --html.basePath <path>, --html.preset <preset>, --html.xhtml <false|true>, --html.includeId <false|true>')
.help()
.command(
'[...images]',
Expand All @@ -38,11 +39,33 @@ export async function startCli(args: string[] = process.argv) {
cli.parse(args)
}

function cleanupCliOptions(cliOptions: any) {
delete cliOptions['--']
delete cliOptions['r']
delete cliOptions['c']
delete cliOptions['p']
delete cliOptions['o']
delete cliOptions['m']
if (typeof cliOptions['html'] === 'object') {
cliOptions.headLinkOptions = { ...cliOptions['html'] }
if (typeof cliOptions.headLinkOptions.preset === 'number')
cliOptions.headLinkOptions.preset = `${cliOptions.headLinkOptions.preset}`
if (typeof cliOptions.headLinkOptions.xhtml === 'string')
cliOptions.headLinkOptions.xhtml = cliOptions.headLinkOptions.xhtml === 'true'
if (typeof cliOptions.headLinkOptions.includeId === 'string')
cliOptions.headLinkOptions.includeId = cliOptions.headLinkOptions.includeId === 'true'

delete cliOptions['html']
}
}

async function run(images: string[] = [], cliOptions: CliOptions = {}) {
consola.log(green(`Zero Config PWA Assets Generator v${version}`))
consola.start('Preparing to generate PWA assets...')

const root = cliOptions?.root ?? process.cwd()
cleanupCliOptions(cliOptions)

const root = cliOptions.root ?? process.cwd()

const { config } = await loadConfig<UserConfig>(root, cliOptions)

Expand Down

0 comments on commit e9b15d3

Please sign in to comment.