Skip to content

Commit

Permalink
refactor: restructure entry points (#2575)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The entry points for the `@sbb-esta/lyne-components` have changed from extension-less to including the extension (e.g. `@sbb-esta/lyne-components/button` to `@sbb-esta/lyne-components/button.js`).
  • Loading branch information
kyubisation committed Apr 11, 2024
1 parent 374d7b7 commit 3d4c8ab
Show file tree
Hide file tree
Showing 770 changed files with 1,885 additions and 1,960 deletions.
5 changes: 3 additions & 2 deletions CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ components which require basic button or link functionality have to extend the c
and they need to implement the `renderTemplate` method, which should return the component's inner content.

```ts
import { SbbButtonBaseElement } from '../../core/base-elements';
import { SbbButtonBaseElement } from '../../core/base-elements.js';
import { html } from 'lit';

@customElement('my-custom-button')
Expand Down Expand Up @@ -133,7 +133,8 @@ As the language can be changed dynamically, you have to listen to the `sbbLangua
event and re-render the view. This can be done by marking the field with `@state` and using the language change handler (see code below).

```ts
import { SbbLanguageController } from '../core/controllers';
import { SbbLanguageController } from '../core/controllers.js';

export class Component extends LitElement {
private _language = new SbbLanguageController(this);

Expand Down
17 changes: 17 additions & 0 deletions scripts/migrate-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync, unlinkSync, writeFileSync } from 'fs';
import { basename, dirname } from 'path';

import * as glob from 'glob';

const indexFiles = glob.sync('**/index.ts', {
cwd: dirname(import.meta.resolve('../src/components')),
absolute: true,
});
for (const indexFile of indexFiles) {
const content = readFileSync(indexFile, 'utf8').replaceAll(
/from '.([^']+)/g,
(_, m) => `from './${basename(dirname(indexFile))}${m.replace(/\/index.js$/, '.js')}`,
);
unlinkSync(indexFile);
writeFileSync(indexFile.replace(/\/index.ts$/, '.ts'), content, 'utf8');
}
1 change: 1 addition & 0 deletions src/components/accordion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './accordion/accordion.js';
8 changes: 4 additions & 4 deletions src/components/accordion/accordion.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { assert, expect } from '@open-wc/testing';
import { nothing } from 'lit';
import { html } from 'lit/static-html.js';

import { waitForCondition, waitForLitRender, EventSpy, isSsr } from '../core/testing/index.js';
import { fixture } from '../core/testing/private/index.js';
import { fixture } from '../core/testing/private.js';
import { waitForCondition, waitForLitRender, EventSpy, isSsr } from '../core/testing.js';
import {
SbbExpansionPanelElement,
type SbbExpansionPanelHeaderElement,
} from '../expansion-panel/index.js';
} from '../expansion-panel.js';

import { SbbAccordionElement } from './accordion.js';

