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

Add --output option to configure output file #48

Open
corbanbrook opened this issue Sep 12, 2018 · 3 comments
Open

Add --output option to configure output file #48

corbanbrook opened this issue Sep 12, 2018 · 3 comments

Comments

@corbanbrook
Copy link

corbanbrook commented Sep 12, 2018

Currently always outputs as index,js but in a typescript project I would like index.ts

I might even want to change the name from index to something else.

@dijs
Copy link

dijs commented Nov 28, 2018

I would also like to change the output directory. I may work on this.

@kvedantmahajan
Copy link

kvedantmahajan commented Dec 5, 2019

@dijs Please do this soon. Traffic is coming from gregberge/svgr#189

+1 for this index.ts naming.

While doing this you may not want to append .tsx or ts in the generated import statements of file i.e.

export { default as Announcement } from './Announcement.tsx';

as it makes tslint unhappy.

@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"

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

Successfully merging a pull request may close this issue.

4 participants