-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: setup lit cohabitation (#4834)
First PR to scaffold the Lit migration, essentially #4787 without the atomic-text migration. Mainly: ## Web Dev Server Replace the Stencil web dev server with a framework-agnostic one. For now, it comes with degraded performance (it will need to be replaced/adapted when the transition is over) This comes with some hack removal in the Cypress tests. ## Autoloader Setup an auto-loader for future Lit Elements, heavily inspired by Shoelace ## Stencil Proxy Proxy some files generated by Stencil to 'plug-in' what's relative to Lit. # Bikeshedding - CSS: ought to setup CSS building for Lit - Decorators & utils setup still
- Loading branch information
1 parent
db77dd0
commit ed66ba0
Showing
89 changed files
with
3,166 additions
and
5,570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import cem from '@coveo/atomic/custom-elements-manifest' with {type: 'json'}; | ||
import { createWriteStream, readFileSync, writeFileSync } from 'fs'; | ||
|
||
const isLitDeclaration = (declaration) => declaration?.superclass?.name === 'LitElement'; | ||
|
||
const atomicAngularModuleFilePath ='projects/atomic-angular/src/lib/stencil-generated/atomic-angular.module.ts'; | ||
const atomicAngularModuleFileContent = readFileSync(atomicAngularModuleFilePath, 'utf-8'); | ||
const atomicAngularComponentFileStream = createWriteStream('projects/atomic-angular/src/lib/stencil-generated/components.ts', {flags: 'a'}); | ||
const litDeclarations = []; | ||
|
||
|
||
const declarationToProxyCmp = (declaration) => | ||
` | ||
@ProxyCmp({ | ||
inputs: [${declaration.attributes.map(attr => `'${attr.name}'`).join(', ')}] | ||
}) | ||
@Component({ | ||
selector: '${declaration.tagName}', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: '<ng-content></ng-content>', | ||
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property | ||
inputs: [${declaration.attributes.map(attr => `'${attr.name}'`).join(', ')}] | ||
}) | ||
export class ${declaration.name} { | ||
protected readonly el: HTMLElement; | ||
constructor(c: ChangeDetectorRef, el: ElementRef, protected z: NgZone) { | ||
c.detach(); | ||
this.el = el.nativeElement; | ||
} | ||
} | ||
export declare interface ${declaration.name} extends Lit${declaration.name} {} | ||
` | ||
|
||
const declarationToLitImport = (declaration) => `${declaration.name} as Lit${declaration.name}`; | ||
|
||
const litImports = [] | ||
|
||
for (const module of cem.modules) { | ||
for (const declaration of module.declarations) { | ||
if (isLitDeclaration(declaration)) { | ||
atomicAngularComponentFileStream.write(declarationToProxyCmp(declaration)); | ||
litImports.push(declarationToLitImport(declaration)); | ||
litDeclarations.push(`${declaration.name}`); | ||
} | ||
} | ||
} | ||
atomicAngularComponentFileStream.write(`\nimport type {${litImports.join(',')}} from '@coveo/atomic/components';`); | ||
atomicAngularComponentFileStream.end(); | ||
|
||
|
||
if(litDeclarations.length > 0) { | ||
writeFileSync( | ||
atomicAngularModuleFilePath, | ||
atomicAngularModuleFileContent | ||
.replace(/const DECLARATIONS = \[\n/m, `const DECLARATIONS = [\n${litDeclarations.join(',\n')},\n`) | ||
.replace(/^import \{$/m, `import {\n${litDeclarations.join(',\n')},`) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import cem from '@coveo/atomic/custom-elements-manifest' with {type: 'json'}; | ||
import {writeFileSync} from 'node:fs'; | ||
import * as prettier from 'prettier'; | ||
|
||
const isLitDeclaration = (declaration) => | ||
declaration?.superclass?.name === 'LitElement'; | ||
|
||
const entries = [ | ||
{ | ||
path: 'src/components/search/components.ts', | ||
content: '', | ||
excludedComponents: [ | ||
'atomic-result-template', | ||
'atomic-recs-result-template', | ||
'atomic-field-condition', | ||
], | ||
excludedComponentDirectories: ['src/components/commerce'], | ||
computedComponentImports: [], | ||
}, | ||
{ | ||
path: 'src/components/commerce/components.ts', | ||
content: '', | ||
excludedComponents: [ | ||
'atomic-product-template', | ||
'atomic-recs-result-template', | ||
'atomic-field-condition', | ||
], | ||
excludedComponentDirectories: [ | ||
'src/components/search', | ||
'src/components/recommendations', | ||
], | ||
computedComponentImports: [], | ||
}, | ||
]; | ||
|
||
const declarationToLitImport = (declaration) => | ||
`${declaration.name} as Lit${declaration.name}`; | ||
|
||
const declarationToComponent = (declaration) => | ||
` | ||
export const ${declaration.name} = createComponent({ | ||
tagName: '${declaration.tagName}', | ||
react: React, | ||
elementClass: Lit${declaration.name}, | ||
}); | ||
`; | ||
|
||
for (const module of cem.modules) { | ||
for (const declaration of module.declarations) { | ||
if (isLitDeclaration(declaration)) { | ||
for (const entry of entries) { | ||
if ( | ||
entry.excludedComponentDirectories.some((directory) => | ||
module.path.startsWith(directory) | ||
) || | ||
entry.excludedComponents.includes(declaration.tagName) | ||
) { | ||
continue; | ||
} | ||
entry.computedComponentImports.push( | ||
declarationToLitImport(declaration) | ||
); | ||
entry.content+=(declarationToComponent(declaration)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const entry of entries) { | ||
const prettierConfig = { | ||
...(await prettier.resolveConfig(entry.path)), | ||
parser: 'typescript' | ||
}; | ||
if(entry.computedComponentImports.length===0) { | ||
writeFileSync(entry.path, await prettier.format('export {}', prettierConfig)); | ||
continue; | ||
} | ||
writeFileSync( | ||
entry.path, | ||
await prettier.format( | ||
[ | ||
`import {createComponent} from '@lit/react';`, | ||
`import React from 'react';`, | ||
`import {${entry.computedComponentImports.join(',')}} from '@coveo/atomic/components';`, | ||
entry.content | ||
].join('\n'), | ||
prettierConfig | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export function getSvg(fileName: string) { | ||
const file = cy.readFile(`./www/build/assets/${fileName}.svg`); | ||
const file = cy.readFile(`./dist/atomic/assets/${fileName}.svg`); | ||
return file; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.