CleverCloud / clever-components

Collection of Web Components by Clever Cloud
https://www.clever-cloud.com/doc/clever-components/
Apache License 2.0
218 stars 19 forks source link

Rework the project structure #501

Closed hsablonniere closed 2 years ago

hsablonniere commented 2 years ago

Context

All components are organized in folders that have some kind of meaning. It can be semantic: atoms or related to the domain: env-vars.

Problems

NOTE: The folder is not used by Storybook for the left menu/tree (even if it's the same). This is done through CSF config.

Proposition

1) Component files in src/components

Example: we move src/atoms/cc-input-text.js to src/components/cc-input-text.js.

2) Component files in src/components/cc-my-component

Example: we move src/atoms/cc-input-text.js to src/components/cc-input-text/cc-input-text.js.

Impacts

In both cases, I propose that we publish to npm with all components directly available in the root folder.

import `@clevercloud/components/dist/cc-input-text.js`;

:warning: This is a breaking change.

roberttran-cc commented 2 years ago

Overall, I would go with option 2: it looks better for maintainability and understanding, especially in the long term.

And I would put everything in the same folder as the component: I could imagine having stories and/or tests in a distinct folder, as they are part of a "different" stack but I've got no true reason to do this (not convinced).

And I agree with the root folder availability.

About this, I know it is possible to explicitly specify the package's entry points but I had trouble using it in a previous project: https://nodejs.org/api/packages.html#package-entry-points

pdesoyres-cc commented 2 years ago

I would choose the second option where we, as much as possible, colocate files together. It's a common practive in JavaScript projects to do so. I find it easier to navigate and understand. It's also easier to know which files are involved in one component.

Galimede commented 2 years ago

I do find the second option to be better as well. Also it will probably be much easier to navigate through the files for us with that option than the first one.

hsablonniere commented 2 years ago

About this, I know it is possible to explicitly specify the package's entry points but I had trouble using it in a previous project: nodejs.org/api/packages.html#package-entry-points

Yes, I tried experimenting with this but support with smart CDNs and some bundlers was still a bit weird... We'll try again in the future.

hsablonniere commented 2 years ago

I did some experiments with rollup and I'm sad :cry:

hsablonniere commented 2 years ago

OK, I tried all files as inputs and it seems to work :tada:

hsablonniere commented 2 years ago

:tada: I found a way to move files automatically with a custom config of Rollup :heart:

Things that feel right:

Things we should discuss:

├── stories
│   ├── assets
│   │   ├── 24-hours-points.js
│   │   ├── addon-plans.js
│   │   ├── country-city-points-big-orga.js
│   │   ├── country-city-points-medium-orga.js
│   │   ├── country-city-points-normal-orga.js
│   │   ├── price-system.js
│   │   └── runtime-plans.js
│   ├── atoms
│   │   └── all-form-controls.js
│   ├── lib
│   │   ├── dom.js
│   │   ├── i18n-control.js
│   │   ├── make-story.js
│   │   ├── sequence.js
│   │   ├── story-names.js
│   │   └── timers.js
│   ├── maps
│   │   └── fake-map-data.js

Those files are only used by stories.

  1. We can move them into src/stories/*
  2. We can keep them "at the root" => stories/*

NOTE: images in stories/assets were moved to src/assets.

Is it bad if we have images in there that are only used by stories?

hsablonniere commented 2 years ago

Thinking about those exceptions:

I propose something like this (where stories is inside src):

├── stories
│   ├── fixtures
│   │   ├── 24-hours-points.js
│   │   ├── addon-plans.js
│   │   ├── country-city-points-big-orga.js
│   │   ├── country-city-points-medium-orga.js
│   │   ├── country-city-points-normal-orga.js
│   │   ├── fake-map-data.js
│   │   ├── price-system.js
│   │   └── runtime-plans.js
│   ├── lib
│   │   ├── dom.js
│   │   ├── i18n-control.js
│   │   ├── make-story.js
│   │   ├── sequence.js
│   │   ├── story-names.js
│   │   └── timers.js
│   └── all-form-controls.js
hsablonniere commented 2 years ago

NOTE: I gave a look at multiple component library repos on GitHub (thanks https://storybook.js.org/showcase/projects) and most of them put everything in src/components/ComponentName. Some of them put the component folders directly in src but I'm not sold on this (even if it means one less level).

hsablonniere commented 2 years ago

NOTE: If we move the tests from test to something inside src/**, we'll have to update our ESLint config.

hsablonniere commented 2 years ago

WARNING: I completely forgot about types.d.ts files, they must be moved and merged manually.

hsablonniere commented 2 years ago

I'm considering removing most of the "folders" in the Storybook and only keep:

pdesoyres-cc commented 2 years ago

I like the organization

├── stories
│   ├── fixtures
│   ├── lib
│   └── all-form-controls.js

I would prefer the assets used only by stories to be located inside the stories directory:

├── stories
│   ├── assets
│   ├── fixtures
│   ├── lib
│   └── all-form-controls.js

I would prefer having a components sub-directory:

├──src
│   ├── components
│   ├── stories
hsablonniere commented 2 years ago

I like the organization

:+1:

I would prefer the assets used only by stories to be located inside the stories directory:

I'm OK with both :+1:

I would prefer having a components sub-directory:

It's already like this :+1: