Skip to content

Commit

Permalink
feat: change generateScheme method and color object
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroreisvieira committed Jan 12, 2021
1 parent bdaae9c commit b72ecf8
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 101 deletions.
54 changes: 32 additions & 22 deletions demo/generate.ts
Original file line number Diff line number Diff line change
@@ -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 <mauroreisvieira@gmail.com>',
'Scheme-Example',
generateScheme({
name: 'Meetio Scheme Example',
author: 'Mauro Reis Vieira <mauroreisvieira@gmail.com>',
schemeName: 'Meetio Scheme Example',
settings,
'schemes'
);
});
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"name": "Scheme-Example",
"name": "Meetio Scheme Example",
"author": "Mauro Reis Vieira <mauroreisvieira@gmail.com>",
"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)",
Expand All @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
63 changes: 40 additions & 23 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -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;
}
22 changes: 9 additions & 13 deletions src/schemeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRules>) => {
Expand All @@ -40,23 +36,23 @@ 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,
},
null,
4
)
);
success(schemeName, dist);
success(schemeName, distFolder);
} catch (e) {
error(e);
}
Expand Down

0 comments on commit b72ecf8

Please sign in to comment.