Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate index.js when --out-dir option is used #189

Closed
gregberge opened this issue Sep 26, 2018 · 9 comments
Closed

Generate index.js when --out-dir option is used #189

gregberge opened this issue Sep 26, 2018 · 9 comments
Labels
enhancement ✨ v5 Released in v5

Comments

@gregberge
Copy link
Owner

As suggested in #161, we could generate an index.js containing all icons when we use --out-dir option.

Be careful to be compatible with #182.

@sis
Copy link

sis commented Jan 24, 2019

This package may help https://github.com/gajus/create-index

@kvedantmahajan
Copy link

@sis @gregberge the package above doesn't have options to generate index.ts. Rest all good.

Open issue here - gajus/create-index#48

@kvedantmahajan
Copy link

Here, I have written a tiny nodejs script to achieve the same after create-index generates an index.js ( I have a Typescript project ).
Basically I had to replace .tsx from all import statements in index.js. Second, I had to rename it to index.ts.

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

const filePath = path.join("src", "icons");
const fileName = "index.js";

fs.readFile(`${filePath}/${fileName}`, "utf8", (err, data) => {
	if (err) throw err;
	const newStr = data.replace(/.tsx/g, "");
	fs.writeFile(`${filePath}/${fileName}`, newStr, writeErr => {
		if (writeErr) throw err;
		fs.rename(`${filePath}/${fileName}`, `${filePath}/index.ts`, renameErr => {
			if (renameErr) throw renameErr;
			console.log("rename completed");
		});
	});
});

package.json scripts as follows:

"build-icons": "rm -rf src/icons && npx @svgr/cli -d src/icons svg-icons --ext tsx",
"create-index": "npx create-index src/icons --extensions tsx",
"recreate-index": "node scripts/regenerate-icon-index.js",
"lint:icons": "eslint './src/icons/*.{ts,tsx}' --fix",
"generate-icons": "yarn run build-icons && yarn run create-index && yarn run recreate-index && yarn run lint:icons"

@gregberge gregberge added the v5 Released in v5 label Dec 22, 2019
@kelly-tock
Copy link

could we have semicolons at the end of the default template or an example of how to customize it?

@gregberge
Copy link
Owner Author

Custom templates are now supported. A next step would be to run prettier on the index file. Do you want to submit a PR to do it?

@kelly-tock
Copy link

Figured it out in a different issue, thanks!

@gucolin
Copy link

gucolin commented Mar 18, 2021

I understand it's nice to have index.js auto generated, but is there a way to not forcing it? I had to specify -d in the CLI but don't want to index.js, is it possible?

@antonhalim
Copy link

I concur with @gucolin, any update on not generating index file? Thanks in advance!
cc @gregberge

@jwpjrdev
Copy link

I have the same request as @gucolin and @antonhalim… I’m currently using a simple bash script to reformat and move my SVGs from a zip file exported from Figma. I could just delete index.js via the script but I’d really rather a configuration option for the CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ v5 Released in v5
Projects
None yet
Development

No branches or pull requests

7 participants