From 5a03f4823f9f9c390783077e2402e798b5aa937c Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 26 Apr 2024 12:03:42 +0200 Subject: [PATCH] Added support for cssContext --- README.md | 4 ++++ src/optionParser.test.ts | 10 ++++++++++ src/optionParser.ts | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b62d6b4..0119bab 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,10 @@ The plugin has an API consisting of one required parameter and multiple optional - `webfontsGenerator.templates.scss` – Default SCSS template path. It generates mixin `webfont-icon` to add icon styles. It is safe to use multiple generated files with mixins together. - See [webfonts-generator#csstemplate](https://github.com/vusion/webfonts-generator#csstemplate) +### cssContext + +- See [webfonts-generator#cssContext](https://github.com/vusion/webfonts-generator#cssContext) + ### cssFontsUrl - **type**: `string` diff --git a/src/optionParser.test.ts b/src/optionParser.test.ts index 3ec6c92..dbd2c67 100644 --- a/src/optionParser.test.ts +++ b/src/optionParser.test.ts @@ -396,6 +396,16 @@ describe('optionParser', () => { expect(resExplicit.cssTemplate).to.eq(cssTemplate); }); + it.concurrent('sets cssContext only if defined in options', () => { + const resDefault = optionParser.parseOptions({ context }); + expect('cssContext' in resDefault).to.be.false; + const cssContext = () => { + throw new Error("Shouldn't be called!"); + }; + const resExplicit = optionParser.parseOptions({ context, cssContext }); + expect(resExplicit.cssContext).to.eq(cssContext); + }); + it.concurrent('concatenates dest to cssTemplate', () => { const dest = '/root'; const cssTemplate = 'cssTemplate'; diff --git a/src/optionParser.ts b/src/optionParser.ts index b3dbd1c..9763723 100644 --- a/src/optionParser.ts +++ b/src/optionParser.ts @@ -2,7 +2,7 @@ import { resolve } from 'path'; import { globSync } from 'glob'; import { hasFileExtension } from './utils'; import { InvalidWriteFilesTypeError, NoIconsAvailableError } from './errors'; -import type { WebfontsGeneratorOptions, GeneratedFontTypes } from '@vusion/webfonts-generator'; +import type { WebfontsGeneratorOptions, GeneratedFontTypes, CSSTemplateContext } from '@vusion/webfonts-generator'; const FILE_TYPE_OPTIONS = ['html', 'css', 'fonts'] as const; type FileType = (typeof FILE_TYPE_OPTIONS)[number]; @@ -66,6 +66,10 @@ export interface IconPluginOptions, handlebars: typeof import('handlebars')) => void; /** * Fonts path used in CSS file. * @default options.cssDest @@ -221,6 +225,7 @@ export function parseOptions( cssDest: resolveFileDest(options.dest, options.cssDest, options.fontName, 'css'), htmlDest: resolveFileDest(options.dest, options.htmlDest, options.fontName, 'html'), ...(options.cssTemplate && { cssTemplate: resolve(options.dest, options.cssTemplate) }), + ...(options.cssContext && { cssContext: options.cssContext }), ...(options.cssFontsUrl && { cssFontsUrl: resolve(options.dest, options.cssFontsUrl) }), ...(options.htmlTemplate && { htmlTemplate: resolve(options.dest, options.htmlTemplate) }), ...(typeof options.fixedWidth !== 'undefined' && { fixedWidth: options.fixedWidth }),