Expand All @@ -33,7 +33,7 @@ describe(`sbb-accordion ${fixture.name}`, () => {
</sbb-expansion-panel>
</sbb-accordion>
`,
{ modules: ['./accordion.ts', '../expansion-panel/index.ts'] },
{ modules: ['./accordion.ts', '../expansion-panel.ts'] },
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/accordion/accordion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../core/testing/private/index.js';
import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js';

import type { SbbAccordionElement } from './accordion.js';
import './accordion.js';
import '../expansion-panel/index.js';
import '../expansion-panel.js';

describe(`sbb-accordion`, () => {
let element: SbbAccordionElement;
Expand Down
2 changes: 1 addition & 1 deletion src/components/accordion/accordion.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { repeat } from 'lit/directives/repeat.js';
import { styleMap } from 'lit/directives/style-map.js';

import { sbbSpread } from '../../storybook/helpers/spread.js';
import { SbbExpansionPanelElement } from '../expansion-panel/index.js';
import { SbbExpansionPanelElement } from '../expansion-panel.js';

import readme from './readme.md?raw';
import './accordion.js';
Expand Down
8 changes: 4 additions & 4 deletions src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import { SbbConnectedAbortController } from '../core/controllers/index.js';
import { SbbHydrationMixin } from '../core/mixins/index.js';
import { SbbExpansionPanelElement } from '../expansion-panel/index.js';
import type { SbbTitleLevel } from '../title/index.js';
import { SbbConnectedAbortController } from '../core/controllers.js';
import { SbbHydrationMixin } from '../core/mixins.js';
import { SbbExpansionPanelElement } from '../expansion-panel.js';
import type { SbbTitleLevel } from '../title.js';

import style from './accordion.scss?lit&inline';

Expand Down
1 change: 0 additions & 1 deletion src/components/accordion/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/components/action-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './action-group/action-group.js';
14 changes: 7 additions & 7 deletions src/components/action-group/action-group.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { assert, expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import type { SbbSecondaryButtonElement } from '../button/index.js';
import { waitForLitRender } from '../core/testing/index.js';
import { fixture } from '../core/testing/private/index.js';
import type { SbbBlockLinkElement } from '../link/index.js';
import type { SbbSecondaryButtonElement } from '../button.js';
import { fixture } from '../core/testing/private.js';
import { waitForLitRender } from '../core/testing.js';
import type { SbbBlockLinkElement } from '../link.js';

import { SbbActionGroupElement } from './action-group.js';

import '../button/secondary-button/index.js';
import '../link/block-link/index.js';
import '../button/secondary-button.js';
import '../link/block-link.js';

describe(`sbb-action-group with ${fixture.name}`, () => {
let element: SbbActionGroupElement;
Expand All @@ -28,7 +28,7 @@ describe(`sbb-action-group with ${fixture.name}`, () => {
</sbb-block-link>
</sbb-action-group>
`,
{ modules: ['./action-group.ts', '../button/index.ts', '../link/index.ts'] },
{ modules: ['./action-group.ts', '../button.ts', '../link.ts'] },
);
});

Expand Down
8 changes: 4 additions & 4 deletions src/components/action-group/action-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import type { SbbSecondaryButtonElement } from '../button/index.js';
import { fixture, testA11yTreeSnapshot } from '../core/testing/private/index.js';
import type { SbbSecondaryButtonElement } from '../button.js';
import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js';

import type { SbbActionGroupElement } from './action-group.js';
import './action-group.js';
import '../button/secondary-button/index.js';
import '../link/block-link/index.js';
import '../button/secondary-button.js';
import '../link/block-link.js';

