1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2025-10-30 23:07:47 +02:00

Restructure the scripts/ directory (#5546)

* Restructure scripts/ directory

And update references to this scripts everywhere.

* Update names of file-level constants in bump-version.js

* Normalize quotes between all scripts

* Move "create-release.yml" scripts to scripts/release

* Move slugs table script to scripts/release

* Update relative path logic in update-slugs-table.js
This commit is contained in:
Eric Cornelissen
2021-05-07 19:55:06 +02:00
committed by GitHub
parent a254c8ae5d
commit 153a029c25
10 changed files with 35 additions and 30 deletions

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env node
/**
* @fileoverview
* Updates the version of this package to the CLI specified version.
*/
const fs = require("fs");
const path = require("path");
const rootDir = path.resolve(__dirname, "..", "..");
const packageJsonFile = path.resolve(rootDir, "package.json");
const packageLockFile = path.resolve(rootDir, "package-lock.json");
function 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";
fs.writeFileSync(file, manifestRaw);
}
function main(newVersion) {
try {
const manifest = readManifest(packageJsonFile);
const manifestLock = readManifest(packageLockFile);
manifest.version = newVersion
manifestLock.version = newVersion
writeManifest(packageJsonFile, manifest);
writeManifest(packageLockFile, manifestLock);
} catch (error) {
console.error(`Failed to bump package version to ${newVersion}:`, error);
process.exit(1);
}
}
main(process.argv[2]);

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env node
/**
* @fileoverview
* Updates the CDN URLs in the README.md to match the major version in the
* NPM package manifest. Does nothing if the README.md is already up-to-date.
*/
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");
function getMajorVersion(semVerVersion) {
const majorVersionAsString = semVerVersion.split('.')[0];
return parseInt(majorVersionAsString);
}
function getManifest() {
const manifestRaw = fs.readFileSync(packageJsonFile).toString();
return JSON.parse(manifestRaw);
}
function updateVersionInReadmeIfNecessary(majorVersion) {
let content = fs.readFileSync(readmeFile).toString();
content = content.replace(
/simple-icons@v[0-9]+/g,
`simple-icons@v${majorVersion}`,
);
fs.writeFileSync(readmeFile, content);
}
function main() {
try {
const manifest = getManifest();
const majorVersion = getMajorVersion(manifest.version);
updateVersionInReadmeIfNecessary(majorVersion);
} catch (error) {
console.error("Failed to update CDN version number:", error);
process.exit(1);
}
}
main();

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env node
/**
* @fileoverview
* Generates a MarkDown file that lists every brand name and their slug.
*/
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 data = require(dataFile);
const { getIconSlug } = require("../utils.js");
let content = `<!--
This file is automatically generated. If you want to change something, please
update the script at '${path.relative(rootDir, __filename)}'.
-->
# Simple Icons slugs
| Brand name | Brand slug |
| :--- | :--- |
`;
data.icons.forEach(icon => {
const brandName = icon.title;
const brandSlug = getIconSlug(icon);
content += `| \`${brandName}\` | \`${brandSlug}\` |\n`
});
fs.writeFileSync(slugsFile, content);