Comments (3)
@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.
from create-index.
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"
from create-index.
I would also like to change the output directory. I may work on this.
from create-index.
Related Issues (20)
- Feature request: Excluding specific files HOT 4
- README uses previous export syntax example HOT 1
- There is no check if the imported file has a default. HOT 2
- Add option to uppercase first char of export HOT 4
- Recursive option when using programmatically HOT 1
- Functions exported as default not picked up
- Include folder name in banner
- Importing created subdirectory index files HOT 5
- JSX Files HOT 2
- Files with hyphen are ignored. HOT 1
- option to "disable" semicolon HOT 2
- implementation with .ts file maybe?
- [bug] can't read file or folder with "-"? HOT 5
- Tests don't work? HOT 2
- 'create-index' is not recognized as an internal or external command, operable program or batch file HOT 1
- Support creating index with default export HOT 9
- Use with typescript, add webpack plugin HOT 2
- Wrong casing in generated index.js
- Conflicts between files and folders with same name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from create-index.