Skip to content

Commit

Permalink
feat(icons): [publish_preview] each icon generates its own dist, pack…
Browse files Browse the repository at this point in the history
…age.json, and entrypoint when yarn build is run
  • Loading branch information
ByronDWall committed Dec 12, 2024
1 parent 717db54 commit a161f87
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 318 deletions.
55 changes: 55 additions & 0 deletions packages/components/icons/generate-dist-folders-for-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { kebabCase } = require('lodash');
const fs = require('node:fs');
const path = require('node:path');
const PackageJson = require('@npmcli/package-json');
const cac = require('cac').cac;

const cli = cac('generate-entrypoints');

cli
.command(
'[...files]',
'generates folders and package.json for each generated icon file to enable them to be bundled individually with preconstruct'
)
.action(async (files, options) => {
if (!files) {
return console.log('you must pass a glob to parse');
}

const folders = files.map(
(file) =>
`/${path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
)}`
);

const rootFolder = path.dirname(folders[0]).split(path.sep)[1];
const currentDir = fs.realpathSync(process.cwd());
const rootDir = `${currentDir}/${rootFolder}`;

fs.rmSync(rootDir, { recursive: true, force: true });

const rootPkgJson = await PackageJson.load(currentDir);
await Promise.all(
folders.map(async (folder) => {
const pkgDir = `${currentDir}${folder}`;
const bundleName = `dist/${kebabCase(
`${rootPkgJson.content.name}/${rootFolder}`
)}-${path.basename(folder)}`;

fs.mkdirSync(pkgDir, { recursive: true });
const pkgJson = await PackageJson.create(pkgDir);
pkgJson.update({
main: `${bundleName}.cjs.js`,
module: `${bundleName}.esm.js`,
});
await pkgJson.save();
return console.log(`added folder and package.json for ${folder}`);
})
);
});

cli.help();

