Skip to content

Commit

Permalink
fix: add output option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove `schemeName` and `distFolder`
  • Loading branch information
mauroreisvieira committed Apr 16, 2021
1 parent aaf5659 commit 7060576
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 143 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const settings: SchemeSetting = {
generateScheme({
name: 'Scheme Example',
author: 'Mauro Reis Vieira <mauroreisvieira@gmail.com>',
schemeName: 'Scheme Example',
output: {
filename: 'Scheme Example',
},
settings,
});
```
Expand Down
4 changes: 3 additions & 1 deletion demo/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const settings: SchemeSetting = {
generateScheme({
name: 'Meetio Scheme Example',
author: 'Mauro Reis Vieira <mauroreisvieira@gmail.com>',
schemeName: 'Meetio Scheme Example',
output: {
filename: 'Meetio Scheme Example',
},
settings,
});
275 changes: 139 additions & 136 deletions lib/interfaces.ts
Original file line number Diff line number Diff line change
@@ -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;
};
}
13 changes: 8 additions & 5 deletions lib/scheme/schemeGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as fs from 'fs';
import * as path from 'path';

import { GenerateScheme, Rules } from '../interfaces';
import { duplicated, error, success } from '../utils/log';

export function generateScheme(options: GenerateScheme) {
const {
name,
author,
schemeName,
settings,
distFolder = 'schemes',
output,
} = options;
const { colors, ui, rules } = settings;
const { base, ...rest } = colors;
Expand All @@ -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,
Expand All @@ -51,7 +54,7 @@ export function generateScheme(options: GenerateScheme) {
4
)
);
success(schemeName, distFolder);
success(output.filename, output.path || 'schemes');
} catch (e) {
error(e);
}
Expand Down

0 comments on commit 7060576

Please sign in to comment.