Skip to content

Commit

Permalink
ci(theme preview): allow gradient themes (#3400)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 committed Oct 23, 2023
1 parent edeebeb commit f8aa2db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Hjson from "hjson";
import snakeCase from "lodash.snakecase";
import parse from "parse-diff";
import { inspect } from "util";
import { isValidHexColor } from "../src/common/utils.js";
import { isValidHexColor, isValidGradient } from "../src/common/utils.js";
import { themes } from "../themes/index.js";
import { getGithubToken, getRepoInfo } from "./helpers.js";

Expand Down Expand Up @@ -42,7 +42,7 @@ const COLOR_PROPS = {
title_color: 6,
icon_color: 6,
text_color: 6,
bg_color: 8,
bg_color: 23,
border_color: 6,
};
const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS);
Expand Down Expand Up @@ -499,7 +499,13 @@ export const run = async () => {
`Theme color property \`${colorKey}\` can not be longer than \`${COLOR_PROPS[colorKey]}\` characters`,
);
invalidColors = true;
} else if (!isValidHexColor(colorValue)) {
} else if (
!isValidHexColor(colorValue) ||
!(
colorKey === "bg_color" &&
isValidGradient(colorValue.split(","))
)
) {
errors.push(
`Theme color property \`${colorKey}\` is not a valid hex color: <code>#${colorValue}</code>`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const clampValue = (number, min, max) => {
* @returns {boolean} True if the given string is a valid gradient.
*/
const isValidGradient = (colors) => {
return isValidHexColor(colors[1]) && isValidHexColor(colors[2]);
return colors.slice(1).every((color) => isValidHexColor(color));
};

/**
Expand Down

0 comments on commit f8aa2db

Please sign in to comment.