Skip to content

Commit

Permalink
fix: add utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroreisvieira committed Mar 12, 2020
1 parent b16aefa commit 835adad
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 31 deletions.
29 changes: 22 additions & 7 deletions schemes/Moonlight.sublime-color-scheme
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@
},
{
"name": "VARIABLE - Declaration",
"scope": "variable.declaration",
"scope": "variable.declaration,variable.other",
"foreground": "var(brown)"
},
{
"name": "VARIABLE - A generic variable",
"scope": "variable.other,variable.other.readwrite",
"scope": "variable.other.readwrite",
"foreground": "var(foreground)"
},
{
Expand Down Expand Up @@ -642,17 +642,32 @@
"foreground": "var(foreground)"
},
{
"name": "Python - Declaration function",
"scope": "source.python meta.function.python storage.type.function.python keyword.declaration.function.python",
"name": "PYTHON - Keyword declaration function",
"scope": "source.python keyword.declaration.function.python",
"foreground": "var(purple)"
},
{
"name": "Python - Function",
"scope": "source.python meta.function.python entity.name.function.python support.function.magic.python",
"name": "PYTHON - Function magic",
"scope": "source.python support.function.magic.python",
"foreground": "var(blue)"
},
{
"name": "Vue - Console, \"console\"",
"name": "PYTHON - Function",
"scope": "source.python meta.function.python",
"foreground": "var(blue)"
},
{
"name": "PYTHON - Qualified name",
"scope": "source.python meta.qualified-name.python",
"foreground": "var(foreground)"
},
{
"name": "PYTHON - Generic name",
"scope": "source.python variable.function.python meta.generic-name.python",
"foreground": "var(blue)"
},
{
"name": "VUE - Console, \"console\"",
"scope": "text.html.vue meta.property.object",
"foreground": "var(foreground)"
},
Expand Down
4 changes: 2 additions & 2 deletions src/common/variable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export default [
{
name: 'VARIABLE - Declaration',
scope: ['variable.declaration'],
scope: ['variable.declaration', 'variable.other'],
settings: {
foreground: 'var(brown)',
},
},
{
name: 'VARIABLE - A generic variable',
scope: ['variable.other', 'variable.other.readwrite'],
scope: ['variable.other.readwrite'],
settings: {
foreground: 'var(foreground)',
},
Expand Down
21 changes: 4 additions & 17 deletions src/schemeGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
import * as fs from 'fs';
import chalk from 'chalk';
import { duplicated, success, error } from './utils';
import { defaultRules } from './rules';
import { defaultGlobals } from './globals';

Expand All @@ -16,19 +16,12 @@ export function generateScheme(
const { colors, ui, rules } = settings;
const allRules: Array<{ name: string; scope: string }> = [];
const allScopes = new Set();
const log = console.log;

[...defaultRules, [...rules]].forEach((rule: Array<IRules>) => {
rule.forEach((item: IRules) => {
item.scope.forEach((i: string) => {
if (allScopes.has(i)) {
log(
chalk.bold.bgRed(' ‼ERROR‼ ') +
' - Duplicated scope [' +
chalk.bold.green(i) +
'] overwrite by ' +
chalk.yellow(item.name)
);
duplicated(i, item.name);
}
allScopes.add(i);
});
Expand Down Expand Up @@ -58,15 +51,9 @@ export function generateScheme(
4
)
);
log(
chalk.bold.bgGreen(' SUCCESS ') +
' - Scheme ' +
chalk.bold.cyan(`${schemeName}.sublime-color-scheme`) +
' created in ' +
chalk.underline.yellow(dist) + ' folder'
);
success(schemeName, dist);
} catch (e) {
log(chalk.bold.red(e));
error(e);
}
});
}
29 changes: 25 additions & 4 deletions src/specific/python.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
export default [
{
name: 'Python - Declaration function',
scope: ['source.python meta.function.python storage.type.function.python keyword.declaration.function.python'],
name: 'PYTHON - Keyword declaration function',
scope: ['source.python keyword.declaration.function.python'],
settings: {
foreground: 'var(purple)',
},
},
{
name: 'Python - Function',
scope: ['source.python meta.function.python entity.name.function.python support.function.magic.python'],
name: 'PYTHON - Function magic',
scope: ['source.python support.function.magic.python'],
settings: {
foreground: 'var(blue)',
},
},
{
name: 'PYTHON - Function',
scope: ['source.python meta.function.python'],
settings: {
foreground: 'var(blue)',
},
},
{
name: 'PYTHON - Qualified name',
scope: ['source.python meta.qualified-name.python'],
settings: {
foreground: 'var(foreground)',
},
},
{
name: 'PYTHON - Generic name',
scope: ['source.python variable.function.python meta.generic-name.python'],
settings: {
foreground: 'var(blue)',
},
Expand Down
2 changes: 1 addition & 1 deletion src/specific/vue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
{
name: 'Vue - Console, "console"',
name: 'VUE - Console, "console"',
scope: ['text.html.vue meta.property.object'],
settings: {
foreground: 'var(foreground)',
Expand Down
25 changes: 25 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import chalk from 'chalk';

export const duplicated = (scope: string, name: string) =>
console.log(
chalk.bold.bgRed(' ‼ERROR‼ ') +
' - Duplicated scope [' +
chalk.bold.green(scope) +
'] overwrite by ' +
chalk.yellow(name)
);

export const success = (scheme: string, folder: string) => {
console.log();
console.log(
chalk.bold.bgGreen(' SUCCESS ') +
' - Scheme ' +
chalk.bold.cyan(`${scheme}.sublime-color-scheme`) +
' created in ' +
chalk.underline.yellow(folder) +
' folder'
);
console.log();
};

export const error = (error: string) => console.log(chalk.bold.red(error));

0 comments on commit 835adad

Please sign in to comment.