describe(`sbb-action-group`, () => {
describe('renders', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/action-group/action-group.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { sbbSpread } from '../../storybook/helpers/spread.js';

import readme from './readme.md?raw';
import './action-group.js';
import '../button/index.js';
import '../link/block-link/index.js';
import '../button.js';
import '../link/block-link.js';

const secondaryButtonTemplate = (alignSelf?: string): TemplateResult => html`
<sbb-secondary-button align-self=${alignSelf || nothing}> Button 1 </sbb-secondary-button>
Expand Down
6 changes: 3 additions & 3 deletions src/components/action-group/action-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import type { SbbButtonCommonElement, SbbButtonSize } from '../button/index.js';
import type { SbbHorizontalFrom, SbbOrientation } from '../core/interfaces/index.js';
import type { SbbButtonCommonElement, SbbButtonSize } from '../button.js';
import type { SbbHorizontalFrom, SbbOrientation } from '../core/interfaces.js';
import type {
SbbBlockLinkButtonElement,
SbbBlockLinkElement,
SbbBlockLinkStaticElement,
SbbLinkSize,
} from '../link/index.js';
} from '../link.js';

import style from './action-group.scss?lit&inline';

Expand Down
1 change: 0 additions & 1 deletion src/components/action-group/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/components/alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './alert/alert.js';
export * from './alert/alert-group.js';
1 change: 1 addition & 0 deletions src/components/alert/alert-group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './alert-group/alert-group.js';
12 changes: 6 additions & 6 deletions src/components/alert/alert-group/alert-group.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import type { SbbTransparentButtonElement } from '../../button/index.js';
import { waitForCondition, EventSpy, waitForLitRender } from '../../core/testing/index.js';
import { fixture } from '../../core/testing/private/index.js';
import type { SbbAlertElement } from '../alert/index.js';
import type { SbbTransparentButtonElement } from '../../button.js';
import { fixture } from '../../core/testing/private.js';
import { waitForCondition, EventSpy, waitForLitRender } from '../../core/testing.js';
import type { SbbAlertElement } from '../alert.js';

import { SbbAlertGroupElement } from './alert-group.js';

import '../alert/index.js';
import '../alert.js';

describe(`sbb-alert-group with ${fixture.name}`, () => {
let element: SbbAlertGroupElement;
Expand All @@ -30,7 +30,7 @@ describe(`sbb-alert-group with ${fixture.name}`, () => {
<sbb-alert title-content="Interruption" href="www.sbb.ch">Second</sbb-alert>
</sbb-alert-group>
`,
{ modules: ['./alert-group.ts', '../alert/index.ts'] },
{ modules: ['./alert-group.ts', '../alert.ts'] },
);
const didDismissAlertSpy = new EventSpy(SbbAlertGroupElement.events.didDismissAlert);
const emptySpy = new EventSpy(SbbAlertGroupElement.events.empty);
Expand Down
4 changes: 2 additions & 2 deletions src/components/alert/alert-group/alert-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../../core/testing/private/index.js';
import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js';

import type { SbbAlertGroupElement } from './alert-group.js';
import './alert-group.js';
import '../alert/index.js';
import '../alert.js';

describe(`sbb-alert-group`, () => {
describe('should render', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/alert/alert-group/alert-group.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { sbbSpread } from '../../../storybook/helpers/spread.js';
import { SbbAlertGroupElement } from './alert-group.js';
import readme from './readme.md?raw';

import '../alert/index.js';
import '../alert.js';

const Template = (args: Args): TemplateResult => html`
<sbb-alert-group ${sbbSpread(args)}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/alert/alert-group/alert-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { LitElement, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { html, unsafeStatic } from 'lit/static-html.js';

import { SbbConnectedAbortController } from '../../core/controllers/index.js';
import { EventEmitter } from '../../core/eventing/index.js';
import type { SbbTitleLevel } from '../../title/index.js';
import { SbbAlertElement } from '../alert/index.js';
import { SbbConnectedAbortController } from '../../core/controllers.js';
import { EventEmitter } from '../../core/eventing.js';
import type { SbbTitleLevel } from '../../title.js';
import { SbbAlertElement } from '../alert.js';

import style from './alert-group.scss?lit&inline';

Expand Down
1 change: 0 additions & 1 deletion src/components/alert/alert-group/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/components/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './alert/alert.js';
4 changes: 2 additions & 2 deletions src/components/alert/alert/alert.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assert, expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { waitForCondition, EventSpy } from '../../core/testing/index.js';
import { fixture } from '../../core/testing/private/index.js';
import { fixture } from '../../core/testing/private.js';
import { waitForCondition, EventSpy } from '../../core/testing.js';

import { SbbAlertElement } from './alert.js';

Expand Down
2 changes: 1 addition & 1 deletion src/components/alert/alert/alert.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { fixture, testA11yTreeSnapshot } from '../../core/testing/private/index.js';
import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js';

import type { SbbAlertElement } from './alert.js';

Expand Down
22 changes: 11 additions & 11 deletions src/components/alert/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { type CSSResultGroup, html, LitElement, nothing, type TemplateResult } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import type { LinkTargetType } from '../../core/base-elements/index.js';
import { SbbLanguageController } from '../../core/controllers/index.js';
import { EventEmitter } from '../../core/eventing/index.js';
import { i18nCloseAlert, i18nFindOutMore } from '../../core/i18n/index.js';
import type { SbbOpenedClosedState } from '../../core/interfaces/index.js';
import { SbbIconNameMixin } from '../../icon/index.js';
import type { SbbTitleLevel } from '../../title/index.js';
import type { LinkTargetType } from '../../core/base-elements.js';
import { SbbLanguageController } from '../../core/controllers.js';
import { EventEmitter } from '../../core/eventing.js';
import { i18nCloseAlert, i18nFindOutMore } from '../../core/i18n.js';
import type { SbbOpenedClosedState } from '../../core/interfaces.js';
import { SbbIconNameMixin } from '../../icon.js';
import type { SbbTitleLevel } from '../../title.js';

import style from './alert.scss?lit&inline';

import '../../button/transparent-button/index.js';
import '../../divider/index.js';
import '../../link/index.js';
import '../../title/index.js';
import '../../button/transparent-button.js';
import '../../divider.js';
import '../../link.js';
import '../../title.js';

type SbbAlertState = Exclude<SbbOpenedClosedState, 'closing'>;

Expand Down
1 change: 0 additions & 1 deletion src/components/alert/alert/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/alert/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/components/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './autocomplete/autocomplete.js';
10 changes: 5 additions & 5 deletions src/components/autocomplete/autocomplete.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { assert, expect } from '@open-wc/testing';
import { sendKeys, sendMouse } from '@web/test-runner-commands';
import { html } from 'lit/static-html.js';

import { waitForCondition, waitForLitRender, EventSpy } from '../core/testing/index.js';
import { fixture } from '../core/testing/private/index.js';
import { SbbFormFieldElement } from '../form-field/index.js';
import { SbbOptionElement } from '../option/index.js';
import { fixture } from '../core/testing/private.js';
import { waitForCondition, waitForLitRender, EventSpy } from '../core/testing.js';
import { SbbFormFieldElement } from '../form-field.js';
import { SbbOptionElement } from '../option.js';

import { SbbAutocompleteElement } from './autocomplete.js';

Expand All @@ -25,7 +25,7 @@ describe(`sbb-autocomplete with ${fixture.name}`, () => {
</sbb-form-field>
<button>Use this for backdrop click</button>
`,
{ modules: ['../form-field/index.ts', './autocomplete.ts', '../option/index.ts'] },
{ modules: ['../form-field.ts', './autocomplete.ts', '../option.ts'] },
);
input = formField.querySelector<HTMLInputElement>('input')!;
element = formField.querySelector<SbbAutocompleteElement>('sbb-autocomplete')!;
Expand Down
12 changes: 6 additions & 6 deletions src/components/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';

import { isSafari } from '../core/dom/index.js';
import { describeIf } from '../core/testing/index.js';
import { fixture, testA11yTreeSnapshot } from '../core/testing/private/index.js';
import type { SbbFormFieldElement } from '../form-field/index.js';
import { isSafari } from '../core/dom.js';
import { fixture, testA11yTreeSnapshot } from '../core/testing/private.js';
import { describeIf } from '../core/testing.js';
import type { SbbFormFieldElement } from '../form-field.js';

import type { SbbAutocompleteElement } from './autocomplete.js';
import '../form-field/index.js';
import '../option/index.js';
import '../form-field.js';
import '../option.js';
import './autocomplete.js';

describe(`sbb-autocomplete`, () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/autocomplete/autocomplete.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { styleMap } from 'lit/directives/style-map.js';

import { waitForComponentsReady } from '../../storybook/testing/wait-for-components-ready.js';
import { waitForStablePosition } from '../../storybook/testing/wait-for-stable-position.js';
import type { SbbFormErrorElement } from '../form-error/index.js';
import { SbbOptionElement } from '../option/index.js';
import type { SbbFormErrorElement } from '../form-error.js';
import { SbbOptionElement } from '../option.js';

import { SbbAutocompleteElement } from './autocomplete.js';
import readme from './readme.md?raw';

import '../form-field/index.js';
import '../form-error/index.js';
import '../form-field.js';
import '../form-error.js';

const wrapperStyle = (context: StoryContext): Record<string, string> => ({
'background-color': context.args.negative ? 'var(--sbb-color-black)' : 'var(--sbb-color-white)',
Expand Down
Loading

0 comments on commit 3d4c8ab

Please sign in to comment.