From b72ecf882217b2d7c1ec280c835b361526c2544d Mon Sep 17 00:00:00 2001 From: Mauro Reis Vieira Date: Tue, 12 Jan 2021 15:09:56 +0000 Subject: [PATCH] feat: change generateScheme method and color object --- demo/generate.ts | 54 +++++++++------- package.json | 28 ++++----- ...eetio Scheme Example.sublime-color-scheme} | 47 +++++++------- scripts/release.sh | 12 ++-- src/index.ts | 2 +- src/interfaces.ts | 63 ++++++++++++------- src/schemeGenerator.ts | 22 +++---- 7 files changed, 127 insertions(+), 101 deletions(-) rename schemes/{Scheme-Example.sublime-color-scheme => Meetio Scheme Example.sublime-color-scheme} (98%) diff --git a/demo/generate.ts b/demo/generate.ts index ea4ca7c..30b625c 100644 --- a/demo/generate.ts +++ b/demo/generate.ts @@ -1,39 +1,49 @@ -/* eslint-disable no-undef */ import { generateScheme, ISchemeSetting } from '../dist/index'; + const settings: ISchemeSetting = { colors: { - accent: '#69bdbd', - cursor: '#e6db30', - foreground: '#A6ACCD', - background: '#292D3E', - comments: '#676E95', - blue: '#82AAFF', - brown: '#916b53', - cyan: '#89DDFF', - green: '#C3E88D', - orange: '#F78C6C', - pink: '#ff9cac', - purple: '#C792EA', - red: '#f07178', - yellow: '#FFCB6B', + accent: '#80CBC4', + cursor: '#FFCC00', + foreground: '#EEFFFF', + background: '#263238', + comments: '#546E7A', deprecated: '#ffc777a1', invalid: '#d46c6c66', diffAdded: '#addb67', diffModified: '#e2b93d', diffDeleted: '#ef5350', + base: { + white: '#ffffff', + black: '#000000', + red: '#f07178', + orange: '#F78C6C', + yellow: '#FFCB6B', + green: '#C3E88D', + cyan: '#89DDFF', + blue: '#82AAFF', + purple: '#C792EA', + brown: '#916b53', + pink: '#ff9cac', + violet: '#bb80b3', + }, }, ui: { caret: 'var(cursor)', tags_options: 'underline', - brackets_options: 'underline, glow' + brackets_options: 'underline, glow', + line_highlight: '#00000040', + selection: '#80CBC420', + gutter_foreground: '#37474F', + shadow: '#00000030', + find_highlight: '#FFCC00', + inactive_selection: '#00000030', }, rules: [], }; -generateScheme( - 'Scheme-Example', - 'Mauro Reis Vieira ', - 'Scheme-Example', +generateScheme({ + name: 'Meetio Scheme Example', + author: 'Mauro Reis Vieira ', + schemeName: 'Meetio Scheme Example', settings, - 'schemes' -); +}); diff --git a/package.json b/package.json index bd11b4f..a871fd6 100644 --- a/package.json +++ b/package.json @@ -31,22 +31,22 @@ } }, "devDependencies": { - "@babel/core": "7.9.6", - "@babel/preset-env": "7.9.6", - "@commitlint/cli": "^8.3.5", - "@commitlint/config-conventional": "^8.3.4", - "@typescript-eslint/eslint-plugin": "2.32.0", - "@typescript-eslint/parser": "2.32.0", + "@babel/core": "7.12.10", + "@babel/preset-env": "7.12.11", + "@commitlint/cli": "^11.0.0", + "@commitlint/config-conventional": "^11.0.0", + "@typescript-eslint/eslint-plugin": "4.13.0", + "@typescript-eslint/parser": "4.13.0", "babel-eslint": "^10.0.3", - "chalk": "^4.0.0", - "conventional-changelog-cli": "^2.0.11", - "eslint": "7.0.0", - "husky": "^4.2.5", - "prettier": "^2.0.5", - "ts-node": "^8.10.1", - "typescript": "^3.7.2" + "chalk": "^4.1.0", + "conventional-changelog-cli": "^2.1.1", + "eslint": "7.17.0", + "husky": "^4.3.7", + "prettier": "^2.2.1", + "ts-node": "^9.1.1", + "typescript": "^4.1.3" }, "dependencies": { - "@types/node": "^13.13.5" + "@types/node": "^14.14.20" } } diff --git a/schemes/Scheme-Example.sublime-color-scheme b/schemes/Meetio Scheme Example.sublime-color-scheme similarity index 98% rename from schemes/Scheme-Example.sublime-color-scheme rename to schemes/Meetio Scheme Example.sublime-color-scheme index ad3a7ed..6226c5e 100644 --- a/schemes/Scheme-Example.sublime-color-scheme +++ b/schemes/Meetio Scheme Example.sublime-color-scheme @@ -1,26 +1,29 @@ { - "name": "Scheme-Example", + "name": "Meetio Scheme Example", "author": "Mauro Reis Vieira ", "variables": { - "accent": "#69bdbd", - "cursor": "#e6db30", - "foreground": "#A6ACCD", - "background": "#292D3E", - "comments": "#676E95", - "blue": "#82AAFF", - "brown": "#916b53", - "cyan": "#89DDFF", - "green": "#C3E88D", - "orange": "#F78C6C", - "pink": "#ff9cac", - "purple": "#C792EA", - "red": "#f07178", - "yellow": "#FFCB6B", + "accent": "#80CBC4", + "cursor": "#FFCC00", + "foreground": "#EEFFFF", + "background": "#263238", + "comments": "#546E7A", "deprecated": "#ffc777a1", "invalid": "#d46c6c66", "diffAdded": "#addb67", "diffModified": "#e2b93d", - "diffDeleted": "#ef5350" + "diffDeleted": "#ef5350", + "white": "#ffffff", + "black": "#000000", + "red": "#f07178", + "orange": "#F78C6C", + "yellow": "#FFCB6B", + "green": "#C3E88D", + "cyan": "#89DDFF", + "blue": "#82AAFF", + "purple": "#C792EA", + "brown": "#916b53", + "pink": "#ff9cac", + "violet": "#bb80b3" }, "globals": { "accent": "var(accent)", @@ -32,27 +35,27 @@ "brackets_foreground": "var(cyan)", "brackets_options": "underline, glow", "caret": "var(cursor)", - "find_highlight": "var(yellow)", + "find_highlight": "#FFCC00", "find_highlight_foreground": "var(background)", "fold_marker": "var(yellow)", "foreground": "var(foreground)", "gutter": "var(background)", - "gutter_foreground": "color(var(foreground) alpha(0.2))", + "gutter_foreground": "#37474F", "highlight": "var(yellow)", - "inactive_selection": "color(var(cyan) alpha(0.1))", + "inactive_selection": "#00000030", "inactive_selection_border": "color(var(cyan) alpha(0.1))", "invisibles": "color(var(foreground) alpha(0.3))", "line_diff_added": "var(diffAdded)", "line_diff_deleted": "var(diffDeleted)", "line_diff_modified": "var(diffModified)", "line_diff_width": "2", - "line_highlight": "color(var(foreground) alpha(0.1))", + "line_highlight": "#00000040", "misspelling": "var(blue)", - "selection": "color(var(foreground) alpha(0.10))", + "selection": "#80CBC420", "selection_border": "var(cyan)", "selection_corner_radius": "cut", "selection_corner_style": "cut", - "shadow": "color(var(background) alpha(0.5))", + "shadow": "#00000030", "stack_guide": "var(brown)", "tags_foreground": "var(cyan)", "tags_options": "underline" diff --git a/scripts/release.sh b/scripts/release.sh index dab6f6e..e3b3b85 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -4,31 +4,31 @@ echo "Enter release version: " read VERSION read -p "Releasing v$VERSION - are you sure? (y/n)" -n 1 -r -echo # (optional) move to a new line +echo # (OPTIONAL) MOVE TO A NEW LINE if [[ $REPLY =~ ^[Yy]$ ]] then echo "Releasing v$VERSION ..." yarn run lint yarn run build - # generate the version so that the changelog can be generated too + # GENERATE THE VERSION SO THAT THE CHANGELOG CAN BE GENERATED TOO yarn version --no-git-tag-version --no-commit-hooks --new-version $VERSION - # changelog + # CHANGELOG yarn run changelog echo "Please check the git history and the changelog and press enter" read OKAY - # commit and tag + # COMMIT AND TAG git add CHANGELOG.md package.json git commit -m "chore(release): v$VERSION" git tag -a "v$VERSION" -m $VERSION - # commit + # COMMIT yarn publish --tag next --new-version "$VERSION" --no-commit-hooks --no-git-tag-version - # publish + # PUBLISH git push origin refs/tags/v$VERSION git push fi diff --git a/src/index.ts b/src/index.ts index 342b8ef..b021084 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ export { generateScheme } from './schemeGenerator'; export { defaultRules } from './rules'; -export { IColors, ISchemeSetting, IRules, IUi } from './interfaces'; +export { IColors, IColorsBase, ISchemeSetting, IRules, IUi } from './interfaces'; diff --git a/src/interfaces.ts b/src/interfaces.ts index 5478779..1a92a58 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,3 +1,32 @@ +export interface IColorsBase { + black: string; + blue: string; + brown: string; + cyan: string; + green: string; + orange: string; + pink: string; + purple: string; + red: string; + violet: string; + white: string; + yellow: string; +} + +export interface IColors { + accent: string; + cursor: string; + foreground: string; + background: string; + comments: string; + invalid: string; + deprecated: string; + diffAdded: string; + diffModified: string; + diffDeleted: string; + base: IColorsBase; +} + export interface IRules { name?: string; scope: string[]; @@ -110,27 +139,15 @@ export interface IUi { shadow_width?: string; } -export interface IColors { - cursor: string; - foreground: string; - background: string; - comments: string; - accent?: string; - white?: string; - black?: string; - blue?: string; - brown?: string; - cyan?: string; - gray?: string; - green?: string; - orange?: string; - pink?: string; - purple?: string; - red?: string; - yellow?: string; - invalid?: string; - deprecated?: string; - diffAdded?: string; - diffModified?: string; - diffDeleted?: string; +export interface IGenerateScheme { + /** Name of file with '.sublime-color-scheme' extension */ + name: string; + /** Author name */ + author: string; + /** Scheme name */ + schemeName: string; + /** Settings of scheme */ + settings: ISchemeSetting; + /** Name of destination folder */ + distFolder?: string; } diff --git a/src/schemeGenerator.ts b/src/schemeGenerator.ts index 1f6e7df..1347a5e 100644 --- a/src/schemeGenerator.ts +++ b/src/schemeGenerator.ts @@ -4,22 +4,18 @@ import { duplicated, success, error } from './utils'; import { defaultRules } from './rules'; import { defaultGlobals } from './globals'; -import { ISchemeSetting, IRules } from './interfaces'; +import { IGenerateScheme, IRules } from './interfaces'; -export function generateScheme( - name: string, - author: string, - schemeName: string, - settings: ISchemeSetting, - dist: string = 'schemes' -) { +export function generateScheme(options: IGenerateScheme) { + const { name, author, schemeName, settings, distFolder = 'schemes' } = options; const { colors, ui, rules, useDefaultRules = true } = settings; + const { base, ...rest } = colors; const allRules: Array<{ name: string; scope: string }> = []; const allScopes = new Set(); let spread = [rules]; if (useDefaultRules) { - spread = [...defaultRules, [...rules]]; + spread = [...defaultRules, [...rules]]; } spread.forEach((rule: Array) => { @@ -40,15 +36,15 @@ export function generateScheme( }); }); - fs.mkdir(dist, () => { + fs.mkdir(distFolder, () => { try { fs.writeFileSync( - `${dist}/${schemeName}.sublime-color-scheme`, + `${distFolder}/${schemeName}.sublime-color-scheme`, JSON.stringify( { name, author, - variables: colors, + variables: { ...rest, ...base }, globals: Object.assign(defaultGlobals, ui), rules: allRules, }, @@ -56,7 +52,7 @@ export function generateScheme( 4 ) ); - success(schemeName, dist); + success(schemeName, distFolder); } catch (e) { error(e); }