Component generator error with single quotes string
nicolas-brousse opened this issue · comments
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.
- import "components/alert/alert";
- import "components/button/button";
- import "components/container/container";
- import "components/footer/footer";
- import "components/navigation/navigation";
- import "components/pagination/pagination";
+ import "components/test/test";
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.
How to reproduce the bug
$ 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 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.