feat: update package.json and add generate-barrel script
- Set project name to "nova-design-system" and updated version to 0.1.0 - Added description for the project - Defined exports for the main entry and styles - Included a new script "barrel" to generate index.ts for components - Added "sass" as a devDependency chore: update package-lock.json - Added "sass" as a devDependency with version ^1.99.0 - Updated dependencies including @parcel/watcher and others refactor: remove unused assets and Welcome component - Deleted astro.svg and background.svg assets - Removed Welcome.astro component as it was no longer needed
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Scans src/components/ and regenerates src/components/index.ts.
|
||||
* Each component folder must have an index.ts that exports the component.
|
||||
* Run: npm run barrel
|
||||
*/
|
||||
|
||||
import { readdir, writeFile, stat } from 'fs/promises';
|
||||
import { join, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
const componentsDir = resolve(__dirname, '../src/components');
|
||||
const outputFile = join(componentsDir, 'index.ts');
|
||||
|
||||
const entries = await readdir(componentsDir);
|
||||
|
||||
const componentFolders = (
|
||||
await Promise.all(
|
||||
entries.map(async (name) => {
|
||||
const fullPath = join(componentsDir, name);
|
||||
const info = await stat(fullPath);
|
||||
return info.isDirectory() ? name : null;
|
||||
})
|
||||
)
|
||||
).filter(Boolean);
|
||||
|
||||
if (componentFolders.length === 0) {
|
||||
console.log('No component folders found.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const lines = [
|
||||
'// Auto-generated by scripts/generate-barrel.mjs — do not edit manually.',
|
||||
'',
|
||||
...componentFolders.map((name) => `export * from './${name}/index.ts';`),
|
||||
'',
|
||||
];
|
||||
|
||||
await writeFile(outputFile, lines.join('\n'), 'utf-8');
|
||||
|
||||
console.log(`Barrel generated with ${componentFolders.length} component(s):`);
|
||||
componentFolders.forEach((name) => console.log(` - ${name}`));
|
||||
Reference in New Issue
Block a user