From 7060576eb9d033e183692ad3a5c6f3fecaeedcfe Mon Sep 17 00:00:00 2001 From: Mauro Reis Vieira Date: Fri, 16 Apr 2021 14:42:00 +0100 Subject: [PATCH] fix: add `output` option BREAKING CHANGE: remove `schemeName` and `distFolder` --- README.md | 4 +- demo/generate.ts | 4 +- lib/interfaces.ts | 275 +++++++++++++++++----------------- lib/scheme/schemeGenerator.ts | 13 +- 4 files changed, 153 insertions(+), 143 deletions(-) diff --git a/README.md b/README.md index 6135503..91ec76a 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,9 @@ const settings: SchemeSetting = { generateScheme({ name: 'Scheme Example', author: 'Mauro Reis Vieira ', - schemeName: 'Scheme Example', + output: { + filename: 'Scheme Example', + }, settings, }); ``` diff --git a/demo/generate.ts b/demo/generate.ts index cddfeb4..d4861e8 100644 --- a/demo/generate.ts +++ b/demo/generate.ts @@ -49,6 +49,8 @@ const settings: SchemeSetting = { generateScheme({ name: 'Meetio Scheme Example', author: 'Mauro Reis Vieira ', - schemeName: 'Meetio Scheme Example', + output: { + filename: 'Meetio Scheme Example', + }, settings, }); diff --git a/lib/interfaces.ts b/lib/interfaces.ts index 4bf618c..121f0f0 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -1,153 +1,156 @@ export interface Base { - black?: string; - blue?: string; - gray?: string; - brown?: string; - cyan?: string; - green?: string; - orange?: string; - pink?: string; - purple?: string; - red?: string; - violet?: string; - white?: string; - yellow?: string; + black?: string; + blue?: string; + gray?: string; + brown?: string; + cyan?: string; + green?: string; + orange?: string; + pink?: string; + purple?: string; + red?: string; + violet?: string; + white?: string; + yellow?: string; } export interface Colors { - accent: string; - cursor: string; - foreground: string; - background: string; - comments: string; - invalid: string; - deprecated: string; - diffAdded: string; - diffModified: string; - diffDeleted: string; - base: Base; + accent: string; + cursor: string; + foreground: string; + background: string; + comments: string; + invalid: string; + deprecated: string; + diffAdded: string; + diffModified: string; + diffDeleted: string; + base: Base; } export interface Rules { - name?: string; - scope?: string[]; - settings?: { - foreground?: string; - background?: string; - foreground_adjust?: string; - selection_foreground?: string; - font_style?: string; - }; + name?: string; + scope?: string[]; + settings?: { + foreground?: string; + background?: string; + foreground_adjust?: string; + selection_foreground?: string; + font_style?: string; + }; } export interface UI { - /** The default background color. */ - background?: string; - /** The default color for text. */ - foreground?: string; - /** The color for whitespace, when rendered. */ - invisibles?: string; - /** The color of the caret. */ - caret?: string; - /** The color of the caret when using a block caret. (+3190) */ - block_caret?: string; - /** The background color of the line containing the caret. */ - line_highlight?: string; - /** The color to use for the squiggly underline drawn under misspelled words. */ - misspelling?: string; - /** The color to use for the marker that indicates content has been folded. */ - fold_marker?: string; - /** The color of the border drawn around the viewport area of the minimap. */ - minimap_border?: string; - /** The color search result positions drawn on top of the scroll bar. */ - scroll_highlight?: string; - /** The color of the selected search result position drawn on top of the scroll bar. (+4050) */ - scroll_selected_highlight?: string; - /** A color made available for use by the theme. (+4050) */ - accent?: string; - /** CSS passed to popups. */ - popup_css?: string; - /** CSS passed to phantoms. */ - phantom_css?: string; - /** CSS passed to HTML sheets. (+4065) */ - sheet_css?: string; - /** The background color of the gutter. */ - gutter?: string; - /** The color of line numbers in the gutter. */ - gutter_foreground?: string; - /** The color of line numbers in the gutter when a line is highlighted. (+4050) */ - gutter_foreground_highlight?: string; - /** The width of the diff lines, between 1 and 8. (+3186) */ - line_diff_width?: string; - /** The color of diff markers for added lines. (+3186) */ - line_diff_added?: string; - /** The color of diff markers for modified lines. (+3186) */ - line_diff_modified?: string; - /** The color of diff markers for deleted lines. (+3186) */ - line_diff_deleted?: string; - /** The background color of selected text. */ - selection?: string; - /** A color that will override the scope-based text color of the selection. */ - selection_foreground?: string; - /** The color for the border of the selection. */ - selection_border?: string; - /** The width of the selection border, from 0 to 4. */ - selection_border_width?: string; - /** The background color of a selection in a view that is not currently focused. */ - inactive_selection?: string; - /** The color for the border of the selection in a view that is not currently focused. (+4074) */ - inactive_selection_border?: string; - /** A color that will override the scope-based text color of the selection in a view that is not currently focused. */ - inactive_selection_foreground?: string; - /** The style of corners to use on selections. */ - selection_corner_style?: 'round' | 'cut' | 'square'; - /** The radius to use when the selection_corner_style. */ - selection_corner_radius?: 'round' | 'cut'; - /** The border color for "other" matches when the Highlight matches option is selected in the Find panel. */ - highlight?: string; - /** The background color of text matched by the Find panel. */ - find_highlight?: string; - /** A color that will override the scope-based text color of text matched by the Find panel. */ - find_highlight_foreground?: string; - /** The color used to draw indent guides. */ - guide?: string; - /** The color used to draw the indent guides for the indentation levels containing the caret. */ - stack_guide?: string; - /** The color used to draw the indent guides for the parent indentation levels of the indentation level containing the caret. */ - active_guide?: string; - /** How brackets are highlighted when the caret is next to one: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` | `bold` | `italic` */ - brackets_options?: string; - /** The color to use when drawing the style specified by `brackets_options`. */ - brackets_foreground?: string; - /** How brackets are highlighted when the caret is positioned in between a pair of brackets: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` */ - bracket_contents_options?: string; - /** The color to use when drawing the style specified by `brackets_contents_options`. */ - bracket_contents_foreground?: string; - /** How tags are highlighted when the caret is inside of one: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` */ - tags_options?: string; - /** he color to use when drawing the style specified by tags_options. */ - tags_foreground?: string; - /** The color of the shadow used to show when a text area can be horizontally scrolled. */ - shadow?: string; - /** The width of the shadow in device-independent pixels. */ - shadow_width?: string; + /** The default background color. */ + background?: string; + /** The default color for text. */ + foreground?: string; + /** The color for whitespace, when rendered. */ + invisibles?: string; + /** The color of the caret. */ + caret?: string; + /** The color of the caret when using a block caret. (+3190) */ + block_caret?: string; + /** The background color of the line containing the caret. */ + line_highlight?: string; + /** The color to use for the squiggly underline drawn under misspelled words. */ + misspelling?: string; + /** The color to use for the marker that indicates content has been folded. */ + fold_marker?: string; + /** The color of the border drawn around the viewport area of the minimap. */ + minimap_border?: string; + /** The color search result positions drawn on top of the scroll bar. */ + scroll_highlight?: string; + /** The color of the selected search result position drawn on top of the scroll bar. (+4050) */ + scroll_selected_highlight?: string; + /** A color made available for use by the theme. (+4050) */ + accent?: string; + /** CSS passed to popups. */ + popup_css?: string; + /** CSS passed to phantoms. */ + phantom_css?: string; + /** CSS passed to HTML sheets. (+4065) */ + sheet_css?: string; + /** The background color of the gutter. */ + gutter?: string; + /** The color of line numbers in the gutter. */ + gutter_foreground?: string; + /** The color of line numbers in the gutter when a line is highlighted. (+4050) */ + gutter_foreground_highlight?: string; + /** The width of the diff lines, between 1 and 8. (+3186) */ + line_diff_width?: string; + /** The color of diff markers for added lines. (+3186) */ + line_diff_added?: string; + /** The color of diff markers for modified lines. (+3186) */ + line_diff_modified?: string; + /** The color of diff markers for deleted lines. (+3186) */ + line_diff_deleted?: string; + /** The background color of selected text. */ + selection?: string; + /** A color that will override the scope-based text color of the selection. */ + selection_foreground?: string; + /** The color for the border of the selection. */ + selection_border?: string; + /** The width of the selection border, from 0 to 4. */ + selection_border_width?: string; + /** The background color of a selection in a view that is not currently focused. */ + inactive_selection?: string; + /** The color for the border of the selection in a view that is not currently focused. (+4074) */ + inactive_selection_border?: string; + /** A color that will override the scope-based text color of the selection in a view that is not currently focused. */ + inactive_selection_foreground?: string; + /** The style of corners to use on selections. */ + selection_corner_style?: 'round' | 'cut' | 'square'; + /** The radius to use when the selection_corner_style. */ + selection_corner_radius?: 'round' | 'cut'; + /** The border color for "other" matches when the Highlight matches option is selected in the Find panel. */ + highlight?: string; + /** The background color of text matched by the Find panel. */ + find_highlight?: string; + /** A color that will override the scope-based text color of text matched by the Find panel. */ + find_highlight_foreground?: string; + /** The color used to draw indent guides. */ + guide?: string; + /** The color used to draw the indent guides for the indentation levels containing the caret. */ + stack_guide?: string; + /** The color used to draw the indent guides for the parent indentation levels of the indentation level containing the caret. */ + active_guide?: string; + /** How brackets are highlighted when the caret is next to one: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` | `bold` | `italic` */ + brackets_options?: string; + /** The color to use when drawing the style specified by `brackets_options`. */ + brackets_foreground?: string; + /** How brackets are highlighted when the caret is positioned in between a pair of brackets: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` */ + bracket_contents_options?: string; + /** The color to use when drawing the style specified by `brackets_contents_options`. */ + bracket_contents_foreground?: string; + /** How tags are highlighted when the caret is inside of one: `underline` | `stippled_underline` | `squiggly_underline` | `foreground` */ + tags_options?: string; + /** he color to use when drawing the style specified by tags_options. */ + tags_foreground?: string; + /** The color of the shadow used to show when a text area can be horizontally scrolled. */ + shadow?: string; + /** The width of the shadow in device-independent pixels. */ + shadow_width?: string; } export interface SchemeSetting { - colors: Colors; - ui?: UI; - rules?: Rules[]; + colors: Colors; + ui?: UI; + rules?: Rules[]; } export interface GenerateScheme { - /** Name of file with '.sublime-color-scheme' extension */ - name: string; - /** Author name */ - author: string; - /** Scheme name */ - schemeName: string; - /** Settings of scheme */ - settings: SchemeSetting; - /** Name of destination folder */ - distFolder?: string; + /** Name of Scheme */ + name: string; + /** Author name */ + author: string; + /** Settings of scheme */ + settings: SchemeSetting; + /** Output Management */ + output: { + /** Scheme file name */ + filename: string; + /** Folder destination */ + path?: string; + }; } diff --git a/lib/scheme/schemeGenerator.ts b/lib/scheme/schemeGenerator.ts index 379fdad..828f03f 100644 --- a/lib/scheme/schemeGenerator.ts +++ b/lib/scheme/schemeGenerator.ts @@ -1,4 +1,6 @@ import * as fs from 'fs'; +import * as path from 'path'; + import { GenerateScheme, Rules } from '../interfaces'; import { duplicated, error, success } from '../utils/log'; @@ -6,9 +8,8 @@ export function generateScheme(options: GenerateScheme) { const { name, author, - schemeName, settings, - distFolder = 'schemes', + output, } = options; const { colors, ui, rules } = settings; const { base, ...rest } = colors; @@ -35,10 +36,12 @@ export function generateScheme(options: GenerateScheme) { }); }); - fs.mkdir(distFolder, () => { + // eslint-disable-next-line no-undef + const dist = output.path || path.resolve('schemes'); + fs.mkdir(dist, () => { try { fs.writeFileSync( - `${distFolder}/${schemeName}.sublime-color-scheme`, + `${dist}/${output.filename}.sublime-color-scheme`, JSON.stringify( { name, @@ -51,7 +54,7 @@ export function generateScheme(options: GenerateScheme) { 4 ) ); - success(schemeName, distFolder); + success(output.filename, output.path || 'schemes'); } catch (e) { error(e); }