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

(Feature) Add custom template function #43

Closed
wants to merge 1 commit into from

Conversation

coleturner
Copy link

@coleturner coleturner commented Jan 28, 2018

  • Tests and lint pass
  • Added new test

This pull request adds the ability to customize the output of create-index, to create different kinds of exports:

writeIndex(['./target_directory'], {}, (varName, fileName) => `export * as ${varName} from './${fileName}`);

// export * as Example from './Example';

Doing so allows the customization for a couple uses cases I've experienced personally and have seen in the issues here.

This change only affects the API. I was not sure what to do for the client, I would suppose a good way to add support would to add a --template file/path.js flag where the JS file must export a function. @gajus please let me know if you have any thoughts on that matter.

Cheers!

@coleturner coleturner changed the title Add custom template function (Feature) Add custom template function Jan 28, 2018
@gajus
Copy link
Owner

gajus commented Jan 28, 2018

Doing so allows the customization for a couple uses cases I've experienced personally and have seen in the issues here. Cheers!

What are those use cases?

This looks like a style issue.

@coleturner
Copy link
Author

For my particular use case now I am exporting GraphQL modules as such:

types/Post
types/Post/schema.graphql
types/Post/resolvers.js
types/Post/index.js // exports both schema and resolvers
types/Comment
types/Comment/schema.graphql
types/Comment/resolvers.js
types/Comment/index.js // exports both schema and resolvers

I would like to manufacture an index where I can import from ./types and get:

{ Post: { schema, resolvers }, Comment: { schema, resolvers } }

But the application has way more potential. For example when working with Redux and React, having the ability to do export * as SELECTORS from './selectors'; would make it easier to structure my app however I like. This also enables create-index to be used in situations where more precise tree-shaking is desired. While it may seem like a style issue I believe it opens up create-index to have it's default use case while accommodating exceptions in an unobtrusive fashion.

@coleturner
Copy link
Author

coleturner commented Jan 28, 2018

Related
#36
#11

@coleturner
Copy link
Author

@gajus have you made a decision whether to accept this change?

@gajus
Copy link
Owner

gajus commented Feb 9, 2018

I would rather keep this addition out of this particular project.

I can leave the PR open and see if more people 👍 .

Meanwhile, you can just for the project.

@coleturner
Copy link
Author

coleturner commented Feb 9, 2018

Alright, I'll maintain a fork of this project @ create-exports-index.

I would like to ask you to reconsider given that there have been three requests for this feature and I myself have run into several use cases where I want to change what's exported. It's not really a matter of style but rather the current output is limiting in scope of use.

Thanks for your time 👍

@develomark
Copy link

I'd also request this be part of the main package. In my scenario, we are restricting the use of default exports and using only named (good practice for tree shaking, amongst other reasons). Therefore our requirement is for create-index to output the following:

export { bar } from './bar.js';
export { baz } from './baz.js';
export { foo } from './foo.js';

We shall migrate over to @coleturner's package.

@develomark
Copy link

@coleturner your NPM package doesn't appear to be built. There is no dist folder. I get the following error:

npm ERR! enoent ENOENT: no such file or directory, chmod '/.../node_modules/create-exports-index/dist/bin/create-index.js'
npm ERR! enoent This is related to npm not being able to find a file.

@coleturner
Copy link
Author

@develomark apologies, I published in haste. Try v1.3.0@create-exports-index

@develomark
Copy link

@coleturner thanks!!

@stubar
Copy link

stubar commented May 19, 2018

I too require a custom template. @coleturner thanks for forking

@coleturner
Copy link
Author

Have to close this now, despite the interest and demand for this feature. It doesn't seem like this library will support more than the current limiting use case.

sadface

@coleturner coleturner closed this Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants