Closed nicolas-brousse closed 6 years ago
$ rails new demo-app --webpack
$ cd demo-app
$ echo "gem 'komponent'" >> Gemfile
$ bundle
$ rails generate komponent:install
$ rails generate component container
$ rails generate component button
After what I got this inside frontend/components/index.js
:
import "components/button/button";
import "components/container/container";
Ok, now I convert double to single quotes inside this file, then I generate a new component rails generate component form
.
And frontend/components/index.js
now contain:
import "components/form/form";
My two previous components are absent from index.js
now.
Thanks for the instructions, it will help!
Maybe the error is due to sort_lines_alphabetically!(path)
and not import_to_packs
.
I think you're right. Can you try modifying the regex from this line?
We would need /^import ["'](.*)["'];$/
to support simple quotes.
I added a failing test case here: https://github.com/komposable/komponent/pull/101 and pushed this commit https://github.com/komposable/komponent/pull/101/commits/086be84f66e0483b97f63960095e49b26f557b98 to fix the issue.
But I'm not sure what behavior we want... Should we rewrite the whole index file with single or double quotes? How do we check what is the expected syntax for the current project?
I think to start it's not really a problem to continue adding new component with double quotes. The main think is to not remove previous added components :)
Okay, let's merge this fix for now, and we may improve this later.
On a project we use single quotes on js files. So our
frontend/components/index.js
has list of components with single quotes.The problem with when we generate a new component, the
import_to_packs
method seems to remove all components import and adding the new one.Not sure what could be done. May be using the
Komponent::Component.all
method a created on #95, could help us to do the import list directly by getting the list of present components.