-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from WestpacGEL/feature/individual-component-…
…exports feature(ui): add script to generate individual component exports
- Loading branch information
Showing
4 changed files
with
188 additions
and
5 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@westpac/ui': minor | ||
--- | ||
|
||
Add individual component exports |
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 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 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,38 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
const exports: Record<string, { default: string }> = { | ||
'.': { | ||
default: './dist/index.js', | ||
}, | ||
'./component-type.json': { | ||
default: './dist/component-type.json', | ||
}, | ||
'./css': { | ||
default: './dist/css/westpac-ui.min.css', | ||
}, | ||
'./hook': { | ||
default: './dist/hook/index.js', | ||
}, | ||
'./tailwind': { | ||
default: './dist/tailwind/index.js', | ||
}, | ||
}; | ||
|
||
const main = async () => { | ||
const components = (await fs.readdir(path.join(process.cwd(), 'src/components'), { withFileTypes: true })) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name); | ||
|
||
components.forEach(component => { | ||
exports[`./${component}`] = { default: `./dist/components/${component}/index.js` }; | ||
}); | ||
|
||
const pkgJsonPath = path.join(process.cwd(), 'package.json'); | ||
const data = await fs.readFile(pkgJsonPath, 'utf-8'); | ||
const pkgJson = JSON.parse(data); | ||
pkgJson.exports = exports; | ||
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJson)); | ||
}; | ||
|
||
main(); |