-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(icons): [publish_preview] each icon generates its own dist, pack…
…age.json, and entrypoint when yarn build is run
- Loading branch information
1 parent
717db54
commit a161f87
Showing
3 changed files
with
57 additions
and
318 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/components/icons/generate-dist-folders-for-icons.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.