tancredi / fantasticon

Icon font generation tool
MIT License
925 stars 103 forks source link

fantasticonrc.json files that use a json $schema property are unusable #260

Open bryanwrightscode opened 3 years ago

bryanwrightscode commented 3 years ago

JSON schemas are used by specifying the JSON schema location as a string for the property whose string key is "$schema". I found it helpful to write a schema for the config structure in my fantasticonrc.json file. However when running fantasticon command, when parseConfig encounters the json file that uses the schema, the function includes all keys within the provided json file, even the one named $schema. Since "$schema" is not listed inside CONFIG_VALIDATORS, parseConfig throws an error that the key is not recognized. I suggest updating the parseConfig function to include an edge case where if a provided key is not part of CONFIG_VALIDATORS, only throw an error if it is also not equal to "$schema." Alternatively, include an optional $schema key to CONFIG_VALIDATORS, whose type is a string.

bryanwrightscode commented 3 years ago

fantasticon -c fantasticonrc.json

The option '$schema' is not recognised npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! bryanwrightscode-icons@0.0.2 fonts: fantasticon -c fantasticonrc.json npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bryanwrightscode-icons@0.0.2 fonts script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\bwright\AppData\Roaming\npm-cache_logs\2021-07-31T01_39_23_000Z-debug.lognpm ERR! code ELIFECYCLELE npm ERR! errno 1 ll cp -Recurse dist/brya npm ERR! bryanwrightscode-icons@0.0.2 dev: npm run clean && npm run move && npm run svgo && npm run fonts && powershell cp -Recurse dist/bryanwrightscode-icons.ttf theme/bryanwrightscode-icons.ttf npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bryanwrightscode-icons@0.0.2 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: scode\extensions\bryanwr npm ERR! C:\Users\bwright\AppData\Roaming\npm-cache_logs\2021-07-31T01_39_23_029Z-debug.logPS C:\Users\bwright.vscode\extensions\bryanwrightscode.product-icons-0.0.2>

bryanwrightscode commented 3 years ago

{ "$schema": "./fantasticonrc.schema.json", "assetTypes": [ "css", "html", "ts" ], "codepoints": { "source-control": 10000 }, "descent": 0, "fontHeight": 1000, "fontsUrl": "", "fontTypes": [ "eot", "woff2", "woff", "ttf" ], "formatOptions": { "svg": { "centerHorizontally": true } }, "inputDir": "src/icons", "name": "bryanwrightscode-icons", "normalize": false, "outputDir": "dist", "pathOptions": {}, "prefix": "bryanwrightscode-icon", "round": 10e12, "selector": "", "tag": "", "templates": { "css": "src/template/styles.hbs", "html": "src/template/preview.hbs" } }

bryanwrightscode commented 3 years ago

