Skip to content

Commit

Permalink
Fix running repository without access to Pro token for @gitbook/icons (
Browse files Browse the repository at this point in the history
…#2417)

Co-authored-by: Valentino Hudhra <2587839+valentin0h@users.noreply.github.com>
  • Loading branch information
SamyPesse and valentin0h authored Aug 2, 2024
1 parent 4638958 commit 776bc31
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-worms-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/icons': minor
---

Fix bin gitbook-icons when installed without the Pro token
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
Expand Down
7 changes: 5 additions & 2 deletions packages/icons/bin/gen-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,4 +69,7 @@ async function writeDataFile(name, content) {
]);
}

main().catch(console.error);
main().catch((error) => {
console.error(error);
process.exit(1);
});
38 changes: 23 additions & 15 deletions packages/icons/bin/gitbook-icons.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
});
7 changes: 5 additions & 2 deletions packages/icons/bin/kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
26 changes: 0 additions & 26 deletions packages/icons/src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 776bc31

Please sign in to comment.