cli.parse();
277 changes: 2 additions & 275 deletions packages/components/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,280 +23,7 @@
"./custom-icon/index.ts",
"./inline-svg/index.ts",
"./leading-icon/index.ts",
"./generated/AngleDownReact.tsx",
"./generated/AngleLeftReact.tsx",
"./generated/AngleRightReact.tsx",
"./generated/AngleThinLeftReact.tsx",
"./generated/AngleThinRightReact.tsx",
"./generated/AngleUpDownReact.tsx",
"./generated/AngleUpReact.tsx",
"./generated/ArrowDownReact.tsx",
"./generated/ArrowLeftReact.tsx",
"./generated/ArrowLongDownReact.tsx",
"./generated/ArrowRightReact.tsx",
"./generated/ArrowTriangleDownReact.tsx",
"./generated/ArrowTriangleUpReact.tsx",
"./generated/ArrowUpReact.tsx",
"./generated/ArrowsMinimizeReact.tsx",
"./generated/ArrowsReact.tsx",
"./generated/BackReact.tsx",
"./generated/BidirectionalArrowReact.tsx",
"./generated/BinFilledReact.tsx",
"./generated/BinLinearReact.tsx",
"./generated/BoxReact.tsx",
"./generated/BrainReact.tsx",
"./generated/CalendarReact.tsx",
"./generated/CameraReact.tsx",
"./generated/CaretDownReact.tsx",
"./generated/CaretDownSmallReact.tsx",
"./generated/CaretUpReact.tsx",
"./generated/CaretUpSmallReact.tsx",
"./generated/CartReact.tsx",
"./generated/ChainBrokenReact.tsx",
"./generated/ChainReact.tsx",
"./generated/CheckActiveReact.tsx",
"./generated/CheckBoldReact.tsx",
"./generated/CheckInactiveReact.tsx",
"./generated/CheckThinReact.tsx",
"./generated/CircleReact.tsx",
"./generated/ClipboardReact.tsx",
"./generated/ClockReact.tsx",
"./generated/ClockWithArrowReact.tsx",
"./generated/CloseBoldReact.tsx",
"./generated/CloseReact.tsx",
"./generated/CodeViewReact.tsx",
"./generated/CoinsReact.tsx",
"./generated/ColumnsReact.tsx",
"./generated/ConnectedSquareReact.tsx",
"./generated/ConnectedTriangleReact.tsx",
"./generated/CopyReact.tsx",
"./generated/CtCheckoutReact.tsx",
"./generated/CubeReact.tsx",
"./generated/CubesReact.tsx",
"./generated/DiamondReact.tsx",
"./generated/DomainReact.tsx",
"./generated/DotReact.tsx",
"./generated/DownloadReact.tsx",
"./generated/DragDropReact.tsx",
"./generated/DragReact.tsx",
"./generated/EditReact.tsx",
"./generated/ErrorReact.tsx",
"./generated/ExpandReact.tsx",
"./generated/ExportReact.tsx",
"./generated/ExternalLinkReact.tsx",
"./generated/EyeCrossedReact.tsx",
"./generated/EyeReact.tsx",
"./generated/FilterAndListReact.tsx",
"./generated/FilterReact.tsx",
"./generated/FlagFilledReact.tsx",
"./generated/FlagLinearReact.tsx",
"./generated/FlameReact.tsx",
"./generated/FractionDigitsReact.tsx",
"./generated/GearReact.tsx",
"./generated/GraduationCapReact.tsx",
"./generated/GraphReact.tsx",
"./generated/GridReact.tsx",
"./generated/GroupAddReact.tsx",
"./generated/HeartReact.tsx",
"./generated/HomeReact.tsx",
"./generated/HubReact.tsx",
"./generated/ImportReact.tsx",
"./generated/InfoReact.tsx",
"./generated/InformationReact.tsx",
"./generated/LayersReact.tsx",
"./generated/ListReact.tsx",
"./generated/ListWithSearchReact.tsx",
"./generated/LockReact.tsx",
"./generated/LogoutReact.tsx",
"./generated/MailReact.tsx",
"./generated/MinimizeReact.tsx",
"./generated/NestedViewReact.tsx",
"./generated/OperationsReact.tsx",
"./generated/PageGearReact.tsx",
"./generated/PagesReact.tsx",
"./generated/PaidReact.tsx",
"./generated/PaperBillInvertedReact.tsx",
"./generated/PaperclipReact.tsx",
"./generated/PinFilledReact.tsx",
"./generated/PinGearReact.tsx",
"./generated/PinLinearReact.tsx",
"./generated/PluginReact.tsx",
"./generated/PlusBoldReact.tsx",
"./generated/PlusThinReact.tsx",
"./generated/RefreshReact.tsx",
"./generated/RestoreReact.tsx",
"./generated/RevertReact.tsx",
"./generated/ReviewReact.tsx",
"./generated/RightTriangleFilledReact.tsx",
"./generated/RightTriangleLinearReact.tsx",
"./generated/RocketReact.tsx",
"./generated/ScreenGearReact.tsx",
"./generated/ScreenUserReact.tsx",
"./generated/SearchReact.tsx",
"./generated/SidebarCollapseReact.tsx",
"./generated/SidebarExpandReact.tsx",
"./generated/SortingReact.tsx",
"./generated/SpeechBubbleReact.tsx",
"./generated/SpeedometerReact.tsx",
"./generated/SplitReact.tsx",
"./generated/StackReact.tsx",
"./generated/StarReact.tsx",
"./generated/SubdirectoryArrowReact.tsx",
"./generated/SupportReact.tsx",
"./generated/SwitcherReact.tsx",
"./generated/TableReact.tsx",
"./generated/TagMultiReact.tsx",
"./generated/TagReact.tsx",
"./generated/TagStackedReact.tsx",
"./generated/TerminalReact.tsx",
"./generated/TreeStructureReact.tsx",
"./generated/TruckReact.tsx",
"./generated/TuneReact.tsx",
"./generated/UserFilledReact.tsx",
"./generated/UserLinearReact.tsx",
"./generated/UsersReact.tsx",
"./generated/VerifiedReact.tsx",
"./generated/ViewGridPlusReact.tsx",
"./generated/WarningReact.tsx",
"./generated/WindowEyeReact.tsx",
"./generated/WorldReact.tsx",
"./generated/AngleDownReact.tsx",
"./generated/AngleLeftReact.tsx",
"./generated/AngleRightReact.tsx",
"./generated/AngleThinLeftReact.tsx",
"./generated/AngleThinRightReact.tsx",
"./generated/AngleUpDownReact.tsx",
"./generated/AngleUpReact.tsx",
"./generated/ArrowDownReact.tsx",
"./generated/ArrowLeftReact.tsx",
"./generated/ArrowLongDownReact.tsx",
"./generated/ArrowRightReact.tsx",
"./generated/ArrowTriangleDownReact.tsx",
"./generated/ArrowTriangleUpReact.tsx",
"./generated/ArrowUpReact.tsx",
"./generated/ArrowsMinimizeReact.tsx",
"./generated/ArrowsReact.tsx",
"./generated/BackReact.tsx",
"./generated/BidirectionalArrowReact.tsx",
"./generated/BinFilledReact.tsx",
"./generated/BinLinearReact.tsx",
"./generated/BoxReact.tsx",
"./generated/BrainReact.tsx",
"./generated/CalendarReact.tsx",
"./generated/CameraReact.tsx",
"./generated/CaretDownReact.tsx",
"./generated/CaretDownSmallReact.tsx",
"./generated/CaretUpReact.tsx",
"./generated/CaretUpSmallReact.tsx",
"./generated/CartReact.tsx",
"./generated/ChainBrokenReact.tsx",
"./generated/ChainReact.tsx",
"./generated/CheckActiveReact.tsx",
"./generated/CheckBoldReact.tsx",
"./generated/CheckInactiveReact.tsx",
"./generated/CheckThinReact.tsx",
"./generated/CircleReact.tsx",
"./generated/ClipboardReact.tsx",
"./generated/ClockReact.tsx",
"./generated/ClockWithArrowReact.tsx",
"./generated/CloseBoldReact.tsx",
"./generated/CloseReact.tsx",
"./generated/CodeViewReact.tsx",
"./generated/CoinsReact.tsx",
"./generated/ColumnsReact.tsx",
"./generated/ConnectedSquareReact.tsx",
"./generated/ConnectedTriangleReact.tsx",
"./generated/CopyReact.tsx",
"./generated/CtCheckoutReact.tsx",
"./generated/CubeReact.tsx",
"./generated/CubesReact.tsx",
"./generated/DiamondReact.tsx",
"./generated/DomainReact.tsx",
"./generated/DotReact.tsx",
"./generated/DownloadReact.tsx",
"./generated/DragDropReact.tsx",
"./generated/DragReact.tsx",
"./generated/EditReact.tsx",
"./generated/ErrorReact.tsx",
"./generated/ExpandReact.tsx",
"./generated/ExportReact.tsx",
"./generated/ExternalLinkReact.tsx",
"./generated/EyeCrossedReact.tsx",
"./generated/EyeReact.tsx",
"./generated/FilterAndListReact.tsx",
"./generated/FilterReact.tsx",
"./generated/FlagFilledReact.tsx",
"./generated/FlagLinearReact.tsx",
"./generated/FlameReact.tsx",
"./generated/FractionDigitsReact.tsx",
"./generated/GearReact.tsx",
"./generated/GraduationCapReact.tsx",
"./generated/GraphReact.tsx",
"./generated/GridReact.tsx",
"./generated/GroupAddReact.tsx",
"./generated/HeartReact.tsx",
"./generated/HomeReact.tsx",
"./generated/HubReact.tsx",
"./generated/ImportReact.tsx",
"./generated/InfoReact.tsx",
"./generated/InformationReact.tsx",
"./generated/LayersReact.tsx",
"./generated/ListReact.tsx",
"./generated/ListWithSearchReact.tsx",
"./generated/LockReact.tsx",
"./generated/LogoutReact.tsx",
"./generated/MailReact.tsx",
"./generated/MinimizeReact.tsx",
"./generated/NestedViewReact.tsx",
"./generated/OperationsReact.tsx",
"./generated/PageGearReact.tsx",
"./generated/PagesReact.tsx",
"./generated/PaidReact.tsx",
"./generated/PaperBillInvertedReact.tsx",
"./generated/PaperclipReact.tsx",
"./generated/PinFilledReact.tsx",
"./generated/PinGearReact.tsx",
"./generated/PinLinearReact.tsx",
"./generated/PluginReact.tsx",
"./generated/PlusBoldReact.tsx",
"./generated/PlusThinReact.tsx",
"./generated/RefreshReact.tsx",
"./generated/RestoreReact.tsx",
"./generated/RevertReact.tsx",
"./generated/ReviewReact.tsx",
"./generated/RightTriangleFilledReact.tsx",
"./generated/RightTriangleLinearReact.tsx",
"./generated/RocketReact.tsx",
"./generated/ScreenGearReact.tsx",
"./generated/ScreenUserReact.tsx",
"./generated/SearchReact.tsx",
"./generated/SidebarCollapseReact.tsx",
"./generated/SidebarExpandReact.tsx",
"./generated/SortingReact.tsx",
"./generated/SpeechBubbleReact.tsx",
"./generated/SpeedometerReact.tsx",
"./generated/SplitReact.tsx",
"./generated/StackReact.tsx",
"./generated/StarReact.tsx",
"./generated/SubdirectoryArrowReact.tsx",
"./generated/SupportReact.tsx",
"./generated/SwitcherReact.tsx",
"./generated/TableReact.tsx",
"./generated/TagMultiReact.tsx",
"./generated/TagReact.tsx",
"./generated/TagStackedReact.tsx",
"./generated/TerminalReact.tsx",
"./generated/TreeStructureReact.tsx",
"./generated/TruckReact.tsx",
"./generated/TuneReact.tsx",
"./generated/UserFilledReact.tsx",
"./generated/UserLinearReact.tsx",
"./generated/UsersReact.tsx",
"./generated/VerifiedReact.tsx",
"./generated/ViewGridPlusReact.tsx",
"./generated/WarningReact.tsx",
"./generated/WindowEyeReact.tsx",
"./generated/WorldReact.tsx"
"./generated/**.tsx"
]
},
"files": [
Expand All @@ -307,7 +34,7 @@
"generated/**"
],
"scripts": {
"generate-icons": "svgr -d src/generated -- src/svg"
"generate-icons": "svgr -d src/generated -- src/svg && node ./generate-dist-folders-for-icons src/generated/**.tsx"
},
"dependencies": {
"@babel/runtime": "^7.20.13",
Expand Down
43 changes: 0 additions & 43 deletions scripts/gernerate-package-json-entrypoints.js

This file was deleted.

0 comments on commit a161f87

Please sign in to comment.