From 776bc3135a6aef6d790511503900514ce5179f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 2 Aug 2024 18:40:44 +0200 Subject: [PATCH] Fix running repository without access to Pro token for @gitbook/icons (#2417) Co-authored-by: Valentino Hudhra <2587839+valentin0h@users.noreply.github.com> --- .changeset/wild-worms-roll.md | 5 ++++ package.json | 3 ++- packages/icons/bin/gen-list.js | 7 ++++-- packages/icons/bin/gitbook-icons.js | 38 +++++++++++++++++------------ packages/icons/bin/kit.js | 7 ++++-- packages/icons/src/icons.ts | 26 -------------------- 6 files changed, 40 insertions(+), 46 deletions(-) create mode 100644 .changeset/wild-worms-roll.md diff --git a/.changeset/wild-worms-roll.md b/.changeset/wild-worms-roll.md new file mode 100644 index 0000000000..dcfa79e96f --- /dev/null +++ b/.changeset/wild-worms-roll.md @@ -0,0 +1,5 @@ +--- +'@gitbook/icons': minor +--- + +Fix bin gitbook-icons when installed without the Pro token diff --git a/package.json b/package.json index fee7a1bdd6..15fcd3d3d0 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "unit": "turbo run unit", "e2e": "turbo run e2e", "changeset": "changeset", - "release": "turbo run release && changeset publish" + "release": "turbo run release && changeset publish", + "download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local" }, "workspaces": [ "packages/*" diff --git a/packages/icons/bin/gen-list.js b/packages/icons/bin/gen-list.js index f7736de7ce..6850a76703 100644 --- a/packages/icons/bin/gen-list.js +++ b/packages/icons/bin/gen-list.js @@ -11,7 +11,7 @@ import { getKitPath } from './kit.js'; async function main() { const source = getKitPath(); const icons = JSON.parse( - await fs.readFile(path.join(source, 'icons/metadata/icon-families.json'), 'utf8'), + await fs.readFile(path.join(source, 'metadata/icon-families.json'), 'utf8'), ); // Only these families have exceptions @@ -69,4 +69,7 @@ async function writeDataFile(name, content) { ]); } -main().catch(console.error); +main().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/packages/icons/bin/gitbook-icons.js b/packages/icons/bin/gitbook-icons.js index 91100e1f2e..8edcae5be1 100755 --- a/packages/icons/bin/gitbook-icons.js +++ b/packages/icons/bin/gitbook-icons.js @@ -1,5 +1,6 @@ #!/usr/bin/env node import fs from 'fs/promises'; +import { existsSync } from 'fs'; import path from 'path'; import { getKitPath } from './kit.js'; @@ -26,24 +27,31 @@ async function main() { // source/sprites to outputFolder/sprites // source/svgs to outputFolder/svgs await Promise.all([ - ...stylesToCopy.map((style) => - fs.cp( - path.join(source, `icons/svgs/${style}`), - path.join(outputFolder, 'svgs', style), - { + ...stylesToCopy.map((style) => { + const stylePath = path.join(source, 'svgs', style); + if (!existsSync(stylePath)) { + console.warn(`❌ Style ${style} does not exist`); + } else { + return fs.cp(stylePath, path.join(outputFolder, 'svgs', style), { recursive: true, - }, - ), - ), - ...stylesToCopy.map((style) => - fs.cp( - path.join(source, `icons/sprites/${style}.svg`), - path.join(outputFolder, 'sprites', style + '.svg'), - ), - ), + }); + } + }), + ...stylesToCopy.map((style) => { + const spritePath = path.join(source, `sprites/${style}.svg`); + if (existsSync(spritePath)) { + return fs.cp( + path.join(source, `sprites/${style}.svg`), + path.join(outputFolder, 'sprites', style + '.svg'), + ); + } + }), ]); console.log(`🎉 Icons copied to ${printOutputFolder}`); } -main().catch(console.error); +main().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/packages/icons/bin/kit.js b/packages/icons/bin/kit.js index 06e0387c60..c44409e49d 100644 --- a/packages/icons/bin/kit.js +++ b/packages/icons/bin/kit.js @@ -9,8 +9,11 @@ export function getKitPath() { url.fileURLToPath(import.meta.resolve('@fortawesome/fontawesome-free/package.json')), ); try { - source = path.dirname( - url.fileURLToPath(import.meta.resolve('@awesome.me/kit-a463935e93/package.json')), + source = path.resolve( + path.dirname( + url.fileURLToPath(import.meta.resolve('@awesome.me/kit-a463935e93/package.json')), + ), + 'icons', ); } catch (error) { console.warn('⚠️ Could not find the Pro kit, using the free kit instead'); diff --git a/packages/icons/src/icons.ts b/packages/icons/src/icons.ts index 7e1feb6a30..6304882b7c 100644 --- a/packages/icons/src/icons.ts +++ b/packages/icons/src/icons.ts @@ -12,32 +12,6 @@ export interface IconDefinition { search?: string[]; } -/** - * List of all icon styles available in the library. - */ -export const iconStyles: IconStyleDefinition[] = [ - { - title: 'Regular', - style: IconStyle.Regular, - }, - { - title: 'Duotone', - style: IconStyle.Duotone, - }, - { - title: 'Light', - style: IconStyle.Light, - }, - { - title: 'Thin', - style: IconStyle.Thin, - }, - { - title: 'Solid', - style: IconStyle.Solid, - }, -]; - /** * List of all icons available in the library. */