mirror of
https://github.com/Mibew/simple-icons.git
synced 2024-11-15 01:44:12 +03:00
Setup prettier (#6758)
* Add prettier as a dependency * Add format command and configure prettier I opted for single quotes to be in line with other simple-icons projects I ignore the data file because changing its formatting is quite a bit of trouble for all open PRs. * Run prettier * Replace all functions by arrow functions * Move prettier configuration to config file Move it to a file so editors (and other software) can pick up on the configuration. I went with .js because (a) it allows for comments and (2) it seems most of the config files are in JavaScript already. * Add prettier --check when running npm run lint (This adds it to the CI as well) * Add husky and format changes before committing * Use object destructuring for imports consistently * Add shebang and fileoverview to jsonlint.js
This commit is contained in:
parent
07c9ba1b54
commit
e0df400494
4
.github/ISSUE_TEMPLATE/documentation.yml
vendored
4
.github/ISSUE_TEMPLATE/documentation.yml
vendored
@ -41,7 +41,7 @@ body:
|
||||
This is an open source project and we welcome contributions. Do you want to
|
||||
work on this issue?
|
||||
options:
|
||||
- "Yes"
|
||||
- "No"
|
||||
- Yes
|
||||
- No
|
||||
validations:
|
||||
required: true
|
||||
|
4
.github/ISSUE_TEMPLATE/icon_removal.yml
vendored
4
.github/ISSUE_TEMPLATE/icon_removal.yml
vendored
@ -1,6 +1,6 @@
|
||||
name: Icon removal
|
||||
description: Report an icon for removal
|
||||
title: "Remove: "
|
||||
title: 'Remove: '
|
||||
labels: [removal request]
|
||||
|
||||
body:
|
||||
@ -18,7 +18,7 @@ body:
|
||||
- type: input
|
||||
attributes:
|
||||
label: Brand Name
|
||||
placeholder: "Example: Simple Icons"
|
||||
placeholder: 'Example: Simple Icons'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
14
.github/ISSUE_TEMPLATE/icon_request.yml
vendored
14
.github/ISSUE_TEMPLATE/icon_request.yml
vendored
@ -1,6 +1,6 @@
|
||||
name: Icon request
|
||||
description: Request a new icon for Simple Icons
|
||||
title: "Request: "
|
||||
title: 'Request: '
|
||||
labels: [new icon]
|
||||
|
||||
body:
|
||||
@ -25,7 +25,7 @@ body:
|
||||
- type: input
|
||||
attributes:
|
||||
label: Brand Name
|
||||
placeholder: "Example: Simple Icons"
|
||||
placeholder: 'Example: Simple Icons'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@ -35,7 +35,7 @@ body:
|
||||
description: >-
|
||||
For non-web brands you can add a relevant link. You can put "None" if you don't
|
||||
think there's a website.
|
||||
placeholder: "Example: https://simpleicons.org"
|
||||
placeholder: 'Example: https://simpleicons.org'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@ -50,7 +50,7 @@ body:
|
||||
|
||||
|
||||
[alexa rank]: https://www.alexa.com/siteinfo
|
||||
placeholder: "Example: The Alexa rank is 249,089. See https://www.alexa.com/siteinfo/simpleicons.org"
|
||||
placeholder: 'Example: The Alexa rank is 249,089. See https://www.alexa.com/siteinfo/simpleicons.org'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@ -75,7 +75,7 @@ body:
|
||||
- Are there multiple options for the logo and/or color?
|
||||
- Is the icon released under a license?
|
||||
- If you think the brand might not be accepted, why do you think it should be considered?
|
||||
placeholder: "Example: There are two variants of this icon..."
|
||||
placeholder: 'Example: There are two variants of this icon...'
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
@ -84,7 +84,7 @@ body:
|
||||
This is an open source project and we welcome contributions. Do you want to
|
||||
add this icon?
|
||||
options:
|
||||
- "Yes"
|
||||
- "No"
|
||||
- Yes
|
||||
- No
|
||||
validations:
|
||||
required: true
|
||||
|
10
.github/ISSUE_TEMPLATE/icon_update.yml
vendored
10
.github/ISSUE_TEMPLATE/icon_update.yml
vendored
@ -1,6 +1,6 @@
|
||||
name: Icon update
|
||||
description: Help us improve by reporting outdated icons
|
||||
title: "Update: "
|
||||
title: 'Update: '
|
||||
labels: [icon outdated]
|
||||
|
||||
body:
|
||||
@ -18,7 +18,7 @@ body:
|
||||
- type: input
|
||||
attributes:
|
||||
label: Brand Name
|
||||
placeholder: "Example: Simple Icons"
|
||||
placeholder: 'Example: Simple Icons'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@ -42,7 +42,7 @@ body:
|
||||
Is there anything else we should know about the brand? Remember that not everyone knows the brand as well as you do. For example:
|
||||
- Are there multiple options for the logo and/or color?
|
||||
- Is the icon released under a license?
|
||||
placeholder: "Example: There are two variants of this icon..."
|
||||
placeholder: 'Example: There are two variants of this icon...'
|
||||
|
||||
- type: dropdown
|
||||
attributes:
|
||||
@ -51,7 +51,7 @@ body:
|
||||
This is an open source project and we welcome contributions. Do you want to
|
||||
update this icon?
|
||||
options:
|
||||
- "Yes"
|
||||
- "No"
|
||||
- Yes
|
||||
- No
|
||||
validations:
|
||||
required: true
|
||||
|
4
.github/ISSUE_TEMPLATE/package.yml
vendored
4
.github/ISSUE_TEMPLATE/package.yml
vendored
@ -34,7 +34,7 @@ body:
|
||||
- type: input
|
||||
attributes:
|
||||
label: Package Version
|
||||
placeholder: "Example: 5.11.0"
|
||||
placeholder: 'Example: 5.11.0'
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@ -59,6 +59,6 @@ body:
|
||||
- For bugs: "Steps to reproduce" and "Expected behavior"
|
||||
- For feature requests: An example of a use case
|
||||
- For performance: An example where performance is poor
|
||||
placeholder: "Example: The NPM package does not work for my use case..."
|
||||
placeholder: 'Example: The NPM package does not work for my use case...'
|
||||
validations:
|
||||
required: true
|
||||
|
8
.github/renovate.json5
vendored
8
.github/renovate.json5
vendored
@ -1,19 +1,19 @@
|
||||
{
|
||||
extends: [
|
||||
"config:base",
|
||||
'config:base',
|
||||
|
||||
// Make sure we get a single PR combining all updates
|
||||
"group:all",
|
||||
'group:all',
|
||||
],
|
||||
|
||||
// Disable dependency dashboard
|
||||
dependencyDashboard: false,
|
||||
|
||||
// Use our labelling system
|
||||
labels: ["dependencies"],
|
||||
labels: ['dependencies'],
|
||||
|
||||
// Schedule the PRs to interleave with our release schedule
|
||||
schedule: "on the 2nd and 4th day instance on sunday after 11pm",
|
||||
schedule: 'on the 2nd and 4th day instance on sunday after 11pm',
|
||||
|
||||
// We generally always want the major version
|
||||
separateMajorMinor: false,
|
||||
|
8
.github/workflows/create-release.yml
vendored
8
.github/workflows/create-release.yml
vendored
@ -5,7 +5,7 @@ on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# "At 00:00 on Sunday" (https://crontab.guru/once-a-week)
|
||||
- cron: "0 0 * * 0"
|
||||
- cron: '0 0 * * 0'
|
||||
|
||||
# This Workflow can be triggered manually through the GitHub UI or API. For the
|
||||
# API use the following request:
|
||||
@ -51,6 +51,6 @@ jobs:
|
||||
uses: stefanzweifel/git-auto-commit-action@v4.12.0
|
||||
with:
|
||||
commit_message: version bump
|
||||
commit_user_name: "github-actions[bot]"
|
||||
commit_user_email: "github-actions[bot]@users.noreply.github.com"
|
||||
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
|
||||
commit_user_name: 'github-actions[bot]'
|
||||
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
|
||||
commit_author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'
|
||||
|
7
.husky/pre-commit
Normal file
7
.husky/pre-commit
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname $0)/_/husky.sh"
|
||||
|
||||
git stash -q --keep-index
|
||||
npm run format
|
||||
git add .
|
||||
git stash pop -q
|
10
.prettierignore
Normal file
10
.prettierignore
Normal file
@ -0,0 +1,10 @@
|
||||
# We prefer our own custom formatting for MarkDown files.
|
||||
# See the following thread for the discussion:
|
||||
# https://github.com/simple-icons/simple-icons-font/pull/73
|
||||
*.md
|
||||
|
||||
# We use our own formatting for the data files.
|
||||
_data/simple-icons.json
|
||||
|
||||
# JavaScript templates are invalid JavaScript so cannot be formatted.
|
||||
scripts/build/templates/*.js
|
4
.prettierrc.js
Normal file
4
.prettierrc.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
trailingComma: 'all',
|
||||
singleQuote: true,
|
||||
};
|
1444
.svglintrc.js
1444
.svglintrc.js
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
cacheDirectory: "./.cache/jest",
|
||||
cacheDirectory: './.cache/jest',
|
||||
};
|
||||
|
@ -19,11 +19,14 @@
|
||||
"license": "CC0-1.0",
|
||||
"devDependencies": {
|
||||
"editorconfig-checker": "4.0.2",
|
||||
"husky": "7.0.2",
|
||||
"is-ci": "3.0.0",
|
||||
"jest": "27.2.5",
|
||||
"jest-diff": "27.2.5",
|
||||
"jsonschema": "1.4.0",
|
||||
"named-html-entities-json": "0.1.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"prettier": "2.4.1",
|
||||
"rimraf": "3.0.2",
|
||||
"svg-path-bbox": "1.0.1",
|
||||
"svg-path-segments": "1.0.0",
|
||||
@ -35,11 +38,14 @@
|
||||
"scripts": {
|
||||
"build": "node scripts/build/package.js",
|
||||
"clean": "rimraf icons/*.js index.js",
|
||||
"lint": "run-s our-lint jsonlint svglint wslint",
|
||||
"format": "prettier --write .",
|
||||
"lint": "run-s our-lint jslint jsonlint svglint wslint",
|
||||
"our-lint": "node scripts/lint/ourlint.js",
|
||||
"jslint": "prettier --check .",
|
||||
"jsonlint": "node scripts/lint/jsonlint.js",
|
||||
"svglint": "svglint icons/*.svg --ci",
|
||||
"wslint": "editorconfig-checker -exclude \\.svg$",
|
||||
"postinstall": "is-ci || husky install",
|
||||
"prepublishOnly": "npm run build",
|
||||
"postpublish": "npm run clean",
|
||||
"test": "jest",
|
||||
|
@ -7,36 +7,36 @@
|
||||
* tree-shakeable
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const minify = require("uglify-js").minify;
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
const { minify } = require('uglify-js');
|
||||
|
||||
const UTF8 = "utf8";
|
||||
const UTF8 = 'utf8';
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const dataFile = path.resolve(rootDir, "_data", "simple-icons.json");
|
||||
const indexFile = path.resolve(rootDir, "index.js");
|
||||
const iconsDir = path.resolve(rootDir, "icons");
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const dataFile = path.resolve(rootDir, '_data', 'simple-icons.json');
|
||||
const indexFile = path.resolve(rootDir, 'index.js');
|
||||
const iconsDir = path.resolve(rootDir, 'icons');
|
||||
|
||||
const templatesDir = path.resolve(__dirname, "templates");
|
||||
const indexTemplateFile = path.resolve(templatesDir, "index.js");
|
||||
const iconObjectTemplateFile = path.resolve(templatesDir, "icon-object.js");
|
||||
const templatesDir = path.resolve(__dirname, 'templates');
|
||||
const indexTemplateFile = path.resolve(templatesDir, 'index.js');
|
||||
const iconObjectTemplateFile = path.resolve(templatesDir, 'icon-object.js');
|
||||
|
||||
const indexTemplate = fs.readFileSync(indexTemplateFile, UTF8);
|
||||
const iconObjectTemplate = fs.readFileSync(iconObjectTemplateFile, UTF8);
|
||||
|
||||
const data = require(dataFile);
|
||||
const { getIconSlug, titleToSlug } = require("../utils.js");
|
||||
const { getIconSlug } = require('../utils.js');
|
||||
|
||||
// Local helper functions
|
||||
function escape(value) {
|
||||
const escape = (value) => {
|
||||
return value.replace(/(?<!\\)'/g, "\\'");
|
||||
}
|
||||
function iconToKeyValue(icon) {
|
||||
};
|
||||
const iconToKeyValue = (icon) => {
|
||||
return `'${icon.slug}':${iconToObject(icon)}`;
|
||||
}
|
||||
function licenseToObject(license) {
|
||||
};
|
||||
const licenseToObject = (license) => {
|
||||
if (license === undefined) {
|
||||
return;
|
||||
}
|
||||
@ -45,9 +45,10 @@ function licenseToObject(license) {
|
||||
license.url = `https://spdx.org/licenses/${license.type}`;
|
||||
}
|
||||
return license;
|
||||
}
|
||||
function iconToObject(icon) {
|
||||
return util.format(iconObjectTemplate,
|
||||
};
|
||||
const iconToObject = (icon) => {
|
||||
return util.format(
|
||||
iconObjectTemplate,
|
||||
escape(icon.title),
|
||||
escape(icon.slug),
|
||||
escape(icon.svg),
|
||||
@ -56,8 +57,8 @@ function iconToObject(icon) {
|
||||
icon.guidelines ? `'${escape(icon.guidelines)}'` : undefined,
|
||||
licenseToObject(icon.license),
|
||||
);
|
||||
}
|
||||
function minifyAndWrite(filepath, rawJavaScript) {
|
||||
};
|
||||
const minifyAndWrite = (filepath, rawJavaScript) => {
|
||||
const { error, code } = minify(rawJavaScript);
|
||||
if (error) {
|
||||
console.error(error);
|
||||
@ -65,11 +66,11 @@ function minifyAndWrite(filepath, rawJavaScript) {
|
||||
} else {
|
||||
fs.writeFileSync(filepath, code);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 'main'
|
||||
const icons = [];
|
||||
data.icons.forEach(icon => {
|
||||
data.icons.forEach((icon) => {
|
||||
const filename = getIconSlug(icon);
|
||||
const svgFilepath = path.resolve(iconsDir, `${filename}.svg`);
|
||||
icon.svg = fs.readFileSync(svgFilepath, UTF8).replace(/\r?\n/, '');
|
||||
@ -82,5 +83,8 @@ data.icons.forEach(icon => {
|
||||
});
|
||||
|
||||
// write our generic index.js
|
||||
const rawIndexJs = util.format(indexTemplate, icons.map(iconToKeyValue).join(','));
|
||||
const rawIndexJs = util.format(
|
||||
indexTemplate,
|
||||
icons.map(iconToKeyValue).join(','),
|
||||
);
|
||||
minifyAndWrite(indexFile, rawIndexJs);
|
||||
|
@ -5,13 +5,14 @@
|
||||
* icon SVG filename to standard output.
|
||||
*/
|
||||
|
||||
const { titleToSlug } = require("./utils.js");
|
||||
const { titleToSlug } = require('./utils.js');
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.error("Provide a brand name as argument");
|
||||
console.error('Provide a brand name as argument');
|
||||
process.exit(1);
|
||||
} else {
|
||||
const brandName = process.argv.slice(3)
|
||||
const brandName = process.argv
|
||||
.slice(3)
|
||||
.reduce((acc, arg) => `${acc} ${arg}`, process.argv[2]);
|
||||
|
||||
const filename = titleToSlug(brandName);
|
||||
|
@ -1,9 +1,15 @@
|
||||
const path = require("path");
|
||||
const Validator = require("jsonschema").Validator;
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @fileoverview
|
||||
* CLI tool to run jsonschema on the simple-icons.json data file.
|
||||
*/
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const schemaFile = path.resolve(rootDir, ".jsonschema.json");
|
||||
const dataFile = path.resolve(rootDir, "_data", "simple-icons.json");
|
||||
const path = require('path');
|
||||
const { Validator } = require('jsonschema');
|
||||
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const schemaFile = path.resolve(rootDir, '.jsonschema.json');
|
||||
const dataFile = path.resolve(rootDir, '_data', 'simple-icons.json');
|
||||
|
||||
const schema = require(schemaFile);
|
||||
const data = require(dataFile);
|
||||
|
@ -5,15 +5,15 @@
|
||||
* linters (e.g. jsonlint/svglint).
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const { diffLinesUnified } = require("jest-diff");
|
||||
const { diffLinesUnified } = require('jest-diff');
|
||||
|
||||
const UTF8 = "utf8";
|
||||
const UTF8 = 'utf8';
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const dataFile = path.resolve(rootDir, "_data", "simple-icons.json");
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const dataFile = path.resolve(rootDir, '_data', 'simple-icons.json');
|
||||
const data = require(dataFile);
|
||||
|
||||
/**
|
||||
@ -22,7 +22,7 @@ const data = require(dataFile);
|
||||
*/
|
||||
const TESTS = {
|
||||
/* Tests whether our icons are in alphabetical order */
|
||||
alphabetical: function() {
|
||||
alphabetical: () => {
|
||||
const collector = (invalidEntries, icon, index, array) => {
|
||||
if (index > 0) {
|
||||
const prev = array[index - 1];
|
||||
@ -39,7 +39,7 @@ const TESTS = {
|
||||
}
|
||||
return invalidEntries;
|
||||
};
|
||||
const format = icon => {
|
||||
const format = (icon) => {
|
||||
if (icon.slug) {
|
||||
return `${icon.title} (${icon.slug})`;
|
||||
}
|
||||
@ -49,35 +49,35 @@ const TESTS = {
|
||||
const invalids = data.icons.reduce(collector, []);
|
||||
if (invalids.length) {
|
||||
return `Some icons aren't in alphabetical order:
|
||||
${invalids.map(icon => format(icon)).join(", ")}`;
|
||||
${invalids.map((icon) => format(icon)).join(', ')}`;
|
||||
}
|
||||
},
|
||||
|
||||
/* Check the formatting of the data file */
|
||||
prettified: function() {
|
||||
prettified: () => {
|
||||
const dataString = fs.readFileSync(dataFile, UTF8).replace(/\r\n/g, '\n');
|
||||
const dataPretty = `${JSON.stringify(data, null, " ")}\n`;
|
||||
const dataPretty = `${JSON.stringify(data, null, ' ')}\n`;
|
||||
if (dataString !== dataPretty) {
|
||||
const dataDiff = diffLinesUnified(
|
||||
dataString.split("\n"),
|
||||
dataPretty.split("\n"),
|
||||
dataString.split('\n'),
|
||||
dataPretty.split('\n'),
|
||||
{
|
||||
expand: false,
|
||||
omitAnnotationLines: true
|
||||
omitAnnotationLines: true,
|
||||
},
|
||||
);
|
||||
|
||||
return `Data file is formatted incorrectly:\n\n${dataDiff}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// execute all tests and log all errors
|
||||
const errors = Object.keys(TESTS)
|
||||
.map(k => TESTS[k]())
|
||||
.map((k) => TESTS[k]())
|
||||
.filter(Boolean);
|
||||
|
||||
if (errors.length > 0) {
|
||||
errors.forEach(error => console.error(`\u001b[31m${error}\u001b[0m`));
|
||||
errors.forEach((error) => console.error(`\u001b[31m${error}\u001b[0m`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
@ -4,34 +4,34 @@
|
||||
* Updates the version of this package to the CLI specified version.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const packageJsonFile = path.resolve(rootDir, "package.json");
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const packageJsonFile = path.resolve(rootDir, 'package.json');
|
||||
|
||||
function readManifest(file) {
|
||||
const readManifest = (file) => {
|
||||
const manifestRaw = fs.readFileSync(file).toString();
|
||||
const manifestJson = JSON.parse(manifestRaw);
|
||||
return manifestJson;
|
||||
}
|
||||
};
|
||||
|
||||
function writeManifest(file, json) {
|
||||
const manifestRaw = JSON.stringify(json, null, 2) + "\n";
|
||||
const writeManifest = (file, json) => {
|
||||
const manifestRaw = JSON.stringify(json, null, 2) + '\n';
|
||||
fs.writeFileSync(file, manifestRaw);
|
||||
}
|
||||
};
|
||||
|
||||
function main(newVersion) {
|
||||
const main = (newVersion) => {
|
||||
try {
|
||||
const manifest = readManifest(packageJsonFile);
|
||||
|
||||
manifest.version = newVersion
|
||||
manifest.version = newVersion;
|
||||
|
||||
writeManifest(packageJsonFile, manifest);
|
||||
} catch (error) {
|
||||
console.error(`Failed to bump package version to ${newVersion}:`, error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
main(process.argv[2]);
|
||||
|
@ -5,24 +5,24 @@
|
||||
* NPM package manifest. Does nothing if the README.md is already up-to-date.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const packageJsonFile = path.resolve(rootDir, "package.json");
|
||||
const readmeFile = path.resolve(rootDir, "README.md");
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const packageJsonFile = path.resolve(rootDir, 'package.json');
|
||||
const readmeFile = path.resolve(rootDir, 'README.md');
|
||||
|
||||
function getMajorVersion(semVerVersion) {
|
||||
const getMajorVersion = (semVerVersion) => {
|
||||
const majorVersionAsString = semVerVersion.split('.')[0];
|
||||
return parseInt(majorVersionAsString);
|
||||
}
|
||||
};
|
||||
|
||||
function getManifest() {
|
||||
const getManifest = () => {
|
||||
const manifestRaw = fs.readFileSync(packageJsonFile).toString();
|
||||
return JSON.parse(manifestRaw);
|
||||
}
|
||||
};
|
||||
|
||||
function updateVersionInReadmeIfNecessary(majorVersion) {
|
||||
const updateVersionInReadmeIfNecessary = (majorVersion) => {
|
||||
let content = fs.readFileSync(readmeFile).toString();
|
||||
|
||||
content = content.replace(
|
||||
@ -31,17 +31,17 @@ function updateVersionInReadmeIfNecessary(majorVersion) {
|
||||
);
|
||||
|
||||
fs.writeFileSync(readmeFile, content);
|
||||
}
|
||||
};
|
||||
|
||||
function main() {
|
||||
const main = () => {
|
||||
try {
|
||||
const manifest = getManifest();
|
||||
const majorVersion = getMajorVersion(manifest.version);
|
||||
updateVersionInReadmeIfNecessary(majorVersion);
|
||||
} catch (error) {
|
||||
console.error("Failed to update CDN version number:", error);
|
||||
console.error('Failed to update CDN version number:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
main();
|
||||
|
@ -4,15 +4,15 @@
|
||||
* Generates a MarkDown file that lists every brand name and their slug.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
const dataFile = path.resolve(rootDir, "_data", "simple-icons.json");
|
||||
const slugsFile = path.resolve(rootDir, "slugs.md");
|
||||
const rootDir = path.resolve(__dirname, '..', '..');
|
||||
const dataFile = path.resolve(rootDir, '_data', 'simple-icons.json');
|
||||
const slugsFile = path.resolve(rootDir, 'slugs.md');
|
||||
|
||||
const data = require(dataFile);
|
||||
const { getIconSlug } = require("../utils.js");
|
||||
const { getIconSlug } = require('../utils.js');
|
||||
|
||||
let content = `<!--
|
||||
This file is automatically generated. If you want to change something, please
|
||||
@ -25,10 +25,10 @@ update the script at '${path.relative(rootDir, __filename)}'.
|
||||
| :--- | :--- |
|
||||
`;
|
||||
|
||||
data.icons.forEach(icon => {
|
||||
data.icons.forEach((icon) => {
|
||||
const brandName = icon.title;
|
||||
const brandSlug = getIconSlug(icon);
|
||||
content += `| \`${brandName}\` | \`${brandSlug}\` |\n`
|
||||
content += `| \`${brandName}\` | \`${brandSlug}\` |\n`;
|
||||
});
|
||||
|
||||
fs.writeFileSync(slugsFile, content);
|
||||
|
@ -8,41 +8,39 @@ module.exports = {
|
||||
* Get the slug/filename for an icon.
|
||||
* @param {Object} icon The icon data as it appears in _data/simple-icons.json
|
||||
*/
|
||||
getIconSlug: icon => icon.slug || module.exports.titleToSlug(icon.title),
|
||||
getIconSlug: (icon) => icon.slug || module.exports.titleToSlug(icon.title),
|
||||
|
||||
/**
|
||||
* Converts a brand title into a slug/filename.
|
||||
* @param {String} title The title to convert
|
||||
*/
|
||||
titleToSlug: title => (
|
||||
title.toLowerCase()
|
||||
.replace(/\+/g, "plus")
|
||||
.replace(/\./g, "dot")
|
||||
.replace(/&/g, "and")
|
||||
.replace(/đ/g, "d")
|
||||
.replace(/ħ/g, "h")
|
||||
.replace(/ı/g, "i")
|
||||
.replace(/ĸ/g, "k")
|
||||
.replace(/ŀ/g, "l")
|
||||
.replace(/ł/g, "l")
|
||||
.replace(/ß/g, "ss")
|
||||
.replace(/ŧ/g, "t")
|
||||
.normalize("NFD")
|
||||
.replace(/[^a-z0-9]/g, "")
|
||||
),
|
||||
titleToSlug: (title) =>
|
||||
title
|
||||
.toLowerCase()
|
||||
.replace(/\+/g, 'plus')
|
||||
.replace(/\./g, 'dot')
|
||||
.replace(/&/g, 'and')
|
||||
.replace(/đ/g, 'd')
|
||||
.replace(/ħ/g, 'h')
|
||||
.replace(/ı/g, 'i')
|
||||
.replace(/ĸ/g, 'k')
|
||||
.replace(/ŀ/g, 'l')
|
||||
.replace(/ł/g, 'l')
|
||||
.replace(/ß/g, 'ss')
|
||||
.replace(/ŧ/g, 't')
|
||||
.normalize('NFD')
|
||||
.replace(/[^a-z0-9]/g, ''),
|
||||
|
||||
/**
|
||||
* Converts a brand title in HTML/SVG friendly format into a brand title (as
|
||||
* it is seen in simple-icons.json)
|
||||
* @param {String} htmlFriendlyTitle The title to convert
|
||||
*/
|
||||
htmlFriendlyToTitle: htmlFriendlyTitle => (
|
||||
htmlFriendlyTitle.replace(
|
||||
/&#([0-9]+);/g,
|
||||
(_, num) => String.fromCharCode(parseInt(num))
|
||||
).replace(
|
||||
/&(quot|amp|lt|gt);/g,
|
||||
(_, ref) => ({quot: '"', amp: '&', lt: '<', gt: '>'}[ref])
|
||||
)
|
||||
),
|
||||
}
|
||||
htmlFriendlyToTitle: (htmlFriendlyTitle) =>
|
||||
htmlFriendlyTitle
|
||||
.replace(/&#([0-9]+);/g, (_, num) => String.fromCharCode(parseInt(num)))
|
||||
.replace(
|
||||
/&(quot|amp|lt|gt);/g,
|
||||
(_, ref) => ({ quot: '"', amp: '&', lt: '<', gt: '>' }[ref]),
|
||||
),
|
||||
};
|
||||
|
@ -38,9 +38,7 @@ module.exports = {
|
||||
// Keep the role="img" attribute and automatically add it
|
||||
// to the <svg> tag if it's not there already
|
||||
addAttributesToSVGElement: {
|
||||
attributes: [
|
||||
{role: 'img'},
|
||||
],
|
||||
attributes: [{ role: 'img' }],
|
||||
},
|
||||
|
||||
// Keep the 'role' attribute, if it's already defined
|
||||
@ -51,11 +49,7 @@ module.exports = {
|
||||
// Remove all attributes except 'role', 'viewBox', and 'xmlns' from
|
||||
// <svg> tags
|
||||
removeAttrs: {
|
||||
attrs: [
|
||||
'baseProfile',
|
||||
'version',
|
||||
'fill-rule',
|
||||
],
|
||||
attrs: ['baseProfile', 'version', 'fill-rule'],
|
||||
},
|
||||
|
||||
// Remove paths with fill="none"
|
||||
|
@ -1,7 +1,7 @@
|
||||
const { icons } = require('../_data/simple-icons.json');
|
||||
const { getIconSlug } = require('../scripts/utils.js');
|
||||
|
||||
icons.forEach(icon => {
|
||||
icons.forEach((icon) => {
|
||||
const filename = getIconSlug(icon);
|
||||
const subject = require(`../icons/${filename}.js`);
|
||||
|
||||
@ -34,7 +34,9 @@ icons.forEach(icon => {
|
||||
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
|
||||
});
|
||||
|
||||
test(`${icon.title} has ${icon.guidelines ? "the correct" : "no"} "guidelines"`, () => {
|
||||
test(`${icon.title} has ${
|
||||
icon.guidelines ? 'the correct' : 'no'
|
||||
} "guidelines"`, () => {
|
||||
if (icon.guidelines) {
|
||||
expect(typeof subject.guidelines).toBe('string');
|
||||
expect(subject.guidelines).toEqual(icon.guidelines);
|
||||
@ -43,11 +45,13 @@ icons.forEach(icon => {
|
||||
}
|
||||
});
|
||||
|
||||
test(`${icon.title} has ${icon.license ? "the correct" : "no"} "license"`, () => {
|
||||
test(`${icon.title} has ${
|
||||
icon.license ? 'the correct' : 'no'
|
||||
} "license"`, () => {
|
||||
if (icon.license) {
|
||||
expect(typeof subject.license).toBe('object');
|
||||
expect(subject.license).toHaveProperty('type', icon.license.type);
|
||||
if (icon.license.type === "custom") {
|
||||
if (icon.license.type === 'custom') {
|
||||
expect(subject.license).toHaveProperty('url', icon.license.url);
|
||||
} else {
|
||||
expect(typeof subject.license.url).toBe('string');
|
||||
|
@ -1,8 +1,8 @@
|
||||
const { icons } = require('../_data/simple-icons.json');
|
||||
const simpleIcons = require('../index.js');
|
||||
const { getIconSlug } = require("../scripts/utils.js");
|
||||
const { getIconSlug } = require('../scripts/utils.js');
|
||||
|
||||
icons.forEach(icon => {
|
||||
icons.forEach((icon) => {
|
||||
const slug = getIconSlug(icon);
|
||||
const subject = simpleIcons[slug];
|
||||
|
||||
@ -35,7 +35,9 @@ icons.forEach(icon => {
|
||||
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
|
||||
});
|
||||
|
||||
test(`${icon.title} has ${icon.guidelines ? "the correct" : "no"} "guidelines"`, () => {
|
||||
test(`${icon.title} has ${
|
||||
icon.guidelines ? 'the correct' : 'no'
|
||||
} "guidelines"`, () => {
|
||||
if (icon.guidelines) {
|
||||
expect(typeof subject.guidelines).toBe('string');
|
||||
expect(subject.guidelines).toEqual(icon.guidelines);
|
||||
@ -44,11 +46,13 @@ icons.forEach(icon => {
|
||||
}
|
||||
});
|
||||
|
||||
test(`${icon.title} has ${icon.license ? "the correct" : "no"} "license"`, () => {
|
||||
test(`${icon.title} has ${
|
||||
icon.license ? 'the correct' : 'no'
|
||||
} "license"`, () => {
|
||||
if (icon.license) {
|
||||
expect(typeof subject.license).toBe('object');
|
||||
expect(subject.license).toHaveProperty('type', icon.license.type);
|
||||
if (icon.license.type === "custom") {
|
||||
if (icon.license.type === 'custom') {
|
||||
expect(subject.license).toHaveProperty('url', icon.license.url);
|
||||
} else {
|
||||
expect(typeof subject.license.url).toBe('string');
|
||||
|
Loading…
Reference in New Issue
Block a user