Skip to content

Commit

Permalink
Squash some eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-hebler committed Sep 14, 2020
1 parent 087b7ef commit c0ed135
Showing 1 changed file with 59 additions and 49 deletions.
108 changes: 59 additions & 49 deletions docs/config/tasks/style-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
const fs = require('fs-extra');
const kss = require('kss');
const ora = require('ora');
const {
passesWcagAaLargeText,
passesWcagAa,
passesWcagAaa,
} = require('passes-wcag');
const {
generateName,
generateClassName,
Expand All @@ -24,20 +29,23 @@ const {
getDetails,
convertArrayToObject,
buildTokenArr,
} = require('../tasks/utils');
} = require('./utils');


const {
passesWcagAaLargeText,
passesWcagAa,
passesWcagAaa,
} = require('passes-wcag');

const GITHUB_URL = 'https://github.com/texastribune/queso-ui/blob/main';

async function createModifier(config: Modifier) {
const modifier = config;
modifier.preview = await renderTemplate(config.template, config);
return modifier;
}

async function createCSSClass(
config: CSSClass,
modifiers: KSSModifier[] | undefined
) {
const cssClass = config;
let modifierData: Modifier[] = [];
let modifierList: string[] = [];
if (modifiers) {
Expand All @@ -56,23 +64,19 @@ async function createCSSClass(
)
);
}
config.modifiers = modifierData;
config.modifierList = modifierList;
return config;
}

async function createModifier(config: Modifier) {
config.preview = await renderTemplate(config.template, config);
return config;
cssClass.modifiers = modifierData;
cssClass.modifierList = modifierList;
return cssClass;
}

function createColor(config: Color) {
config.check = {
const color = config;
color.check = {
aa: passesWcagAa(config.value, '#fff'),
aaLargeText: passesWcagAaLargeText(config.value, '#fff'),
aaa: passesWcagAaa(config.value, '#fff'),
};
return config;
return color;
}

// create a color, color map, section or item
Expand All @@ -89,14 +93,14 @@ async function createEntry(section: KSSData) {
description,
location,
};
// colorMaps and colors
if (colors && colors.length > 0) {
// create a color map
const colorMap = colors.map((color) => {
const { name, description } = color;
const { name } = color;
return createColor({
type: 'color',
name,
description,
description: color.description,
value: color.color,
});
});
Expand All @@ -105,14 +109,16 @@ async function createEntry(section: KSSData) {
type: 'colorMap',
list: colorMap,
};
} else if (parameters && parameters.length > 0) {
}
// tokenMaps and tokens
if (parameters && parameters.length > 0) {
const tokenMap = parameters.map((token) => {
const { data } = token;
const { description, defaultValue, name } = data;
const tokenData = token.data;
const { defaultValue, name } = tokenData;
return {
type: 'token',
name,
description,
description: tokenData.description,
value: defaultValue,
};
});
Expand All @@ -122,30 +128,32 @@ async function createEntry(section: KSSData) {
type: 'tokenMap',
list: tokenMap,
};
} else if (meta.depth < 3) {
}
// section
if (meta.depth < 3) {
return {
...base,
type: 'section',
id,
depth,
list: [],
};
} else {
const className = generateClassName(base.name);
const template = await generateTemplate(markup);
const config = {
...base,
label: generateName(base.name),
type: 'cssClass',
id,
depth: 2,
className,
details,
template: template,
preview: await renderTemplate(template, className),
};
return await createCSSClass(config, modifiers);
}
// cssClass
const className = generateClassName(base.name);
const template = await generateTemplate(markup);
const config = {
...base,
label: generateName(base.name),
type: 'cssClass',
id,
depth: 2,
className,
details,
template,
preview: await renderTemplate(template, className),
};
return createCSSClass(config, modifiers);
}

async function sortByType(arr: (CSSClass | ColorMap | Section | TokenMap)[]) {
Expand All @@ -160,18 +168,19 @@ async function sortByType(arr: (CSSClass | ColorMap | Section | TokenMap)[]) {
arr.forEach((entry: CSSClass | ColorMap | Section) => {
const { type } = entry;
switch (type) {
case 'section':
sections.push(entry as Section);
break;
case 'cssClass':
cssClasses.push(entry as CSSClass);
break;
case 'colorMap':
colorMaps.push(entry as ColorMap);
break;
case 'tokenMap':
tokenMaps.push(entry as TokenMap);
break;
case 'section':
sections.push(entry as Section);
break;
case 'cssClass':
default:
cssClasses.push(entry as CSSClass);
break;
}
});
const sectionMap = convertArrayToObject(sections, 'id');
Expand All @@ -189,10 +198,11 @@ async function sortByType(arr: (CSSClass | ColorMap | Section | TokenMap)[]) {
// append class to section
if (sectionMap[cssClass.id]) {
sections.forEach((section) => {
if (section.id == cssClass.id) {
if (section.id === cssClass.id) {
const { className } = cssClass;
section.list?.push({
className: cssClass.className,
name: cssClass.name,
className,
name: cssClass.name
});
}
});
Expand Down Expand Up @@ -251,7 +261,7 @@ const processComments = async (directory: string) => {

// create json files of style data
for (const [key, value] of Object.entries(sorted)) {
await fs.outputFile(
await fs.outputFileSync(
`./docs/dist/data/${key}.json`,
JSON.stringify({ [key]: value }, null, 2)
);
Expand Down

0 comments on commit c0ed135

Please sign in to comment.