{ "$schema": "http://json-schema.org/schema", "type": "object", "description": "A custom definition for fantasticon config", "properties": { "inputDir": { "type": "string", "format": "path" }, "outputDir": { "type": "string", "format": "path", "description": "Output Directory" }, "name": { "type": "string", "default": "icons" }, "fontTypes": { "type": "array", "description": "specify font formats to generate (default: eot, woff2, woff, available: eot, woff2, woff, ttf, svg)", "default": [ "eot", "woff2", "woff" ], "items": { "type": "string", "enum": [ "eot", "woff2", "woff", "ttf", "svg" ] } }, "assetTypes": { "type": "array", "description": "specify other asset types to generate (default: css, html, json, ts, available: css, scss, sass, html, json, ts)", "default": [ "css", "html", "json", "ts" ], "items": { "type": "string", "enum": [ "css", "scss", "sass", "html", "json", "ts" ] } }, "formatOptions": { "type": "object", "description": "Pass options directly to svgicons2svgfont", "properties": { "woff": { "type": "object", "properties": { "metadata": { "type": "string", "description": "Woff Extended Metadata Block\n\nSee https://www.w3.org/TR/WOFF/#Metadata" } } }, "ttf": { "type": "object", "properties": { "copyright": { "type": "string", "description": "" }, "description": { "type": "string", "description": "" }, "ts": { "type": "number", "description": "Unix timestamp (in seconds) to override creation time" }, "url": { "type": "string", "description": "manufacturer url" }, "version": { "type": "string", "description": "font version string, can be Version x.y or x.y", "default": "Version 1.0" } } }, "svg": { "type": "object", "description": "", "properties": { "fontId": { "type": "string", "default": "the options.fontName value", "description": "The font id you want (Default value: the options.fontName)" }, "fontStyle": { "type": "string", "description": "The font style you want." }, "fontWeight": { "type": "string", "description": "The font weight" }, "fixedWidth": { "type": "boolean", "description": "Creates a monospace font of the width of the largest input icon." }, "centerHorizontally": { "type": "boolean", "description": "Calculate the bounds of a glyph and center it horizontally." }, "round": { "type": "number", "default": 10e12, "description": "The font descent. It is usefull to fix the font baseline yourself.\n\nWarning: The descent is a positive value!" }, "ascent": { "type": "number", "description": "The font ascent.\n\nDefault value: fontHeight - descent\n\nUse this options only if you know what you're doing.\nA suitable value for this is computed for you." }, "metadata": { "type": "string", "description": "The font metadata.\n\nYou can set any character data in but it is the be suited place for a copyright mention." } } }, "json": { "type": "object", "description": "", "properties": { "indent": { "type": "number", "description": "render the JSON human readable with two spaces indentation (default is none, so minified)" } } }, "ts": { "type": "object", "description": "", "properties": { "types": { "type": "array", "description": "select what kind of types you want to generate (default ['enum', 'constant', 'literalId', 'literalKey'])", "default": [ "enum", "constant", "literalId", "literalKey" ], "items": { "type": "string", "enum": [ "enum", "constant", "literalId", "literalKey" ] } }, "singleQuotes": { "type": "boolean", "description": "render the types with single quotes instead of the double quotes", "default": false } } } } }, "pathOptions": { "type": "object", "properties": { "eot": { "type": "object" }, "woff2": { "type": "object" }, "woff": { "type": "object" }, "ttf": { "type": "object" }, "svg": { "type": "object" }, "css": { "type": "object" }, "scss": { "type": "object" }, "sass": { "type": "object" }, "html": { "type": "object" }, "json": { "type": "object" }, "ts": { "type": "object" } } }, "templates": { "type": "object", "description": "Use custom Handlebars template", "propertyNames": { "enum": [ "css", "scss", "sass", "html", "json", "ts" ] }, "patternProperties": { "^.+$": { "type": "string" } } }, "codepoints": { "type": "object", "description": "", "propertyNames": { "pattern": "^[a-z]+(-[a-z]+){0,}$" }, "patternProperties": { "^test?": { "type": "number" } } }, "fontHeight": { "type": "number", "description": "the output font height (icons will be scaled so the highest has this height) (default: 300)", "default": 300 }, "descent": { "type": "number", "description": "the font descent", "default": 0 }, "normalize": { "type": "boolean", "description": "normalize icons by scaling them to the height of the highest icon" }, "round": { "type": "number", "description": "setup the SVG path rounding [10e12]", "default": 10e12 }, "selector": { "type": "string", "description": "use a CSS selector instead of 'tag + prefix' (default: null)", "default": "" }, "tag": { "type": "string", "description": "CSS base tag for icons (default: i)", "default": "i" }, "prefix": { "type": "string", "description": "CSS class prefix (default: icon)", "default": "icon" }, "fontsUrl": { "type": "string", "description": "public URL to the fonts directory (used in the generated CSS)", "format": "path", "default": "./" } }, "required": [ "inputDir", "outputDir", "codepoints" ] }