bencoveney / barrelsby

Automatic TypeScript barrels (index.ts files) for your entire code base

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Support JSONs

TomerSalton opened this issue · comments

Hey,

TypeScript enables to import JSON files very easily:
import data from ./file.json
It could be useful to export many JSON files from index.ts, something such as:

import a from ./a.json;
import b from ./b.json;
import c from ./c.json;

export let aJSON = a;
export let bJSON = b;
export let cJSON = c;

Thanks for the contribution 😄 Sounds like a great idea 👍

This idea can be expanded to all kinds of files. E.g. I have a directory full of svgs. I have a declare module '*.svg' that defines a type for default exports.

I'd like to create a barrel like follows:

export { default as Send } from './Send.svg';
export { default as System } from './System.svg';
...

But it's not a big deal, I use the following and it does the job.

const fs = require('fs');
const path = require('path');

const files = fs.readdirSync(__dirname);
// files.forEach(f => console.log(f));
const result = files
  .filter(f => f.endsWith('.svg'))
  .map(f => `export { default as ${f.slice(0, -4)} } from './${f}';`)
  .join('\n');

fs.writeFileSync(path.resolve(__dirname, 'index.ts'), result, { encoding: 'utf8' });

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator